Fix formatting samplecnt_t (aka int64_t aka long long int)
[ardour.git] / gtk2_ardour / session_metadata_dialog.cc
index 90e978903cee303c786ad21b2dc80a37e35ca351..169efaaaef508caf428249a5451f3512e7ef9ff9 100644 (file)
@@ -1,27 +1,29 @@
 /*
-    Copyright (C) 2008 Paul Davis
-    Author: Sakari Bergen
-
-    This program is free software; you can redistribute it and/or modify it
-    under the terms of the GNU General Public License as published by the Free
-    Software Foundation; either version 2 of the License, or (at your option)
-    any later version.
-
-    This program is distributed in the hope that it will be useful, but WITHOUT
-    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-    for more details.
-
-    You should have received a copy of the GNU General Public License along
-    with this program; if not, write to the Free Software Foundation, Inc.,
-    675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "session_metadata_dialog.h"
+ * Copyright (C) 2008-2016 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
+ * Copyright (C) 2015-2016 Colin Fletcher <colin.m.fletcher@googlemail.com>
+ * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #include <sstream>
-
-#include <gtkmm2ext/utils.h>
+#include <gtkmm/filechooserdialog.h>
+#include <gtkmm/messagedialog.h>
+#include <gtkmm/stock.h>
 
 #include "pbd/xml++.h"
 #include "pbd/error.h"
 #include "ardour/session.h"
 #include "ardour/session_utils.h"
 
-#include "i18n.h"
+#include "gtkmm2ext/utils.h"
+
+#include "session_metadata_dialog.h"
+
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace Glib;
@@ -85,7 +91,7 @@ Gtk::Widget &
 TextMetadataField::name_widget ()
 {
        label = Gtk::manage (new Gtk::Label(_name + ':'));
-       label->set_alignment (1, 0.5);
+       label->set_alignment (1, 0);
        return *label;
 }
 
@@ -114,6 +120,44 @@ TextMetadataField::update_value ()
        _value = entry->get_text ();
 }
 
+/* LongTextMetadataField */
+
+LongTextMetadataField::LongTextMetadataField (Getter getter, Setter setter, string const & field_name, guint width ) :
+  TextMetadataField (getter, setter, field_name, width)
+{
+       tview = 0;
+       label = 0;
+       value_label = 0;
+}
+
+MetadataPtr
+LongTextMetadataField::copy ()
+{
+       return MetadataPtr (new TextMetadataField (getter, setter, _name, width));
+}
+
+Gtk::Widget &
+LongTextMetadataField::edit_widget ()
+{
+       tview = Gtk::manage (new Gtk::TextView());
+
+       tview->get_buffer()->set_text (_value);
+       tview->set_wrap_mode (Gtk::WRAP_WORD);
+       tview->set_size_request (-1, 400);
+       tview->set_editable (true);
+
+       Glib::RefPtr<Gtk::TextBuffer> tb (tview->get_buffer());
+       tb->signal_changed().connect (sigc::mem_fun(*this, &LongTextMetadataField::update_value));
+
+       return *tview;
+}
+
+void
+LongTextMetadataField::update_value ()
+{
+       _value = tview->get_buffer()->get_text ();
+}
+
 /* NumberMetadataField */
 
 NumberMetadataField::NumberMetadataField (Getter getter, Setter setter, string const & field_name, guint numbers, guint width) :
@@ -164,7 +208,7 @@ Gtk::Widget &
 NumberMetadataField::name_widget ()
 {
        label = Gtk::manage (new Gtk::Label(_name + ':'));
-       label->set_alignment (1, 0.5);
+       label->set_alignment (1, 0);
        return *label;
 }
 
@@ -270,15 +314,18 @@ EAN13MetadataField::update_status ()
                // calculate EAN-13 modulo 10 check digit
                int sum = 0;
                const char *p = _value.c_str();
-               for (int i =0; i < 12; i++) {
+               for (int i = 0; i < 12; i++) {
                        char c = p[i] - '0';
                        if (i % 2) {
-                               sum += c;
-                       } else {
                                sum += c * 3;
+                       } else {
+                               sum += c;
                        }
                }
                sum %= 10;
+               if (sum)
+                       sum = 10 - sum;
+
                if (sum == p[12] - '0') {
                        status_label->set_markup (string_compose(
                                                "<span color=\"green\">%1: %2</span>",
@@ -301,7 +348,7 @@ Gtk::Widget &
 EAN13MetadataField::name_widget ()
 {
        label = Gtk::manage (new Gtk::Label(_name + ':'));
-       label->set_alignment (1, 0.5);
+       label->set_alignment (1, 0);
        return *label;
 }
 
@@ -563,6 +610,7 @@ SessionMetadataDialog<DataSet>::init_data ( bool skip_user )
        init_album_data ();
        init_people_data ();
        init_school_data ();
+       init_description_data ();
 
        for (DataSetList::iterator it = data_list.begin(); it != data_list.end(); ++it) {
                (*it)->set_session (_session);
@@ -660,6 +708,20 @@ SessionMetadataDialog<DataSet>::init_user_data ()
 
 }
 
+template <typename DataSet>
+void
+SessionMetadataDialog<DataSet>::init_description_data ()
+{
+       DataSetPtr data_set (new DataSet (_("Description")));
+       data_list.push_back (data_set);
+
+       MetadataPtr ptr;
+
+       ptr = MetadataPtr (new LongTextMetadataField (&ARDOUR::SessionMetadata::description, &ARDOUR::SessionMetadata::set_description, _("Description")));
+       data_set->add_data_field (ptr);
+}
+
+
 template <typename DataSet>
 void
 SessionMetadataDialog<DataSet>::init_track_data ()
@@ -849,6 +911,7 @@ SessionMetadataImporter::run ()
        /* Open session file selector */
 
        Gtk::FileChooserDialog session_selector(_("Choose session to import metadata from"), Gtk::FILE_CHOOSER_ACTION_OPEN);
+       Gtkmm2ext::add_volume_shortcuts (session_selector);
        session_selector.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
        session_selector.add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
        session_selector.set_default_response(Gtk::RESPONSE_ACCEPT);
@@ -900,7 +963,7 @@ SessionMetadataImporter::run ()
                return;
        }
 
-       //create a temporary 
+       //create a temporary
        ARDOUR::SessionMetadata data;
        data.set_state (*node, version);
        init_data ( true );  //skip user data here