X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=gtk2_ardour%2Fsession_metadata_dialog.cc;h=67d04faa9e58d75ec5bfcaac80a614bd1b77a086;hb=237741d18722252abd4a6a20d3422315481ccffe;hp=be2e6fe0121b5fe34b8f1f8c1551ab1f3b7ce520;hpb=bb9cc45cd22af67ac275a5e73accbe14fee664d8;p=ardour.git diff --git a/gtk2_ardour/session_metadata_dialog.cc b/gtk2_ardour/session_metadata_dialog.cc index be2e6fe012..67d04faa9e 100644 --- a/gtk2_ardour/session_metadata_dialog.cc +++ b/gtk2_ardour/session_metadata_dialog.cc @@ -22,23 +22,24 @@ #include #include -#include #include "pbd/xml++.h" +#include "pbd/error.h" + #include "ardour/session.h" -#include "ardour/session_directory.h" #include "ardour/session_utils.h" #include "i18n.h" using namespace std; using namespace Glib; +using namespace PBD; #define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) /*** MetadataField ***/ -MetadataField::MetadataField (ustring const & field_name) : +MetadataField::MetadataField (string const & field_name) : _name (field_name) { } @@ -47,7 +48,7 @@ MetadataField::~MetadataField() { } /* TextMetadataField */ -TextMetadataField::TextMetadataField (Getter getter, Setter setter, ustring const & field_name, guint width ) : +TextMetadataField::TextMetadataField (Getter getter, Setter setter, string const & field_name, guint width ) : MetadataField (field_name), getter (getter), setter (setter), @@ -82,7 +83,8 @@ TextMetadataField::load_data (ARDOUR::SessionMetadata const & data) Gtk::Widget & TextMetadataField::name_widget () { - label = Gtk::manage (new Gtk::Label(_name + ':', Gtk::ALIGN_LEFT)); + label = Gtk::manage (new Gtk::Label(_name + ':')); + label->set_alignment (1, 0.5); return *label; } @@ -113,7 +115,7 @@ TextMetadataField::update_value () /* NumberMetadataField */ -NumberMetadataField::NumberMetadataField (Getter getter, Setter setter, ustring const & field_name, guint numbers, guint width) : +NumberMetadataField::NumberMetadataField (Getter getter, Setter setter, string const & field_name, guint numbers, guint width) : MetadataField (field_name), getter (getter), setter (setter), @@ -160,7 +162,8 @@ NumberMetadataField::update_value () Gtk::Widget & NumberMetadataField::name_widget () { - label = Gtk::manage (new Gtk::Label(_name + ':', Gtk::ALIGN_LEFT)); + label = Gtk::manage (new Gtk::Label(_name + ':')); + label->set_alignment (1, 0.5); return *label; } @@ -184,7 +187,7 @@ NumberMetadataField::edit_widget () return *entry; } -ustring +string NumberMetadataField::uint_to_str (uint32_t i) const { std::ostringstream oss (""); @@ -197,11 +200,11 @@ NumberMetadataField::uint_to_str (uint32_t i) const } uint32_t -NumberMetadataField::str_to_uint (ustring const & str) const +NumberMetadataField::str_to_uint (string const & str) const { - ustring tmp (str); - ustring::size_type i; - while ((i = tmp.find_first_not_of("1234567890")) != ustring::npos) { + string tmp (str); + string::size_type i; + while ((i = tmp.find_first_not_of("1234567890")) != string::npos) { tmp.erase (i, 1); } @@ -214,10 +217,9 @@ NumberMetadataField::str_to_uint (ustring const & str) const /* SessionMetadataSet */ -SessionMetadataSet::SessionMetadataSet (ustring const & name) : - name (name) +SessionMetadataSet::SessionMetadataSet (string const & name) + : name (name) { - session = 0; } void @@ -228,11 +230,12 @@ SessionMetadataSet::add_data_field (MetadataPtr field) /* SessionMetadataSetEditable */ -SessionMetadataSetEditable::SessionMetadataSetEditable (ustring const & name) : - SessionMetadataSet (name) +SessionMetadataSetEditable::SessionMetadataSetEditable (string const & name) + : SessionMetadataSet (name) { table.set_row_spacings (6); table.set_col_spacings (12); + table.set_homogeneous (false); vbox.pack_start (table, false, false); vbox.set_spacing (6); vbox.set_border_width (6); @@ -248,9 +251,13 @@ SessionMetadataSetEditable::get_tab_widget () void SessionMetadataSetEditable::set_session (ARDOUR::Session * s) { - session = s; + SessionHandlePtr::set_session (s); - ARDOUR::SessionMetadata const & data = session->metadata(); + if (!_session) { + return; + } + + ARDOUR::SessionMetadata const & data = *(ARDOUR::SessionMetadata::Metadata()); table.resize (list.size(), 2); uint32_t row = 0; @@ -258,7 +265,7 @@ SessionMetadataSetEditable::set_session (ARDOUR::Session * s) for (DataList::const_iterator it = list.begin(); it != list.end(); ++it) { field = *it; field->load_data (data); - table.attach (field->name_widget(), 0, 1, row, row + 1); + table.attach (field->name_widget(), 0, 1, row, row + 1, Gtk::FILL); table.attach (field->edit_widget(), 1, 2, row, row + 1); ++row; } @@ -267,7 +274,7 @@ SessionMetadataSetEditable::set_session (ARDOUR::Session * s) void SessionMetadataSetEditable::save_data () { - ARDOUR::SessionMetadata & data = session->metadata(); + ARDOUR::SessionMetadata & data = *(ARDOUR::SessionMetadata::Metadata()); for (DataList::const_iterator it = list.begin(); it != list.end(); ++it) { (*it)->save_data(data); } @@ -275,9 +282,9 @@ SessionMetadataSetEditable::save_data () /* SessionMetadataSetImportable */ -SessionMetadataSetImportable::SessionMetadataSetImportable (ustring const & name) : - SessionMetadataSet (name), - session_list (list) +SessionMetadataSetImportable::SessionMetadataSetImportable (string const & name) + : SessionMetadataSet (name) + , session_list (list) { tree = Gtk::ListStore::create (tree_cols); tree_view.set_model (tree); @@ -301,8 +308,6 @@ SessionMetadataSetImportable::SessionMetadataSetImportable (ustring const & name tree_view.append_column (*viewcol); select_all_check.signal_toggled().connect (sigc::mem_fun(*this, &SessionMetadataSetImportable::select_all)); - - session = 0; } Gtk::Widget & @@ -322,12 +327,12 @@ SessionMetadataSetImportable::get_select_all_widget () void SessionMetadataSetImportable::load_extra_data (ARDOUR::SessionMetadata const & data) { - if (!session) { - std::cerr << "Programming error: no session set for SessionMetaDataSetImportable (in load_data)!" << std::endl; + if (!_session) { + error << string_compose (_("programming error: %1"), "no session set for SessionMetaDataSetImportable (in load_data)!") << endmsg; return; } - ARDOUR::SessionMetadata & session_data = session->metadata(); + ARDOUR::SessionMetadata const & session_data = *(ARDOUR::SessionMetadata::Metadata()); MetadataPtr session_field; MetadataPtr import_field; @@ -351,8 +356,8 @@ SessionMetadataSetImportable::load_extra_data (ARDOUR::SessionMetadata const & d import_field->load_data(data); // hasn't been done yet // Make string for values TODO get color from somewhere? - ustring values = "" + session_field->value() + "\n" - + "" + import_field->value() + ""; + string values = "" + session_field->value() + "\n" + + "" + import_field->value() + ""; Gtk::TreeModel::iterator row_iter = tree->append(); Gtk::TreeModel::Row row = *row_iter; @@ -370,12 +375,12 @@ SessionMetadataSetImportable::load_extra_data (ARDOUR::SessionMetadata const & d void SessionMetadataSetImportable::save_data () { - if (!session) { - std::cerr << "Programming error: no session set for SessionMetaDataSetImportable (in import_data)!" << std::endl; + if (!_session) { + error << string_compose (_("programming error: %1"), "no session set for SessionMetaDataSetImportable (in import_data)!") << endmsg; return; } - ARDOUR::SessionMetadata & session_data = session->metadata(); + ARDOUR::SessionMetadata & session_data = *(ARDOUR::SessionMetadata::Metadata()); Gtk::TreeModel::Children fields = tree->children(); Gtk::TreeModel::Children::iterator it; @@ -401,7 +406,7 @@ SessionMetadataSetImportable::select_all () } void -SessionMetadataSetImportable::selection_changed (ustring const & path) +SessionMetadataSetImportable::selection_changed (string const & path) { select_all_check.set_inconsistent (true); @@ -413,30 +418,33 @@ SessionMetadataSetImportable::selection_changed (ustring const & path) /* SessionMetadataDialog */ template -SessionMetadataDialog::SessionMetadataDialog (ustring const & name) : +SessionMetadataDialog::SessionMetadataDialog (string const & name) : ArdourDialog (name, true) { cancel_button = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - cancel_button->signal_clicked().connect (mem_fun(*this, &SessionMetadataDialog::end_dialog)); - save_button = add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); - save_button->signal_clicked().connect (mem_fun(*this, &SessionMetadataDialog::save_and_close)); + cancel_button->signal_clicked().connect (sigc::mem_fun(*this, &SessionMetadataDialog::end_dialog)); + save_button = add_button (Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); + save_button->signal_clicked().connect (sigc::mem_fun(*this, &SessionMetadataDialog::save_and_close)); } template void -SessionMetadataDialog::init_data () +SessionMetadataDialog::init_data ( bool skip_user ) { - if (!session) { - std::cerr << "Programming error: no session set for SessionMetaDataDialog (in init_data)!" << std::endl; + if (!_session) { + error << string_compose (_("programming error: %1"), "no session set for SessionMetaDataDialog (in init_data)!") << endmsg; return; } + if (!skip_user) + init_user_data (); init_track_data (); init_album_data (); init_people_data (); + init_school_data (); for (DataSetList::iterator it = data_list.begin(); it != data_list.end(); ++it) { - (*it)->set_session (session); + (*it)->set_session (_session); notebook.append_page ((*it)->get_widget(), (*it)->get_tab_widget()); } @@ -465,6 +473,7 @@ void SessionMetadataDialog::save_and_close () { save_data (); + _session->set_dirty(); end_dialog (); } @@ -477,7 +486,7 @@ SessionMetadataDialog::end_dialog () template void -SessionMetadataDialog::warn_user (ustring const & string) +SessionMetadataDialog::warn_user (string const & string) { Gtk::MessageDialog msg (string, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true); msg.run(); @@ -504,6 +513,32 @@ SessionMetadataDialog::add_widget (Gtk::Widget & widget) get_vbox()->pack_start (widget, true, true, 0); } +template +void +SessionMetadataDialog::init_user_data () +{ + DataSetPtr data_set (new DataSet (_("User"))); + data_list.push_back (data_set); + + MetadataPtr ptr; + + ptr = MetadataPtr (new TextMetadataField (&ARDOUR::SessionMetadata::user_name, &ARDOUR::SessionMetadata::set_user_name, _("Name"))); + data_set->add_data_field (ptr); + + ptr = MetadataPtr (new TextMetadataField (&ARDOUR::SessionMetadata::user_email, &ARDOUR::SessionMetadata::set_user_email, _("Email"))); + data_set->add_data_field (ptr); + + ptr = MetadataPtr (new TextMetadataField (&ARDOUR::SessionMetadata::user_web, &ARDOUR::SessionMetadata::set_user_web, _("Web"))); + data_set->add_data_field (ptr); + + ptr = MetadataPtr (new TextMetadataField (&ARDOUR::SessionMetadata::organization, &ARDOUR::SessionMetadata::set_organization, _("Organization"))); + data_set->add_data_field (ptr); + + ptr = MetadataPtr (new TextMetadataField (&ARDOUR::SessionMetadata::country, &ARDOUR::SessionMetadata::set_country, _("Country"))); + data_set->add_data_field (ptr); + +} + template void SessionMetadataDialog::init_track_data () @@ -608,14 +643,31 @@ SessionMetadataDialog::init_people_data () ptr = MetadataPtr (new TextMetadataField (&ARDOUR::SessionMetadata::dj_mixer, &ARDOUR::SessionMetadata::set_dj_mixer, _("DJ Mixer"))); data_set->add_data_field (ptr); - ptr = MetadataPtr (new TextMetadataField (&ARDOUR::SessionMetadata::mixer, &ARDOUR::SessionMetadata::set_mixer, _("Mixer"))); + ptr = MetadataPtr (new TextMetadataField (&ARDOUR::SessionMetadata::mixer, &ARDOUR::SessionMetadata::set_mixer, S_("Metadata|Mixer"))); + data_set->add_data_field (ptr); +} + +template +void +SessionMetadataDialog::init_school_data () +{ + DataSetPtr data_set (new DataSet (_("School"))); + data_list.push_back (data_set); + + MetadataPtr ptr; + + ptr = MetadataPtr (new TextMetadataField (&ARDOUR::SessionMetadata::instructor, &ARDOUR::SessionMetadata::set_instructor, _("Instructor"))); + data_set->add_data_field (ptr); + + ptr = MetadataPtr (new TextMetadataField (&ARDOUR::SessionMetadata::course, &ARDOUR::SessionMetadata::set_course, _("Course"))); data_set->add_data_field (ptr); + } /* SessionMetadataEditor */ SessionMetadataEditor::SessionMetadataEditor () : - SessionMetadataDialog (_("Edit session metadata")) + SessionMetadataDialog (_("Edit Session Metadata")) { } @@ -660,8 +712,8 @@ SessionMetadataImporter::~SessionMetadataImporter () void SessionMetadataImporter::run () { - if (!session) { - std::cerr << "Programming error: no session set for SessionMetaDataImporter (in run)!" << std::endl; + if (!_session) { + error << string_compose (_("programming error: %1"), "no session set for SessionMetaDataImporter (in run)!") << endmsg; return; } @@ -674,7 +726,7 @@ SessionMetadataImporter::run () Gtk::FileFilter session_filter; session_filter.add_pattern ("*.ardour"); - session_filter.set_name (_("Ardour sessions")); + session_filter.set_name (string_compose (_("%1 sessions"), PROGRAM_NAME)); session_selector.add_filter (session_filter); session_selector.set_filter (session_filter); @@ -705,10 +757,13 @@ SessionMetadataImporter::run () string filename = Glib::build_filename (path, name + ".ardour"); XMLTree session_tree; if (!session_tree.read (filename)) { - warn_user (_("A proper ardour session file was not selected!")); + warn_user (_("This session file could not be read!")); return; } + /* XXX GET VERSION FROM TREE */ + int version = 3000; + XMLNode * node = session_tree.root()->child ("Metadata"); if (!node) { @@ -716,10 +771,10 @@ SessionMetadataImporter::run () return; } + //create a temporary ARDOUR::SessionMetadata data; - data.set_state (*node); - - init_data (); + data.set_state (*node, version); + init_data ( true ); //skip user data here load_extra_data (data); init_gui();