Add an option to preload lift details in the background
[beifahrer] / src / query-window.vala
index 1ab7e49..d5c9bc9 100644 (file)
@@ -25,10 +25,8 @@ public class QueryWindow : StackableWindow {
        public const string GCONF_KEY_USE_LOCATION = "/apps/beifahrer/use_location";
 
        AdacMitfahrclub adac;
-       TouchSelector city_from_selector;
-       TouchSelector city_to_selector;
-       TouchSelector umkreis_from_selector;
-       TouchSelector umkreis_to_selector;
+       CityButton departure_button;
+       CityButton arrival_button;
        DateButton date;
        TouchSelector tolerance_selector;
        Location.GPSDControl control;
@@ -49,20 +47,6 @@ public class QueryWindow : StackableWindow {
                adac = new AdacMitfahrclub ();
                gconf = GConf.Client.get_default ();
 
-               city_from_selector = new TouchSelectorEntry.text ();
-               city_to_selector = new TouchSelectorEntry.text ();
-               foreach (unowned City city in adac.get_city_list ()) {
-                       city_from_selector.append_text (city.name);
-                       city_to_selector.append_text (city.name);
-               }
-
-               umkreis_from_selector = new TouchSelector.text ();
-               umkreis_to_selector = new TouchSelector.text ();
-               for (int km = 0; km <= 50; km += 10) {
-                       umkreis_from_selector.append_text ("%d km".printf (km));
-                       umkreis_to_selector.append_text ("%d km".printf (km));
-               }
-
                tolerance_selector = new TouchSelector.text ();
                for (int days = 0; days <= 4; days += 1)
                        tolerance_selector.append_text (_("+/- %d days").printf (days));
@@ -73,59 +57,41 @@ public class QueryWindow : StackableWindow {
                alignment.right_padding = MARGIN_DOUBLE;
                var table = new Table (5, 2, false);
 
-               var button = new PickerButton (SizeType.FINGER_HEIGHT,
-                                              ButtonArrangement.VERTICAL);
-               button.set_selector (city_from_selector);
-               button.set_title (_("Departure"));
-               button.set_value (_("Please select"));
-               button.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
-               table.attach (button, 0, 1, 0, 1, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+               departure_button = new CityButton (SizeType.FINGER_HEIGHT,
+                                                  ButtonArrangement.VERTICAL, adac.get_city_list ());
+               departure_button.set_title (_("Departure"));
+               departure_button.set_value (_("Please select"));
+               departure_button.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
+               table.attach (departure_button, 0, 2, 0, 1, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
 
                try {
-                       button.set_active (gconf.get_int ("/apps/beifahrer/departure"));
+                       departure_button.set_active (gconf.get_int ("/apps/beifahrer/departure"));
                } catch (Error e) {
                }
 
-               button = new PickerButton (SizeType.FINGER_HEIGHT,
-                                          ButtonArrangement.VERTICAL);
-               button.set_selector (umkreis_from_selector);
-               button.set_title (_("Vicinity"));
-               button.set_value ("0 km");
-               button.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
-               table.attach (button, 1, 2, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-
-               button = new PickerButton (SizeType.FINGER_HEIGHT,
-                                          ButtonArrangement.VERTICAL);
-               button.set_selector (city_to_selector);
-               button.set_title (_("Arrival"));
-               button.set_value (_("Please select"));
-               button.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
-               table.attach (button, 0, 1, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+               arrival_button = new CityButton (SizeType.FINGER_HEIGHT,
+                                                ButtonArrangement.VERTICAL, adac.get_city_list ());
+               arrival_button.set_title (_("Arrival"));
+               arrival_button.set_value (_("Please select"));
+               arrival_button.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
+               table.attach (arrival_button, 0, 2, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
 
                try {
-                       button.set_active (gconf.get_int ("/apps/beifahrer/arrival"));
+                       arrival_button.set_active (gconf.get_int ("/apps/beifahrer/arrival"));
                } catch (Error e) {
                }
 
-               button = new PickerButton (SizeType.FINGER_HEIGHT,
-                                          ButtonArrangement.VERTICAL);
-               button.set_selector (umkreis_to_selector);
-               button.set_title (_("Vicinity"));
-               button.set_value ("0 km");
-               button.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
-               table.attach (button, 1, 2, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-
                var switch_button = new Gtk.Button.with_label (_("Switch departure and arrival"));
                Hildon.gtk_widget_set_theme_size (switch_button, SizeType.FINGER_HEIGHT);
                switch_button.set_alignment (0.0f, 0.5f);
-               table.attach (switch_button, 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+               table.attach (switch_button, 0, 2, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
 
                date = new DateButton (SizeType.FINGER_HEIGHT,
                                       ButtonArrangement.VERTICAL);
                date.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
                table.attach (date, 0, 1, 3, 4, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
 
-               button = new PickerButton (SizeType.FINGER_HEIGHT,
+               var button = new PickerButton (SizeType.FINGER_HEIGHT,
                                           ButtonArrangement.VERTICAL);
                button.set_selector (tolerance_selector);
                button.set_title (_("Tolerance"));
@@ -199,17 +165,17 @@ public class QueryWindow : StackableWindow {
                        unowned City city = adac.find_nearest_city (device.fix.latitude, device.fix.longitude);
                        if (city != null) {
                                int n = adac.get_city_list ().index (city);
-                               int n_from = city_from_selector.get_active (0);
-                               int n_to = city_to_selector.get_active (0);
+                               int n_from = departure_button.get_active ();
+                               int n_to = arrival_button.get_active ();
 
                                print ("city(%d): %s (%d)\n", n, city.name, city.number);
 
                                if (n != n_from) {
-                                       city_from_selector.set_active (0, n);
+                                       departure_button.set_active (n);
 
                                        // If we are at the previous point of arrival, prepare for return trip
                                        if (n == n_to)
-                                               city_to_selector.set_active (0, n_from);
+                                               arrival_button.set_active (n_from);
                                }
                        }
 
@@ -221,7 +187,7 @@ public class QueryWindow : StackableWindow {
        void on_search_button_clicked (Gtk.Button button) {
                int n;
 
-               n = city_from_selector.get_active (0);
+               n = departure_button.get_active ();
                if (n == -1)
                        return;
                string city_from = adac.get_city_list ().nth_data (n).name;
@@ -231,7 +197,7 @@ public class QueryWindow : StackableWindow {
                } catch (Error e) {
                }
 
-               n = city_to_selector.get_active (0);
+               n = arrival_button.get_active ();
                if (n == -1)
                        return;
                string city_to = adac.get_city_list ().nth_data (n).name;
@@ -252,17 +218,17 @@ public class QueryWindow : StackableWindow {
 
                var window = new LiftListWindow (adac);
                window.show ();
-               window.find_lifts.begin (city_from, city_to, date, tolerance);
+               window.find_lifts.begin (city_from, departure_button.get_radius (), city_to, arrival_button.get_radius (), date, tolerance);
        }
 
        // Switch departure and arrival
        void on_switch_button_clicked () {
-               int n = city_from_selector.get_active (0);
-               city_from_selector.set_active (0, city_to_selector.get_active (0));
-               city_to_selector.set_active (0, n);
-               n = umkreis_from_selector.get_active (0);
-               umkreis_from_selector.set_active (0, umkreis_to_selector.get_active (0));
-               umkreis_to_selector.set_active (0, n);
+               int n = departure_button.get_active ();
+               departure_button.set_active (arrival_button.get_active ());
+               arrival_button.set_active (n);
+               n = departure_button.get_radius ();
+               departure_button.set_radius (arrival_button.get_radius ());
+               arrival_button.set_radius (n);
        }
 
        void on_settings_clicked () {