2d219dc252b590877b0f8239291ab526640324b6
[ardour.git] / gtk2_ardour / template_dialog.h
1 /*
2     Copyright (C) 2010 Paul Davis
3     Author: Johannes Mueller
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __gtk2_ardour_template_dialog_h__
22 #define __gtk2_ardour_template_dialog_h__
23
24 #include <vector>
25
26 #include <gtkmm/liststore.h>
27 #include <gtkmm/progressbar.h>
28 #include <gtkmm/textview.h>
29 #include <gtkmm/treeview.h>
30
31 #include "ardour_dialog.h"
32 #include "progress_reporter.h"
33
34 namespace ARDOUR {
35         struct TemplateInfo;
36 }
37
38 class XMLTree;
39 class XMLNode;
40
41 class TemplateDialog : public ArdourDialog,
42                        public PBD::ScopedConnectionList
43 {
44 public:
45         TemplateDialog ();
46         ~TemplateDialog () {}
47 };
48
49 class TemplateManager : public Gtk::HBox,
50                         public ProgressReporter
51 {
52         friend class TemplateDialog;
53 public:
54         virtual ~TemplateManager () {}
55         virtual void init () = 0;
56
57         PBD::Signal0<void> TemplatesImported;
58
59 protected:
60         TemplateManager ();
61
62         void setup_model (const std::vector<ARDOUR::TemplateInfo>& templates);
63
64         void row_selection_changed ();
65         void render_template_names (Gtk::CellRenderer* rnd, const Gtk::TreeModel::iterator& it);
66         void validate_edit (const Glib::ustring& path_string, const Glib::ustring& new_name);
67         void start_edit ();
68
69         void set_desc_dirty ();
70
71         bool key_event (GdkEventKey* ev);
72
73         virtual void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name) = 0;
74         virtual void delete_selected_template () = 0;
75
76         void handle_dirty_description ();
77         virtual void save_template_desc ();
78
79         void export_all_templates ();
80         void import_template_set ();
81
82         virtual std::string templates_dir () const = 0;
83         virtual std::string template_file (const Gtk::TreeModel::const_iterator& item) const = 0;
84
85         virtual bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const = 0;
86
87         bool adjust_plugin_paths (XMLNode* node, const std::string& name, const std::string& new_name) const;
88
89         struct SessionTemplateColumns : public Gtk::TreeModel::ColumnRecord {
90                 SessionTemplateColumns () {
91                         add (name);
92                         add (path);
93                         add (description);
94                 }
95
96                 Gtk::TreeModelColumn<std::string> name;
97                 Gtk::TreeModelColumn<std::string> path;
98                 Gtk::TreeModelColumn<std::string> description;
99         };
100
101         SessionTemplateColumns _template_columns;
102         Glib::RefPtr<Gtk::ListStore>  _template_model;
103
104         Gtk::TreeModel::const_iterator _current_selection;
105
106         Gtk::TreeView _template_treeview;
107         Gtk::CellRendererText _validating_cellrenderer;
108         Gtk::TreeView::Column _validated_column;
109
110         Gtk::TextView _description_editor;
111         Gtk::Button _save_desc;
112         bool _desc_dirty;
113
114         Gtk::Button _remove_button;
115         Gtk::Button _rename_button;
116
117         Gtk::Button _export_all_templates_button;
118         Gtk::Button _import_template_set_button;
119
120         Gtk::ProgressBar _progress_bar;
121         std::string _current_action;
122
123         void update_progress_gui (float p);
124 };
125
126 class SessionTemplateManager : public TemplateManager
127 {
128 public:
129         SessionTemplateManager () : TemplateManager () {}
130         ~SessionTemplateManager () {}
131
132         void init ();
133
134 private:
135         void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name);
136         void delete_selected_template ();
137
138         std::string templates_dir () const;
139         std::string template_file (const Gtk::TreeModel::const_iterator& item) const;
140
141         bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const;
142 };
143
144
145 class RouteTemplateManager : public TemplateManager
146 {
147 public:
148         RouteTemplateManager () : TemplateManager () {}
149         ~RouteTemplateManager () {}
150
151         void init ();
152
153 private:
154         void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name);
155         void delete_selected_template ();
156
157         std::string templates_dir () const;
158         std::string template_file (const Gtk::TreeModel::const_iterator& item) const;
159
160         bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const;
161 };
162
163
164 #endif /* __gtk2_ardour_template_dialog_h__ */