Various tweaks to the port matrix: open to full size; remove buttons and move their...
[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 #include <gtkmm.h>
26 #include <boost/shared_ptr.hpp>
27
28 #include <string>
29 #include <list>
30
31 #include "ardour/session_metadata.h"
32
33 class MetadataField;
34 typedef boost::shared_ptr<MetadataField> MetadataPtr; 
35
36 /// Wraps a metadata field to be used in a GUI
37 class MetadataField {
38   public:
39         MetadataField (Glib::ustring const & field_name);
40         virtual ~MetadataField();
41         virtual MetadataPtr copy () = 0;
42         
43         virtual void save_data (ARDOUR::SessionMetadata & data) const = 0;
44         virtual void load_data (ARDOUR::SessionMetadata const & data) = 0;
45         
46         virtual Glib::ustring name() { return _name; }
47         virtual Glib::ustring value() { return _value; }
48         
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;
55   protected:
56         Glib::ustring _name;
57         Glib::ustring _value;
58 };
59
60 /// MetadataField that contains text
61 class TextMetadataField : public MetadataField {
62   private:
63         typedef Glib::ustring (ARDOUR::SessionMetadata::*Getter) () const;
64         typedef void (ARDOUR::SessionMetadata::*Setter) (Glib::ustring const &);
65   public:
66         TextMetadataField (Getter getter, Setter setter, Glib::ustring const & field_name, guint width = 50);
67         MetadataPtr copy ();
68         
69         void save_data (ARDOUR::SessionMetadata & data) const;
70         void load_data (ARDOUR::SessionMetadata const & data);
71         
72         Gtk::Widget & name_widget ();
73         Gtk::Widget & value_widget ();
74         Gtk::Widget & edit_widget ();
75   private:
76         void update_value ();
77         
78         Getter getter;
79         Setter setter;
80         
81         Gtk::Label* label;
82         Gtk::Label* value_label;
83         Gtk::Entry* entry;
84         
85         uint width;
86 };
87
88 /// MetadataField that accepts only numbers
89 class NumberMetadataField : public MetadataField {
90   private:
91         typedef uint32_t (ARDOUR::SessionMetadata::*Getter) () const;
92         typedef void (ARDOUR::SessionMetadata::*Setter) (uint32_t);
93   public:
94         NumberMetadataField (Getter getter, Setter setter, Glib::ustring const & field_name, guint numbers, guint width = 50);
95         MetadataPtr copy ();
96         
97         void save_data (ARDOUR::SessionMetadata & data) const;
98         void load_data (ARDOUR::SessionMetadata const & data);
99         
100         Gtk::Widget & name_widget ();
101         Gtk::Widget & value_widget ();
102         Gtk::Widget & edit_widget ();
103   private:
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;
107         
108         Getter getter;
109         Setter setter;
110         
111         Gtk::Label* label;
112         Gtk::Label* value_label;
113         Gtk::Entry* entry;
114         
115         guint numbers;
116         guint width;
117 };
118
119 /// Interface for MetadataFields
120 class SessionMetadataSet {
121   public:
122         SessionMetadataSet (Glib::ustring const & name);
123         virtual ~SessionMetadataSet () {};
124         
125         void add_data_field (MetadataPtr field);
126         
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;
133         
134         virtual Gtk::Widget & get_widget () = 0;
135         virtual Gtk::Widget & get_tab_widget () = 0;
136         
137   protected:
138         typedef std::list<MetadataPtr> DataList;
139         DataList list;
140         Glib::ustring name;
141         ARDOUR::Session *session;
142 };
143
144 /// Contains MetadataFields for editing
145 class SessionMetadataSetEditable : public SessionMetadataSet {
146   public:
147         SessionMetadataSetEditable (Glib::ustring const & name);
148         
149         Gtk::Widget & get_widget () { return table; }
150         Gtk::Widget & get_tab_widget ();
151         
152         /// Sets session and loads data
153         void set_session (ARDOUR::Session * s);
154         /// Saves from MetadataFields into data
155         void save_data ();
156         
157   private:
158         Gtk::Table table;
159         Gtk::Label tab_widget;
160 };
161
162 /// Contains MetadataFields for importing
163 class SessionMetadataSetImportable : public SessionMetadataSet {
164   public:
165         SessionMetadataSetImportable (Glib::ustring const & name);
166         
167         Gtk::Widget & get_widget () { return tree_view; }
168         Gtk::Widget & get_tab_widget ();
169         Gtk::Widget & get_select_all_widget ();
170         
171         /// Loads importable data from data
172         void load_extra_data (ARDOUR::SessionMetadata const & data);
173         /// Saves from importable data (see load_data) to session_data
174         void save_data ();
175         
176   private:
177         DataList & session_list; // References MetadataSet::list
178         DataList import_list;
179         
180         struct Columns : public Gtk::TreeModel::ColumnRecord
181         {
182           public:
183                 Gtk::TreeModelColumn<Glib::ustring>     field;
184                 Gtk::TreeModelColumn<Glib::ustring>     values;
185                 Gtk::TreeModelColumn<bool>        import;
186                 Gtk::TreeModelColumn<MetadataPtr> data;
187         
188                 Columns() { add (field); add (values); add (import); add (data); }
189         };
190         
191         Glib::RefPtr<Gtk::ListStore>  tree;
192         Columns                       tree_cols;
193         Gtk::TreeView                 tree_view;
194         
195         Gtk::Label                    tab_widget;       
196         Gtk::CheckButton              select_all_check;
197         
198         void select_all ();
199         void selection_changed (Glib::ustring const & path);
200 };
201
202 /// Metadata dialog interface
203 /**
204  * The DataSets are initalized in this class so that all
205  * Dialogs have the same sets of data in the same order.
206  */
207 template <typename DataSet>
208 class SessionMetadataDialog : public ArdourDialog
209 {
210   public:
211         SessionMetadataDialog (Glib::ustring const & name);
212
213   protected:
214         void init_data ();
215         void load_extra_data (ARDOUR::SessionMetadata const & data);
216         void save_data ();
217         
218         virtual void init_gui () = 0;
219         virtual void save_and_close ();
220         virtual void end_dialog ();
221         
222         void warn_user (Glib::ustring const & string);
223         
224         typedef std::list<Gtk::Widget *> WidgetList;
225         typedef boost::shared_ptr<WidgetList> WidgetListPtr;
226         typedef Gtk::Widget & (DataSet::*WidgetFunc) ();
227         
228         /// Returns list of widgets gathered by calling f for each data set
229         WidgetListPtr get_custom_widgets (WidgetFunc f);
230         
231         /// Adds a widget to the table (vertical stacking) with automatic spacing
232         void add_widget (Gtk::Widget & widget);
233
234         Gtk::Notebook     notebook;
235
236   private:
237         void init_track_data ();
238         void init_album_data ();
239         void init_people_data ();
240
241         typedef boost::shared_ptr<SessionMetadataSet> DataSetPtr;
242         typedef std::list<DataSetPtr> DataSetList;
243         DataSetList data_list;
244         
245         Gtk::Button *     save_button;
246         Gtk::Button *     cancel_button;
247 };
248
249 class SessionMetadataEditor : public SessionMetadataDialog<SessionMetadataSetEditable> {
250   public:
251         SessionMetadataEditor ();
252         ~SessionMetadataEditor ();
253         void run ();
254   private:
255         void init_gui ();
256 };
257
258 class SessionMetadataImporter : public SessionMetadataDialog<SessionMetadataSetImportable> {
259   public:
260         SessionMetadataImporter ();
261         ~SessionMetadataImporter ();
262         void run ();
263
264   private:
265         void init_gui ();
266         
267         // Select all from -widget
268         Gtk::HBox    selection_hbox;
269         Gtk::Label   selection_label;
270         
271 };
272
273 #endif