diff --git a/gui/collection.cpp b/gui/collection.cpp index 613ae440..1233bf9f 100644 --- a/gui/collection.cpp +++ b/gui/collection.cpp @@ -20,11 +20,11 @@ public: CollectionTab :: CollectionTab() : Tab(library::get_queue()) { - tab_random = lib :: get_widget("o_collection_random"); - tab_search = lib :: get_widget("o_collection_entry"); - tab_size = lib :: get_widget("o_collection_size"); - tab_treeview = lib :: get_widget("o_collection_pq_treeview"); - tab_widget = lib :: get_widget("o_collection_page"); + tab_random = gui :: get_widget("o_collection_random"); + tab_search = gui :: get_widget("o_collection_entry"); + tab_size = gui :: get_widget("o_collection_size"); + tab_treeview = gui :: get_widget("o_collection_pq_treeview"); + tab_widget = gui :: get_widget("o_collection_page"); tab_finish_init(); } diff --git a/gui/gst.cpp b/gui/gst.cpp index 3c16be08..eff6ca32 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -208,22 +208,22 @@ void gst :: init(int *argc, char ***argv) gst_bus = gst_pipeline_get_bus(GST_PIPELINE(gst_player)); gst_driver = new GSTDriver(); - o_next = lib :: get_widget("o_next"); - o_pause = lib :: get_widget("o_pause"); - o_play = lib :: get_widget("o_play"); - o_prev = lib :: get_widget("o_prev"); - o_seek = lib :: get_widget("o_seek"); - o_stop = lib :: get_widget("o_stop"); + o_next = gui :: get_widget("o_next"); + o_pause = gui :: get_widget("o_pause"); + o_play = gui :: get_widget("o_play"); + o_prev = gui :: get_widget("o_prev"); + o_seek = gui :: get_widget("o_seek"); + o_stop = gui :: get_widget("o_stop"); - o_count = lib :: get_widget("o_pause_count"); - o_enabled = lib :: get_widget("o_pause_enabled"); + o_count = gui :: get_widget("o_pause_count"); + o_enabled = gui :: get_widget("o_pause_enabled"); - o_album = lib :: get_widget("o_album"); - o_artist = lib :: get_widget("o_artist"); - o_duration = lib :: get_widget("o_duration"); - o_position = lib :: get_widget("o_position"); - o_title = lib :: get_widget("o_title"); - o_progress = lib :: get_object("o_progress"); + o_album = gui :: get_widget("o_album"); + o_artist = gui :: get_widget("o_artist"); + o_duration = gui :: get_widget("o_duration"); + o_position = gui :: get_widget("o_position"); + o_title = gui :: get_widget("o_title"); + o_progress = gui :: get_object("o_progress"); o_next->signal_clicked().connect(sigc::ptr_fun(next)); o_pause->signal_clicked().connect(sigc::ptr_fun(audio :: pause)); diff --git a/gui/history.cpp b/gui/history.cpp index 6706db71..fd41c42d 100644 --- a/gui/history.cpp +++ b/gui/history.cpp @@ -15,10 +15,10 @@ public: HistoryTab :: HistoryTab() : Tab(deck :: get_queue()) { - tab_search = lib :: get_widget("o_history_entry"); - tab_size = lib :: get_widget("o_history_size"); - tab_treeview = lib :: get_widget("o_history_treeview"); - tab_widget = lib :: get_widget("o_history_page"); + tab_search = gui :: get_widget("o_history_entry"); + tab_size = gui :: get_widget("o_history_size"); + tab_treeview = gui :: get_widget("o_history_treeview"); + tab_widget = gui :: get_widget("o_history_page"); tab_finish_init(); } diff --git a/gui/main.cpp b/gui/main.cpp index 80469990..4a3728a0 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -7,11 +7,22 @@ #include #include + +namespace gui +{ + Glib::RefPtr __O_BUILDER; +} + + Gtk::Window *ocarina_init(int *argc, char ***argv) { Gtk::Window *window; - lib :: init(argc, argv, "ocarina6.glade"); + lib :: init(argc, argv); + + gui :: __O_BUILDER = Gtk::Builder::create(); + if (!gui :: __O_BUILDER->add_from_file(lib :: share_file("ocarina6.glade"))) + exit(1); gst :: init(argc, argv); plist :: init(); diff --git a/gui/manager.cpp b/gui/manager.cpp index 963067b5..1ae3aa97 100644 --- a/gui/manager.cpp +++ b/gui/manager.cpp @@ -175,14 +175,14 @@ static void on_toggled(const Glib::ustring &str) void manager :: init() { - c_add = lib :: get_widget("colmgr_add"); - c_update = lib :: get_widget("colmgr_update"); + c_add = gui :: get_widget("colmgr_add"); + c_update = gui :: get_widget("colmgr_update"); - c_chooser = lib :: get_widget("colmgr_chooser"); - c_progress = lib :: get_widget("o_idle_progress"); - c_toggle = lib :: get_object("colmgr_toggle"); - c_list = lib :: get_object("colmgr_list"); - c_treeview = lib :: get_widget("colmgr_treeview"); + c_chooser = gui :: get_widget("colmgr_chooser"); + c_progress = gui :: get_widget("o_idle_progress"); + c_toggle = gui :: get_object("colmgr_toggle"); + c_list = gui :: get_object("colmgr_list"); + c_treeview = gui :: get_widget("colmgr_treeview"); c_add->signal_clicked().connect(sigc::ptr_fun(on_add)); c_update->signal_clicked().connect(sigc::ptr_fun(on_update)); diff --git a/gui/playlist.cpp b/gui/playlist.cpp index 55ce2145..786ce4ef 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -26,9 +26,9 @@ static class PlaylistTab : public Tab { public: PlaylistTab() : Tab(playlist :: get_queue()) { - tab_search = lib :: get_widget("o_playlist_entry"); - tab_treeview = lib :: get_widget("o_playlist_pq_treeview"); - tab_widget = lib :: get_widget("o_playlist_page"); + tab_search = gui :: get_widget("o_playlist_entry"); + tab_treeview = gui :: get_widget("o_playlist_pq_treeview"); + tab_widget = gui :: get_widget("o_playlist_page"); tab_finish_init(); } @@ -111,14 +111,14 @@ void plist :: track_loaded(Track *track) void plist :: init() { p_tab = new PlaylistTab; - p_list = lib :: get_object("plist_list"); - p_treeview = lib :: get_widget("plist_treeview"); + p_list = gui :: get_object("plist_list"); + p_treeview = gui :: get_widget("plist_treeview"); p_treeview->signal_cursor_changed().connect(sigc::ptr_fun(on_cursor_changed)); p_treeview->signal_button_press_event().connect(sigc::ptr_fun(on_clicked)); - o_ban = lib :: get_widget("o_ban"); - o_fav = lib :: get_widget("o_favorite"); + o_ban = gui :: get_widget("o_ban"); + o_fav = gui :: get_widget("o_favorite"); o_ban->signal_toggled().connect(sigc::ptr_fun(on_ban)); o_fav->signal_toggled().connect(sigc::ptr_fun(on_favorite)); diff --git a/gui/queue.cpp b/gui/queue.cpp index f0711c3d..198ad424 100644 --- a/gui/queue.cpp +++ b/gui/queue.cpp @@ -165,8 +165,8 @@ QueueTab :: QueueTab(Queue *pq, unsigned int num) tab_finish_init(); queue_mapping[tab_widget] = this; - lib :: get_widget("o_notebook")->insert_page(q_vbox, q_tab_box, num); - lib :: get_widget("o_notebook")->set_tab_reorderable(q_vbox); + gui :: get_widget("o_notebook")->insert_page(q_vbox, q_tab_box, num); + gui :: get_widget("o_notebook")->set_tab_reorderable(q_vbox); q_vbox.show_all(); } @@ -174,7 +174,7 @@ QueueTab :: ~QueueTab() { queue_mapping.erase(tab_widget); tab_unmap(); - lib :: get_widget("o_notebook")->remove_page(q_vbox); + gui :: get_widget("o_notebook")->remove_page(q_vbox); } @@ -336,7 +336,7 @@ static void on_pq_removed(Queue *pq) static void on_page_reordered(Gtk::Widget *page, int num) { - Gtk::Notebook *notebook = lib :: get_widget("o_notebook"); + Gtk::Notebook *notebook = gui :: get_widget("o_notebook"); if ((unsigned int)num >= deck :: get_queues().size()) { notebook->reorder_child(*page, deck::get_queues().size() - 1); @@ -356,7 +356,7 @@ void init_queue_tabs() struct Callbacks *cb = get_callbacks(); cb->on_pq_removed = on_pq_removed; - Gtk::Notebook *notebook = lib :: get_widget("o_notebook"); + Gtk::Notebook *notebook = gui :: get_widget("o_notebook"); notebook->signal_page_reordered().connect(sigc::ptr_fun(on_page_reordered)); } diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 54911164..28edde7e 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -96,20 +96,20 @@ void Tab :: tab_toggle_button(Gtk::ToggleButton *button, queue_flags flag) int Tab :: tab_page_num() { - Gtk::Notebook *notebook = lib :: get_widget("o_notebook"); + Gtk::Notebook *notebook = gui :: get_widget("o_notebook"); return notebook->page_num(*tab_widget); } bool Tab :: tab_is_cur() { - Gtk::Notebook *notebook = lib :: get_widget("o_notebook"); + Gtk::Notebook *notebook = gui :: get_widget("o_notebook"); return notebook->page_num(*tab_widget) == notebook->get_current_page(); } void Tab :: tab_runtime_changed() { if (tab_is_cur()) - lib :: get_widget("o_queue_time")->set_text(tab_pq->length_str()); + gui :: get_widget("o_queue_time")->set_text(tab_pq->length_str()); } void Tab :: tab_display_sorting() @@ -117,7 +117,7 @@ void Tab :: tab_display_sorting() std::string text = ""; if ((tab_sorting_count > 0) && tab_is_cur()) text = "Sorting within " + tab_sorting_title; - lib :: get_widget("o_sorting_indicator")->set_text(text); + gui :: get_widget("o_sorting_indicator")->set_text(text); } void Tab :: tab_dec_sort_count() @@ -258,23 +258,23 @@ void Tab :: on_show_rc_menu() unsigned int size = deck :: get_queues().size(); if (size == 0) { - lib :: get_widget("o_add_to_pq")->hide(); + gui :: get_widget("o_add_to_pq")->hide(); return; } - lib :: get_widget("o_add_to_pq")->show(); + gui :: get_widget("o_add_to_pq")->show(); if (size == 10) - lib :: get_widget("o_new_pq")->hide(); + gui :: get_widget("o_new_pq")->hide(); else - lib :: get_widget("o_new_pq")->show(); + gui :: get_widget("o_new_pq")->show(); for (unsigned int i = 0; i < 10; i++) { item = "o_pq_"; item += '0' + i; if (i < size) - lib :: get_widget(item)->show(); + gui :: get_widget(item)->show(); else - lib :: get_widget(item)->hide(); + gui :: get_widget(item)->hide(); } } @@ -338,7 +338,7 @@ bool Tab :: on_button_pressed(GdkEventButton *button) tab_treeview->get_selection()->select(path); on_show_rc_menu(); - lib :: get_widget("o_rc_menu")->popup(button->button, button->time); + gui :: get_widget("o_rc_menu")->popup(button->button, button->time); return true; } @@ -440,12 +440,12 @@ static void on_switch_page(Gtk::Widget *page, int num) tab->tab_runtime_changed(); tab->tab_display_sorting(); } else - lib :: get_widget("o_queue_time")->set_text(""); + gui :: get_widget("o_queue_time")->set_text(""); } void tab_focus_search() { - int page = lib :: get_widget("o_notebook")->get_current_page(); + int page = gui :: get_widget("o_notebook")->get_current_page(); Tab *tab = find_tab(page); if (tab) tab->tab_focus_search(); @@ -482,7 +482,7 @@ static void on_add_to_queue(unsigned int n) static void init_menu_item(const std::string &pq, unsigned int n) { - lib :: get_widget(pq)->signal_activate().connect( + gui :: get_widget(pq)->signal_activate().connect( sigc::bind (sigc::ptr_fun(on_add_to_queue), n)); } @@ -494,16 +494,16 @@ void init_tabs() cb->on_queue_track_changed = on_track_changed; /* Notebook signals */ - struct Gtk::Notebook *notebook = lib :: get_widget("o_notebook"); + struct Gtk::Notebook *notebook = gui :: get_widget("o_notebook"); notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page)); /* Menu signals */ - lib :: get_widget("o_rc_menu")->show_all(); - lib :: get_widget("o_new_pq")->signal_activate().connect( + gui :: get_widget("o_rc_menu")->show_all(); + gui :: get_widget("o_new_pq")->signal_activate().connect( sigc::ptr_fun(on_new_pq)); - lib :: get_widget("o_add_to_favorites")->signal_activate().connect( + gui :: get_widget("o_add_to_favorites")->signal_activate().connect( sigc::ptr_fun(on_add_to_favs)); - lib :: get_widget("o_add_to_banned")->signal_activate().connect( + gui :: get_widget("o_add_to_banned")->signal_activate().connect( sigc::ptr_fun(on_add_to_banned)); for (unsigned int i = 0; i < 10; i++) { std::string pq = "o_pq_"; @@ -530,7 +530,7 @@ void post_init_tabs() if ((deck :: get(tab)->has_flag(Q_ENABLED))) break; } - lib :: get_widget("o_notebook")->set_current_page(tab); + gui :: get_widget("o_notebook")->set_current_page(tab); } void cleanup_tabs() diff --git a/gui/window.cpp b/gui/window.cpp index 4ce49dc2..0cf6566d 100644 --- a/gui/window.cpp +++ b/gui/window.cpp @@ -11,8 +11,8 @@ const std::string appname = "Ocarina "; static bool on_window_key_pressed(GdkEventKey *event) { - Gtk::Notebook *notebook = lib :: get_widget("o_notebook"); - Gtk::Window *window = lib :: get_widget("o_window"); + Gtk::Notebook *notebook = gui :: get_widget("o_notebook"); + Gtk::Window *window = gui :: get_widget("o_window"); std::string key = gdk_keyval_name(event->keyval); if (key.size() >= 3) { @@ -58,7 +58,7 @@ static bool on_window_key_released(GdkEventKey *event) Gtk::Window *window_init() { - Gtk::Window *window = lib :: get_widget("o_window"); + Gtk::Window *window = gui :: get_widget("o_window"); window->set_can_focus(); window->set_title(appname + get_version()); diff --git a/include/gui/ocarina.h b/include/gui/ocarina.h index 288331c9..885d186f 100644 --- a/include/gui/ocarina.h +++ b/include/gui/ocarina.h @@ -9,6 +9,25 @@ /* main.cpp */ +namespace gui +{ + extern Glib::RefPtr __O_BUILDER; + + template + static inline T *get_widget(const std::string &name) + { + T *widget; + __O_BUILDER->get_widget(name, widget); + return widget; + } + + template + static inline Glib::RefPtr get_object(const std::string &name) + { + return Glib::RefPtr::cast_static(__O_BUILDER->get_object(name)); + } +} + Gtk::Window *ocarina_init(int *, char ***); diff --git a/include/lib/lib.h b/include/lib/lib.h index 2138a8f2..c1f813ad 100644 --- a/include/lib/lib.h +++ b/include/lib/lib.h @@ -10,23 +10,8 @@ namespace lib { - void init(int *, char ***, const std::string &); + void init(int *, char ***); const std::string share_file(const std::string &); - Glib::RefPtr &get_builder(); - - template - static inline T *get_widget(const std::string &name) - { - T *widget; - get_builder()->get_widget(name, widget); - return widget; - } - - template - static inline Glib::RefPtr get_object(const std::string &name) - { - return Glib::RefPtr::cast_static(get_builder()->get_object(name)); - } } diff --git a/lib/lib.cpp b/lib/lib.cpp index 97e75eff..54d2110b 100644 --- a/lib/lib.cpp +++ b/lib/lib.cpp @@ -5,7 +5,6 @@ #include #include -static Glib::RefPtr builder; static std::string share_dir = ""; static void setup_share(const std::string &path) @@ -22,21 +21,12 @@ static void setup_share(const std::string &path) share_dir = share_dir + "share/ocarina/"; } -void lib :: init(int *argc, char ***argv, const std::string >k_xml) +void lib :: init(int *argc, char ***argv) { setup_share((*argv)[0]); - - builder = Gtk::Builder::create(); - if (!builder->add_from_file(lib :: share_file(gtk_xml))) - exit(1); } const std::string lib :: share_file(const std::string &f) { return share_dir + f; } - -Glib::RefPtr &lib :: get_builder() -{ - return builder; -}