Guitarix
gx_preset_window.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3  * Copyright (C) 2011 Pete Shorthose
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  * ---------------------------------------------------------------------------
19  *
20  *
21  * ----------------------------------------------------------------------------
22  */
23 
24 /****************************************************************
25  ** class PresetWindow
26  */
27 
28 
29 class PresetStore: public Gtk::ListStore {
30 public:
31  class PresetModelColumns : public Gtk::TreeModel::ColumnRecord {
32  public:
33  Gtk::TreeModelColumn<Glib::ustring> name;
34  Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > edit_pb;
35  Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > del_pb;
36 
37  PresetModelColumns() { add(name); add(edit_pb); add(del_pb); }
38  } col;
39 public:
40  PresetStore();
41  virtual bool row_draggable_vfunc(const TreeModel::Path& path) const;
42 };
43 
44 class TargetModelColumns : public Gtk::TreeModel::ColumnRecord {
45 public:
46  Gtk::TreeModelColumn<Glib::ustring> name;
47  TargetModelColumns() { add(name); }
48 };
49 
50 class BankModelColumns : public Gtk::TreeModel::ColumnRecord {
51 public:
52  Gtk::TreeModelColumn<Glib::ustring> name;
53  Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > type_pb;
54  Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > edit_pb;
55  Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > del_pb;
56  Gtk::TreeModelColumn<int> tp;
57  BankModelColumns() { add(name); add(type_pb); add(edit_pb); add(del_pb); add(tp); }
58 };
59 
60 class MyTreeView: public Gtk::TreeView {
61 private:
62  MyTreeView(BaseObjectType* cobject): Gtk::TreeView(cobject) {}
63 public:
64  static MyTreeView *create_from_builder(BaseObjectType* cobject) { return new MyTreeView(cobject); }
65  //virtual bool on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint timestamp);
66  using Gtk::TreeView::on_drag_motion;
67 };
68 
69 
71 public:
72  DownloadWatch() : watcher(0), stop(false) {}
73  Glib::RefPtr<Gio::Cancellable> cancellable;
74  Gio::File::SlotFileProgress file_state;
75  static void f_progress(goffset read, goffset total);
76  void start ();
77  ~DownloadWatch();
78  Glib::Dispatcher timeout;
79 
80 protected:
81  void watch ();
82  void load ();
83  Glib::Thread * watcher;
84  Glib::Mutex w_mutex;
85  bool stop;
86 };
87 
88 
89 struct GxActions;
90 
91 class PresetWindow: public sigc::trackable {
92 private:
93  enum {
94  TEXT_TARGETS = 0,
95  MODELROW_TARGET = 1,
96  URILIST_TARGET = 2,
97  };
98  gx_engine::GxMachineBase& machine;
99  GxActions& actions;
100  DownloadWatch *watch;
101  void go_watch ();
102  void watch_done();
103  bool in_edit;
104  Gtk::TreeModel::iterator edit_iter;
105  Glib::RefPtr<Gdk::Pixbuf> pb_edit;
106  Glib::RefPtr<Gdk::Pixbuf> pb_del;
107  Glib::RefPtr<Gdk::Pixbuf> pb_scratch;
108  Glib::RefPtr<Gdk::Pixbuf> pb_versiondiff;
109  Glib::RefPtr<Gdk::Pixbuf> pb_readonly;
110  Glib::RefPtr<Gdk::Pixbuf> pb_factory;
111  Glib::RefPtr<PresetStore> pstore;
112  TargetModelColumns target_col;
113  BankModelColumns bank_col;
114  sigc::connection bank_row_del_conn;
115  sigc::connection preset_row_del_conn;
116  int vpaned_pos;
117  int vpaned_step;
118  int vpaned_target;
119  const gx_system::CmdlineOptions& options;
120  bool in_current_preset;
121  sigc::connection on_map_conn;
122 
123  // widget pointers (keep last)
124  Gtk::Button *close_preset;
125  Gtk::Button *save_preset;
126  Gtk::Button *new_preset_bank;
127  Gtk::ToggleButton *organize_presets;
128  Gtk::Button *online_preset;
129  MyTreeView *bank_treeview;
130  Gtk::CellRendererText *bank_cellrenderer;
131  MyTreeView *preset_treeview;
132  Gtk::CellRendererText *preset_cellrenderer;
133  Gtk::ComboBox *banks_combobox;
134  MyTreeView *presets_target_treeview;
135  Gtk::Label *preset_title;
136  Gtk::ScrolledWindow *presets_target_scrolledbox;
137  Gtk::TreeViewColumn *bank_column_edit;
138  Gtk::TreeViewColumn *bank_column_delete;
139  Gtk::TreeViewColumn *preset_column_edit;
140  Gtk::TreeViewColumn *preset_column_delete;
141  Gtk::VPaned *main_vpaned;
142  Gtk::ScrolledWindow *preset_scrolledbox;
143  GtkSizeGroup *left_column;
144 private:
145  void load_widget_pointers(Glib::RefPtr<gx_gui::GxBuilder> bld);
146  void target_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& data, guint info, guint timestamp);
147  bool on_target_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint timestamp);
148  Glib::ustring get_combo_selection();
149  void reload_combo();
150  void on_preset_combo_changed();
151  void reload_target();
152  bool select_func(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreePath& path, bool path_currently_selected);
153  void highlight_current_bank(Gtk::CellRenderer *cell, const Gtk::TreeModel::iterator& iter);
154  void text_func(Gtk::CellRenderer *cell, const Gtk::TreeModel::iterator& iter);
155  void on_editing_started(const Gtk::CellEditable* edit, const Glib::ustring& path, Glib::RefPtr<Gtk::TreeModel>& model);
156  bool edit_cell(Gtk::TreeModel::Path pt, Gtk::TreeViewColumn& col, Gtk::CellRenderer& cell);
157  void reset_edit(Gtk::TreeViewColumn& col);
158  void on_edit_canceled(Gtk::TreeViewColumn *col);
159  void start_edit(const Gtk::TreeModel::Path& pt, Gtk::TreeViewColumn& col, Gtk::CellRenderer& cell);
160  Gtk::TreeIter get_current_bank_iter() { return bank_treeview->get_selection()->get_selected(); }
161  Glib::ustring get_current_bank();
162  bool run_message_dialog(Gtk::Widget& w, const Glib::ustring& msg);
163  bool on_bank_button_release(GdkEventButton *ev);
164  void on_bank_edited(const Glib::ustring& path, const Glib::ustring& newtext, Gtk::TreeView* w);
165  bool is_row_separator(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::iterator& iter);
166  void on_new_bank();
167  void on_preset_save();
168  const std::string pdir() { return options.get_preset_dir();}
169  void on_online_preset();
170  void replace_inline(std::string& l, const std::string& s, const std::string& r);
171  void show_online_preset();
172  void popup_pos( int& x, int& y, bool& push_in );
173  void downloadPreset(Gtk::Menu *presetMenu,std::string uri);
174  bool download_file(Glib::ustring from_uri, Glib::ustring to_path);
175  Glib::ustring resolve_hostname();
176  void create_preset_menu(bool is_new);
177  void read_preset_menu();
178  std::vector< std::tuple<std::string,std::string,std::string> > olp;
179  bool on_bank_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint timestamp);
180  void on_bank_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& data, guint info, guint timestamp);
181  void on_bank_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection, int info, int timestamp);
182  void on_bank_changed();
183  bool on_bank_query_tooltip(int x, int y, bool kb_tooltip, Glib::RefPtr<Gtk::Tooltip> tooltip);
184  void reload_banks(const Glib::ustring& sel_bank);
185  void set_presets();
186  void on_bank_reordered(const Gtk::TreeModel::Path& path);
187  bool on_preset_button_release(GdkEventButton *ev);
188  bool on_preset_button_press(GdkEventButton *ev);
189  void on_preset_row_activated(const Gtk::TreePath& path, Gtk::TreeViewColumn* column);
190  void on_preset_edited(const Glib::ustring& path, const Glib::ustring& newtext);
191  void on_cursor_changed();
192  void on_preset_changed();
193  bool on_preset_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint timestamp);
194  void on_preset_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection, int info, int timestamp);
195  void on_preset_reordered(const Gtk::TreeModel::Path& path);
196  void autosize();
197  void on_organize();
198  void on_presets_close();
199  bool animate_preset_show();
200  bool animate_preset_hide();
201  void set_row_for_presetfile(Gtk::TreeIter i, gx_system::PresetFileGui *f);
202  void display_paned(bool show_preset, int paned_child_height);
203  void on_selection_changed();
204 public:
205  PresetWindow(Glib::RefPtr<gx_gui::GxBuilder> bld, gx_engine::GxMachineBase& machine,
206  const gx_system::CmdlineOptions& options, GxActions& actions, GtkSizeGroup *lc);
207  ~PresetWindow();
208  void on_preset_select(bool v, bool animated, int preset_window_height);
209 };
Gio::File::SlotFileProgress file_state
Glib::RefPtr< Gio::Cancellable > cancellable
CmdConnection::msg_type start
Definition: jsonrpc.cpp:255
const std::string & get_preset_dir() const
Definition: gx_system.h:473
Gtk::TreeModelColumn< Glib::RefPtr< Gdk::Pixbuf > > type_pb
Gtk::TreeModelColumn< Glib::RefPtr< Gdk::Pixbuf > > edit_pb
static MyTreeView * create_from_builder(BaseObjectType *cobject)
Glib::Mutex w_mutex
Glib::Thread * watcher
Gtk::TreeModelColumn< Glib::RefPtr< Gdk::Pixbuf > > del_pb
virtual bool row_draggable_vfunc(const TreeModel::Path &path) const
Gtk::TreeModelColumn< Glib::RefPtr< Gdk::Pixbuf > > edit_pb
PresetStore::PresetModelColumns col
Gtk::TreeModelColumn< Glib::RefPtr< Gdk::Pixbuf > > del_pb
Gtk::TreeModelColumn< Glib::ustring > name
Gtk::TreeModelColumn< int > tp
Gtk::TreeModelColumn< Glib::ustring > name
Gtk::TreeModelColumn< Glib::ustring > name
Glib::Dispatcher timeout