Implemented keyboard action and service
authorEnrico Zini <enrico@enricozini.org>
Wed, 22 Jul 2009 18:48:24 +0000 (20:48 +0200)
committerEnrico Zini <enrico@enricozini.org>
Wed, 22 Jul 2009 18:48:24 +0000 (20:48 +0200)
src/app_keyboard.vala

index 790ffa1097a682b07e8f184894d9d3dde9f39d1e..ad2e69356febcb58de88a778549fad60f156bced 100644 (file)
@@ -28,6 +28,11 @@ public class Keyboard : Service
 {
        protected Pid pid;
 
+       public Keyboard()
+       {
+               name = "keyboard";
+       }
+
        private void on_child_quit(Pid pid, int status)
        {
                Process.close_pid(pid);
@@ -191,33 +196,39 @@ class GPXAudioTracer(gtk.ToggleAction):
             self.recorder.stop()
 */
 
-/*
-public class GPSRequestLink : Gtk.ToggleButton
+public class KeyboardIcon : Gtk.StatusIcon
 {
-       protected string service_name;
-       protected string label_start;
-       protected string label_stop;
-    protected Gtk.StatusIcon status_icon;
-    protected int fix_status = 0;
+       bool requested = false;
 
-       public GPSRequestLink()
+       public KeyboardIcon()
        {
-        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;
+               activate += on_activate;
+               update_icon();
+       }
 
-               set_label(get_active() ? label_stop : label_start);
+       private void on_activate()
+       {
+               requested = !requested;
+               update_icon();
+               if (requested)
+                       keyboard.request("keyboardicon");
+               else
+                       keyboard.release("keyboardicon");
+       }
 
-        //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;
+       protected void update_icon()
+       {
+               string name = zavai.config.icondir + "/" + (requested ? "kbd_on.png" : "kbd_off.png");
+               stderr.printf("load icon from %s\n", name);
+               set_from_file(name);
+       }
+}
 
+/*
+public class GPSRequestLink : Gtk.ToggleButton
+{
+       public GPSRequestLink()
+       {
         // GPS status icon
         status_icon = new Gtk.StatusIcon();
         status_icon.set_visible(true);
@@ -225,17 +236,6 @@ public class GPSRequestLink : Gtk.ToggleButton
         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;
@@ -260,39 +260,16 @@ stderr.printf("load icon from %s\n", name);
 }
 */
 
+Keyboard keyboard;
+KeyboardIcon icon;
+
 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");
-    menu_gps.add_service_toggle("gps.gpx", "Start GPX trace", "Stop GPX trace");
-    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");
-    */
+stderr.printf("INIT KBD\n");
+       keyboard = new Keyboard();
+       zavai.registry.register_service(keyboard);
+       icon = new KeyboardIcon();
+       icon.set_visible(true);
 }
 
 }