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;
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));
- 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);
settings.clicked.connect (on_settings_clicked);
show_all ();
control = Location.GPSDControl.get_default ();
- control.preferred_method = Location.METHOD_CWP | Location.METHOD_ACWP;
+ control.preferred_method = Location.METHOD_ACWP;
control.preferred_interval = Location.GPSDControlInterval.@1S;
control.error.connect (() => { print ("control error\n"); });
control.error_verbose.connect ((e) => {
}
void on_location_changed () requires (device.fix != null) {
- if (!want_location)
+ if (!want_location || device.status == Location.GPSDeviceStatus.NO_FIX)
return;
if (Location.GPS_DEVICE_LATLONG_SET in (int) device.fix.fields) {
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);
}
}
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;
} 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;
date.set_month ((DateMonth) (month + DateMonth.JANUARY));
date.set_year ((DateYear) year);
- Hildon.gtk_window_set_progress_indicator (this, 1);
+ int tolerance = tolerance_selector.get_active (0);
+
var window = new LiftListWindow (adac);
- window.show_all ();
- window.find_lifts (city_from, city_to, date);
- Hildon.gtk_window_set_progress_indicator (this, 0);
+ window.show ();
+ window.find_lifts.begin (city_from, city_to, 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_settings_clicked () {