2 Copyright (C) 2008 Paul Davis
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2 of the License, or (at your option)
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __session_metadata_dialog_h__
21 #define __session_metadata_dialog_h__
23 #include "ardour_dialog.h"
26 #include <boost/shared_ptr.hpp>
31 #include "ardour/session_metadata.h"
34 typedef boost::shared_ptr<MetadataField> MetadataPtr;
36 /// Wraps a metadata field to be used in a GUI
39 MetadataField (Glib::ustring const & field_name);
40 virtual ~MetadataField();
41 virtual MetadataPtr copy () = 0;
43 virtual void save_data (ARDOUR::SessionMetadata & data) const = 0;
44 virtual void load_data (ARDOUR::SessionMetadata const & data) = 0;
46 virtual Glib::ustring name() { return _name; }
47 virtual Glib::ustring value() { return _value; }
49 /// Get widget containing name of field
50 virtual Gtk::Widget & name_widget () = 0;
51 /// Get label containing value of field
52 virtual Gtk::Widget & value_widget () = 0;
53 /// Get widget for editing value
54 virtual Gtk::Widget & edit_widget () = 0;
60 /// MetadataField that contains text
61 class TextMetadataField : public MetadataField {
63 typedef Glib::ustring (ARDOUR::SessionMetadata::*Getter) () const;
64 typedef void (ARDOUR::SessionMetadata::*Setter) (Glib::ustring const &);
66 TextMetadataField (Getter getter, Setter setter, Glib::ustring const & field_name, guint width = 50);
69 void save_data (ARDOUR::SessionMetadata & data) const;
70 void load_data (ARDOUR::SessionMetadata const & data);
72 Gtk::Widget & name_widget ();
73 Gtk::Widget & value_widget ();
74 Gtk::Widget & edit_widget ();
82 Gtk::Label* value_label;
88 /// MetadataField that accepts only numbers
89 class NumberMetadataField : public MetadataField {
91 typedef uint32_t (ARDOUR::SessionMetadata::*Getter) () const;
92 typedef void (ARDOUR::SessionMetadata::*Setter) (uint32_t);
94 NumberMetadataField (Getter getter, Setter setter, Glib::ustring const & field_name, guint numbers, guint width = 50);
97 void save_data (ARDOUR::SessionMetadata & data) const;
98 void load_data (ARDOUR::SessionMetadata const & data);
100 Gtk::Widget & name_widget ();
101 Gtk::Widget & value_widget ();
102 Gtk::Widget & edit_widget ();
104 void update_value ();
105 Glib::ustring uint_to_str (uint32_t i) const;
106 uint32_t str_to_uint (Glib::ustring const & str) const;
112 Gtk::Label* value_label;
119 /// Interface for MetadataFields
120 class SessionMetadataSet {
122 SessionMetadataSet (Glib::ustring const & name);
123 virtual ~SessionMetadataSet () {};
125 void add_data_field (MetadataPtr field);
127 /// Sets session, into which the data is eventually saved
128 virtual void set_session (ARDOUR::Session * s) { session = s; }
129 /// allows loading extra data into data sets (for importing etc.)
130 virtual void load_extra_data (ARDOUR::SessionMetadata const & /*data*/) { }
131 /// Saves data to session
132 virtual void save_data () = 0;
134 virtual Gtk::Widget & get_widget () = 0;
135 virtual Gtk::Widget & get_tab_widget () = 0;
138 typedef std::list<MetadataPtr> DataList;
141 ARDOUR::Session *session;
144 /// Contains MetadataFields for editing
145 class SessionMetadataSetEditable : public SessionMetadataSet {
147 SessionMetadataSetEditable (Glib::ustring const & name);
149 Gtk::Widget & get_widget () { return vbox; }
150 Gtk::Widget & get_tab_widget ();
152 /// Sets session and loads data
153 void set_session (ARDOUR::Session * s);
154 /// Saves from MetadataFields into data
160 Gtk::Label tab_widget;
163 /// Contains MetadataFields for importing
164 class SessionMetadataSetImportable : public SessionMetadataSet {
166 SessionMetadataSetImportable (Glib::ustring const & name);
168 Gtk::Widget & get_widget () { return tree_view; }
169 Gtk::Widget & get_tab_widget ();
170 Gtk::Widget & get_select_all_widget ();
172 /// Loads importable data from data
173 void load_extra_data (ARDOUR::SessionMetadata const & data);
174 /// Saves from importable data (see load_data) to session_data
178 DataList & session_list; // References MetadataSet::list
179 DataList import_list;
181 struct Columns : public Gtk::TreeModel::ColumnRecord
184 Gtk::TreeModelColumn<Glib::ustring> field;
185 Gtk::TreeModelColumn<Glib::ustring> values;
186 Gtk::TreeModelColumn<bool> import;
187 Gtk::TreeModelColumn<MetadataPtr> data;
189 Columns() { add (field); add (values); add (import); add (data); }
192 Glib::RefPtr<Gtk::ListStore> tree;
194 Gtk::TreeView tree_view;
196 Gtk::Label tab_widget;
197 Gtk::CheckButton select_all_check;
200 void selection_changed (Glib::ustring const & path);
203 /// Metadata dialog interface
205 * The DataSets are initalized in this class so that all
206 * Dialogs have the same sets of data in the same order.
208 template <typename DataSet>
209 class SessionMetadataDialog : public ArdourDialog
212 SessionMetadataDialog (Glib::ustring const & name);
216 void load_extra_data (ARDOUR::SessionMetadata const & data);
219 virtual void init_gui () = 0;
220 virtual void save_and_close ();
221 virtual void end_dialog ();
223 void warn_user (Glib::ustring const & string);
225 typedef std::list<Gtk::Widget *> WidgetList;
226 typedef boost::shared_ptr<WidgetList> WidgetListPtr;
227 typedef Gtk::Widget & (DataSet::*WidgetFunc) ();
229 /// Returns list of widgets gathered by calling f for each data set
230 WidgetListPtr get_custom_widgets (WidgetFunc f);
232 /// Adds a widget to the table (vertical stacking) with automatic spacing
233 void add_widget (Gtk::Widget & widget);
235 Gtk::Notebook notebook;
238 void init_track_data ();
239 void init_album_data ();
240 void init_people_data ();
242 typedef boost::shared_ptr<SessionMetadataSet> DataSetPtr;
243 typedef std::list<DataSetPtr> DataSetList;
244 DataSetList data_list;
246 Gtk::Button * save_button;
247 Gtk::Button * cancel_button;
250 class SessionMetadataEditor : public SessionMetadataDialog<SessionMetadataSetEditable> {
252 SessionMetadataEditor ();
253 ~SessionMetadataEditor ();
259 class SessionMetadataImporter : public SessionMetadataDialog<SessionMetadataSetImportable> {
261 SessionMetadataImporter ();
262 ~SessionMetadataImporter ();
268 // Select all from -widget
269 Gtk::HBox selection_hbox;
270 Gtk::Label selection_label;