gui: Improve functions for accessing widgets
I made a couple of templated functions to get widgets and objects out of the Gtk::Builder easier. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
3eb5bd3adb
commit
480cf92519
|
@ -39,16 +39,16 @@ static void on_config_pause()
|
|||
|
||||
static void on_play()
|
||||
{
|
||||
get_button("o_play")->hide();
|
||||
get_button("o_pause")->show();
|
||||
get_widget<Gtk::Button>("o_play")->hide();
|
||||
get_widget<Gtk::Button>("o_pause")->show();
|
||||
audio_playing = true;
|
||||
enable_timeout();
|
||||
}
|
||||
|
||||
static void on_pause()
|
||||
{
|
||||
get_button("o_play")->show();
|
||||
get_button("o_pause")->hide();
|
||||
get_widget<Gtk::Button>("o_play")->show();
|
||||
get_widget<Gtk::Button>("o_pause")->hide();
|
||||
audio_playing = false;
|
||||
}
|
||||
|
||||
|
@ -243,9 +243,8 @@ static void on_collection_row_activated(const Gtk::TreePath &path,
|
|||
Gtk::TreeViewColumn *col)
|
||||
{
|
||||
Gtk::FileChooser *chooser;
|
||||
Glib::RefPtr<Gtk::ListStore> list;
|
||||
Glib::RefPtr<Gtk::ListStore> list = get_object<Gtk::ListStore>("o_collection_dirs");
|
||||
|
||||
get_object("o_collection_dirs", list);
|
||||
builder->get_widget("o_collection_chooser", chooser);
|
||||
|
||||
Gtk::TreeModel::Row row = *(list->get_iter(path));
|
||||
|
@ -265,8 +264,7 @@ void do_collection_delete()
|
|||
builder->get_widget("o_collection_treeview", treeview);
|
||||
treeview->get_cursor(path, col);
|
||||
if (path) {
|
||||
Glib::RefPtr<Gtk::ListStore> list;
|
||||
get_object("o_collection_dirs", list);
|
||||
Glib::RefPtr<Gtk::ListStore> list = get_object<Gtk::ListStore>("o_collection_dirs");
|
||||
Gtk::TreeModel::Row row = *(list->get_iter(path));
|
||||
library :: del_path(row[collection_cols.c_col_id]);
|
||||
list->erase(row);
|
||||
|
@ -288,8 +286,7 @@ static
|
|||
#endif /* CONFIG_TEST */
|
||||
void on_collection_toggled(const Glib::ustring &path)
|
||||
{
|
||||
Glib::RefPtr<Gtk::ListStore> list;
|
||||
get_object("o_collection_dirs", list);
|
||||
Glib::RefPtr<Gtk::ListStore> list = get_object<Gtk::ListStore>("o_collection_dirs");
|
||||
Gtk::TreeModel::Row row = *(list->get_iter(path));
|
||||
row[collection_cols.c_col_enabled] = !row[collection_cols.c_col_enabled];
|
||||
library :: set_enabled(row[collection_cols.c_col_id],
|
||||
|
@ -299,8 +296,7 @@ void on_collection_toggled(const Glib::ustring &path)
|
|||
static void on_library_add(unsigned int id, library :: Library *path)
|
||||
{
|
||||
Gtk::TreeModel::Row row;
|
||||
Glib::RefPtr<Gtk::ListStore> list;
|
||||
get_object("o_collection_dirs", list);
|
||||
Glib::RefPtr<Gtk::ListStore> list = get_object<Gtk::ListStore>("o_collection_dirs");
|
||||
|
||||
row = *(list->append());
|
||||
row[collection_cols.c_col_id] = id;
|
||||
|
@ -312,8 +308,7 @@ static void on_library_add(unsigned int id, library :: Library *path)
|
|||
static void on_library_update(unsigned int id, library :: Library *path)
|
||||
{
|
||||
Gtk::TreeModel::Row row;
|
||||
Glib::RefPtr<Gtk::ListStore> list;
|
||||
get_object("o_collection_dirs", list);
|
||||
Glib::RefPtr<Gtk::ListStore> list = get_object<Gtk::ListStore>("o_collection_dirs");
|
||||
Gtk::TreeModel::Children children = list->children();
|
||||
|
||||
for (Gtk::TreeModel::Children::iterator it = children.begin();
|
||||
|
@ -356,11 +351,8 @@ void enable_idle()
|
|||
*/
|
||||
bool on_timeout()
|
||||
{
|
||||
Gtk::Label *position;
|
||||
Glib::RefPtr<Gtk::Adjustment> bar;
|
||||
|
||||
builder->get_widget("o_cur_position", position);
|
||||
get_object("o_progress", bar);
|
||||
Gtk::Label *position = get_widget<Gtk::Label>("o_cur_position");
|
||||
Glib::RefPtr<Gtk::Adjustment> bar = get_object<Gtk::Adjustment>("o_progress");
|
||||
|
||||
position->set_text(audio :: position_str());
|
||||
bar->set_upper(audio :: duration());
|
||||
|
@ -383,22 +375,9 @@ Glib::RefPtr<Gtk::Builder> &get_builder()
|
|||
return builder;
|
||||
}
|
||||
|
||||
Gtk::Button *get_button(const std::string &name)
|
||||
{
|
||||
Gtk::Button *button;
|
||||
builder->get_widget(name, button);
|
||||
return button;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void get_object(const std::string &name, Glib::RefPtr<T> &obj)
|
||||
{
|
||||
obj = Glib::RefPtr<T>::cast_static(builder->get_object(name));
|
||||
}
|
||||
|
||||
static void connect_button(const std::string &name, void (*func)())
|
||||
{
|
||||
get_button(name)->signal_clicked().connect(sigc::ptr_fun(func));
|
||||
get_widget<Gtk::Button>(name)->signal_clicked().connect(sigc::ptr_fun(func));
|
||||
}
|
||||
|
||||
Gtk::Window *connect_wires()
|
||||
|
@ -425,7 +404,7 @@ Gtk::Window *connect_wires()
|
|||
cb->on_track_loaded = on_track_loaded;
|
||||
cb->on_pause_count_changed = on_pause_count_changed;
|
||||
|
||||
builder->get_widget("o_pause_count", count);
|
||||
count = get_widget<Gtk::SpinButton>("o_pause_count");
|
||||
builder->get_widget("o_pause_enabled", enabled);
|
||||
builder->get_widget("o_position_scale", position);
|
||||
count->signal_changed().connect(sigc::ptr_fun(on_config_pause));
|
||||
|
@ -448,11 +427,11 @@ Gtk::Window *connect_wires()
|
|||
/* Collection manager */
|
||||
cb->on_library_add = on_library_add;
|
||||
cb->on_library_update = on_library_update;
|
||||
get_object("o_collection_dirs", list);
|
||||
list = get_object<Gtk::ListStore>("o_collection_dirs");
|
||||
list->set_sort_column(collection_cols.c_col_path, Gtk::SORT_ASCENDING);
|
||||
|
||||
builder->get_widget("o_collection_treeview", treeview);
|
||||
get_object("o_collection_toggle", toggle);
|
||||
toggle = get_object<Gtk::CellRendererToggle>("o_collection_toggle");
|
||||
treeview->signal_row_activated().connect(sigc::ptr_fun(on_collection_row_activated));
|
||||
treeview->signal_key_press_event().connect(sigc::ptr_fun(on_collection_key_pressed));
|
||||
toggle->signal_toggled().connect(sigc::ptr_fun(on_collection_toggled));
|
||||
|
|
|
@ -60,6 +60,22 @@ Gtk::Window *connect_wires();
|
|||
Gtk::Button *get_button(const std::string &);
|
||||
Glib::RefPtr<Gtk::Builder> &get_builder();
|
||||
|
||||
template <class T>
|
||||
static T *get_widget(const std::string &name)
|
||||
{
|
||||
T *widget;
|
||||
get_builder()->get_widget(name, widget);
|
||||
return widget;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static Glib::RefPtr<T> get_object(const std::string &name)
|
||||
{
|
||||
return Glib::RefPtr<T>::cast_static(get_builder()->get_object(name));
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef CONFIG_TEST
|
||||
void do_collection_delete();
|
||||
void on_collection_toggled(const Glib::ustring &);
|
||||
|
|
Loading…
Reference in New Issue