Lift list view: add sorting by time or price
[beifahrer] / src / lift-list-window.vala
index e4c5ae2..c1a2611 100644 (file)
@@ -24,6 +24,7 @@ public class LiftListWindow : StackableWindow {
 
        AdacMitfahrclub adac;
        ListStore store;
+       TreeSortable sortable;
        Alignment alignment;
        TreeView tree;
        TreeViewColumn route_column;
@@ -42,19 +43,28 @@ public class LiftListWindow : StackableWindow {
                set_title ("Beifahrer");
 
                var menu = new AppMenu ();
+               var sort_by_time = new RadioButton.with_label (null, _("Time"));
+                sort_by_time.set_mode (false);
+               sort_by_time.show ();
+               var sort_by_price = new RadioButton.with_label_from_widget (sort_by_time, _("Price"));
+                sort_by_price.set_mode (false);
+               sort_by_price.show ();
+               menu.add_filter (sort_by_time);
+               menu.add_filter (sort_by_price);
                goto_website = new Gtk.Button.with_label (_("Show website"));
                menu.append (goto_website);
                set_main_menu (menu);
 
                gconf = GConf.Client.get_default ();
                store = new ListStore (6, typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (Lift));
+               sortable = new TreeModelSort.with_model (store);
 
                alignment = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
                alignment.top_padding = MARGIN_HALF;
                alignment.left_padding = MARGIN_DOUBLE;
                alignment.right_padding = MARGIN_DOUBLE;
 
-               tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, store);
+               tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, sortable);
                Hildon.gtk_widget_set_theme_size (tree, SizeType.FINGER_HEIGHT);
 
                tree.set_headers_visible (false);
@@ -122,6 +132,14 @@ public class LiftListWindow : StackableWindow {
                tree.row_activated.connect (this.on_row_activated);
                Gdk.Screen.get_default ().size_changed.connect (this.on_orientation_changed);
                goto_website.clicked.connect (on_goto_website_clicked);
+               sort_by_time.toggled.connect (button => {
+                       if (button.get_active ())
+                               sortable.set_sort_column_id (1, Gtk.SortType.ASCENDING);
+               });
+               sort_by_price.toggled.connect (button => {
+                       if (button.get_active ())
+                               sortable.set_sort_column_id (3, Gtk.SortType.ASCENDING);
+               });
        }
 
        public async void find_lifts (string city_from, int radius_from, string city_to, int radius_to, Date date, int tolerance = 0) {