Debian packaging: 0.0.4-1
[beifahrer] / src / query-window.vala
index 1730193..85c73f1 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;
@@ -41,96 +39,87 @@ public class QueryWindow : StackableWindow {
                set_title ("Beifahrer");
 
                var menu = new AppMenu ();
+               var my_info = new Gtk.Button.with_label (_("My information"));
+               var my_offers = new Gtk.Button.with_label (_("My offers"));
                var settings = new Gtk.Button.with_label (_("Settings"));
-               settings.show ();
+               menu.append (my_info);
+               menu.append (my_offers);
                menu.append (settings);
+               menu.show_all ();
                set_main_menu (menu);
 
                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));
+               try {
+                       adac.set_credentials (gconf.get_string ("/apps/beifahrer/adac/username"),
+                                             gconf.get_string ("/apps/beifahrer/adac/password"));
+               } catch (Error e) {
                }
 
                tolerance_selector = new TouchSelector.text ();
                for (int days = 0; days <= 4; days += 1)
                        tolerance_selector.append_text (_("+/- %d days").printf (days));
 
-               var table = new Table (4, 2, false);
+               var 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;
+               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, 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, 2, 3, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+               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"));
                button.set_value (_("+/- 0 days"));
                button.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
-               table.attach (button, 1, 2, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+               table.attach (button, 1, 2, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
 
                var search_button = new Gtk.Button.with_label (_("Search"));
                Hildon.gtk_widget_set_theme_size (search_button, SizeType.FINGER_HEIGHT);
-               table.attach (search_button, 0, 2, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+               table.attach (search_button, 0, 2, 4, 5, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
 
-               add (table);
+               alignment.add (table);
+               add (alignment);
 
+               switch_button.clicked.connect (on_switch_button_clicked);
                search_button.clicked.connect (on_search_button_clicked);
+               my_info.clicked.connect (on_my_info_clicked);
+               my_offers.clicked.connect (on_my_offers_clicked);
                settings.clicked.connect (on_settings_clicked);
 
                show_all ();
@@ -188,17 +177,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);
                                }
                        }
 
@@ -210,7 +199,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;
@@ -220,7 +209,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;
@@ -239,11 +228,30 @@ public class QueryWindow : StackableWindow {
 
                int tolerance = tolerance_selector.get_active (0);
 
-               Hildon.gtk_window_set_progress_indicator (this, 1);
                var window = new LiftListWindow (adac);
                window.show ();
-               window.find_lifts (city_from, city_to, date, tolerance);
-               Hildon.gtk_window_set_progress_indicator (this, 0);
+               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 = 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_my_info_clicked () {
+               var window = new MyInformationWindow (adac);
+               window.show ();
+       }
+
+       void on_my_offers_clicked () {
+               var window = new MyOffersWindow (adac);
+               window.show ();
+               window.get_my_offers.begin ();
        }
 
        void on_settings_clicked () {