--- /dev/null
+/*
+ * 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 label_start;
+ protected string label_stop;
+ protected zavai.StatusIcon status_icon;
+ protected bool power = false;
+
+ public WiFiRequest()
+ {
+ 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)
+ {
+ if (get_active())
+ zavai.wifi.wifi.request("servicerequestlink");
+ else
+ zavai.wifi.wifi.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();
+}
+
+}
+}
+}
--- /dev/null
+/*
+ * 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()
+ {
+ Object(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");
+ }
+
+ /// 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();
+}
+
+}
+}