Do not try to restore Route solo state after clearing all solo state
[ardour.git] / gtk2_ardour / session_metadata_dialog.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
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)
8     any later version.
9
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
13     for more details.
14
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.
18 */
19
20 #ifndef __session_metadata_dialog_h__
21 #define __session_metadata_dialog_h__
22
23 #include "ardour_dialog.h"
24
25 #ifdef interface
26 #undef interface
27 #endif
28
29 #include <gtkmm.h>
30 #include <boost/shared_ptr.hpp>
31
32 #include <string>
33 #include <list>
34
35 #include "ardour/session_metadata.h"
36
37 class MetadataField;
38 typedef boost::shared_ptr<MetadataField> MetadataPtr;
39
40 /// Wraps a metadata field to be used in a GUI
41 class MetadataField {
42   public:
43         MetadataField (std::string const & field_name);
44         virtual ~MetadataField();
45         virtual MetadataPtr copy () = 0;
46
47         virtual void save_data (ARDOUR::SessionMetadata & data) const = 0;
48         virtual void load_data (ARDOUR::SessionMetadata const & data) = 0;
49
50         virtual std::string name() { return _name; }
51         virtual std::string value() { return _value; }
52
53         /// Get widget containing name of field
54         virtual Gtk::Widget & name_widget () = 0;
55         /// Get label containing value of field
56         virtual Gtk::Widget & value_widget () = 0;
57         /// Get widget for editing value
58         virtual Gtk::Widget & edit_widget () = 0;
59   protected:
60         std::string _name;
61         std::string _value;
62 };
63
64 /// MetadataField that contains text
65 class TextMetadataField : public MetadataField {
66   private:
67         typedef std::string (ARDOUR::SessionMetadata::*Getter) () const;
68         typedef void (ARDOUR::SessionMetadata::*Setter) (std::string const &);
69   public:
70         TextMetadataField (Getter getter, Setter setter, std::string const & field_name, guint width = 50);
71         MetadataPtr copy ();
72
73         void save_data (ARDOUR::SessionMetadata & data) const;
74         void load_data (ARDOUR::SessionMetadata const & data);
75
76         Gtk::Widget & name_widget ();
77         Gtk::Widget & value_widget ();
78         Gtk::Widget & edit_widget ();
79   private:
80         void update_value ();
81
82         Getter getter;
83         Setter setter;
84
85         Gtk::Label* label;
86         Gtk::Label* value_label;
87         Gtk::Entry* entry;
88
89         guint width;
90 };
91
92 /// MetadataField that accepts only numbers
93 class NumberMetadataField : public MetadataField {
94   private:
95         typedef uint32_t (ARDOUR::SessionMetadata::*Getter) () const;
96         typedef void (ARDOUR::SessionMetadata::*Setter) (uint32_t);
97   public:
98         NumberMetadataField (Getter getter, Setter setter, std::string const & field_name, guint numbers, guint width = 50);
99         MetadataPtr copy ();
100
101         void save_data (ARDOUR::SessionMetadata & data) const;
102         void load_data (ARDOUR::SessionMetadata const & data);
103
104         Gtk::Widget & name_widget ();
105         Gtk::Widget & value_widget ();
106         Gtk::Widget & edit_widget ();
107   private:
108         void update_value ();
109         std::string uint_to_str (uint32_t i) const;
110         uint32_t str_to_uint (std::string const & str) const;
111
112         Getter getter;
113         Setter setter;
114
115         Gtk::Label* label;
116         Gtk::Label* value_label;
117         Gtk::Entry* entry;
118
119         guint numbers;
120         guint width;
121 };
122
123 /// MetadataField that accepts EAN-13 data only
124 class EAN13MetadataField : public MetadataField {
125   private:
126         typedef std::string (ARDOUR::SessionMetadata::*Getter) () const;
127         typedef void (ARDOUR::SessionMetadata::*Setter) (std::string const &);
128   public:
129         EAN13MetadataField (Getter getter, Setter setter, std::string const & field_name, guint width = 13);
130         MetadataPtr copy ();
131
132         void save_data (ARDOUR::SessionMetadata & data) const;
133         void load_data (ARDOUR::SessionMetadata const & data);
134
135         Gtk::Widget & name_widget ();
136         Gtk::Widget & value_widget ();
137         Gtk::Widget & edit_widget ();
138
139         Gtk::Label* status_label;
140         void update_status ();
141   private:
142         void update_value ();
143         std::string numeric_string (std::string const & str) const;
144
145         Getter getter;
146         Setter setter;
147
148         Gtk::Label* label;
149         Gtk::Label* value_label;
150         Gtk::Entry* entry;
151
152         guint width;
153 };
154
155 /// Interface for MetadataFields
156 class SessionMetadataSet : public ARDOUR::SessionHandlePtr {
157   public:
158         SessionMetadataSet (std::string const & name);
159         virtual ~SessionMetadataSet () {};
160
161         void add_data_field (MetadataPtr field);
162
163         /// allows loading extra data into data sets (for importing etc.)
164         virtual void load_extra_data (ARDOUR::SessionMetadata const & /*data*/) { }
165         /// Saves data to session
166         virtual void save_data () = 0;
167
168         virtual Gtk::Widget & get_widget () = 0;
169         virtual Gtk::Widget & get_tab_widget () = 0;
170
171   protected:
172         typedef std::list<MetadataPtr> DataList;
173         DataList list;
174         std::string name;
175 };
176
177 /// Contains MetadataFields for editing
178 class SessionMetadataSetEditable : public SessionMetadataSet {
179   public:
180         SessionMetadataSetEditable (std::string const & name);
181
182         Gtk::Widget & get_widget () { return vbox; }
183         Gtk::Widget & get_tab_widget ();
184
185         /// Sets session and loads data
186         void set_session (ARDOUR::Session * s);
187         /// Saves from MetadataFields into data
188         void save_data ();
189
190   private:
191         Gtk::VBox vbox;
192         Gtk::Table table;
193         Gtk::Label tab_widget;
194 };
195
196 /// Contains MetadataFields for importing
197 class SessionMetadataSetImportable : public SessionMetadataSet {
198   public:
199         SessionMetadataSetImportable (std::string const & name);
200
201         Gtk::Widget & get_widget () { return tree_view; }
202         Gtk::Widget & get_tab_widget ();
203         Gtk::Widget & get_select_all_widget ();
204
205         /// Loads importable data from data
206         void load_extra_data (ARDOUR::SessionMetadata const & data);
207         /// Saves from importable data (see load_data) to session_data
208         void save_data ();
209
210   private:
211         DataList & session_list; // References MetadataSet::list
212         DataList import_list;
213
214         struct Columns : public Gtk::TreeModel::ColumnRecord
215         {
216           public:
217                 Gtk::TreeModelColumn<std::string>     field;
218                 Gtk::TreeModelColumn<std::string>     values;
219                 Gtk::TreeModelColumn<bool>        import;
220                 Gtk::TreeModelColumn<MetadataPtr> data;
221
222                 Columns() { add (field); add (values); add (import); add (data); }
223         };
224
225         Glib::RefPtr<Gtk::ListStore>  tree;
226         Columns                       tree_cols;
227         Gtk::TreeView                 tree_view;
228
229         Gtk::Label                    tab_widget;
230         Gtk::CheckButton              select_all_check;
231
232         void select_all ();
233         void selection_changed (std::string const & path);
234 };
235
236 /// Metadata dialog interface
237 /**
238  * The DataSets are initalized in this class so that all
239  * Dialogs have the same sets of data in the same order.
240  */
241 template <typename DataSet>
242 class SessionMetadataDialog : public ArdourDialog
243 {
244   public:
245         SessionMetadataDialog (std::string const & name);
246
247   protected:
248         void init_data ( bool skip_user = false );
249         void load_extra_data (ARDOUR::SessionMetadata const & data);
250         void save_data ();
251
252         virtual void init_gui () = 0;
253         virtual void save_and_close ();
254         virtual void end_dialog ();
255
256         void warn_user (std::string const & string);
257
258         typedef std::list<Gtk::Widget *> WidgetList;
259         typedef boost::shared_ptr<WidgetList> WidgetListPtr;
260         typedef Gtk::Widget & (DataSet::*WidgetFunc) ();
261
262         /// Returns list of widgets gathered by calling f for each data set
263         WidgetListPtr get_custom_widgets (WidgetFunc f);
264
265         /// Adds a widget to the table (vertical stacking) with automatic spacing
266         void add_widget (Gtk::Widget & widget);
267
268         Gtk::Notebook     notebook;
269
270   private:
271         void init_user_data ();
272         void init_track_data ();
273         void init_album_data ();
274         void init_people_data ();
275         void init_school_data ();
276
277         typedef boost::shared_ptr<SessionMetadataSet> DataSetPtr;
278         typedef std::list<DataSetPtr> DataSetList;
279         DataSetList data_list;
280
281         Gtk::Button *     save_button;
282         Gtk::Button *     cancel_button;
283 };
284
285 class SessionMetadataEditor : public SessionMetadataDialog<SessionMetadataSetEditable> {
286   public:
287         SessionMetadataEditor ();
288         ~SessionMetadataEditor ();
289         void run ();
290   private:
291         void init_gui ();
292 };
293
294 class SessionMetadataImporter : public SessionMetadataDialog<SessionMetadataSetImportable> {
295   public:
296         SessionMetadataImporter ();
297         ~SessionMetadataImporter ();
298         void run ();
299
300   private:
301         void init_gui ();
302
303         // Select all from -widget
304         Gtk::HBox    selection_hbox;
305         Gtk::Label   selection_label;
306
307 };
308
309 #endif