Add an option to preload lift details in the background
authorPhilipp Zabel <philipp.zabel@gmail.com>
Fri, 28 May 2010 18:54:06 +0000 (20:54 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Fri, 28 May 2010 20:18:35 +0000 (22:18 +0200)
Improves user experience at the expense of higher network usage.

src/lift-list-window.vala
src/settings-dialog.vala

index eba0adc..118a81a 100644 (file)
@@ -20,11 +20,15 @@ using Gtk;
 using Hildon;
 
 public class LiftListWindow : StackableWindow {
+       public const string GCONF_KEY_PRELOAD = "/apps/beifahrer/preload";
+
        AdacMitfahrclub adac;
        ListStore store;
        TreeView tree;
        TreeViewColumn route_column;
        Label no_lifts;
+       GConf.Client gconf;
+       bool preload = false;
 
        public LiftListWindow (AdacMitfahrclub _adac) {
                adac = _adac;
@@ -33,6 +37,7 @@ public class LiftListWindow : StackableWindow {
        construct {
                set_title ("Beifahrer");
 
+               gconf = GConf.Client.get_default ();
                store = new ListStore (6, typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (Lift));
 
                tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, store);
@@ -128,6 +133,23 @@ public class LiftListWindow : StackableWindow {
                }
                if (lift_list.length () == 0)
                        no_lifts.show ();
+
+               bool preload = false;
+               try {
+                       preload = gconf.get_bool (GCONF_KEY_PRELOAD);
+               } catch (Error e) {
+               }
+               if (preload) {
+                       if (store.get_iter_first (out iter)) do {
+                               Lift lift2;
+                               store.@get (iter, 5, out lift2);
+                               if (lift2 == null)
+                                       continue;
+                               if (lift2.description == null)
+                                       yield adac.update_lift_details (lift2);
+                       } while (store.iter_next (ref iter));
+               }
+
                Hildon.gtk_window_set_progress_indicator (this, 0);
        }
 
index c872455..8617e83 100644 (file)
@@ -21,8 +21,10 @@ using Hildon;
 
 public class SettingsDialog : Gtk.Dialog {
        public const string GCONF_KEY_USE_LOCATION = "/apps/beifahrer/use_location";
+       public const string GCONF_KEY_PRELOAD = "/apps/beifahrer/preload";
 
        Hildon.CheckButton use_location;
+       Hildon.CheckButton preload;
        GConf.Client gconf;
 
        public SettingsDialog (Gtk.Window window) {
@@ -32,7 +34,10 @@ public class SettingsDialog : Gtk.Dialog {
                var vbox = (VBox) get_content_area ();
                use_location = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
                use_location.set_label (_("Determine point of departure automatically"));
+               preload = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
+               preload.set_label (_("Preload lift details in the background"));
                vbox.pack_start (use_location, true, true, 0);
+               vbox.pack_start (preload, true, true, 0);
                vbox.show_all ();
 
                add_button (_("Save"), ResponseType.APPLY);
@@ -40,6 +45,7 @@ public class SettingsDialog : Gtk.Dialog {
                gconf = GConf.Client.get_default ();
                try {
                        use_location.set_active (gconf.get_bool (GCONF_KEY_USE_LOCATION));
+                       preload.set_active (gconf.get_bool (GCONF_KEY_PRELOAD));
                } catch (Error e) {
                        use_location.set_active (true);
                }
@@ -50,7 +56,8 @@ public class SettingsDialog : Gtk.Dialog {
        void on_response (int response_id) {
                if (response_id == ResponseType.APPLY) try {
                        gconf.set_bool (GCONF_KEY_USE_LOCATION, use_location.get_active ());
-                       this.destroy ();
+                       gconf.set_bool (GCONF_KEY_PRELOAD, preload.get_active ());
+                       this.destroy ();
                } catch (Error e) {
                }
        }