Commits

jjacky committed 21f7169

kalu updater: one can now click on columns to sort packages (close #1)

Comments (0)

Files changed (1)

     }
 }
 
+static void
+column_clicked_cb (GtkTreeViewColumn *column, gpointer data _UNUSED_)
+{
+    /* reverse the sort indicator, because when DESCending we should point to
+     * the bottom, not the top; and vice versa */
+    gtk_tree_view_column_set_sort_order (column,
+        !gtk_tree_view_column_get_sort_order (column));
+}
+
 static gboolean
 window_delete_event_cb (GtkWidget *window _UNUSED_, GdkEvent *event _UNUSED_,
                         gpointer data _UNUSED_)
                 G_TYPE_DOUBLE   /* pctg done */
                 );
     updater->store = store;
-    gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
-                                          UCOL_PACKAGE,
-                                          GTK_SORT_ASCENDING);
     
     /* said list */
     GtkWidget *list;
                                                        "text", UCOL_PACKAGE,
                                                        NULL);
     gtk_tree_view_column_set_resizable (column, TRUE);
+    gtk_tree_view_column_set_sort_column_id (column, UCOL_PACKAGE);
+    g_signal_connect (G_OBJECT (column), "clicked",
+                      G_CALLBACK (column_clicked_cb), NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (list), column);
     /* column: Old version */
     column = gtk_tree_view_column_new_with_attributes ("Old/Current",
                                                        "text", UCOL_OLD,
                                                        NULL);
     gtk_tree_view_column_set_resizable (column, TRUE);
+    gtk_tree_view_column_set_sort_column_id (column, UCOL_OLD);
+    g_signal_connect (G_OBJECT (column), "clicked",
+                      G_CALLBACK (column_clicked_cb), NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (list), column);
     /* column: New version */
     column = gtk_tree_view_column_new_with_attributes ("New",
                                                        "text", UCOL_NEW,
                                                        NULL);
     gtk_tree_view_column_set_resizable (column, TRUE);
+    gtk_tree_view_column_set_sort_column_id (column, UCOL_NEW);
+    g_signal_connect (G_OBJECT (column), "clicked",
+                      G_CALLBACK (column_clicked_cb), NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (list), column);
     /* column: Download size */
     renderer_lbl = gtk_cell_renderer_text_new ();
         (GtkTreeCellDataFunc) rend_pbar_pb, (gpointer) TRUE, NULL);
     gtk_tree_view_column_pack_start (column, renderer_pbar, TRUE);
     gtk_tree_view_column_set_resizable (column, TRUE);
+    gtk_tree_view_column_set_sort_column_id (column, UCOL_DL_SIZE);
+    g_signal_connect (G_OBJECT (column), "clicked",
+                      G_CALLBACK (column_clicked_cb), NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (list), column);
     /* column: Installed size */
     renderer_lbl = gtk_cell_renderer_text_new ();
         (GtkTreeCellDataFunc) rend_pbar_pb, (gpointer) FALSE, NULL);
     gtk_tree_view_column_pack_start (column, renderer_pbar, TRUE);
     gtk_tree_view_column_set_resizable (column, TRUE);
+    gtk_tree_view_column_set_sort_column_id (column, UCOL_NEW_SIZE);
+    g_signal_connect (G_OBJECT (column), "clicked",
+                      G_CALLBACK (column_clicked_cb), NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (list), column);
     /* column: Net size */
     column = gtk_tree_view_column_new_with_attributes ("Net",
     gtk_tree_view_column_set_cell_data_func (column, renderer,
         (GtkTreeCellDataFunc) rend_net_size, NULL, NULL);
     gtk_tree_view_column_set_resizable (column, TRUE);
+    gtk_tree_view_column_set_sort_column_id (column, UCOL_NET_SIZE);
+    g_signal_connect (G_OBJECT (column), "clicked",
+                      G_CALLBACK (column_clicked_cb), NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW (list), column);
     
+    /* set the tree ordered by package ASC */
+    gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+                                          UCOL_PACKAGE,
+                                          GTK_SORT_ASCENDING);
+    /* reverse the initial arrow */
+    column = gtk_tree_view_get_column (GTK_TREE_VIEW (list), 0);
+    gtk_tree_view_column_set_sort_order (column, GTK_SORT_DESCENDING);
+    
     gtk_container_add (GTK_CONTAINER (scrolled_window), list);
     gtk_widget_show (list);