summaryrefslogtreecommitdiff
path: root/gtk2_ardour/session_metadata_dialog.h
blob: 9ae97b2626eb734069cd43982400f7cd4dd6edd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/*
 * Copyright (C) 2008-2013 Paul Davis <paul@linuxaudiosystems.com>
 * Copyright (C) 2009 Carl Hetherington <carl@carlh.net>
 * Copyright (C) 2009 David Robillard <d@drobilla.net>
 * Copyright (C) 2015 Colin Fletcher <colin.m.fletcher@googlemail.com>
 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __session_metadata_dialog_h__
#define __session_metadata_dialog_h__

#include "ardour_dialog.h"

#ifdef interface
#undef interface
#endif

#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/checkbutton.h>
#include <gtkmm/entry.h>
#include <gtkmm/label.h>
#include <gtkmm/liststore.h>
#include <gtkmm/notebook.h>
#include <gtkmm/table.h>
#include <gtkmm/textview.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/treeview.h>

#include <boost/shared_ptr.hpp>

#include <string>
#include <list>

#include "ardour/session_metadata.h"

class MetadataField;
typedef boost::shared_ptr<MetadataField> MetadataPtr;

/// Wraps a metadata field to be used in a GUI
class MetadataField
{
public:
	MetadataField (std::string const & field_name);
	virtual ~MetadataField();
	virtual MetadataPtr copy () = 0;

	virtual void save_data (ARDOUR::SessionMetadata & data) const = 0;
	virtual void load_data (ARDOUR::SessionMetadata const & data) = 0;

	virtual std::string name() { return _name; }
	virtual std::string value() { return _value; }

	/// Get widget containing name of field
	virtual Gtk::Widget & name_widget () = 0;
	/// Get label containing value of field
	virtual Gtk::Widget & value_widget () = 0;
	/// Get widget for editing value
	virtual Gtk::Widget & edit_widget () = 0;
protected:
	std::string _name;
	std::string _value;
};

/// MetadataField that contains text
class TextMetadataField : public MetadataField
{
protected:
	typedef std::string (ARDOUR::SessionMetadata::*Getter) () const;
	typedef void (ARDOUR::SessionMetadata::*Setter) (std::string const &);
public:
	TextMetadataField (Getter getter, Setter setter, std::string const & field_name, guint width = 50);
	MetadataPtr copy ();

	void save_data (ARDOUR::SessionMetadata & data) const;
	void load_data (ARDOUR::SessionMetadata const & data);

	Gtk::Widget & name_widget ();
	Gtk::Widget & value_widget ();
	Gtk::Widget & edit_widget ();
protected:
	void update_value ();

	Getter getter;
	Setter setter;

	Gtk::Label* label;
	Gtk::Label* value_label;
	Gtk::Entry* entry;

	guint width;
};

/// MetadataField that contains longform text
class LongTextMetadataField : public TextMetadataField
{
public:
	LongTextMetadataField (Getter getter, Setter setter, std::string const & field_name, guint width = 50);
	MetadataPtr copy ();

	Gtk::Widget & edit_widget ();
private:
	void update_value ();

	Gtk::TextView* tview;
};

/// MetadataField that accepts only numbers
class NumberMetadataField : public MetadataField
{
private:
	typedef uint32_t (ARDOUR::SessionMetadata::*Getter) () const;
	typedef void (ARDOUR::SessionMetadata::*Setter) (uint32_t);
public:
	NumberMetadataField (Getter getter, Setter setter, std::string const & field_name, guint numbers, guint width = 50);
	MetadataPtr copy ();

	void save_data (ARDOUR::SessionMetadata & data) const;
	void load_data (ARDOUR::SessionMetadata const & data);

	Gtk::Widget & name_widget ();
	Gtk::Widget & value_widget ();
	Gtk::Widget & edit_widget ();
private:
	void update_value ();
	std::string uint_to_str (uint32_t i) const;
	uint32_t str_to_uint (std::string const & str) const;

	Getter getter;
	Setter setter;

	Gtk::Label* label;
	Gtk::Label* value_label;
	Gtk::Entry* entry;

	guint numbers;
	guint width;
};

/// MetadataField that accepts EAN-13 data only
class EAN13MetadataField : public MetadataField
{
private:
	typedef std::string (ARDOUR::SessionMetadata::*Getter) () const;
	typedef void (ARDOUR::SessionMetadata::*Setter) (std::string const &);
public:
	EAN13MetadataField (Getter getter, Setter setter, std::string const & field_name, guint width = 13);
	MetadataPtr copy ();

	void save_data (ARDOUR::SessionMetadata & data) const;
	void load_data (ARDOUR::SessionMetadata const & data);

	Gtk::Widget & name_widget ();
	Gtk::Widget & value_widget ();
	Gtk::Widget & edit_widget ();

	Gtk::Label* status_label;
	void update_status ();
private:
	void update_value ();
	std::string numeric_string (std::string const & str) const;

	Getter getter;
	Setter setter;

	Gtk::Label* label;
	Gtk::Label* value_label;
	Gtk::Entry* entry;

	guint width;
};

/// Interface for MetadataFields
class SessionMetadataSet : public ARDOUR::SessionHandlePtr
{
public:
	SessionMetadataSet (std::string const & name);
	virtual ~SessionMetadataSet () {};

	void add_data_field (MetadataPtr field);

	/// allows loading extra data into data sets (for importing etc.)
	virtual void load_extra_data (ARDOUR::SessionMetadata const & /*data*/) { }
	/// Saves data to session
	virtual void save_data () = 0;

	virtual Gtk::Widget & get_widget () = 0;
	virtual Gtk::Widget & get_tab_widget () = 0;

