Debian packaging: 0.0.4-1
[beifahrer] / src / lift-list-window.vala
index 4c59c5e..2e5d6ef 100644 (file)
@@ -68,6 +68,8 @@ public class LiftListWindow : StackableWindow {
                gconf = GConf.Client.get_default ();
                store = new ListStore (7, typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (Lift));
                sortable = new TreeModelSort.with_model (store);
+               sortable.set_sort_func (Columns.DATETIME, datetime_sort_func);
+               sortable.set_sort_func (Columns.PRICE, price_sort_func);
 
                alignment = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
                alignment.top_padding = MARGIN_HALF;
@@ -185,6 +187,49 @@ public class LiftListWindow : StackableWindow {
                });
        }
 
+       private int datetime_sort_func (TreeModel model, TreeIter a, TreeIter b) {
+               Lift la;
+               Lift lb;
+               model.get (a, Columns.LIFT, out la);
+               model.get (b, Columns.LIFT, out lb);
+               int year = la.time.year - lb.time.year;
+               if (year != 0)
+                       return year;
+               int month = la.time.month - lb.time.month;
+               if (month != 0)
+                       return month;
+               int day = la.time.day - lb.time.day;
+               if (day != 0)
+                       return day;
+               int hour = la.time.hour - lb.time.hour;
+               // Negative hour means no exact time available
+               // - sort those entries last
+               if (la.time.hour < 0) {
+                       hour += 24;
+                       return hour;
+               }
+               if (lb.time.hour < 0) {
+                       hour -= 24;
+                       return hour;
+               }
+               if (hour != 0)
+                       return hour;
+               int minute = la.time.minute - lb.time.minute;
+               return minute;
+       }
+
+       private int price_sort_func (TreeModel model, TreeIter a, TreeIter b) {
+               string pa;
+               string pb;
+               model.get (a, Columns.PRICE, out pa);
+               model.get (b, Columns.PRICE, out pb);
+               if (pa == null && pb != null)
+                       return 1;
+               if (pa != null && pb == null)
+                       return -1;
+               return strcmp (pa, pb);
+       }
+
        private void vbox_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) {
                unowned string text;
                CellRendererText renderer;