/*
- * app_wifi - WiFi buttons
- * copied from app_gps.vala
+ * app_wifi - zavai Wifi ui functions
*
- * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
- * Copyright (C) 2009 gregor herrmann <gregor.herrmann@comodo.priv.at>
+ * Copyright (C) 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
namespace ui {
namespace wifi {
-public class WiFiRequest : Gtk.ToggleButton
+public class WifiIcon : Gtk.StatusIcon
{
- protected string service_name;
- protected string label_start;
- protected string label_stop;
- protected zavai.StatusIcon status_icon;
- protected bool power = false;
+ bool requested = 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;
+ public WifiIcon()
+ {
+ activate += on_activate;
+ update_icon();
+ }
- 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");
+ private void on_activate()
+ {
+ requested = !requested;
+ update_icon();
+ if (requested)
+ {
+ //zavai.wifi.wifi.start();
+ stderr.printf("wifi should be started here\n");
+ stderr.printf("wifi status: %d\n", (int) zavai.wifi.wifi.started);
}
- else {
- s.release("servicerequestlink");
+ else
+ {
+ //zavai.wifi.wifi.stop();
+ stderr.printf("wifi should be stopped here\n");
+ stderr.printf("wifi status: %d\n", (int) zavai.wifi.wifi.started);
}
- set_label(get_active() ? label_stop : label_start);
- update_icon();
- }
+ }
+
+ protected void update_icon()
+ {
+ string name = zavai.config.icondir + "/";
+ name += (active() ? "wifi_1.png" : "wifi_0.png");
+ stderr.printf("load icon from %s\n", name);
+ set_from_file(name);
+ }
- private void on_status_clicked(Gtk.Button b)
- {
- set_active(!get_active());
- }
+ private bool active()
+ {
+ return zavai.wifi.wifi.started;
+ }
}
-WiFiRequest wifirequest;
+WifiIcon icon;
public void init()
{
- wifirequest = new WiFiRequest();
+ // Menus
+ zavai.menu_misc.add_service_toggle(zavai.wifi.wifi, "Start Wifi", "Stop Wifi");
+ // Icon
+ icon = new WifiIcon();
+ icon.set_visible(true);
}
}