[gnome-bluetooth] properties: Implement "Powered" switch
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth] properties: Implement "Powered" switch
- Date: Fri, 4 Mar 2011 14:14:24 +0000 (UTC)
commit 726b9257b94d617108c713f4143d7714764a4413
Author: Bastien Nocera <hadess hadess net>
Date: Fri Mar 4 14:10:24 2011 +0000
properties: Implement "Powered" switch
Handle setting the initial state of the Powered switch, as well
as killswitch changes, and powered state changes.
Still no feedback on the current state of the switches though.
properties/cc-bluetooth-panel.c | 82 ++++++++++++++++++++++++++++++++++++++-
1 files changed, 81 insertions(+), 1 deletions(-)
---
diff --git a/properties/cc-bluetooth-panel.c b/properties/cc-bluetooth-panel.c
index 5d4a48f..c1dd629 100644
--- a/properties/cc-bluetooth-panel.c
+++ b/properties/cc-bluetooth-panel.c
@@ -276,6 +276,65 @@ cc_bluetooth_panel_update_properties (CcBluetoothPanel *self)
}
static void
+power_callback (GObject *object,
+ GParamSpec *spec,
+ CcBluetoothPanel *self)
+{
+ gboolean state;
+
+ state = gtk_switch_get_active (GTK_SWITCH (WID ("switch_bluetooth")));
+ g_debug ("Power switched to %s", state ? "off" : "on");
+ bluetooth_killswitch_set_state (self->priv->killswitch,
+ state ? KILLSWITCH_STATE_UNBLOCKED : KILLSWITCH_STATE_SOFT_BLOCKED);
+}
+
+static void
+cc_bluetooth_panel_update_power (CcBluetoothPanel *self)
+{
+ KillswitchState state;
+ char *bdaddr;
+ gboolean powered, sensitive;
+ GtkSwitch *button;
+
+ g_object_get (G_OBJECT (self->priv->client),
+ "default-adapter", &bdaddr,
+ "default-adapter-powered", &powered,
+ NULL);
+ state = bluetooth_killswitch_get_state (self->priv->killswitch);
+
+ g_debug ("Updating power, default adapter: %s (powered: %s), killswitch: %s",
+ bdaddr ? bdaddr : "(none)",
+ powered ? "on" : "off",
+ bluetooth_killswitch_state_to_string (state));
+
+ if (bdaddr == NULL &&
+ bluetooth_killswitch_has_killswitches (self->priv->killswitch) &&
+ state != KILLSWITCH_STATE_HARD_BLOCKED) {
+ g_debug ("Default adapter is unpowered, but should be available");
+ sensitive = TRUE;
+ } else if (bdaddr == NULL &&
+ state == KILLSWITCH_STATE_HARD_BLOCKED) {
+ g_debug ("Bluetooth is Hard blocked");
+ sensitive = FALSE;
+ } else if (bdaddr == NULL) {
+ sensitive = FALSE;
+ g_debug ("No Bluetooth available");
+ } else {
+ sensitive = TRUE;
+ g_debug ("Bluetooth is available and powered");
+ }
+
+ g_free (bdaddr);
+ gtk_widget_set_sensitive (WID ("hbox2") , sensitive);
+
+ button = GTK_SWITCH (WID ("switch_bluetooth"));
+
+ g_signal_handlers_block_by_func (button, power_callback, self);
+ gtk_switch_set_active (button, powered);
+ g_signal_handlers_unblock_by_func (button, power_callback, self);
+}
+
+static void
keyboard_callback (GtkButton *button,
CcBluetoothPanel *self)
{
@@ -382,8 +441,12 @@ static void
cc_bluetooth_panel_update_state (CcBluetoothPanel *self)
{
char *bdaddr;
+ gboolean powered;
- g_object_get (G_OBJECT (self->priv->client), "default-adapter", &bdaddr, NULL);
+ g_object_get (G_OBJECT (self->priv->client),
+ "default-adapter", &bdaddr,
+ "default-adapter-powered", &powered,
+ NULL);
gtk_widget_set_sensitive (WID ("toolbar"), (bdaddr != NULL));
g_free (bdaddr);
}
@@ -394,6 +457,16 @@ default_adapter_changed (BluetoothClient *client,
CcBluetoothPanel *self)
{
cc_bluetooth_panel_update_state (self);
+ cc_bluetooth_panel_update_power (self);
+}
+
+static void
+killswitch_changed (BluetoothKillswitch *killswitch,
+ KillswitchState state,
+ CcBluetoothPanel *self)
+{
+ cc_bluetooth_panel_update_state (self);
+ cc_bluetooth_panel_update_power (self);
}
static void
@@ -484,6 +557,13 @@ cc_bluetooth_panel_init (CcBluetoothPanel *self)
g_signal_connect (G_OBJECT (WID ("switch_connection")), "notify::active",
G_CALLBACK (switch_connected_active_changed), self);
+ /* Set the initial state of power */
+ g_signal_connect (G_OBJECT (WID ("switch_bluetooth")), "notify::active",
+ G_CALLBACK (power_callback), self);
+ g_signal_connect (G_OBJECT (self->priv->killswitch), "state-changed",
+ G_CALLBACK (killswitch_changed), self);
+ cc_bluetooth_panel_update_power (self);
+
gtk_widget_show_all (GTK_WIDGET (self));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]