gui/view: Sort queue when columns are clicked

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-22 12:18:34 -05:00
parent 8e6b963eb8
commit cacd344741
4 changed files with 83 additions and 80 deletions

View File

@ -18,12 +18,6 @@ extern "C" {
static std::map<queue *, Tab *> queue_mapping;
static compare_t sort_fields[] = {
COMPARE_TRACK, COMPARE_TITLE, COMPARE_LENGTH,
COMPARE_ARTIST, COMPARE_ALBUM, COMPARE_YEAR,
COMPARE_GENRE, COMPARE_COUNT, COMPARE_PLAYED
};
static void *tempq_init(struct queue *queue)
{
struct gui_queue *gq = gui_queue_alloc(queue, "Queued Tracks",
@ -85,11 +79,6 @@ Tab :: Tab(queue *pq)
tab_window->init(tab_pq);
for (unsigned int i = 0; i < tab_window->q_treeview->get_n_columns(); i++)
tab_window->q_treeview->get_column(i)->signal_clicked().connect(
sigc::bind<unsigned int> (sigc::mem_fun(
*this, &Tab::on_column_clicked), i));
tab_vbox.set_margin_start(1);
tab_vbox.set_margin_end(1);
tab_vbox.set_homogeneous(false);
@ -134,20 +123,6 @@ bool Tab :: tab_is_cur()
return notebook->page_num(tab_vbox) == notebook->get_current_page();
}
void Tab :: tab_display_sorting()
{
std::string text = "";
if ((tab_sorting_count > 0) && tab_is_cur())
text = "Sorting within " + tab_sorting_title;
Glib :: wrap(GTK_LABEL(gui_builder_widget("o_sorting_indicator")), false)->set_text(text);
}
void Tab :: tab_dec_sort_count()
{
tab_sorting_count--;
tab_display_sorting();
}
void Tab :: tab_unmap()
{
queue_mapping.erase(tab_pq);
@ -155,28 +130,6 @@ void Tab :: tab_unmap()
/**
*
* GTK-MM callback functions
*
*/
void Tab :: on_column_clicked(unsigned int col)
{
if (tab_sorting_count == 0) {
tab_sorting_title = tab_window->q_treeview->get_column(col)->get_title();
queue_sort(tab_pq, sort_fields[col], true);
} else
queue_sort(tab_pq, sort_fields[col], false);
tab_sorting_count++;
tab_display_sorting();
Glib::signal_timeout().connect_seconds_once(
sigc::mem_fun(*this, &Tab::tab_dec_sort_count), 2);
}
/**
*
* Global functions
@ -192,25 +145,6 @@ Tab *find_tab(queue *pq)
return NULL;
}
static Tab *find_tab(int num)
{
std::map<queue *, Tab *>::iterator it;
for (it = queue_mapping.begin(); it != queue_mapping.end(); it++) {
if (it->second->tab_page_num() == num)
return it->second;
}
return NULL;
}
static void on_switch_page(Gtk::Widget *page, int num)
{
Tab *tab = find_tab(num);
if (tab) {
tab->tab_display_sorting();
} else
Glib :: wrap(GTK_LABEL(gui_builder_widget("o_queue_time")), false)->set_text("");
}
static bool on_window_key_pressed(GdkEventKey *event)
{
Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false);
@ -242,9 +176,6 @@ static bool on_window_key_pressed(GdkEventKey *event)
void init_tabs()
{
Gtk::Window *window = Glib :: wrap(GTK_WINDOW(gui_builder_widget("o_window")), false);
/* Notebook signals */
struct Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false);
notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page));
/* Initialize other tabs */
init_history_tab();

View File

