Added dbus config
[gregoa/zavai.git] / src / app_gps.vala
index f414444eb7ce7ca795103d92d89b5c36cff4eb54..72545bcfd10a5f1a16a29f71643a36b9ea799449 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+using GLib;
+
 namespace zavai {
 namespace ui {
 namespace gps {
 
-/*
-class GPSOn(gtk.ToggleAction):
-    states = [_("GPS always on"), _("GPS on when needed")]
-
-    def __init__(self, registry, **kw):
-        self.state = 0
-        super(GPSOn, self).__init__("menu.main.gps.alwayson", self.states[self.state], None, None)
-
-        self.registry = registry
-        self.set_active(False)
-
-        self.connect("toggled", self.on_toggle)
-
-    def on_toggle(self, *args):
-        self.state = (self.state + 1) % len(self.states)
-        self.set_property("label", self.states[self.state])
-        if self.get_active():
-            self.start()
-        else:
-            self.stop()
-
-    def start(self):
-        self.registry.resource("gps").connect("gps", self)
-
-    def stop(self):
-        self.registry.resource("gps").disconnect("gps", self)
-
-class GPXTracer(gtk.ToggleAction):
-    states = [_("Start GPX trace"), _("Stop GPX trace")]
-
-    def __init__(self, registry, **kw):
-        self.state = 0
-        super(GPXTracer, self).__init__("menu.main.gps.gpx", self.states[self.state], None, None)
-
-        self.registry = registry
-        self.set_active(False)
-
-        self.connect("toggled", self.on_toggle)
-
-    def on_toggle(self, *args):
-        self.state = (self.state + 1) % len(self.states)
-        self.set_property("label", self.states[self.state])
-        if self.get_active():
-            self.start()
-        else:
-            self.stop()
-
-    def start(self):
-        zavai.info("GPX trace started")
-        self.registry.resource("gpx").connect("gpx", self)
-
-    def stop(self):
-        zavai.info("GPX trace ended")
-        self.registry.resource("gpx").disconnect("gpx", self)
-*/
-
 public class Waypoint : BigButton
 {
-    public Waypoint()
-    {
-        set_label("Take waypoint");
-        zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
-        clicked += on_clicked;
-        set_sensitive(zavai.gps.gpx.tracking);
-    }
-
-    protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
-    {
-stderr.printf("Toggled %d\n", (int)new_state);
-        set_sensitive(new_state);
-    }
-
-    protected void on_clicked()
-    {
-stderr.printf("Activate\n");
-        zavai.gps.gpx.waypoint();
-    }
+       public Waypoint()
+       {
+               set_label("Take waypoint");
+               zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
+               clicked += on_clicked;
+               set_sensitive(zavai.gps.gpx.tracking);
+       }
+
+       protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
+       {
+               stderr.printf("Toggled %d\n", (int)new_state);
+               set_sensitive(new_state);
+       }
+
+       protected void on_clicked()
+       {
+               stderr.printf("Activate\n");
+               zavai.gps.gpx.waypoint();
+       }
 }
 
 /*
@@ -152,50 +98,50 @@ public class GPSRequestLink : Gtk.ToggleButton
        protected string service_name;
        protected string label_start;
        protected string label_stop;
-    protected Gtk.StatusIcon status_icon;
-    protected int fix_status = 0;
+       protected zavai.StatusIcon status_icon;
+       protected int fix_status = 0;
 
        public GPSRequestLink()
        {
-        service_name = "gps";
-        label_start = "Keep GPS on";
-        label_stop = "Stop keeping GPS on";
+               service_name = "gps";
+               label_start = "Keep GPS on";
+               label_stop = "Stop keeping GPS on";
                set_size_request(0, zavai.config.min_button_height);
                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;
-
-        // GPS status icon
-        status_icon = new Gtk.StatusIcon();
-        status_icon.set_visible(true);
-        status_icon.activate += on_status_activate;
-        update_icon();
+               //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;
+
+               // GPS status icon
+               status_icon = new zavai.StatusIcon();
+               status_icon.install();
+               status_icon.clicked += on_status_clicked;
+               update_icon();
+       }
+
+       protected void update_icon()
+       {
+               string name;
+               if (fix_status == 2 || fix_status == 3)
+                       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");
+               stderr.printf("load icon from %s\n", name);
+               status_icon.set_from_file(name);
        }
 
-    protected void update_icon()
-    {
-        string name;
-        if (fix_status == 2 || fix_status == 3)
-            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");
-stderr.printf("load icon from %s\n", name);
-        status_icon.set_from_file(name);
-    }
-
-    private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
-    {
-        this.fix_status = fix_status;
-        update_icon();
-    }
+       private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
+       {
+               this.fix_status = fix_status;
+               update_icon();
+       }
 
        private void on_toggled(Gtk.Button src)
        {
@@ -205,45 +151,31 @@ stderr.printf("load icon from %s\n", name);
                else
                        s.release("servicerequestlink");
                set_label(get_active() ? label_stop : label_start);
-        update_icon();
+               update_icon();
        }
 
-    private void on_status_activate()
-    {
-        set_active(!get_active());
-    }
+       private void on_status_clicked(Gtk.Button b)
+       {
+               set_active(!get_active());
+       }
 }
 
 public void init()
 {
     /*
     registry.register(GPXAudioTracer(registry))
-    registry.register(GPXWaypoint(registry))
+    */
 
     // Apps
-    var useless = new Useless();
-    zavai.registry.register_applet("app.debug.useless", useless);
-    */
     var menu_waypoint = new Waypoint();
     var menu_gpsrequest = new GPSRequestLink();
-               //label_on = "Stop GPX trace";
-               //label_off = "Start GPX trace";
-               //label_on = "Stop GPS monitor";
-               //label_off = "Start GPS monitor";
-               //label_on = "Stop GPS position tracking";
-               //label_off = "Start GPS position tracking";
-               //label_on = "Stop keeping GPS on";
-               //label_off = "Keep GPS on";
 
     // Menus
-    var menu_gps = new zavai.Menu("GPS");
-    //menu_gps.add_applet("app.debug.useless");
+    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);
-
-    zavai.registry.register_menu("menu.gps", menu_gps);
-    zavai.registry.getmenu("menu.main").add_applet("menu.gps");
 }
 
 }