1 /* This file is part of Beifahrer.
3 * Copyright (C) 2010 Philipp Zabel
5 * Beifahrer is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Beifahrer is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Beifahrer. If not, see <http://www.gnu.org/licenses/>.
22 class CityButton : Hildon.Button {
23 private enum Response {
28 TouchSelector city_selector;
29 PickerButton radius_button;
33 public CityButton (SizeType size, ButtonArrangement arrangement, List<City> city_list) {
34 GLib.Object (arrangement: arrangement, size: size);
35 set_style (ButtonStyle.PICKER);
37 city_selector = new TouchSelectorEntry.text ();
38 foreach (unowned City city in city_list)
39 city_selector.append_text (city.name);
41 clicked.connect (on_clicked);
44 public void set_active (int _active) {
46 city_selector.set_active (0, active);
50 public int get_active () {
54 public void set_radius (int _radius) {
59 public int get_radius () {
63 private void on_clicked () {
64 dialog = new Gtk.Dialog ();
65 dialog.set_transient_for (find_parent_window ());
67 var content_area = (Box) dialog.get_content_area ();
68 content_area.pack_start (city_selector, true, true, 0);
69 city_selector.set_size_request (-1, 5*70);
71 var radius_selector = new TouchSelector.text ();
72 for (int km = 0; km <= 50; km += 10)
73 radius_selector.append_text ("%d km".printf (km));
75 radius_button = new PickerButton (SizeType.FINGER_HEIGHT,
76 ButtonArrangement.VERTICAL);
77 radius_button.set_selector (radius_selector);
78 radius_button.set_title (_("Radius"));
79 radius_button.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
80 radius_button.set_active (radius / 10);
81 dialog.add_action_widget (radius_button, Response.RADIUS);
83 var action_area = (ButtonBox) dialog.get_action_area ();
84 action_area.set_child_secondary (radius_button, true);
86 dialog.add_button (_("Done"), Gtk.ResponseType.OK);
88 dialog.response.connect (on_response);
93 private void on_response (int response_id) {
94 if (response_id == Gtk.ResponseType.OK) {
95 active = city_selector.get_active (0);
96 radius = radius_button.get_active () * 10;
99 if (response_id != Response.RADIUS) {
100 // Unlink the city_selector so it doesn't get destroyed with the dialog
101 var content_area = (Box) dialog.get_content_area ();
102 content_area.remove (city_selector);
108 private void update_value () {
109 if (get_radius () == 0)
110 set_value (city_selector.get_current_text ());
112 set_value ("%s, radius %d km".printf (city_selector.get_current_text (), radius));
115 private Gtk.Window? find_parent_window () {
116 for (Gtk.Widget p = parent; p != null; p = p.parent)
118 return (Gtk.Window) p;