protected:
	typedef std::list<MetadataPtr> DataList;
	DataList list;
	std::string name;
};

/// Contains MetadataFields for editing
class SessionMetadataSetEditable : public SessionMetadataSet
{
public:
	SessionMetadataSetEditable (std::string const & name);

	Gtk::Widget & get_widget () { return vbox; }
	Gtk::Widget & get_tab_widget ();

	/// Sets session and loads data
	void set_session (ARDOUR::Session * s);
	/// Saves from MetadataFields into data
	void save_data ();

private:
	Gtk::VBox vbox;
	Gtk::Table table;
	Gtk::Label tab_widget;
};

/// Contains MetadataFields for importing
class SessionMetadataSetImportable : public SessionMetadataSet
{
public:
	SessionMetadataSetImportable (std::string const & name);

	Gtk::Widget & get_widget () { return tree_view; }
	Gtk::Widget & get_tab_widget ();
	Gtk::Widget & get_select_all_widget ();

	/// Loads importable data from data
	void load_extra_data (ARDOUR::SessionMetadata const & data);
	/// Saves from importable data (see load_data) to session_data
	void save_data ();

private:
	DataList & session_list; // References MetadataSet::list
	DataList import_list;

	struct Columns : public Gtk::TreeModel::ColumnRecord
	{
	public:
		Gtk::TreeModelColumn<std::string>     field;
		Gtk::TreeModelColumn<std::string>     values;
		Gtk::TreeModelColumn<bool>        import;
		Gtk::TreeModelColumn<MetadataPtr> data;

		Columns() { add (field); add (values); add (import); add (data); }
	};

	Glib::RefPtr<Gtk::ListStore>  tree;
	Columns                       tree_cols;
	Gtk::TreeView                 tree_view;

	Gtk::Label                    tab_widget;
	Gtk::CheckButton              select_all_check;

	void select_all ();
	void selection_changed (std::string const & path);
};

/// Metadata dialog interface
/**
 * The DataSets are initalized in this class so that all
 * Dialogs have the same sets of data in the same order.
 */
template <typename DataSet>
class SessionMetadataDialog : public ArdourDialog
{
public:
	SessionMetadataDialog (std::string const & name);

protected:
	void init_data ( bool skip_user = false );
	void load_extra_data (ARDOUR::SessionMetadata const & data);
	void save_data ();

	virtual void init_gui () = 0;
	virtual void save_and_close ();
	virtual void end_dialog ();

	void warn_user (std::string const & string);

	typedef std::list<Gtk::Widget *> WidgetList;
	typedef boost::shared_ptr<WidgetList> WidgetListPtr;
	typedef Gtk::Widget & (DataSet::*WidgetFunc) ();

	/// Returns list of widgets gathered by calling f for each data set
	WidgetListPtr get_custom_widgets (WidgetFunc f);

	/// Adds a widget to the table (vertical stacking) with automatic spacing
	void add_widget (Gtk::Widget & widget);

	Gtk::Notebook     notebook;

private:
	void init_user_data ();
	void init_description_data ();
	void init_track_data ();
	void init_album_data ();
	void init_people_data ();
	void init_school_data ();

	typedef boost::shared_ptr<SessionMetadataSet> DataSetPtr;
	typedef std::list<DataSetPtr> DataSetList;
	DataSetList data_list;

	Gtk::Button *     save_button;
	Gtk::Button *     cancel_button;
};

class SessionMetadataEditor : public SessionMetadataDialog<SessionMetadataSetEditable>
{
public:
	SessionMetadataEditor ();
	~SessionMetadataEditor ();
	void run ();
private:
	void init_gui ();
};

class SessionMetadataImporter : public SessionMetadataDialog<SessionMetadataSetImportable> {
  public:
	SessionMetadataImporter ();
	~SessionMetadataImporter ();
	void run ();

  private:
	void init_gui ();

	// Select all from -widget
	Gtk::HBox    selection_hbox;
	Gtk::Label   selection_label;

};

#endif