Ardour  9.0-pre0-582-g084a23a80d
session_metadata_dialog.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2013 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2009 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2009 David Robillard <d@drobilla.net>
5  * Copyright (C) 2015 Colin Fletcher <colin.m.fletcher@googlemail.com>
6  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
25 #include <memory>
26 
27 #include "ardour_dialog.h"
28 
29 #ifdef interface
30 #undef interface
31 #endif
32 
33 #include <gtkmm/box.h>
34 #include <gtkmm/button.h>
35 #include <gtkmm/checkbutton.h>
36 #include <gtkmm/entry.h>
37 #include <gtkmm/label.h>
38 #include <gtkmm/liststore.h>
39 #include <gtkmm/notebook.h>
40 #include <gtkmm/table.h>
41 #include <gtkmm/textview.h>
42 #include <gtkmm/treemodel.h>
43 #include <gtkmm/treeview.h>
44 
45 #include <string>
46 #include <list>
47 
49 
50 class MetadataField;
51 typedef std::shared_ptr<MetadataField> MetadataPtr;
52 
55 {
56 public:
57  MetadataField (std::string const & field_name);
58  virtual ~MetadataField();
59  virtual MetadataPtr copy () = 0;
60 
61  virtual void save_data (ARDOUR::SessionMetadata & data) const = 0;
62  virtual void load_data (ARDOUR::SessionMetadata const & data) = 0;
63 
64  virtual std::string name() { return _name; }
65  virtual std::string value() { return _value; }
66 
68  virtual Gtk::Widget & name_widget () = 0;
70  virtual Gtk::Widget & value_widget () = 0;
72  virtual Gtk::Widget & edit_widget () = 0;
73 protected:
74  std::string _name;
75  std::string _value;
76 };
77 
80 {
81 protected:
82  typedef std::string (ARDOUR::SessionMetadata::*Getter) () const;
83  typedef void (ARDOUR::SessionMetadata::*Setter) (std::string const &);
84 public:
85  TextMetadataField (Getter getter, Setter setter, std::string const & field_name, guint width = 50);
87 
88  void save_data (ARDOUR::SessionMetadata & data) const;
89  void load_data (ARDOUR::SessionMetadata const & data);
90 
94 protected:
95  void update_value ();
96 
99 
103 
104  guint width;
105 };
106 
109 {
110 public:
111  LongTextMetadataField (Getter getter, Setter setter, std::string const & field_name, guint width = 50);
113 
115 private:
116  void update_value ();
117 
119 };
120 
123 {
124 private:
125  typedef uint32_t (ARDOUR::SessionMetadata::*Getter) () const;
126  typedef void (ARDOUR::SessionMetadata::*Setter) (uint32_t);
127 public:
128  NumberMetadataField (Getter getter, Setter setter, std::string const & field_name, guint numbers, guint width = 50);
130 
131  void save_data (ARDOUR::SessionMetadata & data) const;
132  void load_data (ARDOUR::SessionMetadata const & data);
133 
137 private:
138  void update_value ();
139  std::string uint_to_str (uint32_t i) const;
140  uint32_t str_to_uint (std::string const & str) const;
141 
144 
148 
149  guint numbers;
150  guint width;
151 };
152 
155 {
156 private:
157  typedef std::string (ARDOUR::SessionMetadata::*Getter) () const;
158  typedef void (ARDOUR::SessionMetadata::*Setter) (std::string const &);
159 public:
160  EAN13MetadataField (Getter getter, Setter setter, std::string const & field_name, guint width = 13);
162 
163  void save_data (ARDOUR::SessionMetadata & data) const;
164  void load_data (ARDOUR::SessionMetadata const & data);
165 
169 
171  void update_status ();
172 private:
173  void update_value ();
174  std::string numeric_string (std::string const & str) const;
175 
178 
182 
183  guint width;
184 };
185 
188 {
189 public:
190  SessionMetadataSet (std::string const & name);
191  virtual ~SessionMetadataSet () {};
192 
194 
196  virtual void load_extra_data (ARDOUR::SessionMetadata const & /*data*/) { }
198  virtual void save_data () = 0;
199 
200  virtual Gtk::Widget & get_widget () = 0;
201  virtual Gtk::Widget & get_tab_widget () = 0;
202 
203 protected:
204  typedef std::list<MetadataPtr> DataList;
206  std::string name;
207 };
208 
211 {
212 public:
213  SessionMetadataSetEditable (std::string const & name);
214 
215  Gtk::Widget & get_widget () { return vbox; }
217 
221  void save_data ();
222 
223 private:
227 };
228 
231 {
232 public:
233  SessionMetadataSetImportable (std::string const & name);
234 
238 
242  void save_data ();
243 
244 private:
245  DataList & session_list; // References MetadataSet::list
247 
249  {
250  public:
255 
256  Columns() { add (field); add (values); add (import); add (data); }
257  };
258 
259  Glib::RefPtr<Gtk::ListStore> tree;
262 
265 
266  void select_all ();
267  void selection_changed (std::string const & path);
268 };
269 
271 
275 template <typename DataSet>
277 {
278 public:
279  SessionMetadataDialog (std::string const & name);
280 
281 protected:
282  void init_data ( bool skip_user = false );
284  void save_data ();
285 
286  virtual void init_gui () = 0;
287  virtual void save_and_close ();
288  virtual void end_dialog ();
289 
290  void warn_user (std::string const & string);
291 
292  typedef std::list<Gtk::Widget *> WidgetList;
293  typedef std::shared_ptr<WidgetList> WidgetListPtr;
294  typedef Gtk::Widget & (DataSet::*WidgetFunc) ();
295 
298 
300  void add_widget (Gtk::Widget & widget);
301 
303 
304 private:
305  void init_user_data ();
311 
312  typedef std::shared_ptr<SessionMetadataSet> DataSetPtr;
313  typedef std::list<DataSetPtr> DataSetList;
315 
318 };
319 
320 class SessionMetadataEditor : public SessionMetadataDialog<SessionMetadataSetEditable>
321 {
322 public:
325  void run ();
326 private:
327  void init_gui ();
328 };
329 
330 class SessionMetadataImporter : public SessionMetadataDialog<SessionMetadataSetImportable> {
331  public:
334  void run ();
335 
336  private:
337  void init_gui ();
338 
339  // Select all from -widget
342 
343 };
344 
MetadataField that accepts EAN-13 data only.
void save_data(ARDOUR::SessionMetadata &data) const
Gtk::Widget & value_widget()
Get label containing value of field.
MetadataPtr copy()
void load_data(ARDOUR::SessionMetadata const &data)
EAN13MetadataField(Getter getter, Setter setter, std::string const &field_name, guint width=13)
Gtk::Widget & name_widget()
Get widget containing name of field.
void(ARDOUR::SessionMetadata::* Setter)(std::string const &)
std::string numeric_string(std::string const &str) const
Gtk::Widget & edit_widget()
Get widget for editing value.
std::string(ARDOUR::SessionMetadata::* Getter)() const
void add(TreeModelColumnBase &column)
MetadataField that contains longform text.
LongTextMetadataField(Getter getter, Setter setter, std::string const &field_name, guint width=50)
Gtk::Widget & edit_widget()
Get widget for editing value.
MetadataPtr copy()
Wraps a metadata field to be used in a GUI.
virtual void save_data(ARDOUR::SessionMetadata &data) const =0
MetadataField(std::string const &field_name)
virtual MetadataPtr copy()=0
virtual std::string name()
virtual Gtk::Widget & name_widget()=0
Get widget containing name of field.
virtual std::string value()
virtual void load_data(ARDOUR::SessionMetadata const &data)=0
virtual ~MetadataField()
virtual Gtk::Widget & edit_widget()=0
Get widget for editing value.
virtual Gtk::Widget & value_widget()=0
Get label containing value of field.
MetadataField that accepts only numbers.
std::string uint_to_str(uint32_t i) const
MetadataPtr copy()
uint32_t(ARDOUR::SessionMetadata::* Getter)() const
NumberMetadataField(Getter getter, Setter setter, std::string const &field_name, guint numbers, guint width=50)
void(ARDOUR::SessionMetadata::* Setter)(uint32_t)
void load_data(ARDOUR::SessionMetadata const &data)
void save_data(ARDOUR::SessionMetadata &data) const
uint32_t str_to_uint(std::string const &str) const
Gtk::Widget & value_widget()
Get label containing value of field.
Gtk::Widget & name_widget()
Get widget containing name of field.
Gtk::Widget & edit_widget()
Get widget for editing value.
Metadata dialog interface.
void add_widget(Gtk::Widget &widget)
Adds a widget to the table (vertical stacking) with automatic spacing.
virtual void init_gui()=0
void load_extra_data(ARDOUR::SessionMetadata const &data)
std::list< Gtk::Widget * > WidgetList
std::shared_ptr< SessionMetadataSet > DataSetPtr
std::shared_ptr< WidgetList > WidgetListPtr
virtual void save_and_close()
WidgetListPtr get_custom_widgets(WidgetFunc f)
Returns list of widgets gathered by calling f for each data set.
void init_data(bool skip_user=false)
void warn_user(std::string const &string)
SessionMetadataDialog(std::string const &name)
Gtk::Widget &(DataSet::* WidgetFunc)()
std::list< DataSetPtr > DataSetList
virtual void end_dialog()
Contains MetadataFields for editing.
SessionMetadataSetEditable(std::string const &name)
void save_data()
Saves from MetadataFields into data.
Gtk::Widget & get_tab_widget()
void set_session(ARDOUR::Session *s)
Sets session and loads data.
Contains MetadataFields for importing.
Glib::RefPtr< Gtk::ListStore > tree
SessionMetadataSetImportable(std::string const &name)
Gtk::Widget & get_tab_widget()
void selection_changed(std::string const &path)
void save_data()
Saves from importable data (see load_data) to session_data.
Gtk::Widget & get_select_all_widget()
void load_extra_data(ARDOUR::SessionMetadata const &data)
Loads importable data from data.
Interface for MetadataFields.
virtual void load_extra_data(ARDOUR::SessionMetadata const &)
allows loading extra data into data sets (for importing etc.)
virtual Gtk::Widget & get_tab_widget()=0
virtual Gtk::Widget & get_widget()=0
SessionMetadataSet(std::string const &name)
void add_data_field(MetadataPtr field)
std::list< MetadataPtr > DataList
virtual void save_data()=0
Saves data to session.
MetadataField that contains text.
void save_data(ARDOUR::SessionMetadata &data) const
Gtk::Widget & value_widget()
Get label containing value of field.
TextMetadataField(Getter getter, Setter setter, std::string const &field_name, guint width=50)
Gtk::Widget & name_widget()
Get widget containing name of field.
MetadataPtr copy()
Gtk::Widget & edit_widget()
Get widget for editing value.
void(ARDOUR::SessionMetadata::* Setter)(std::string const &)
std::string(ARDOUR::SessionMetadata::* Getter)() const
void load_data(ARDOUR::SessionMetadata const &data)
GtkImageIconNameData name
Definition: gtkimage.h:6
std::shared_ptr< MetadataField > MetadataPtr
Gtk::TreeModelColumn< MetadataPtr > data
Gtk::TreeModelColumn< std::string > field
Gtk::TreeModelColumn< std::string > values