gnome-bluetooth r396 - trunk/applet
- From: hadess svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-bluetooth r396 - trunk/applet
- Date: Fri, 27 Feb 2009 16:38:12 +0000 (UTC)
Author: hadess
Date: Fri Feb 27 16:38:12 2009
New Revision: 396
URL: http://svn.gnome.org/viewvc/gnome-bluetooth?rev=396&view=rev
Log:
Gray out the applet when adapters are off
When all the adapters are powered off, gray out the applet's icon.
Doesn't handle killswitches yet.
Modified:
trunk/applet/main.c
trunk/applet/notify.c
trunk/applet/notify.h
Modified: trunk/applet/main.c
==============================================================================
--- trunk/applet/main.c (original)
+++ trunk/applet/main.c Fri Feb 27 16:38:12 2009
@@ -40,8 +40,8 @@
static BluetoothClient *client;
static GtkTreeModel *adapter_model;
-
-static gboolean adapter_present = FALSE;
+static guint num_adapters_present = 0;
+static guint num_adapters_powered = 0;
enum {
ICON_POLICY_NEVER,
@@ -247,14 +247,17 @@
guint activate_time, gpointer user_data)
{
GtkWidget *menu = user_data;
+ gboolean enabled;
+
+ enabled = (num_adapters_present - num_adapters_powered) >= 0;
gtk_widget_set_sensitive(menuitem_sendto,
program_available("obex-data-server") &&
- adapter_present == TRUE);
+ enabled);
gtk_widget_set_sensitive(menuitem_browse,
program_available("nautilus") &&
- adapter_present == TRUE);
+ enabled);
gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
gtk_status_icon_position_menu,
@@ -320,27 +323,56 @@
else if (icon_policy == ICON_POLICY_ALWAYS)
show_icon();
else if (icon_policy == ICON_POLICY_PRESENT) {
- if (adapter_present == TRUE)
+ if (num_adapters_powered == 0)
+ set_icon (FALSE);
+ else
+ set_icon (TRUE);
+ if (num_adapters_present > 0)
show_icon();
else
hide_icon();
}
}
-static void adapter_added(GtkTreeModel *model, GtkTreePath *path,
- GtkTreeIter *iter, gpointer user_data)
-{
- adapter_present = TRUE;
+static void adapter_changed (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *_iter,
+ gpointer data)
+{
+ GtkTreeIter iter;
+ gboolean powered, cont;
+
+ num_adapters_present = num_adapters_powered = 0;
+
+ cont = gtk_tree_model_get_iter_first (model, &iter);
+ while (cont) {
+ num_adapters_present++;
+
+ gtk_tree_model_get (model, &iter,
+ BLUETOOTH_COLUMN_POWERED, &powered,
+ -1);
+ if (powered)
+ num_adapters_powered++;
+
+ cont = gtk_tree_model_iter_next (model, &iter);
+ }
+
update_icon_visibility ();
}
-static void adapter_removed(GtkTreeModel *model, GtkTreePath *path,
- gpointer user_data)
+static void adapter_added(GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer user_data)
{
- if (gtk_tree_model_iter_n_children(model, NULL) < 1) {
- adapter_present = FALSE;
- update_icon_visibility ();
- }
+ adapter_changed (model, NULL, NULL, NULL);
+}
+
+static void adapter_removed(GtkTreeModel *model,
+ GtkTreePath *path,
+ gpointer user_data)
+{
+ adapter_changed (model, NULL, NULL, NULL);
}
static GConfEnumStringPair icon_policy_enum_map [] = {
@@ -415,13 +447,13 @@
adapter_model = bluetooth_client_get_adapter_model(client);
g_signal_connect(G_OBJECT(adapter_model), "row-inserted",
- G_CALLBACK(adapter_added), NULL);
-
+ G_CALLBACK(adapter_added), NULL);
g_signal_connect(G_OBJECT(adapter_model), "row-deleted",
- G_CALLBACK(adapter_removed), NULL);
-
- if (gtk_tree_model_iter_n_children(adapter_model, NULL) > 0)
- adapter_present = TRUE;
+ G_CALLBACK(adapter_removed), NULL);
+ g_signal_connect (G_OBJECT (adapter_model), "row-changed",
+ G_CALLBACK (adapter_changed), NULL);
+ /* Set the default */
+ adapter_changed (adapter_model, NULL, NULL, NULL);
gconf = gconf_client_get_default();
Modified: trunk/applet/notify.c
==============================================================================
--- trunk/applet/notify.c (original)
+++ trunk/applet/notify.c Fri Feb 27 16:38:12 2009
@@ -32,6 +32,7 @@
#include "notify.h"
static GtkStatusIcon *statusicon = NULL;
+static char *icon_name = NULL;
static NotifyNotification *notify = NULL;
static void notify_action(NotifyNotification *notify,
@@ -54,7 +55,7 @@
notify_notification_close(notify, NULL);
}
- notify = notify_notification_new(summary, message, "bluetooth", NULL);
+ notify = notify_notification_new(summary, message, icon_name, NULL);
notify_notification_set_timeout(notify, timeout);
@@ -93,7 +94,7 @@
{
notify_init("bluetooth-manager");
- statusicon = gtk_status_icon_new_from_icon_name("bluetooth");
+ statusicon = gtk_status_icon_new_from_icon_name(icon_name);
#if GTK_CHECK_VERSION(2,15,0)
gtk_status_icon_set_tooltip_markup(statusicon, _("Bluetooth Manager"));
@@ -108,17 +109,34 @@
g_object_unref(statusicon);
+ g_free (icon_name);
+ icon_name = NULL;
+
notify_uninit();
}
void show_icon(void)
{
- gtk_status_icon_set_visible(statusicon, TRUE);
+ if (statusicon != NULL)
+ gtk_status_icon_set_visible(statusicon, TRUE);
}
void hide_icon(void)
{
- gtk_status_icon_set_visible(statusicon, FALSE);
+ if (statusicon != NULL)
+ gtk_status_icon_set_visible(statusicon, FALSE);
+}
+
+void set_icon(gboolean enabled)
+{
+ const char *name = (enabled ? "bluetooth" : "bluetooth-disabled");
+
+ if (statusicon == NULL) {
+ g_free (icon_name);
+ icon_name = g_strdup (name);
+ } else {
+ gtk_status_icon_set_from_icon_name (statusicon, name);
+ }
}
void enable_blinking(void)
Modified: trunk/applet/notify.h
==============================================================================
--- trunk/applet/notify.h (original)
+++ trunk/applet/notify.h Fri Feb 27 16:38:12 2009
@@ -31,6 +31,7 @@
void show_icon(void);
void hide_icon(void);
+void set_icon(gboolean enabled);
void enable_blinking(void);
void disable_blinking(void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]