Show gsm info
authorEnrico Zini <enrico@enricozini.org>
Fri, 26 Mar 2010 19:03:33 +0000 (19:03 +0000)
committerEnrico Zini <enrico@enricozini.org>
Fri, 26 Mar 2010 19:03:33 +0000 (19:03 +0000)
src/app_main.vala
zavai/gsm.vala

index b7752cb423f34168eb3d16d0cf642987c8e5c6fe..1f101dfd7789800245b9f5851ae0b383f2f8a527 100644 (file)
@@ -131,6 +131,7 @@ public class Status : Applet
     public Gtk.HBox status_icons;
     public Clock clock;
     public Gtk.Label gsm_status;
+    public Gtk.Label gsm_info;
     public AppletPushLink menu;
 
     public Status(string label)
@@ -144,10 +145,14 @@ public class Status : Applet
         pack_start(status_icons, false, false, 0);
         pack_start(clock, false, false, 0);
         pack_start(gsm_status, false, false, 0);
+        pack_start(gsm_info, false, false, 0);
         // pack_start(music.player, false, false, 0);
         pack_end(menu, false, false, 0);
 
         zavai.gsm.gsm.status_changed += (msg) => { gsm_status.set_text(msg); };
+        zavai.gsm.gsm.info_changed += () => {
+            gsm_info.set_text("%s %d%%".printf(zavai.gsm.gsm.info_provider, zavai.gsm.gsm.info_signal_strength));
+        };
     }
 }
 
index dcb8646b42a45197dd568680d27aec69fad1f231..6829a291380b9cdfc5959bf86e74496584d4495d 100644 (file)
@@ -109,32 +109,59 @@ public class GSM: zavai.ScriptMonitorService
     public FSO_GSM_SIM sim;
     public dynamic DBus.Object call;
 
+    public string info_provider;
+    public int info_signal_strength;
+
     public signal void status_changed(string message);
+    public signal void info_changed();
 
-    public GSM()
+    protected void dump_table(HashTable<string, Value?> vals)
     {
-        Object(name: "gsm");
+        vals.for_each((pk, pv) => {
+            string k = (string)pk;
+            Value? v = (Value?)pv;
+            stderr.printf("K: %s V: %s\n", k, v == null ? "(null)" : v.strdup_contents());
+        });
+    }
 
-        device = null;
-        network = null;
-        sim = null;
-        call = null;
+    protected void acquire_new_status(HashTable<string, Value?> status)
+    {
+        // NETWORK STATUS
+        // K: provider V: "vodafone UK"
+        // K: mode V: "automatic"
+        // K: registration V: "roaming"
+        // K: cid V: "157F"
+        // K: lac V: "0031"
+        // K: act V: "GSM"
+        // K: code V: "23415"
+        bool changed = false;
 
-        dbus = zavai.registry.sbus.get_object(
-                "org.freedesktop.DBus",
-                "/org/freedesktop/DBus",
-                "org.freedesktop.DBus");
-        dbus.NameOwnerChanged += on_name_owner_changed;
+        var vprovider = status.lookup("provider");
+        if (vprovider != null)
+        {
+            if (info_provider != vprovider.get_string())
+            {
+                info_provider = vprovider.get_string();
+                changed = true;
+            }
+        }
+
+        if (changed)
+            info_changed();
     }
 
-    /// Request GPS resource
-    public override void start()
+    protected void acquire_new_signal_strength(int strength)
     {
-        if (started) return;
-
-        status_changed("Starting");
+        if (info_signal_strength != strength)
+        {
+            info_signal_strength = strength;
+            info_changed();
+        }
+    }
 
-        script_start();
+    public GSM()
+    {
+        Object(name: "gsm");
 
         device = (FSO_GSM_Device)zavai.registry.sbus.get_object(
                 "org.freesmartphone.ogsmd", 
@@ -152,6 +179,35 @@ public class GSM: zavai.ScriptMonitorService
             "org.freesmartphone.ogsmd", 
             "/org/freesmartphone/GSM/Device",
             "org.freesmartphone.GSM.Call");
+        dbus = zavai.registry.sbus.get_object(
+                "org.freedesktop.DBus",
+                "/org/freedesktop/DBus",
+                "org.freedesktop.DBus");
+        dbus.NameOwnerChanged += on_name_owner_changed;
+
+        info_provider = "(unknown)";
+        info_signal_strength = -1;
+
+        network.status += (status) => {
+            stderr.printf("NETWORK STATUS\n");
+            dump_table(status);
+            acquire_new_status(status);
+        };
+
+        network.signal_strength += (strength) => {
+            stderr.printf("SIGNAL STRENGTH %d\n", strength);
+            acquire_new_signal_strength(strength);
+        };
+    }
+
+    /// Request GPS resource
+    public override void start()
+    {
+        if (started) return;
+
+        status_changed("Starting");
+
+        script_start();
 
         base.start();
     }
@@ -222,6 +278,9 @@ public class GSM: zavai.ScriptMonitorService
         status_changed("Registering with network");
         yield network.register_();
         status_changed("Registered with network");
+
+        acquire_new_status(yield network.get_status());
+        acquire_new_signal_strength(yield network.get_signal_strength());
     }
 }