First version of a WiFi app.
authorgregor herrmann <gregoa@debian.org>
Sat, 10 Oct 2009 01:07:58 +0000 (03:07 +0200)
committergregor herrmann <gregoa@debian.org>
Fri, 8 Jan 2010 01:39:39 +0000 (02:39 +0100)
Adds app_wifi.vala and wifi.vala and icons.
The icon appears on the main screen and a service is registered.

icons/wifi_0.png [new file with mode: 0644]
icons/wifi_1.png [new file with mode: 0644]
src/Makefile.am [new file with mode: 0644]
src/app_wifi.vala [new file with mode: 0644]
src/wifi.vala [new file with mode: 0644]
src/zavai.vala

diff --git a/icons/wifi_0.png b/icons/wifi_0.png
new file mode 100644 (file)
index 0000000..928d615
Binary files /dev/null and b/icons/wifi_0.png differ
diff --git a/icons/wifi_1.png b/icons/wifi_1.png
new file mode 100644 (file)
index 0000000..ff28d9e
Binary files /dev/null and b/icons/wifi_1.png differ
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644 (file)
index 0000000..bfa6003
--- /dev/null
@@ -0,0 +1,81 @@
+VFLAGS=-g --pkg gee-1.0 --pkg dbus-glib-1 --pkg gtk+-2.0 --pkg posix --pkg libwnck-1.0 --vapidir=. --pkg linux-input --pkg dbus-extra --pkg devkit-power-gobject
+
+#zavai: $(SOURCES)
+#      valac -o zavai $(VFLAGS) $^
+#
+#C: $(SOURCES)
+#      valac -C $(VFLAGS) $^
+#
+##zavai: $(SOURCES:.vala=.vala.o)
+##     echo $<
+##     gcc $(LDFLAGS) -o zavai $*
+##
+##%.vala.o: %.vala
+##     valac $(VFLAGS) -c $<
+
+AM_CPPFLAGS = \
+       -I$(top_srcdir) \
+       $(GLIB_CFLAGS) \
+       $(DBUS_CFLAGS) \
+       $(GEE_CFLAGS) \
+       $(GTK_CFLAGS) \
+       $(WNCK_CFLAGS) \
+       $(DEVKITPOWER_CFLAGS) \
+       -DWNCK_I_KNOW_THIS_IS_UNSTABLE \
+       -DI_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE
+
+BUILT_SOURCES = zavai.vala.stamp $(zavai_VALASOURCES:.vala=.c)
+
+bin_PROGRAMS = zavai
+
+bin_SCRIPTS = sat-monitor
+
+zavai_VALASOURCES = \
+       log.vala \
+       config.vala \
+       registry.vala \
+       input.vala \
+       gps.vala \
+       gsm.vala \
+       clock.vala \
+       audio.vala \
+       app.vala \
+       app_keyboard.vala \
+       app_power.vala \
+       app_wm.vala \
+       app_gps.vala \
+       app_gsm.vala \
+       app_calendar.vala \
+       app_polygen.vala \
+       app_main.vala \
+       app_debug.vala \
+       zavai.vala
+
+zavai_VAPIS = linux-input.vapi dbus-extra.vapi devkit-power-gobject.vapi
+
+zavai_SOURCES = \
+       zavai.vala.stamp \
+       $(zavai_VALASOURCES:.vala=.c)
+
+zavai.vapi zavai.vala.stamp: $(zavai_VALASOURCES) $(zavai_VAPIS)
+       $(VALAC) -C --basedir $(top_srcdir) $(VFLAGS) $(zavai_VALASOURCES)
+       touch $@
+
+%.c: %.vala
+
+zavai_LDADD = \
+       $(GLIB_LIBS) \
+       $(DBUS_LIBS) \
+       $(GEE_LIBS) \
+       $(GTK_LIBS) \
+       $(WNCK_LIBS) \
+       $(DEVKITPOWER_LIBS)
+
+#vapidir = $(datadir)/vala/vapi
+
+#dist_vapi_DATA = \
+#      gee-1.0.vapi \
+#      $(NULL)
+
+EXTRA_DIST = $(zavai_VAPIS) sat-monitor update-polygen-info
+#$(libgee_la_VALASOURCES) gee-1.0.vapi gee.vala.stamp
diff --git a/src/app_wifi.vala b/src/app_wifi.vala
new file mode 100644 (file)
index 0000000..ccfa874
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * app_wifi - WiFi buttons
+ * copied from app_gps.vala
+ *
+ * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
+ * Copyright (C) 2009  gregor herrmann <gregor.herrmann@comodo.priv.at>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+using GLib;
+
+namespace zavai {
+namespace ui {
+namespace wifi {
+
+public class WiFiRequest : Gtk.ToggleButton
+{
+       protected string service_name;
+       protected string label_start;
+       protected string label_stop;
+       protected zavai.StatusIcon status_icon;
+       protected bool power = false;
+
+       public WiFiRequest()
+       {
+               service_name = "wifi.wifi";
+               label_start = "Start WiFi";
+               label_stop = "Stop WiFi";
+               set_size_request(0, zavai.config.min_button_height);
+               toggled += on_toggled;
+
+               set_label(get_active() ? label_stop : label_start);
+
+               //tooltip = "WiFi status";
+               try {
+                       power = zavai.wifi.wifi.device.GetPower();
+               } catch (Error e) {
+                       power = false;
+               }
+               zavai.wifi.wifi.device.Power += on_power_status_changed;
+
+               // WiFi 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 (power)
+                       name = zavai.config.icondir + "/" + "wifi_1.png";
+               else
+                       name = zavai.config.icondir + "/" + "wifi_0.png";
+               status_icon.set_from_file(name);
+       }
+
+       private void on_power_status_changed(dynamic DBus.Object pos, string device, bool power)
+       {
+               this.power = power;
+               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());
+       }
+}
+
+WiFiRequest wifirequest;
+
+public void init()
+{
+    wifirequest = new WiFiRequest();
+}
+
+}
+}
+}
diff --git a/src/wifi.vala b/src/wifi.vala
new file mode 100644 (file)
index 0000000..ee8069e
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * wifi - wifi resource for zavai
+ * copied from gps.vala
+ *
+ * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
+ * Copyright (C) 2009  gregor herrmann <gregor.herrmann@comodo.priv.at>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+using GLib;
+
+namespace zavai {
+namespace wifi {
+
+// For a list of dbus services, look in /etc/dbus-1/system.d/
+public class WiFi: zavai.Service
+{
+       public dynamic DBus.Object usage;
+       public dynamic DBus.Object device;
+       protected bool s = false;
+
+       public WiFi()
+       {
+               name = "wifi.wifi";
+
+               // see mdbus -s org.freesmartphone.ousaged /org/freesmartphone/Usage
+               usage = zavai.registry.sbus.get_object(
+                       "org.freesmartphone.ousaged",
+                       "/org/freesmartphone/Usage",
+                       "org.freesmartphone.Usage");
+
+               device = zavai.registry.sbus.get_object(
+                       "org.freesmartphone.odeviced", 
+                       "/org/freesmartphone/Device/PowerControl/WiFi",
+                       "org.freesmartphone.Device.PowerControl");
+       }
+
+    public void power_cycle()
+    {
+        // "Have you tried turning it off and on again?"
+               try {
+            usage.SetResourcePolicy("WiFi", "disabled");
+               } catch (GLib.Error e) {
+                       zavai.log.error(e.message);
+               }
+        Thread.usleep(500000);
+               try {
+            usage.SetResourcePolicy("WiFi", "auto");
+               } catch (GLib.Error e) {
+                       zavai.log.error(e.message);
+               }
+    }
+
+       /// Request WiFi resource
+       public override void start()
+       {
+               if (started) return;
+               try {
+                       usage.RequestResource("WiFi");
+                       zavai.log.info("Acquired WiFi");
+                       base.start();
+               } catch (GLib.Error e) {
+                       zavai.log.error(e.message);
+               }
+               base.start();
+       }
+
+       // Release usage of WiFi
+       public override void stop()
+       {
+               if (!started) return;
+               try {
+                       usage.ReleaseResource("WiFi");
+                       zavai.log.info("Released WiFi");
+                       base.stop();
+               } catch (GLib.Error e) {
+                       zavai.log.error(e.message);
+               }
+               base.stop();
+       }
+}
+
+
+public zavai.wifi.WiFi wifi = null;
+
+public void init()
+{
+       wifi = new WiFi();
+       zavai.registry.register_service(wifi);
+}
+
+}
+}
index 423cfbb6b6fd9e376566fb448377c86c348b4edb..bb3bc6714ad1863eca0a9c8010a3c0814fdd0e2d 100644 (file)
@@ -98,6 +98,7 @@ static int main (string[] args) {
        zavai.power.init();
        zavai.gps.init();
        zavai.gsm.init();
+       zavai.wifi.init();
        zavai.audio.init();
        zavai.clock.init();
 
@@ -112,6 +113,7 @@ static int main (string[] args) {
        zavai.ui.main.init();
        zavai.ui.gps.init();
        zavai.ui.gsm.init();
+       zavai.ui.wifi.init();
        zavai.app.run_script(zavai.config.homedir + "/display init");
        zavai.ui.power.init();
        zavai.ui.kbd.init();