Inflate template archives rather in `.config/ardour5/` than in ...
[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/treeview.h>
29
30 #include "ardour_dialog.h"
31 #include "progress_reporter.h"
32
33 namespace ARDOUR {
34         struct TemplateInfo;
35 }
36
37 class XMLTree;
38 class XMLNode;
39
40 class TemplateDialog : public ArdourDialog,
41                        public PBD::ScopedConnectionList
42 {
43 public:
44         TemplateDialog ();
45         ~TemplateDialog () {}
46 };
47
48 class TemplateManager : public Gtk::HBox,
49                         public ProgressReporter
50 {
51 public:
52         virtual ~TemplateManager () {}
53         virtual void init () = 0;
54
55         PBD::Signal0<void> TemplatesImported;
56
57 protected:
58         TemplateManager ();
59
60         void setup_model (const std::vector<ARDOUR::TemplateInfo>& templates);
61
62         void row_selection_changed ();
63         void render_template_names (Gtk::CellRenderer* rnd, const Gtk::TreeModel::iterator& it);
64         void validate_edit (const Glib::ustring& path_string, const Glib::ustring& new_name);
65         void start_edit ();
66
67         bool key_event (GdkEventKey* ev);
68
69         virtual void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name) = 0;
70         virtual void delete_selected_template () = 0;
71
72         void export_all_templates ();
73         void import_template_set ();
74
75         virtual std::string templates_dir () const = 0;
76
77         virtual bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const = 0;
78
79         bool adjust_plugin_paths (XMLNode* node, const std::string& name, const std::string& new_name) const;
80
81         struct SessionTemplateColumns : public Gtk::TreeModel::ColumnRecord {
82                 SessionTemplateColumns () {
83                         add (name);
84                         add (path);
85                 }
86
87                 Gtk::TreeModelColumn<std::string> name;
88                 Gtk::TreeModelColumn<std::string> path;
89         };
90
91         SessionTemplateColumns _template_columns;
92         Glib::RefPtr<Gtk::ListStore>  _template_model;
93
94         Gtk::TreeView _template_treeview;
95         Gtk::CellRendererText _validating_cellrenderer;
96         Gtk::TreeView::Column _validated_column;
97
98         Gtk::Button _remove_button;
99         Gtk::Button _rename_button;
100
101         Gtk::Button _export_all_templates_button;
102         Gtk::Button _import_template_set_button;
103
104         Gtk::ProgressBar _progress_bar;
105         std::string _current_action;
106
107         void update_progress_gui (float p);
108 };
109
110 class SessionTemplateManager : public TemplateManager
111 {
112 public:
113         SessionTemplateManager () : TemplateManager () {}
114         ~SessionTemplateManager () {}
115
116         void init ();
117
118 private:
119         void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name);
120         void delete_selected_template ();
121
122         std::string templates_dir () const;
123
124         bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const;
125 };
126
127
128 class RouteTemplateManager : public TemplateManager
129 {
130 public:
131         RouteTemplateManager () : TemplateManager () {}
132         ~RouteTemplateManager () {}
133
134         void init ();
135
136 private:
137         void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name);
138         void delete_selected_template ();
139
140         std::string templates_dir () const;
141
142         bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const;
143 };
144
145
146 #endif /* __gtk2_ardour_template_dialog_h__ */