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  sigc::signal<void()> m_signal_row_clicked;
64  virtual bool on_button_press_event(GdkEventButton* button_event);
65 public:
66  static MyTreeView *create_from_builder(BaseObjectType* cobject) { return new MyTreeView(cobject); }
67  //virtual bool on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint timestamp);
68  using Gtk::TreeView::on_drag_motion;
70  sigc::signal<void()>& signal_row_clicked() { return m_signal_row_clicked; }
71 };
72 
73 class GxActions;
74 class UIManager;
75 
76 class PresetWindow: public sigc::trackable {
77 private:
78  enum {
79  TEXT_TARGETS = 0,
80  MODELROW_TARGET = 1,
81  URILIST_TARGET = 2,
82  };
85  Glib::RefPtr<Gtk::AccelGroup> accelgroup;
86  CURL *curl;
87  bool in_edit;
88  Gtk::TreeModel::iterator edit_iter;
89  Glib::RefPtr<Gdk::Pixbuf> pb_edit;
90  Glib::RefPtr<Gdk::Pixbuf> pb_del;
91  Glib::RefPtr<Gdk::Pixbuf> pb_scratch;
92  Glib::RefPtr<Gdk::Pixbuf> pb_versiondiff;
93  Glib::RefPtr<Gdk::Pixbuf> pb_readonly;
94  Glib::RefPtr<Gdk::Pixbuf> pb_factory;
95  Glib::RefPtr<PresetStore> pstore;
104  sigc::connection on_map_conn;
105 
106  // widget pointers (keep last)
107  Gtk::Button *save_preset;
108  Gtk::Button *new_preset_bank;
109  Gtk::ToggleButton *organize_presets;
110  Gtk::Button *online_preset;
112  Gtk::CellRendererText *bank_cellrenderer;
114  Gtk::CellRendererText *preset_cellrenderer;
115  Gtk::ComboBox *banks_combobox;
117  Gtk::Label *preset_title;
118  Gtk::ScrolledWindow *presets_target_scrolledbox;
119  Gtk::TreeViewColumn* bank_column_flags;
120  Gtk::TreeViewColumn* bank_column_bank;
121  Gtk::TreeViewColumn* bank_column_edit;
122  Gtk::TreeViewColumn* bank_column_delete;
123  Gtk::TreeViewColumn* bank_column_spacer;
124  Gtk::TreeViewColumn* preset_column_preset;
125  Gtk::TreeViewColumn* preset_column_edit;
126  Gtk::TreeViewColumn* preset_column_delete;
127  Gtk::TreeViewColumn* preset_column_spacer;
128  Gtk::Paned *main_vpaned;
129  Gtk::ScrolledWindow *preset_scrolledbox;
130 private:
131  void load_widget_pointers(Glib::RefPtr<gx_gui::GxBuilder> bld);
132  void target_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& data, guint info, guint timestamp);
133  bool on_target_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint timestamp);
134  Glib::ustring get_combo_selection();
135  void reload_combo();
136  void on_preset_combo_changed();
137  bool select_func(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreePath& path, bool path_currently_selected);
138  void set_cell_text(Gtk::Widget *widget, Gtk::CellRenderer *cell, const Glib::ustring& text, bool selected);
139  void highlight_current_bank(Gtk::CellRenderer *cell, const Gtk::TreeModel::iterator& iter);
140  void text_func(Gtk::CellRenderer *cell, const Gtk::TreeModel::iterator& iter);
141  void on_editing_started(const Gtk::CellEditable* edit, const Glib::ustring& path, Glib::RefPtr<Gtk::TreeModel>& model);
142  void reset_edit(Gtk::TreeViewColumn& col);
143  void on_edit_canceled(Gtk::TreeViewColumn *col);
144  void start_edit(const Gtk::TreeModel::Path& pt, Gtk::TreeViewColumn& col, Gtk::CellRenderer& cell);
145  Gtk::TreeIter get_current_bank_iter() { return bank_treeview->get_selection()->get_selected(); }
146  Glib::ustring get_current_bank();
147  bool run_message_dialog(Gtk::Widget& w, const Glib::ustring& msg);
148  bool on_bank_button_release(GdkEventButton *ev);
149  void on_bank_edited(const Glib::ustring& path, const Glib::ustring& newtext, Gtk::TreeView* w);
150  bool is_row_separator(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::iterator& iter);
151  void on_new_bank();
152  void on_preset_save();
153  const std::string pdir() { return options.get_preset_dir();}
154  void on_online_preset();
155  void show_online_preset();
156  void popup_pos( int& x, int& y, bool& push_in );
157  void downloadPreset(Gtk::Menu *presetMenu,std::string uri);
158  bool download_file(Glib::ustring from_uri, Glib::ustring to_path);
159  Glib::ustring resolve_hostname();
160  void create_preset_menu();
161  void read_preset_menu();
162  std::vector< std::tuple<std::string,std::string,std::string> > olp;
163  bool on_bank_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint timestamp);
164  bool bank_drag_moveable(Gtk::TreePath pt);
165  bool bank_find_drop_position(int x, int y, Gtk::TreeModel::Path& pt, Gtk::TreeViewDropPosition& dst);
166  void on_bank_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& data, guint info, guint timestamp);
167  void on_bank_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection, int info, int timestamp);
168  void on_bank_changed();
169  bool on_bank_query_tooltip(int x, int y, bool kb_tooltip, Glib::RefPtr<Gtk::Tooltip> tooltip);
170  void on_bank_reordered(const Gtk::TreeModel::Path& path);
171  bool on_preset_button_release(GdkEventButton *ev);
172  void on_preset_row_activated(const Gtk::TreePath& path, Gtk::TreeViewColumn* column);
173  void on_preset_edited(const Glib::ustring& path, const Glib::ustring& newtext);
174  void on_preset_changed();
175  bool on_preset_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint timestamp);
176  void on_preset_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection, int info, int timestamp);
177  void on_preset_reordered(const Gtk::TreeModel::Path& path);
178  void autosize();
179  void on_organize();
180  bool animate_preset_show();
181  bool animate_preset_hide();
182  void set_row_for_presetfile(Gtk::TreeIter i, gx_system::PresetFileGui *f);
183  void display_paned(bool show_preset, int paned_child_height);
184  void on_selection_changed();
185  void on_presetlist_changed();
186 public:
187  PresetWindow(Glib::RefPtr<gx_gui::GxBuilder> bld, gx_engine::GxMachineBase& machine,
188  const gx_system::CmdlineOptions& options, GxActions& actions, UIManager& uimanager);
189  ~PresetWindow();
190  void on_preset_select(bool v, bool animated, int preset_window_height);
191 };
Gtk::ToggleButton * organize_presets
Gtk::TreeViewColumn * bank_column_bank
Gtk::TreeViewColumn * preset_column_edit
const std::string & get_preset_dir() const
Definition: gx_system.h:482
Gtk::TreeModelColumn< Glib::RefPtr< Gdk::Pixbuf > > type_pb
const std::string pdir()
Gtk::TreeViewColumn * bank_column_edit
TargetModelColumns target_col
GxActions & actions
Gtk::TreeViewColumn * preset_column_preset
sigc::connection on_map_conn
Gtk::ScrolledWindow * preset_scrolledbox
MyTreeView(BaseObjectType *cobject)
Gtk::ScrolledWindow * presets_target_scrolledbox
Glib::RefPtr< PresetStore > pstore
Gtk::TreeModelColumn< Glib::RefPtr< Gdk::Pixbuf > > edit_pb
Glib::RefPtr< Gdk::Pixbuf > pb_edit
const gx_system::CmdlineOptions & options
BankModelColumns bank_col
Glib::RefPtr< Gdk::Pixbuf > pb_readonly
Gtk::Button * new_preset_bank
static MyTreeView * create_from_builder(BaseObjectType *cobject)
MyTreeView * presets_target_treeview
Glib::RefPtr< Gdk::Pixbuf > pb_del
Gtk::Paned * main_vpaned
Gtk::TreeModel::iterator edit_iter
MyTreeView * preset_treeview
Gtk::TreeModelColumn< Glib::RefPtr< Gdk::Pixbuf > > del_pb
sigc::signal< void()> m_signal_row_clicked
std::vector< std::tuple< std::string, std::string, std::string > > olp
Gtk::TreeModelColumn< Glib::RefPtr< Gdk::Pixbuf > > edit_pb
gx_engine::GxMachineBase & machine
PresetStore::PresetModelColumns col
Gtk::CellRendererText * bank_cellrenderer
sigc::signal< void()> & signal_row_clicked()
like Gtk::TreeSelection::signal_changed, but is also emitted when the selection didn&#39;t change ...
Gtk::TreeViewColumn * bank_column_flags
Gtk::TreeModelColumn< Glib::RefPtr< Gdk::Pixbuf > > del_pb
Glib::RefPtr< Gdk::Pixbuf > pb_scratch
Gtk::TreeModelColumn< Glib::ustring > name
virtual bool row_draggable_vfunc(const TreeModel::Path &path) const
Glib::RefPtr< Gdk::Pixbuf > pb_versiondiff
Glib::RefPtr< Gdk::Pixbuf > pb_factory
Gtk::TreeModelColumn< int > tp
Gtk::Button * save_preset
Gtk::TreeViewColumn * bank_column_delete
Gtk::TreeModelColumn< Glib::ustring > name
MyTreeView * bank_treeview
Gtk::ComboBox * banks_combobox
Gtk::Button * online_preset
Gtk::Label * preset_title
Gtk::TreeViewColumn * bank_column_spacer
Gtk::TreeModelColumn< Glib::ustring > name
Gtk::TreeViewColumn * preset_column_spacer
Glib::RefPtr< Gtk::AccelGroup > accelgroup
Gtk::CellRendererText * preset_cellrenderer
Gtk::TreeIter get_current_bank_iter()
Gtk::TreeViewColumn * preset_column_delete