@ -24,8 +24,21 @@ static const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
[Q_MODEL_FILE_PATH] = "gui.queue.filepath",
};
static const enum compare_t QUEUE_SORT[Q_MODEL_N_COLUMNS] = {
[Q_MODEL_TRACK_NR] = COMPARE_TRACK,
[Q_MODEL_TITLE] = COMPARE_TITLE,
[Q_MODEL_LENGTH] = COMPARE_LENGTH,
[Q_MODEL_ARTIST] = COMPARE_ARTIST,
[Q_MODEL_ALBUM] = COMPARE_ALBUM,
[Q_MODEL_YEAR] = COMPARE_YEAR,
[Q_MODEL_GENRE] = COMPARE_GENRE,
[Q_MODEL_COUNT] = COMPARE_COUNT,
[Q_MODEL_LAST_PLAY] = COMPARE_PLAYED,
};
static GtkTreeView *view_treeview = NULL;
static GtkTreeModelFilter *view_filter = NULL;
static unsigned int view_sort_count = 0;
static inline GuiQueueModel *__view_filter_get_model()
{
@ -34,6 +47,13 @@ static inline GuiQueueModel *__view_filter_get_model()
return GUI_QUEUE_MODEL(gtk_tree_model_filter_get_model(view_filter));
}
static inline struct queue *__view_filter_get_queue()
{
if (view_filter == NULL)
return NULL;
return __view_filter_get_model()->gqm_queue;
}
static inline GtkTreePath *__view_filter_convert_path(GtkTreePath *orig)
{
return gtk_tree_model_filter_convert_path_to_child_path(view_filter, orig);
@ -58,6 +78,32 @@ static unsigned int __view_filter_get_index(GtkTreePath *orig)
return ret;
}
static unsigned int __view_get_column_index(GtkTreeViewColumn *col)
{
unsigned int i;
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
if (col == gtk_tree_view_get_column(view_treeview, i))
return i;
}
return Q_MODEL_N_COLUMNS;
}
static inline void __view_display_sorting(gchar *text)
{
gtk_label_set_text(GTK_LABEL(gui_builder_widget("o_sorting")), text);
}
static int __view_dec_sort(gpointer data)
{
if (view_sort_count > 0)
view_sort_count--;
if (view_sort_count == 0)
__view_display_sorting("");
return FALSE;
}
void __view_row_activated(GtkTreeView *treeview, GtkTreePath *path,
GtkTreeViewColumn *col, gpointer data)
{
@ -69,15 +115,31 @@ void __view_row_activated(GtkTreeView *treeview, GtkTreePath *path,
void __view_column_resized(GtkTreeViewColumn *col, GParamSpec *pspec,
gpointer data)
{
unsigned int i;
unsigned int index = __view_get_column_index(col);
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
if (col == gtk_tree_view_get_column(view_treeview, i)) {
gui_settings_set(QUEUE_SETTINGS[i],
gtk_tree_view_column_get_width(col));
break;
}
gui_settings_set(QUEUE_SETTINGS[index],
gtk_tree_view_column_get_width(col));
}
void __view_column_clicked(GtkTreeViewColumn *col, gpointer data)
{
struct queue *queue = __view_filter_get_queue();
unsigned int index = __view_get_column_index(col);
gchar *text;
if (!queue || queue_has_flag(queue, Q_NO_SORT))
return;
queue_sort(queue, QUEUE_SORT[index], view_sort_count == 0);
if (view_sort_count == 0) {
text = g_strdup_printf("Sorting within %s",
gtk_tree_view_column_get_title(col));
__view_display_sorting(text);
g_free(text);
}
view_sort_count++;
g_timeout_add_seconds(3, __view_dec_sort, NULL);
}
static void __view_add_to_queue(GtkTreeModel *model, GtkTreePath *path,
@ -94,7 +156,7 @@ static void __view_add_to_playlist(GtkTreeModel *model, GtkTreePath *path,
static void __view_delete_selection(GtkTreeSelection *selection)
{
struct queue * queue = __view_filter_get_model()->gqm_queue;
struct queue *queue = __view_filter_get_queue();
GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL);
GList *cur = g_list_reverse(rows);
@ -234,4 +296,7 @@ void gui_view_set_model(GtkTreeModelFilter *filter)
{
view_filter = filter;
gtk_tree_view_set_model(view_treeview, GTK_TREE_MODEL(filter));
view_sort_count = 0;
__view_display_sorting("");
}

View File

@ -25,7 +25,6 @@ protected:
/**
* Class helper functions
*/
void tab_dec_sort_count();
void tab_unmap();
public:
@ -47,7 +46,6 @@ public:
int tab_page_num();
bool tab_is_cur();
void tab_runtime_changed();
void tab_display_sorting();
void tab_focus_search();
/**

View File

@ -1138,6 +1138,7 @@
<property name="fixed_width">20</property>
<property name="title" translatable="yes">#</property>
<property name="clickable">True</property>
<signal name="clicked" handler="__view_column_clicked" swapped="no"/>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext4"/>
@ -1154,6 +1155,7 @@
<property name="fixed_width">300</property>
<property name="title" translatable="yes">Title</property>
<property name="clickable">True</property>
<signal name="clicked" handler="__view_column_clicked" swapped="no"/>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext5"/>
@ -1170,6 +1172,7 @@
<property name="fixed_width">60</property>
<property name="title" translatable="yes">Length</property>
<property name="clickable">True</property>
<signal name="clicked" handler="__view_column_clicked" swapped="no"/>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext6"/>
@ -1186,6 +1189,7 @@
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Artist</property>
<property name="clickable">True</property>
<signal name="clicked" handler="__view_column_clicked" swapped="no"/>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext7"/>
@ -1202,6 +1206,7 @@
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Album</property>
<property name="clickable">True</property>
<signal name="clicked" handler="__view_column_clicked" swapped="no"/>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext8"/>
@ -1218,6 +1223,7 @@
<property name="fixed_width">45</property>
<property name="title" translatable="yes">Year</property>
<property name="clickable">True</property>
<signal name="clicked" handler="__view_column_clicked" swapped="no"/>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext9"/>
@ -1234,6 +1240,7 @@
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Genre</property>
<property name="clickable">True</property>
<signal name="clicked" handler="__view_column_clicked" swapped="no"/>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext10"/>
@ -1250,6 +1257,7 @@
<property name="fixed_width">60</property>
<property name="title" translatable="yes">Count</property>
<property name="clickable">True</property>
<signal name="clicked" handler="__view_column_clicked" swapped="no"/>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext11"/>
@ -1266,6 +1274,7 @@
<property name="fixed_width">1</property>
<property name="title" translatable="yes">Played</property>
<property name="clickable">True</property>
<signal name="clicked" handler="__view_column_clicked" swapped="no"/>
<signal name="notify::width" handler="__view_column_resized" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext12"/>
@ -1398,7 +1407,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="o_sorting_indicator">
<object class="GtkLabel" id="o_sorting">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>