From 4ce08ef22eb146272ce924617f765ea496dd60ae Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 21 Feb 2014 22:06:42 -0500 Subject: [PATCH] gui: Begin yet another tab framework This one is based on inheritance, and I think it will be the best way to create several tab types that do things just slightly differently. Signed-off-by: Anna Schumaker --- gui/collection.cpp | 118 ++++----------- gui/history.cpp | 100 +++---------- gui/main.cpp | 3 +- gui/ocarina6.glade | 2 +- gui/playlist.cpp | 121 ++++++---------- gui/tabs.cpp | 351 ++++++++++++++++++++++++++------------------- gui/wires.cpp | 13 +- include/ocarina.h | 7 +- include/tabs.h | 94 +++++++----- 9 files changed, 367 insertions(+), 442 deletions(-) diff --git a/gui/collection.cpp b/gui/collection.cpp index 807e453c..7d957e0d 100644 --- a/gui/collection.cpp +++ b/gui/collection.cpp @@ -2,105 +2,43 @@ * Copyright 2014 (c) Anna Schumaker. */ #include -#include #include -static Glib::RefPtr model; - -/* - * Basic helper functions - */ -static inline Playqueue *library_pq() -{ - return deck::get_library_pq(); -} - -static Gtk::ToggleButton *get_random_button() -{ - return get_widget("o_collection_random"); -} - -static void set_queue_size() -{ - Gtk::Label *label = get_widget("o_collection_size"); - label->set_text(itoa(library_pq()->size())); -} - - - -/* - * Gtk signal functions - */ - -static void on_random_toggled() -{ - if (get_random_button()->get_active()) - library_pq()->set_flag(PQ_RANDOM); - else - library_pq()->unset_flag(PQ_RANDOM); -} - - - -/* - * Functions exposed through a TabFuncs structure - */ - -static void collection_init_late() -{ - set_queue_size(); - get_random_button()->set_active(library_pq()->get_flags() & PQ_RANDOM); -} - -static void collection_cleanup() {} - -static bool collection_has_queue(Playqueue *pq) -{ - return pq == library_pq(); -} - -static void collection_track_added(Playqueue *pq, unsigned int row) -{ - model->on_row_inserted(row); - set_queue_size(); -} - -static void collection_track_deleted(Playqueue *pq, unsigned int row) -{ - model->on_row_deleted(row); - set_queue_size(); -} - - -static struct TabType collection_funcs = { - .init_late = collection_init_late, - .cleanup = collection_cleanup, - - .has_queue = collection_has_queue, - .track_added = collection_track_added, - .track_deleted = collection_track_deleted, +class CollectionTab : public Tab { +public: + CollectionTab(); + ~CollectionTab(); + void on_post_init(); }; -static struct FilterDesc filter_desc; + +CollectionTab :: CollectionTab() + : Tab(deck::get_library_pq()) +{ + 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_finish_init(); +} + +CollectionTab :: ~CollectionTab() +{ + tab_unmap(); +} + +void CollectionTab :: on_post_init() +{ + tab_init_random(); +} -/* - * Basic tab setup - */ +static CollectionTab *collection_tab; void init_collection_tab() { - model = Glib::RefPtr(new PlayqueueModel(library_pq())); - - filter_desc.model = model; - filter_desc.entry = get_widget("o_collection_entry"); - init_filter(&filter_desc); - - get_widget("o_collection_pq_treeview")->set_model(filter_desc.filter); - - get_random_button()->signal_toggled().connect(sigc::ptr_fun(on_random_toggled)); - - register_tab_type(&collection_funcs); + collection_tab = new CollectionTab; } diff --git a/gui/history.cpp b/gui/history.cpp index bd736d34..9fafe716 100644 --- a/gui/history.cpp +++ b/gui/history.cpp @@ -2,94 +2,36 @@ * Copyright 2014 (c) Anna Schumaker. */ #include -#include -#include #include -#include -static std::set visible_ids; -static Glib::RefPtr history_filter; -static Glib::RefPtr model; - - -/* - * Basic helper functions - */ -static inline Playqueue *history_pq() -{ - return audio::get_recent_pq(); -} - -static void set_queue_size() -{ - Gtk::Label *label = get_widget("o_history_size"); - label->set_text(itoa(history_pq()->size())); -} - - - -/* - * Gtk signal functions - */ - - - -/* - * Functions exposed through a TabFuncs structure - */ - -static void history_init_late() -{ - set_queue_size(); -} - -static void history_cleanup() {} - -static bool history_has_queue(Playqueue *pq) -{ - return pq == history_pq(); -} - -static void history_track_added(Playqueue *pq, unsigned int row) -{ - model->on_row_inserted(row); - set_queue_size(); -} - -static void history_track_deleted(Playqueue *pq, unsigned int row) -{ - model->on_row_deleted(row); - set_queue_size(); -} - - -static struct TabType history_funcs = { - .init_late = history_init_late, - .cleanup = history_cleanup, - - .has_queue = history_has_queue, - .track_added = history_track_added, - .track_deleted = history_track_deleted, +class HistoryTab : public Tab { +public: + HistoryTab(); + ~HistoryTab(); }; -static struct FilterDesc filter_desc; + +HistoryTab :: HistoryTab() + : Tab(audio::get_recent_pq()) +{ + tab_search = get_widget("o_history_entry"); + tab_size = get_widget("o_history_size"); + tab_treeview = get_widget("o_history_treeview"); + + tab_finish_init(); +} + +HistoryTab :: ~HistoryTab() +{ + tab_unmap(); +} -/* - * Basic tab setup - */ +static HistoryTab *history_tab; void init_history_tab() { - model = Glib::RefPtr(new PlayqueueModel(history_pq())); - - filter_desc.model = model; - filter_desc.entry = get_widget("o_history_entry"); - init_filter(&filter_desc); - - get_widget("o_history_treeview")->set_model(filter_desc.filter); - - register_tab_type(&history_funcs); + history_tab = new HistoryTab; } diff --git a/gui/main.cpp b/gui/main.cpp index 448d4214..2f964b1f 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include Gtk::Window *ocarina_init(int *argc, char ***argv) { @@ -14,7 +15,7 @@ Gtk::Window *ocarina_init(int *argc, char ***argv) library::init(); playlist::init(); - init_tabs2(); + post_init_tabs(); return window; } diff --git a/gui/ocarina6.glade b/gui/ocarina6.glade index a65cc411..102c58c2 100644 --- a/gui/ocarina6.glade +++ b/gui/ocarina6.glade @@ -731,7 +731,7 @@ 1 vertical - + True True 5 diff --git a/gui/playlist.cpp b/gui/playlist.cpp index e0c1eaf5..1c62ee22 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -2,10 +2,39 @@ * Copyright 2014 (c) Anna Schumaker. */ #include -#include #include -static Glib::RefPtr model; + +/** + * Playlist tab stuff + */ + +class PlaylistTab : public Tab { +public: + PlaylistTab(); + ~PlaylistTab(); +}; + + +PlaylistTab :: PlaylistTab() + : Tab(playlist :: get_pq()) +{ + tab_search = get_widget("o_playlist_entry"); + tab_treeview = get_widget("o_playlist_pq_treeview"); + + tab_finish_init(); +} + +PlaylistTab :: ~PlaylistTab() +{ + tab_unmap(); +} + + + +/** + * Playlist "sidebar" stuff + */ static class PlaylistColumns : public Gtk::TreeModelColumnRecord { public: @@ -15,42 +44,19 @@ public: Gtk::TreeModelColumn plist_col_name; } plist_cols; +static Glib::RefPtr playlist_ls; +static Gtk::TreeView *playlist_tv; -/* - * Basic helper functions - */ -static inline Playqueue *playlist_pq() -{ - return playlist::get_pq(); -} - -static Gtk::TreeView *get_playlist_treeview() -{ - return get_widget("o_playlist_treeview"); -} - -static Glib::RefPtr get_playlists() -{ - return get_object("o_playlists"); -} - - - -/* - * Gtk signal functions - */ static void on_playlist_cursor_changed() { Gtk::TreePath path; Gtk::TreeViewColumn *col; - Gtk::TreeModel::Row row; + playlist_tv->get_cursor(path, col); - get_playlist_treeview()->get_cursor(path, col); - row = *(get_playlists()->get_iter(path)); - - print("%s\n", row[plist_cols.plist_col_name]); - //playlist::select(row[plist_cols.plist_col_name]); + Gtk::TreeModel::Row row = *(playlist_ls->get_iter(path)); + std::string res = row[plist_cols.plist_col_name]; + playlist::select(res); } static bool on_playlist_clicked(GdkEventButton *button) @@ -62,54 +68,15 @@ static bool on_playlist_clicked(GdkEventButton *button) -/* - * Functions exposed through a TabFuncs structure - */ - -static void playlist_init_late() {} -static void playlist_cleanup() {} - -static bool playlist_has_queue(Playqueue *pq) -{ - return pq == playlist_pq(); -} - -static void playlist_track_added(Playqueue *pq, unsigned int row) -{ - model->on_row_inserted(row); -} - -static void playlist_track_deleted(Playqueue *pq, unsigned int row) -{ - model->on_row_deleted(row); -} - - -static struct TabType playlist_funcs = { - .init_late = playlist_init_late, - .cleanup = playlist_cleanup, - - .has_queue = playlist_has_queue, - .track_added = playlist_track_added, - .track_deleted = playlist_track_deleted, -}; - - - -/* - * Basic tab setup - */ +static PlaylistTab *playlist_tab; void init_playlist_tab() { - Gtk::TreeView *playlist = get_playlist_treeview(); + playlist_tab = new PlaylistTab; + playlist_ls = get_object("o_playlists"); + playlist_tv = get_widget("o_playlist_treeview"); - model = Glib::RefPtr(new PlayqueueModel(playlist_pq())); - get_widget("o_playlist_pq_treeview")->set_model(model); - - playlist->signal_cursor_changed().connect(sigc::ptr_fun(on_playlist_cursor_changed)); - playlist->signal_button_press_event().connect(sigc::ptr_fun(on_playlist_clicked)); - playlist->set_cursor(Gtk::TreePath("0")); - - register_tab_type(&playlist_funcs); + 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)); + playlist_tv->set_cursor(Gtk::TreePath("0")); } diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 467c8064..265597d1 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -1,27 +1,197 @@ /* * Copyright 2014 (c) Anna Schumaker. */ -#include #include -#include #include -#include -#include -#include #include -#include #include -#include #include -#include + + +static std::map queue_mapping; + + +/** + * Tab class basics + */ + +Tab :: Tab(Playqueue *pq) + : tab_pq(pq), tab_size(NULL) +{ + tab_model = Glib::RefPtr(new PlayqueueModel(tab_pq)); + queue_mapping[tab_pq] = this; +} + +Tab :: ~Tab() {} + +void Tab :: tab_finish_init() +{ + tab_filter = Gtk::TreeModelFilter::create(tab_model); + tab_filter->set_visible_func(sigc::mem_fun(*this, + &Tab::on_filter_visible)); + tab_search->signal_key_release_event().connect(sigc::mem_fun(*this, + &Tab::on_entry_key_released)); + tab_search->signal_changed().connect(sigc::mem_fun(*this, + &Tab::on_entry_changed)); + + tab_treeview->set_model(tab_filter); +} + + + +/** + * Tab class helper functions + */ + +void Tab :: tab_init_random() +{ + tab_random->set_active(tab_pq->get_flags() & PQ_RANDOM); + tab_random->signal_toggled().connect(sigc::mem_fun(*this, + &Tab::on_random_toggled)); +} + +void Tab :: tab_set_size() +{ + if (tab_size) { + std::stringstream ss; + ss << tab_pq->size(); + tab_size->set_text(ss.str()); + } +} + +void Tab :: tab_unmap() +{ + queue_mapping.erase(tab_pq); +} + + + +/** + * Tab internal callback functions + */ + +void Tab :: on_post_init() {} + +void Tab :: on_track_added(unsigned int row) +{ + tab_model->on_row_inserted(row); + tab_set_size(); +} + +void Tab :: on_track_deleted(unsigned int row) +{ + tab_model->on_row_deleted(row); + tab_set_size(); +} + + + +/** + * GTK-MM callback functions + */ + +void Tab :: on_random_toggled() +{ + if (tab_random->get_active()) + tab_pq->set_flag(PQ_RANDOM); + else + tab_pq->unset_flag(PQ_RANDOM); +} + + + +/** + * Tab filtering functions + */ + +bool Tab :: on_filter_visible(const Gtk::TreeIter &iter) +{ + unsigned int pq_id; + std::set::iterator it; + + if (tab_search->get_text_length() == 0) + return true; + + pq_id = tab_model->iter_to_id(iter); + it = visible_ids.find(tab_pq->operator[](pq_id)); + return it != visible_ids.end(); +} + +bool Tab :: on_entry_key_released(GdkEventKey *event) +{ + std::string key = gdk_keyval_name(event->keyval); + return key == "space"; +} + +void Tab :: on_entry_changed() +{ + filter :: search(tab_search->get_text(), visible_ids); + tab_filter->refilter(); +} + + + +/** + * Global functions + */ + +Tab *find_tab(Playqueue *pq) +{ + std::map::iterator it; + it = queue_mapping.find(pq); + if (it != queue_mapping.end()) + return it->second; + return NULL; +} + +void on_track_added(Playqueue *pq, unsigned int row) +{ + Tab *tab = find_tab(pq); + if (tab) + tab->on_track_added(row); +} + +void on_track_deleted(Playqueue *pq, unsigned int row) +{ + Tab *tab = find_tab(pq); + if (tab) + tab->on_track_deleted(row); +} + +void init_tabs() +{ + struct Callbacks *cb = get_callbacks(); + + cb->on_queue_track_add = on_track_added; + cb->on_queue_track_del = on_track_deleted; + + /* Initialize other tabs */ + init_collection_tab(); + init_history_tab(); + init_playlist_tab(); +} + +void post_init_tabs() +{ + std::map::iterator it; + for (it = queue_mapping.begin(); it != queue_mapping.end(); it++) + it->second->on_post_init(); +} + +void cleanup_tabs() +{ + while (queue_mapping.size() > 0) + delete queue_mapping.begin()->second; +} + /* * Generic tab functions for filtering */ -static bool on_entry_key_released(GdkEventKey *event) +/*static bool on_entry_key_released(GdkEventKey *event) { std::string key = gdk_keyval_name(event->keyval); return key == "space"; @@ -60,12 +230,12 @@ void init_filter(struct FilterDesc *filter) - +*/ /* * Mostly legacy code .... */ -class OcarinaPage; +/*class OcarinaPage; static std::map tab_map; static std::list tab_types; static unsigned int sort_timeout_count = 0; @@ -118,9 +288,9 @@ static Gtk::Widget *get_menu_widget(const std::string &name) static void prepare_rc_menu() { unsigned int size = deck::size(); - +*/ /* Set widgets visible */ - switch (size) { +/* switch (size) { case 10: get_menu_widget("o_pq_9")->show(); case 9: @@ -147,9 +317,9 @@ static void prepare_rc_menu() get_menu_widget("o_new_pq")->show(); break; } - +*/ /* Set widgets invisible */ - switch (size) { +/* switch (size) { case 0: get_menu_widget("o_add_to_pq")->hide(); get_menu_widget("o_pq_0")->hide(); @@ -177,12 +347,12 @@ static void prepare_rc_menu() }; } - +*/ /* * Tab class definition */ -class OcarinaTab : public Gtk::HBox { +/*class OcarinaTab : public Gtk::HBox { public: OcarinaTab(); ~OcarinaTab(); @@ -235,23 +405,23 @@ void PQTab::set_number(unsigned int num) ss << "" << num << ". "; number_label.set_markup(ss.str()); } - +*/ /* * Ocarina class definition */ -class OcarinaPage : public Gtk::VBox { +/*class OcarinaPage : public Gtk::VBox { private: unsigned int init_flags; Gtk::Notebook *notebook; OcarinaTab *tab; - +*/ /* Filter state */ - std::set visible_ids; +// std::set visible_ids; /* Page widgets */ - Gtk::HBox page_toolbar; +/* Gtk::HBox page_toolbar; Gtk::SearchEntry page_entry; Gtk::ToggleButton page_repeat; Gtk::ScrolledWindow page_scroll; @@ -330,9 +500,9 @@ void OcarinaPage::setup_common(Playqueue *pq, unsigned int pg) setup_treeview(); pack_start(page_viewbox); show_all(); - +*/ /* Add to notebook */ - notebook->insert_page(*this, *tab, pg); +/* notebook->insert_page(*this, *tab, pg); tab_map[pq] = this; set_tab_size(); } @@ -343,17 +513,17 @@ void OcarinaPage::setup_toolbar() page_toolbar.pack_start(page_entry); page_toolbar.set_margin_left(5); page_toolbar.set_margin_right(5); - +*/ /* Set up entry */ - page_entry.set_margin_top(5); +/* page_entry.set_margin_top(5); page_entry.set_margin_bottom(5); page_entry.signal_changed().connect(sigc::mem_fun(*this, &OcarinaPage::on_entry_changed)); page_entry.signal_key_release_event().connect(sigc::mem_fun(*this, &OcarinaPage::on_entry_key_released)); - +*/ /* Make buttons */ - if (init_flags & PQ_RANDOM) { +/* if (init_flags & PQ_RANDOM) { page_random.set_image_from_icon_name("media-playlist-shuffle"); page_toolbar.pack_start(page_random, false, false); } @@ -366,9 +536,9 @@ void OcarinaPage::setup_toolbar() } void OcarinaPage::setup_treeview() -{ +{*/ /* Make page content */ - page_view.append_column("#", queue_cols.q_col_track); + /*page_view.append_column("#", queue_cols.q_col_track); page_view.append_column("Title", queue_cols.q_col_title); page_view.append_column("Length", queue_cols.q_col_length); page_view.append_column("Artist", queue_cols.q_col_artist); @@ -423,11 +593,6 @@ bool OcarinaPage::is_current_tab() void OcarinaPage::check_pq_flags() { - if (init_flags & PQ_RANDOM) { - page_random.set_active(model->queue->get_flags() & PQ_RANDOM); - page_random.signal_toggled().connect(sigc::mem_fun(*this, - &OcarinaPage::on_random_toggled)); - } if (init_flags & PQ_REPEAT) { page_repeat.set_active(model->queue->get_flags() & PQ_REPEAT); page_repeat.signal_toggled().connect(sigc::mem_fun(*this, @@ -435,11 +600,6 @@ void OcarinaPage::check_pq_flags() } } -void OcarinaPage::set_tab_size() -{ - tab->set_size(model->queue->size()); -} - void OcarinaPage::queue_selected(bool random) { Playqueue *pq; @@ -493,14 +653,6 @@ void OcarinaPage::on_runtime_changed() label->set_text(model->queue->get_length_str()); } -void OcarinaPage::on_random_toggled() -{ - if (page_random.get_active()) - model->queue->set_flag(PQ_RANDOM); - else - model->queue->unset_flag(PQ_RANDOM); -} - void OcarinaPage::on_repeat_toggled() { if (page_repeat.get_active()) @@ -531,30 +683,6 @@ void OcarinaPage::on_column_clicked(unsigned int col_index) sigc::ptr_fun(dec_sort_timeout), 2); } -void OcarinaPage::on_entry_changed() -{ - filter :: search(page_entry.get_text(), visible_ids); - filter->refilter(); -} - -bool OcarinaPage::on_entry_key_released(GdkEventKey *event) -{ - std::string key = gdk_keyval_name(event->keyval); - return key == "space"; -} - -bool OcarinaPage::on_filter_visible(const Gtk::TreeIter &iter) -{ - unsigned int pq_id; - std::set::iterator it; - - if (page_entry.get_text().size() == 0) - return true; - - pq_id = model->iter_to_id(iter); - return visible_ids.find(model->queue->operator[](pq_id)) != visible_ids.end(); -} - void OcarinaPage::on_page_renumbered() { tab->set_number(notebook->page_num(*this)); @@ -647,49 +775,13 @@ void OcarinaPage::on_focus_search() { page_entry.grab_focus(); } - +*/ /* * Do stuff with tabs */ -static TabType *find_tab_funcs(Playqueue *pq) -{ - std::list::iterator tab_it; - for (tab_it = tab_types.begin(); tab_it != tab_types.end(); tab_it++) { - if ((*tab_it)->has_queue(pq)) - return *tab_it; - } - return NULL; -} - -static void on_track_added(Playqueue *pq, unsigned int row) -{ - std::map::iterator it; - - it = tab_map.find(pq); - if (it != tab_map.end()) - it->second->on_row_inserted(row); - - struct TabType *tab; - tab = find_tab_funcs(pq); - if (tab) - tab->track_added(pq, row); -} - -static void on_track_deleted(Playqueue *pq, unsigned int row) -{ - std::map::iterator it; - it = tab_map.find(pq); - if (it != tab_map.end()) - it->second->on_row_deleted(row); - - struct TabType *tab; - tab = find_tab_funcs(pq); - if (tab) - tab->track_deleted(pq, row); -} - +/* static void on_track_changed(Playqueue *pq, unsigned int row) { std::map::iterator it; @@ -768,7 +860,7 @@ void queue_selected(bool random) } } } - +*/ /*static void on_new_queue() { queue_selected(false); @@ -792,7 +884,7 @@ static void init_menu_item(const std::string &name, unsigned int num) sigc::ptr_fun(on_add_to_queue), num)); }*/ -void focus_tab_search() +/*void focus_tab_search() { std::map::iterator it; for (it = tab_map.begin(); it != tab_map.end(); it++) { @@ -810,11 +902,9 @@ void init_tabs() get_callbacks()->on_pq_created = on_pq_created; get_callbacks()->on_pq_removed = on_pq_removed; - get_callbacks()->on_queue_track_add = on_track_added; - get_callbacks()->on_queue_track_del = on_track_deleted; get_callbacks()->on_queue_track_changed = on_track_changed; - +*/ /*Glib::RefPtr new_pq = Glib::RefPtr::cast_static(get_builder()->get_object("o_new_pq")); new_pq->signal_activate().connect(sigc::ptr_fun(on_new_queue)); @@ -828,38 +918,11 @@ void init_tabs() init_menu_item("o_pq_7", 7); init_menu_item("o_pq_8", 8); init_menu_item("o_pq_9", 9);*/ - - init_collection_tab(); +/* init_history_tab(); init_playlist_tab(); notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page)); notebook->signal_page_reordered().connect(sigc::ptr_fun(on_page_reordered)); notebook->set_current_page(0); -} - -void register_tab_type(struct TabType *tab) -{ - tab_types.push_back(tab); -} - -void init_tabs2() -{ - std::map::iterator it; - for (it = tab_map.begin(); it != tab_map.end(); it++) - it->second->check_pq_flags(); - - std::list::iterator tab_it; - for (tab_it = tab_types.begin(); tab_it != tab_types.end(); tab_it++) - (*tab_it)->init_late(); -} - -void cleanup_tabs() -{ - while (tab_map.size() > 0) - delete tab_map.begin()->second; - - std::list::iterator it; - for (it = tab_types.begin(); it != tab_types.end(); it++) - (*it)->cleanup(); -} +}*/ diff --git a/gui/wires.cpp b/gui/wires.cpp index 48754ee1..bb50524d 100644 --- a/gui/wires.cpp +++ b/gui/wires.cpp @@ -9,6 +9,7 @@ #include #include +#include static bool audio_playing = false; static Glib::RefPtr builder; @@ -142,8 +143,8 @@ static bool on_window_key_pressed(GdkEventKey *event) if (key == "Escape") window->set_focus(*window); - else if (key == "slash") - focus_tab_search(); + //else if (key == "slash") + // focus_tab_search(); else if (key >= "0" && key <= "9") { unsigned int n = atoi(key.c_str()); if (n < deck::size()) @@ -160,10 +161,10 @@ static bool on_window_key_pressed(GdkEventKey *event) audio :: previous(); else if (key == "p") notebook->set_current_page(deck::size() + 2); - else if (key == "q") - queue_selected(false); - else if (key == "s") - queue_selected(true); + //else if (key == "q") + // queue_selected(false); + //else if (key == "s") + // queue_selected(true); else return false; return true; diff --git a/include/ocarina.h b/include/ocarina.h index 6a1dfc06..d98c295a 100644 --- a/include/ocarina.h +++ b/include/ocarina.h @@ -56,11 +56,8 @@ public: /* tabs.cpp */ -void queue_selected(bool); -void focus_tab_search(); -void init_tabs(); -void init_tabs2(); -void cleanup_tabs(); +//void queue_selected(bool); +//void focus_tab_search(); /* wires.cpp */ diff --git a/include/tabs.h b/include/tabs.h index 03e6eaf2..18b7685f 100644 --- a/include/tabs.h +++ b/include/tabs.h @@ -4,55 +4,71 @@ #ifndef OCARINA_TABS_H #define OCARINA_TABS_H -#include -#include +#include +#include -struct FilterDesc { - /* - * Set these variables - */ - Glib::RefPtr model; - Gtk::SearchEntry *entry; - /* - * These are configured automatically - */ - Glib::RefPtr filter; +class Tab { +private: std::set visible_ids; + Glib::RefPtr tab_filter; + +protected: + Playqueue *tab_pq; + Glib::RefPtr tab_model; + + + /** + * Widgets that MUST be set by a child class + */ + Gtk::SearchEntry *tab_search; + Gtk::TreeView *tab_treeview; + + /** + * Optional widgets that MAY be set + */ + Gtk::ToggleButton *tab_random; + Gtk::Label *tab_size; + + + /** + * Class helper functions + */ + void tab_init_random(); + void tab_set_size(); + void tab_unmap(); + +public: + Tab(Playqueue *); + virtual ~Tab(); + void tab_finish_init(); + + /** + * internal callback functions + */ + virtual void on_post_init(); + virtual void on_track_added(unsigned int); + virtual void on_track_deleted(unsigned int); + + /** + * GTK-MM callback functions + */ + void on_random_toggled(); + + /* Filtering functions */ + bool on_filter_visible(const Gtk::TreeIter &); + bool on_entry_key_released(GdkEventKey *); + void on_entry_changed(); }; -struct TabType { - void (*init_late)(); - void (*cleanup)(); - - bool (*has_queue)(Playqueue *); - void (*track_added)(Playqueue *, unsigned int); - void (*track_deleted)(Playqueue *, unsigned int); -}; +void init_tabs(); +void post_init_tabs(); +void cleanup_tabs(); -static inline std::string itoa(unsigned int i) -{ - std::stringstream ss; - ss << i; - return ss.str(); -} - - -/* collection.cpp */ void init_collection_tab(); - -/* history.cpp */ void init_history_tab(); - -/* playlist.cpp */ void init_playlist_tab(); -/* tabs.cpp */ -void init_filter(struct FilterDesc *); -void register_tab_type(struct TabType *); - - - #endif /* OCARINA_TABS_H */