]> ToastFreeware Gitweb - gregoa/zavai.git/blobdiff - src/app_gps.vala
butcher butcher butcher
[gregoa/zavai.git] / src / app_gps.vala
index aac99d770fb87a878d90cae2b0be7c219fc45d71..65aebb464bcef68fff24f93f7d6567cb85cb88b6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * gpx_trace - zavai GPX trace functions
  *
- * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
+ * Copyright (C) 2009--2010  Enrico Zini <enrico@enricozini.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,12 +29,12 @@ public class Waypoint : BigButton
     public Waypoint()
     {
         set_label("Take waypoint");
-        zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
+        zavai.gps.gpx.toggled += on_gpx_toggled;
         clicked += on_clicked;
-        set_sensitive(zavai.gps.gpx.tracking);
+        set_sensitive(zavai.gps.gpx.started);
     }
 
-    protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
+    protected void on_gpx_toggled(bool new_state)
     {
         stderr.printf("Toggled %d\n", (int)new_state);
         set_sensitive(new_state);
@@ -95,7 +95,6 @@ class GPXAudioTracer(gtk.ToggleAction):
 
 public class GPSRequestLink : Gtk.ToggleButton
 {
-    protected string service_name;
     protected string label_start;
     protected string label_stop;
     protected zavai.StatusIcon status_icon;
@@ -103,21 +102,17 @@ public class GPSRequestLink : Gtk.ToggleButton
 
     public GPSRequestLink()
     {
-        service_name = "gps";
         label_start = "Keep GPS on";
         label_stop = "Stop keeping GPS on";
         set_size_request(0, zavai.config.min_button_height);
+        set_active(zavai.gps.gps.started);
         toggled += on_toggled;
 
         set_label(get_active() ? label_stop : label_start);
 
         //tooltip = "GPS status";
-        try {
-            fix_status = zavai.gps.gps.device.GetFixStatus();
-        } catch (Error e) {
-            fix_status = 0;
-        }
-        zavai.gps.gps.device.FixStatusChanged += on_fix_status_changed;
+        fix_status = zavai.gps.gps.fix_status();
+        zavai.gps.gps.fix_status_changed += on_fix_status_changed;
 
         // GPS status icon
         status_icon = new zavai.StatusIcon();
@@ -129,7 +124,7 @@ public class GPSRequestLink : Gtk.ToggleButton
     protected void update_icon()
     {
         string name;
-        if (fix_status == 2 || fix_status == 3)
+        if (fix_status != libgps.STATUS_NO_FIX)
             name = zavai.config.icondir + "/" + (get_active() ? "gps_fix_on.png" : "gps_fix_off.png");
         else
             name = zavai.config.icondir + "/" + (get_active() ? "gps_nofix_on.png" : "gps_nofix_off.png");
@@ -137,7 +132,7 @@ public class GPSRequestLink : Gtk.ToggleButton
         status_icon.set_from_file(name);
     }
 
-    private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
+    private void on_fix_status_changed(int fix_status)
     {
         this.fix_status = fix_status;
         update_icon();
@@ -145,11 +140,10 @@ public class GPSRequestLink : Gtk.ToggleButton
 
     private void on_toggled(Gtk.Button src)
     {
-        Service s = zavai.registry.gets(service_name);
         if (get_active())
-            s.request("servicerequestlink");
+            zavai.gps.gps.request("servicerequestlink");
         else
-            s.release("servicerequestlink");
+            zavai.gps.gps.release("servicerequestlink");
         set_label(get_active() ? label_stop : label_start);
         update_icon();
     }
@@ -160,29 +154,6 @@ public class GPSRequestLink : Gtk.ToggleButton
     }
 }
 
-public class GPSStuck : Gtk.Button
-{
-    protected bool happened;
-
-    public GPSStuck()
-    {
-        label = "The GPS is stuck";
-        happened = false;
-        clicked += on_clicked;
-        set_size_request(0, zavai.config.min_button_height);
-    }
-
-    public void on_clicked()
-    {
-        zavai.gps.gps.power_cycle(happened);
-        happened = !happened;
-        if (happened)
-            label = "The GPS is stuck AGAIN";
-        else
-            label = "The GPS is stuck";
-    }
-}
-
 public void init()
 {
     /*
@@ -194,12 +165,11 @@ public void init()
     var menu_gpsrequest = new GPSRequestLink();
 
     // Menus
-    var menu_gps = zavai.registry.getmenu("menu.gps");
-    menu_gps.add_service_toggle("gps.gpx", "Start GPX trace", "Stop GPX trace");
-    //menu_gps.add_applet("ui.gps.monitor");
-    menu_gps.add_widget(menu_waypoint);
-    menu_gps.add_widget(menu_gpsrequest);
-    menu_gps.add_widget(new GPSStuck());
+    zavai.menu_gps.add_service_toggle(zavai.gps.gpx, "Start GPX trace", "Stop GPX trace");
+    //zavai.menu_gps.add_applet("ui.gps.monitor");
+    zavai.menu_gps.add_widget(menu_waypoint);
+    zavai.menu_gps.add_widget(menu_gpsrequest);
+    //zavai.menu_gps.add_widget(new GPSStuck());
 }
 
 }