From 67228ef8b162f5332c8cadf9b1627a625ee4d319 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 3 Apr 2015 12:02:49 -0400 Subject: [PATCH] gui: Turn the Tab class into a QNotifier Now we can respond to notifications directly. Signed-off-by: Anna Schumaker --- gui/tabs.cpp | 29 ++++++++++++++--------------- include/gui/tabs.h | 8 ++++++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 2f585e72..5c90e1b5 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -32,6 +32,7 @@ Tab :: Tab(Queue *pq) : tab_sorting_count(0), tab_pq(pq), tab_size(NULL) { tab_model = Glib::RefPtr(new QueueModel(tab_pq)); + pq->set_notifier(this); queue_mapping[tab_pq] = this; } @@ -66,6 +67,19 @@ void Tab :: tab_finish_init() } +/** + * + * QNotifier implementation. + * + */ + +void Tab :: on_track_added(unsigned int row) +{ + tab_model->on_row_inserted(row); + tab_set_size(); + tab_runtime_changed(); +} + /** * @@ -217,13 +231,6 @@ void Tab :: tab_ban_selected() void Tab :: on_post_init() {} -void Tab :: on_track_added(unsigned int row) -{ - tab_model->on_row_inserted(row); - tab_set_size(); - tab_runtime_changed(); -} - void Tab :: on_track_deleted(unsigned int row) { tab_model->on_row_deleted(row); @@ -410,13 +417,6 @@ static Tab *cur_tab() return NULL; } -static void on_track_added(Queue *pq, unsigned int row) -{ - Tab *tab = find_tab(pq); - if (tab) - tab->on_track_added(row); -} - static void on_track_deleted(Queue *pq, unsigned int row) { Tab *tab = find_tab(pq); @@ -487,7 +487,6 @@ static void init_menu_item(const std::string &pq, unsigned int n) void init_tabs() { struct Callbacks *cb = get_callbacks(); - cb->on_queue_track_add = on_track_added; cb->on_queue_track_del = on_track_deleted; cb->on_queue_track_changed = on_track_changed; diff --git a/include/gui/tabs.h b/include/gui/tabs.h index 5b08bfb4..e601ddb7 100644 --- a/include/gui/tabs.h +++ b/include/gui/tabs.h @@ -9,7 +9,7 @@ #include #include -class Tab { +class Tab : public QNotifier { private: std::set visible_ids; unsigned int tab_sorting_count; @@ -50,6 +50,11 @@ public: Tab(Queue *); virtual ~Tab(); + /** + * QNotifier implementation + */ + void on_track_added(unsigned int); + /** * More helper functions */ @@ -71,7 +76,6 @@ public: * internal callback functions that can be overridden if necessary */ virtual void on_post_init(); - virtual void on_track_added(unsigned int); virtual void on_track_deleted(unsigned int); virtual void on_track_changed(unsigned int); virtual bool on_key_press_event(const std::string &);