diff --git a/gui/tabs.cpp b/gui/tabs.cpp index cf58f506..80b9b9dc 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -12,6 +12,13 @@ static std::map queue_mapping; +static sort_t sort_fields[] = { + SORT_TRACK, SORT_TITLE, SORT_LENGTH, + SORT_ARTIST, SORT_ALBUM, SORT_YEAR, + SORT_GENRE, SORT_COUNT, SORT_PLAYED +}; + + /** * @@ -20,7 +27,7 @@ static std::map queue_mapping; */ Tab :: Tab(Playqueue *pq) - : tab_pq(pq), tab_size(NULL) + : tab_sorting_count(0), tab_pq(pq), tab_size(NULL) { tab_model = Glib::RefPtr(new PlayqueueModel(tab_pq)); queue_mapping[tab_pq] = this; @@ -43,6 +50,12 @@ void Tab :: tab_finish_init() &Tab :: on_row_activated)); tab_treeview->signal_key_press_event().connect(sigc::mem_fun(*this, &Tab :: on_key_pressed)); + + std::vector columns = tab_treeview->get_columns(); + for (unsigned int i = 0; i < columns.size(); i++) { + columns[i]->signal_clicked().connect(sigc::bind ( + sigc::mem_fun(*this, &Tab::on_column_clicked), i)); + } } @@ -93,6 +106,20 @@ void Tab :: tab_runtime_changed() get_widget("o_queue_time")->set_text(tab_pq->get_length_str()); } +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); +} + +void Tab :: tab_dec_sort_count() +{ + tab_sorting_count--; + tab_display_sorting(); +} + void Tab :: tab_set_size() { if (tab_size) { @@ -229,6 +256,20 @@ bool Tab :: on_key_pressed(GdkEventKey *event) return on_key_press_event(key); } +void Tab :: on_column_clicked(unsigned int col) +{ + if (tab_sorting_count == 0) { + tab_sorting_title = tab_treeview->get_column(col)->get_title(); + tab_pq->reset_sort(sort_fields[col]); + } else + tab_pq->add_sort(sort_fields[col]); + + tab_sorting_count++; + tab_display_sorting(); + Glib::signal_timeout().connect_seconds_once( + sigc::mem_fun(*this, &Tab::tab_dec_sort_count), 2); +} + /** @@ -313,9 +354,10 @@ static void on_track_changed(Playqueue *pq, unsigned int row) static void on_switch_page(Gtk::Widget *page, int num) { Tab *tab = find_tab(num); - if (tab) + if (tab) { tab->tab_runtime_changed(); - else + tab->tab_display_sorting(); + } else get_widget("o_queue_time")->set_text(""); } @@ -367,26 +409,8 @@ void cleanup_tabs() /*class OcarinaPage; static std::map tab_map; static std::list tab_types; -static unsigned int sort_timeout_count = 0; -static sort_t q_col_sorts[] = { - SORT_TRACK, SORT_TITLE, SORT_LENGTH, - SORT_ARTIST, SORT_ALBUM, SORT_YEAR, - SORT_GENRE, SORT_COUNT, SORT_PLAYED -}; - -static void dec_sort_timeout() -{ - if (sort_timeout_count > 0) - sort_timeout_count--; - if (sort_timeout_count == 0) { - Gtk::Label *label; - get_builder()->get_widget("o_sorting_indicator", label); - label->set_text(""); - } -} - static Gtk::Widget *get_menu_widget(const std::string &name) { Gtk::Widget *widget; @@ -516,31 +540,6 @@ public: void on_focus_search(); }; -void OcarinaPage::setup_columns() -{ - std::vector columns = page_view.get_columns(); - for (unsigned int i = 0; i < columns.size(); i++) { - columns[i]->signal_clicked().connect(sigc::bind ( - sigc::mem_fun(*this, &OcarinaPage::on_column_clicked), - i)); - } -} - -void OcarinaPage::on_column_clicked(unsigned int col_index) -{ - Gtk::Label *sorting; - get_builder()->get_widget("o_sorting_indicator", sorting); - - if (sort_timeout_count == 0) { - sorting->set_text("Sorting within " + page_view.get_column(col_index)->get_title()); - model->queue->reset_sort(q_col_sorts[col_index]); - } else - model->queue->add_sort(q_col_sorts[col_index]); - sort_timeout_count++; - Glib::signal_timeout().connect_seconds_once( - sigc::ptr_fun(dec_sort_timeout), 2); -} - bool OcarinaPage::on_delete_selected() { Glib::RefPtr sel = page_view.get_selection(); diff --git a/include/tabs.h b/include/tabs.h index 4d84b7f2..8bfae562 100644 --- a/include/tabs.h +++ b/include/tabs.h @@ -12,6 +12,8 @@ class Tab { private: std::set visible_ids; Glib::RefPtr tab_filter; + unsigned int tab_sorting_count; + std::string tab_sorting_title; protected: Playqueue *tab_pq; @@ -40,6 +42,7 @@ protected: void tab_init_repeat(); void tab_toggle_button(Gtk::ToggleButton *, playqueue_flags); bool tab_is_cur(); + void tab_dec_sort_count(); virtual void tab_set_size(); void tab_unmap(); @@ -53,6 +56,7 @@ public: void tab_finish_init(); int tab_page_num(); void tab_runtime_changed(); + void tab_display_sorting(); void tab_focus_search(); void tab_queue_add(Playqueue *); bool tab_queue_selected(bool); @@ -66,6 +70,7 @@ public: virtual void on_track_deleted(unsigned int); virtual void on_track_changed(unsigned int); virtual bool on_key_press_event(const std::string &); + virtual void on_column_clicked(unsigned int); /** * GTK-MM callback functions