From 194a09bed4d8c7fce84021c2309b02061cb64faf Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sun, 15 Jun 2014 11:30:33 -0400 Subject: [PATCH] lib: Initialize the GtkBuilder from the middle layer This will provide an interface for accessing widgets, and make it easier to swap out different builder files. Signed-off-by: Anna Schumaker --- Sconstruct | 1 + gui/Sconscript | 4 --- gui/collection.cpp | 11 +++---- gui/collection_mgr.cpp | 12 ++++---- gui/gui.cpp | 66 ++++++++++++++++++------------------------ gui/history.cpp | 8 ++--- gui/main.cpp | 6 ++-- gui/playlist.cpp | 10 +++---- gui/queue.cpp | 10 +++---- gui/tabs.cpp | 40 ++++++++++++------------- include/gui/ocarina.h | 17 +---------- include/gui/tabs.h | 1 + include/lib/lib.h | 23 ++++++++++++++- lib/Sconscript | 2 ++ lib/lib.cpp | 13 ++++++++- tests/Sconscript | 2 +- tests/lib/Sconscript | 6 ++-- tests/lib/lib.cpp | 13 +++++++-- 18 files changed, 130 insertions(+), 115 deletions(-) diff --git a/Sconstruct b/Sconstruct index a65c41ec..c5739d64 100644 --- a/Sconstruct +++ b/Sconstruct @@ -23,6 +23,7 @@ class OEnvironment(Environment): def __init__(self, CCFLAGS = CONFIG_CCFLAGS): Environment.__init__(self, CCFLAGS = CCFLAGS) + self.Append(ENV = os.environ) self.Append(CPPPATH = os.path.abspath("include")) self.Append(CXXCOMSTR = "C++ $TARGET") self.Append(LINKCOMSTR = "Linking $TARGET") diff --git a/gui/Sconscript b/gui/Sconscript index abc00633..10f42567 100644 --- a/gui/Sconscript +++ b/gui/Sconscript @@ -1,7 +1,3 @@ #!/usr/bin/python -Import("env") - -env.UsePackage("gtkmm-3.0") - res = Glob("*.cpp") Return("res") diff --git a/gui/collection.cpp b/gui/collection.cpp index 801406d3..ce6768ce 100644 --- a/gui/collection.cpp +++ b/gui/collection.cpp @@ -5,6 +5,7 @@ #include #include #include +#include class CollectionTab : public Tab { @@ -19,11 +20,11 @@ public: CollectionTab :: CollectionTab() : Tab(library::get_queue()) { - tab_random = get_widget("o_collection_random"); - tab_search = get_widget("o_collection_entry"); - tab_size = get_widget("o_collection_size"); - tab_treeview = get_widget("o_collection_pq_treeview"); - tab_widget = get_widget("o_collection_page"); + 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_finish_init(); } diff --git a/gui/collection_mgr.cpp b/gui/collection_mgr.cpp index 6cafc087..e8a5869a 100644 --- a/gui/collection_mgr.cpp +++ b/gui/collection_mgr.cpp @@ -20,7 +20,7 @@ public: static Glib::RefPtr get_collection_list() { - return get_object("o_collection_dirs"); + return lib :: get_object("o_collection_dirs"); } static void on_collection_ok() @@ -28,7 +28,7 @@ static void on_collection_ok() std::string path; Gtk::FileChooserWidget *chooser; - chooser = get_widget("o_collection_chooser"); + chooser = lib :: get_widget("o_collection_chooser"); path = chooser->get_filename(); Library *library = library::add(path); enable_idle(); @@ -44,7 +44,7 @@ static void on_collection_update() static void on_collection_row_activated(const Gtk::TreePath &path, Gtk::TreeViewColumn *col) { - Gtk::FileChooser *chooser = get_widget("o_collection_chooser"); + Gtk::FileChooser *chooser = lib :: get_widget("o_collection_chooser"); Glib::RefPtr list = get_collection_list(); Gtk::TreeModel::Row row = *(list->get_iter(path)); @@ -59,7 +59,7 @@ void do_collection_delete() { Gtk::TreePath path; Gtk::TreeViewColumn *col; - Gtk::TreeView *treeview = get_widget("o_collection_treeview"); + Gtk::TreeView *treeview = lib :: get_widget("o_collection_treeview"); treeview->get_cursor(path, col); if (path) { @@ -120,11 +120,11 @@ static void on_library_update(unsigned int id, Library *library) void collection_mgr_init() { - Gtk::TreeView *treeview = get_widget("o_collection_treeview"); + Gtk::TreeView *treeview = lib :: get_widget("o_collection_treeview"); Glib::RefPtr list = get_collection_list(); Glib::RefPtr toggle; - toggle = get_object("o_collection_toggle"); + toggle = lib :: get_object("o_collection_toggle"); connect_button("o_collection_ok", on_collection_ok); connect_button("o_collection_update", on_collection_update); diff --git a/gui/gui.cpp b/gui/gui.cpp index 1993da1b..324d45fd 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -14,7 +14,6 @@ #include static bool audio_playing = false; -static Glib::RefPtr builder; static sigc::connection fav_connection; static sigc::connection ban_connection; void enable_timeout(); @@ -26,24 +25,24 @@ void enable_timeout(); */ static void on_config_pause() { - Gtk::SpinButton *count = get_widget("o_pause_count"); - Gtk::CheckButton *enabled = get_widget("o_pause_enabled"); + Gtk::SpinButton *count = lib :: get_widget("o_pause_count"); + Gtk::CheckButton *enabled = lib :: get_widget("o_pause_enabled"); audio :: pause_after(enabled->get_active(), count->get_value()); } static void on_play() { - get_widget("o_play")->hide(); - get_widget("o_pause")->show(); + lib :: get_widget("o_play")->hide(); + lib :: get_widget("o_pause")->show(); audio_playing = true; enable_timeout(); } static void on_pause() { - get_widget("o_play")->show(); - get_widget("o_pause")->hide(); + lib :: get_widget("o_play")->show(); + lib :: get_widget("o_pause")->hide(); audio_playing = false; } @@ -68,12 +67,12 @@ static void set_label_text(Gtk::Label *label, const std::string &size, static void on_track_loaded(Track *track) { - Gtk::ToggleButton *ban = get_widget("o_ban"); - Gtk::ToggleButton *fav = get_widget("o_favorite"); - Gtk::Label *title = get_widget("o_title"); - Gtk::Label *artist = get_widget("o_artist"); - Gtk::Label *album = get_widget("o_album"); - Gtk::Label *duration = get_widget("o_total_time"); + Gtk::ToggleButton *ban = lib :: get_widget("o_ban"); + Gtk::ToggleButton *fav = lib :: get_widget("o_favorite"); + Gtk::Label *title = lib :: get_widget("o_title"); + Gtk::Label *artist = lib :: get_widget("o_artist"); + Gtk::Label *album = lib :: get_widget("o_album"); + Gtk::Label *duration = lib :: get_widget("o_total_time"); set_label_text(title, "xx-large", track->title); set_label_text(artist, "x-large", "By: " + track->artist->name); @@ -95,8 +94,8 @@ static void on_track_loaded(Track *track) static void on_pause_count_changed(bool enabled, unsigned int count) { - Gtk::CheckButton *p_enabled = get_widget("o_pause_enabled"); - Gtk::SpinButton *p_count = get_widget("o_pause_count");; + Gtk::CheckButton *p_enabled = lib :: get_widget("o_pause_enabled"); + Gtk::SpinButton *p_count = lib :: get_widget("o_pause_count");; if (p_enabled->get_active() != enabled) p_enabled->set_active(enabled); @@ -106,7 +105,7 @@ static void on_pause_count_changed(bool enabled, unsigned int count) static void on_ban_toggled() { - Gtk::ToggleButton *ban = get_widget("o_ban"); + Gtk::ToggleButton *ban = lib :: get_widget("o_ban"); if (ban->get_active() == true) playlist :: add(audio :: current_track(), "Banned"); @@ -116,7 +115,7 @@ static void on_ban_toggled() static void on_fav_toggled() { - Gtk::ToggleButton *fav = get_widget("o_favorite"); + Gtk::ToggleButton *fav = lib :: get_widget("o_favorite"); if (fav->get_active() == true) playlist :: add(audio::current_track(), "Favorites"); @@ -131,8 +130,8 @@ static void on_fav_toggled() */ static bool on_window_key_pressed(GdkEventKey *event) { - Gtk::Notebook *notebook = get_widget("o_notebook"); - Gtk::Window *window = get_widget("o_window"); + Gtk::Notebook *notebook = lib :: get_widget("o_notebook"); + Gtk::Window *window = lib :: get_widget("o_window"); std::string key = gdk_keyval_name(event->keyval); if (key.size() >= 3) { @@ -186,7 +185,7 @@ static bool on_window_key_released(GdkEventKey *event) */ bool on_idle() { - Gtk::ProgressBar *prog = get_widget("o_idle_progress"); + Gtk::ProgressBar *prog = lib :: get_widget("o_idle_progress"); bool ret = idle::run_task(); if (ret == false) @@ -212,8 +211,8 @@ void enable_idle() */ bool on_timeout() { - Gtk::Label *position = get_widget("o_cur_position"); - Glib::RefPtr bar = get_object("o_progress"); + Gtk::Label *position = lib :: get_widget("o_cur_position"); + Glib::RefPtr bar = lib :: get_object("o_progress"); position->set_text(audio :: position_str()); bar->set_upper(audio :: duration()); @@ -231,28 +230,19 @@ void enable_timeout() /* * Ocarina functions */ -Glib::RefPtr &get_builder() -{ - return builder; -} - void connect_button(const std::string &name, void (*func)()) { - get_widget(name)->signal_clicked().connect(sigc::ptr_fun(func)); + lib :: get_widget(name)->signal_clicked().connect(sigc::ptr_fun(func)); } Gtk::Window *setup_gui() { struct Callbacks *cb = get_callbacks(); - builder = Gtk::Builder::create(); - builder->add_from_file(lib :: share_file("ocarina6.glade")); - - /* Controls */ - Gtk::SpinButton *count = get_widget("o_pause_count"); - Gtk::CheckButton *enabled = get_widget("o_pause_enabled"); - Gtk::Scale *position = get_widget("o_position_scale"); + Gtk::SpinButton *count = lib :: get_widget("o_pause_count"); + Gtk::CheckButton *enabled = lib :: get_widget("o_pause_enabled"); + Gtk::Scale *position = lib :: get_widget("o_position_scale"); cb->on_play = on_play; cb->on_pause = on_pause; @@ -271,7 +261,7 @@ Gtk::Window *setup_gui() /* Keyboard shortcuts */ - Gtk::Window *window = get_widget("o_window"); + Gtk::Window *window = lib :: get_widget("o_window"); window->signal_key_press_event().connect(sigc::ptr_fun(on_window_key_pressed)); window->signal_key_release_event().connect(sigc::ptr_fun(on_window_key_released)); @@ -280,8 +270,8 @@ Gtk::Window *setup_gui() /* Favorite and ban buttons */ - Gtk::ToggleButton *ban = get_widget("o_ban"); - Gtk::ToggleButton *fav = get_widget("o_favorite"); + Gtk::ToggleButton *ban = lib :: get_widget("o_ban"); + Gtk::ToggleButton *fav = lib :: get_widget("o_favorite"); ban_connection = ban->signal_toggled().connect(sigc::ptr_fun(on_ban_toggled)); fav_connection = fav->signal_toggled().connect(sigc::ptr_fun(on_fav_toggled)); diff --git a/gui/history.cpp b/gui/history.cpp index 6290034f..6706db71 100644 --- a/gui/history.cpp +++ b/gui/history.cpp @@ -15,10 +15,10 @@ public: HistoryTab :: HistoryTab() : Tab(deck :: get_queue()) { - tab_search = get_widget("o_history_entry"); - tab_size = get_widget("o_history_size"); - tab_treeview = get_widget("o_history_treeview"); - tab_widget = get_widget("o_history_page"); + 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_finish_init(); } diff --git a/gui/main.cpp b/gui/main.cpp index 6e1a6446..ee638b8d 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -8,10 +8,10 @@ Gtk::Window *ocarina_init(int *argc, char ***argv) { + + lib :: init(argc, argv, "ocarina6.glade"); + Gtk::Window *window = setup_gui(); - - lib :: init(argc, argv); - playlist :: select("Favorites"); post_init_tabs(); collection_mgr_init2(); diff --git a/gui/playlist.cpp b/gui/playlist.cpp index d9982f9f..ba78c35b 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -22,9 +22,9 @@ public: PlaylistTab :: PlaylistTab() : Tab(playlist :: get_queue()) { - tab_search = get_widget("o_playlist_entry"); - tab_treeview = get_widget("o_playlist_pq_treeview"); - tab_widget = get_widget("o_playlist_page"); + 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_finish_init(); } @@ -95,8 +95,8 @@ static PlaylistTab *playlist_tab; void init_playlist_tab() { playlist_tab = new PlaylistTab; - playlist_ls = get_object("o_playlists"); - playlist_tv = get_widget("o_playlist_treeview"); + playlist_ls = lib :: get_object("o_playlists"); + playlist_tv = lib :: get_widget("o_playlist_treeview"); playlist_tv->signal_cursor_changed().connect(sigc::ptr_fun(on_playlist_cursor_changed)); playlist_tv->signal_button_press_event().connect(sigc::ptr_fun(on_playlist_clicked)); diff --git a/gui/queue.cpp b/gui/queue.cpp index 29449288..f0711c3d 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; - get_widget("o_notebook")->insert_page(q_vbox, q_tab_box, num); - get_widget("o_notebook")->set_tab_reorderable(q_vbox); + lib :: get_widget("o_notebook")->insert_page(q_vbox, q_tab_box, num); + lib :: 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(); - get_widget("o_notebook")->remove_page(q_vbox); + lib :: 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 = get_widget("o_notebook"); + Gtk::Notebook *notebook = lib :: 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 = get_widget("o_notebook"); + Gtk::Notebook *notebook = lib :: 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 e47b503e..053a0dad 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -93,20 +93,20 @@ void Tab :: tab_toggle_button(Gtk::ToggleButton *button, queue_flags flag) int Tab :: tab_page_num() { - Gtk::Notebook *notebook = get_widget("o_notebook"); + Gtk::Notebook *notebook = lib :: get_widget("o_notebook"); return notebook->page_num(*tab_widget); } bool Tab :: tab_is_cur() { - Gtk::Notebook *notebook = get_widget("o_notebook"); + Gtk::Notebook *notebook = lib :: get_widget("o_notebook"); return notebook->page_num(*tab_widget) == notebook->get_current_page(); } void Tab :: tab_runtime_changed() { if (tab_is_cur()) - get_widget("o_queue_time")->set_text(tab_pq->length_str()); + lib :: get_widget("o_queue_time")->set_text(tab_pq->length_str()); } void Tab :: tab_display_sorting() @@ -114,7 +114,7 @@ void Tab :: tab_display_sorting() std::string text = ""; if ((tab_sorting_count > 0) && tab_is_cur()) text = "Sorting within " + tab_sorting_title; - get_widget("o_sorting_indicator")->set_text(text); + lib :: get_widget("o_sorting_indicator")->set_text(text); } void Tab :: tab_dec_sort_count() @@ -255,23 +255,23 @@ void Tab :: on_show_rc_menu() unsigned int size = deck :: get_queues().size(); if (size == 0) { - get_widget("o_add_to_pq")->hide(); + lib :: get_widget("o_add_to_pq")->hide(); return; } - get_widget("o_add_to_pq")->show(); + lib :: get_widget("o_add_to_pq")->show(); if (size == 10) - get_widget("o_new_pq")->hide(); + lib :: get_widget("o_new_pq")->hide(); else - get_widget("o_new_pq")->show(); + lib :: get_widget("o_new_pq")->show(); for (unsigned int i = 0; i < 10; i++) { item = "o_pq_"; item += '0' + i; if (i < size) - get_widget(item)->show(); + lib :: get_widget(item)->show(); else - get_widget(item)->hide(); + lib :: get_widget(item)->hide(); } } @@ -335,7 +335,7 @@ bool Tab :: on_button_pressed(GdkEventButton *button) tab_treeview->get_selection()->select(path); on_show_rc_menu(); - get_widget("o_rc_menu")->popup(button->button, button->time); + lib :: get_widget("o_rc_menu")->popup(button->button, button->time); return true; } @@ -437,12 +437,12 @@ static void on_switch_page(Gtk::Widget *page, int num) tab->tab_runtime_changed(); tab->tab_display_sorting(); } else - get_widget("o_queue_time")->set_text(""); + lib :: get_widget("o_queue_time")->set_text(""); } void tab_focus_search() { - int page = get_widget("o_notebook")->get_current_page(); + int page = lib :: get_widget("o_notebook")->get_current_page(); Tab *tab = find_tab(page); if (tab) tab->tab_focus_search(); @@ -479,7 +479,7 @@ static void on_add_to_queue(unsigned int n) static void init_menu_item(const std::string &pq, unsigned int n) { - get_widget(pq)->signal_activate().connect( + lib :: get_widget(pq)->signal_activate().connect( sigc::bind (sigc::ptr_fun(on_add_to_queue), n)); } @@ -491,16 +491,16 @@ void init_tabs() cb->on_queue_track_changed = on_track_changed; /* Notebook signals */ - struct Gtk::Notebook *notebook = get_widget("o_notebook"); + struct Gtk::Notebook *notebook = lib :: get_widget("o_notebook"); notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page)); /* Menu signals */ - get_widget("o_rc_menu")->show_all(); - get_widget("o_new_pq")->signal_activate().connect( + lib :: get_widget("o_rc_menu")->show_all(); + lib :: get_widget("o_new_pq")->signal_activate().connect( sigc::ptr_fun(on_new_pq)); - get_widget("o_add_to_favorites")->signal_activate().connect( + lib :: get_widget("o_add_to_favorites")->signal_activate().connect( sigc::ptr_fun(on_add_to_favs)); - get_widget("o_add_to_banned")->signal_activate().connect( + lib :: 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_"; @@ -528,7 +528,7 @@ void post_init_tabs() if ((deck :: get(tab)->has_flag(Q_ENABLED))) break; } - get_widget("o_notebook")->set_current_page(tab); + lib :: get_widget("o_notebook")->set_current_page(tab); } void cleanup_tabs() diff --git a/include/gui/ocarina.h b/include/gui/ocarina.h index e00f5d3b..4716fd73 100644 --- a/include/gui/ocarina.h +++ b/include/gui/ocarina.h @@ -5,7 +5,7 @@ #define OCARINA_H #include -#include +#include /* collection_mgr.cpp */ @@ -61,21 +61,6 @@ public: void enable_idle(); void connect_button(const std::string &, void (*func)()); Gtk::Window *setup_gui(); -Glib::RefPtr &get_builder(); - -template -static T *get_widget(const std::string &name) -{ - T *widget; - get_builder()->get_widget(name, widget); - return widget; -} - -template -static Glib::RefPtr get_object(const std::string &name) -{ - return Glib::RefPtr::cast_static(get_builder()->get_object(name)); -} void on_pq_created(Queue *, unsigned int); void post_init_queue_tabs(); diff --git a/include/gui/tabs.h b/include/gui/tabs.h index 6ba20c44..3230f2bc 100644 --- a/include/gui/tabs.h +++ b/include/gui/tabs.h @@ -4,6 +4,7 @@ #ifndef OCARINA_TABS_H #define OCARINA_TABS_H +#include #include #include #include diff --git a/include/lib/lib.h b/include/lib/lib.h index a6b64ca3..2138a8f2 100644 --- a/include/lib/lib.h +++ b/include/lib/lib.h @@ -1,12 +1,33 @@ /* * Copyright 2014 (c) Anna Schumaker. */ +#ifndef OCARINA_LIB_LIB_H +#define OCARINA_LIB_LIB_H + #include +#include namespace lib { - void init(int *, char ***); + void init(int *, char ***, const std::string &); 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)); + } } + +#endif /* OCARINA_LIB_LIB_H */ diff --git a/lib/Sconscript b/lib/Sconscript index 10f42567..d7d8a604 100644 --- a/lib/Sconscript +++ b/lib/Sconscript @@ -1,3 +1,5 @@ #!/usr/bin/python +Import("env") +env.UsePackage("gtkmm-3.0") res = Glob("*.cpp") Return("res") diff --git a/lib/lib.cpp b/lib/lib.cpp index 957a1dbb..565123e0 100644 --- a/lib/lib.cpp +++ b/lib/lib.cpp @@ -8,7 +8,9 @@ #include #include #include +#include +static Glib::RefPtr builder; static std::string share_dir = ""; static void setup_share(const std::string &path) @@ -19,10 +21,14 @@ static void setup_share(const std::string &path) share_dir = "./share/ocarina/"; } -void lib :: init(int *argc, char ***argv) +void lib :: init(int *argc, char ***argv, const std::string >k_xml) { setup_share((*argv)[0]); + builder = Gtk::Builder::create(); + if (!builder->add_from_file(lib :: share_file(gtk_xml))) + exit(1); + tagdb :: init(); library :: init(); playlist :: init(); @@ -34,3 +40,8 @@ const std::string lib :: share_file(const std::string &f) { return share_dir + f; } + +Glib::RefPtr &lib :: get_builder() +{ + return builder; +} diff --git a/tests/Sconscript b/tests/Sconscript index de731f7f..af4070ac 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -44,7 +44,7 @@ class OTest: cmd = "%s | tee %s.out" % (path, path) if test_env.Valgrind == True: cmd = "%s %s" % (valgrind, cmd) - test = Command("%s.out" % self.Name, [], "set -x pipefail; %s" % cmd) + test = test_env.Command("%s.out" % self.Name, [], "set -x pipefail; %s" % cmd) Depends(test, prog) if (check_depends == True) and (OTest.Prev != None): diff --git a/tests/lib/Sconscript b/tests/lib/Sconscript index 245cdb66..a239aa0e 100644 --- a/tests/lib/Sconscript +++ b/tests/lib/Sconscript @@ -12,8 +12,8 @@ for f in Glob("../../core/*.cpp"): class LibTest(OTest): Objs = core - def __init__(self, src): - OTest.__init__(self, src) + def __init__(self, src, pkg = None): + OTest.__init__(self, src, pkg = pkg) def get_program(self): path = "../../lib/%s" % self.Src @@ -23,7 +23,7 @@ class LibTest(OTest): res = TestList("lib", [ - LibTest("lib.cpp"), + LibTest("lib.cpp", "gtkmm-3.0"), ]).prepare() diff --git a/tests/lib/lib.cpp b/tests/lib/lib.cpp index b5f6651a..f22bf8b2 100644 --- a/tests/lib/lib.cpp +++ b/tests/lib/lib.cpp @@ -4,20 +4,27 @@ #include #include #include +#include -static void test_init(int argc, char **argv) +static void test_init(int *argc, char ***argv) { + Gtk::Window *window; + test_equal(deck :: get_queues().size(), (size_t)0); test :: cp_data_dir(); - lib :: init(&argc, &argv); + lib :: init(argc, argv, "ocarina6.glade"); test_equal(deck :: get_queues().size(), (size_t)2); test_equal(lib :: share_file("saria"), (std::string)"./share/ocarina/saria"); + + window = lib :: get_widget("o_window"); + test_not_equal(window, (Gtk::Window *)NULL); } int main(int argc, char **argv) { - run_test("Lib Test", test_init, argc, argv); + Gtk::Main ocarina(&argc, &argv); + run_test("Lib Test", test_init, &argc, &argv); return 0; }