Debian packaging: 0.0.4-1
[beifahrer] / src / city-button.vala
index d1a2a63..793b8e3 100644 (file)
@@ -29,11 +29,13 @@ class CityButton : Hildon.Button {
        PickerButton radius_button;
        int active = 0;
        int radius = 0;
+       bool use_radius;
 
-       public CityButton (SizeType size, ButtonArrangement arrangement, List<City> city_list) {
+       public CityButton (SizeType size, ButtonArrangement arrangement, List<City> city_list, bool with_radius = true) {
                GLib.Object (arrangement: arrangement, size: size);
                set_style (ButtonStyle.PICKER);
 
+               use_radius = with_radius;
                city_selector = new TouchSelectorEntry.text ();
                foreach (unowned City city in city_list)
                        city_selector.append_text (city.name);
@@ -41,6 +43,24 @@ class CityButton : Hildon.Button {
                clicked.connect (on_clicked);
        }
 
+       public void set_city (string city) {
+               var model = city_selector.get_model (0);
+               string _city;
+               int n = 0;
+
+               TreeIter iter;
+               if (model.get_iter_first (out iter)) {
+                       do {
+                               model.get (iter, 0, out _city);
+                               if (city == _city) {
+                                       set_active (n);
+                                       return;
+                               }
+                               n++;
+                       } while (model.iter_next (ref iter));
+               }
+       }
+
        public void set_active (int _active) {
                active = _active;
                city_selector.set_active (0, active);
@@ -63,25 +83,28 @@ class CityButton : Hildon.Button {
        private void on_clicked () {
                dialog = new Gtk.Dialog ();
                dialog.set_transient_for (find_parent_window ());
+               dialog.set_title (get_title ());
 
                var content_area = (Box) dialog.get_content_area ();
-               content_area.set_size_request (-1, 5*70);
                content_area.pack_start (city_selector, true, true, 0);
+               city_selector.set_size_request (-1, 5*70);
 
                var radius_selector = new TouchSelector.text ();
                for (int km = 0; km <= 50; km += 10)
                        radius_selector.append_text ("%d km".printf (km));
 
-               radius_button = new PickerButton (SizeType.FINGER_HEIGHT,
-                                                 ButtonArrangement.VERTICAL);
-               radius_button.set_selector (radius_selector);
-               radius_button.set_title (_("Radius"));
-               radius_button.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
-               radius_button.set_active (radius / 10);
-               dialog.add_action_widget (radius_button, Response.RADIUS);
-
-               var action_area = (ButtonBox) dialog.get_action_area ();
-               action_area.set_child_secondary (radius_button, true);
+               if (use_radius) {
+                       radius_button = new PickerButton (SizeType.FINGER_HEIGHT,
+                                                         ButtonArrangement.VERTICAL);
+                       radius_button.set_selector (radius_selector);
+                       radius_button.set_title (_("Radius"));
+                       radius_button.set_alignment (0.0f, 0.0f, 0.5f, 0.5f);
+                       radius_button.set_active (radius / 10);
+                       dialog.add_action_widget (radius_button, Response.RADIUS);
+
+                       var action_area = (ButtonBox) dialog.get_action_area ();
+                       action_area.set_child_secondary (radius_button, true);
+               }
 
                dialog.add_button (_("Done"), Gtk.ResponseType.OK);