/*
* 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
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.toggled += on_gpx_toggled;
+ clicked += on_clicked;
+ set_sensitive(zavai.gps.gpx.started);
+ }
+
+ protected void on_gpx_toggled(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 class GPSRequestLink : Gtk.ToggleButton
{
- protected string service_name;
- protected string label_start;
- protected string label_stop;
- 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";
- 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 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);
- }
-
- 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)
- {
- Service s = zavai.registry.gets(service_name);
- if (get_active())
- s.request("servicerequestlink");
- else
- s.release("servicerequestlink");
- set_label(get_active() ? label_stop : label_start);
- update_icon();
- }
-
- private void on_status_clicked(Gtk.Button b)
- {
- set_active(!get_active());
- }
+ protected string label_start;
+ protected string label_stop;
+ protected zavai.StatusIcon status_icon;
+ protected int fix_status = 0;
+
+ public GPSRequestLink()
+ {
+ 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";
+ 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();
+ status_icon.install();
+ status_icon.clicked += on_status_clicked;
+ update_icon();
+ }
+
+ protected void update_icon()
+ {
+ string name;
+ 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");
+ stderr.printf("load icon from %s\n", name);
+ status_icon.set_from_file(name);
+ }
+
+ private void on_fix_status_changed(int fix_status)
+ {
+ this.fix_status = fix_status;
+ update_icon();
+ }
+
+ private void on_toggled(Gtk.Button src)
+ {
+ if (get_active())
+ zavai.gps.gps.request("servicerequestlink");
+ else
+ zavai.gps.gps.release("servicerequestlink");
+ set_label(get_active() ? label_stop : label_start);
+ update_icon();
+ }
+
+ private void on_status_clicked(Gtk.Button b)
+ {
+ set_active(!get_active());
+ }
}
public void init()
var menu_gpsrequest = new GPSRequestLink();
// Menus
- var menu_gps = new zavai.Menu("GPS");
- //menu_gps.add_applet("app.debug.useless");
- 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");
+ 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());
}
}