[gnome-bluetooth] Change the toolbar icon when connecting



commit 1dfe328141296ab287b9af8611f1e2611257f180
Author: Joshua Lock <josh linux intel com>
Date:   Fri Oct 9 15:06:09 2009 +0100

    Change the toolbar icon when connecting
    
    This change adds a member to track whether there is a device connecting.
    Each time the model changes we iterate to see if there are any devices
    connecting and set the member variable accordingly. When the boolean
    connecting variable changes a signal "status-connecting" is emitted with
    the value of the connecting member.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=597811

 moblin/main.c                                      |   39 +++++++---
 moblin/moblin-icons/Makefile.am                    |   10 +--
 moblin/moblin-icons/bluetooth-connecting-hover.png |  Bin 0 -> 921 bytes
 moblin/moblin-icons/bluetooth-connecting.png       |  Bin 0 -> 842 bytes
 moblin/moblin-icons/bluetooth-idle-hover.png       |  Bin 0 -> 2565 bytes
 moblin/moblin-icons/bluetooth-idle.png             |  Bin 0 -> 2544 bytes
 moblin/moblin-icons/bluetooth-not-paired-hover.png |  Bin 915 -> 0 bytes
 moblin/moblin-icons/bluetooth-not-paired.png       |  Bin 932 -> 0 bytes
 moblin/moblin-icons/bluetooth-strong-hover.png     |  Bin 881 -> 0 bytes
 moblin/moblin-icons/bluetooth-strong.png           |  Bin 891 -> 0 bytes
 moblin/moblin-icons/bluetooth-weak-hover.png       |  Bin 832 -> 0 bytes
 moblin/moblin-icons/bluetooth-weak.png             |  Bin 842 -> 0 bytes
 moblin/moblin-panel.c                              |   73 +++++++++++++++++++-
 moblin/moblin-panel.h                              |    2 +
 moblin/theme/bluetooth-panel.css.in                |   14 ++--
 15 files changed, 112 insertions(+), 26 deletions(-)
---
diff --git a/moblin/main.c b/moblin/main.c
index 7794c3a..adf3362 100644
--- a/moblin/main.c
+++ b/moblin/main.c
@@ -30,29 +30,34 @@
 #include <nbtk/nbtk-gtk.h>
 #include <moblin-panel/mpl-panel-common.h>
 #include <moblin-panel/mpl-panel-gtk.h>
+#include <bluetooth-enums.h>
 
 #include "moblin-panel.h"
 
 #define PKGTHEMEDIR PKGDATADIR"/theme"
 
 static void
-make_window_content (GtkWidget *panel)
+bluetooth_status_changed (MoblinPanel *panel, gboolean connecting, gpointer user_data)
 {
-	GtkWidget *content;
+	MplPanelClient *client = MPL_PANEL_CLIENT (user_data);
+	gchar *style = NULL;
 
-	content = moblin_panel_new ();
-	gtk_widget_set_size_request (content, 800, -1);
-	gtk_widget_show (content);
+	if (connecting) {
+		style = g_strdup ("state-connecting");
+	} else {
+		style = g_strdup ("state-idle");
+	}
 
-	gtk_container_add (GTK_CONTAINER (panel), content);
-	gtk_widget_show (panel);
+	mpl_panel_client_request_button_style (client, style);
+	g_free (style);
 }
 
 int
 main (int argc, char *argv[])
 {
 	MplPanelClient *panel;
-	GtkWidget      *window;
+	GtkWidget      *window, *content;
+	GtkRequisition  req;
 	gboolean        standalone = FALSE;
 	GtkSettings    *settings;
 	GError         *error = NULL;
@@ -86,16 +91,26 @@ main (int argc, char *argv[])
 		g_signal_connect (window, "delete-event", (GCallback) gtk_main_quit,
 				NULL);
 		gtk_widget_set_size_request (window, 1000, -1);
-		make_window_content (window);
+		content = moblin_panel_new ();
+		gtk_widget_show (content);
+
+		gtk_container_add (GTK_CONTAINER (window), content);
+		gtk_widget_show (window);
 	}  else {
 		panel = mpl_panel_gtk_new (MPL_PANEL_BLUETOOTH, _("bluetooth"),
 					PKGTHEMEDIR "/bluetooth-panel.css",
 					"state-idle", TRUE);
 		window  = mpl_panel_gtk_get_window (MPL_PANEL_GTK (panel));
 
-		window = mpl_panel_gtk_get_window (MPL_PANEL_GTK (panel));
-		make_window_content (window);
-		mpl_panel_client_set_height_request (panel, 280);
+		content = moblin_panel_new ();
+		g_signal_connect (content, "state-changed",
+				G_CALLBACK (bluetooth_status_changed), panel);
+		gtk_widget_show (content);
+
+		gtk_container_add (GTK_CONTAINER (window), content);
+		gtk_widget_show (window);
+		gtk_widget_size_request (window, &req);
+		mpl_panel_client_set_height_request (panel, req.height);
 	}
 
 	gtk_main ();
diff --git a/moblin/moblin-icons/Makefile.am b/moblin/moblin-icons/Makefile.am
index 5d67910..f0d2d39 100644
--- a/moblin/moblin-icons/Makefile.am
+++ b/moblin/moblin-icons/Makefile.am
@@ -1,12 +1,10 @@
 iconsdir = $(pkgdatadir)/moblin-icons
 
 icons_DATA = \
-	bluetooth-not-paired-hover.png \
-	bluetooth-not-paired.png \
-	bluetooth-strong-hover.png \
-	bluetooth-strong.png \
-	bluetooth-weak-hover.png \
-	bluetooth-weak.png \
+	bluetooth-idle-hover.png \
+	bluetooth-idle.png \
+	bluetooth-connecting-hover.png \
+	bluetooth-connecting.png \
 	toolbar-button-hover.png \
 	toolbar-button-active.png
 
diff --git a/moblin/moblin-icons/bluetooth-connecting-hover.png b/moblin/moblin-icons/bluetooth-connecting-hover.png
new file mode 100644
index 0000000..2646199
Binary files /dev/null and b/moblin/moblin-icons/bluetooth-connecting-hover.png differ
diff --git a/moblin/moblin-icons/bluetooth-connecting.png b/moblin/moblin-icons/bluetooth-connecting.png
new file mode 100644
index 0000000..efd798d
Binary files /dev/null and b/moblin/moblin-icons/bluetooth-connecting.png differ
diff --git a/moblin/moblin-icons/bluetooth-idle-hover.png b/moblin/moblin-icons/bluetooth-idle-hover.png
new file mode 100644
index 0000000..e9e5b94
Binary files /dev/null and b/moblin/moblin-icons/bluetooth-idle-hover.png differ
diff --git a/moblin/moblin-icons/bluetooth-idle.png b/moblin/moblin-icons/bluetooth-idle.png
new file mode 100644
index 0000000..a38030e
Binary files /dev/null and b/moblin/moblin-icons/bluetooth-idle.png differ
diff --git a/moblin/moblin-panel.c b/moblin/moblin-panel.c
index 24fd6e3..b0f636b 100644
--- a/moblin/moblin-panel.c
+++ b/moblin/moblin-panel.c
@@ -39,6 +39,7 @@
 #include "bluetooth-killswitch.h"
 #include "bluetooth-plugin-manager.h"
 #include "bluetooth-filter-widget.h"
+#include "gnome-bluetooth-enum-types.h"
 
 #include "pin.h"
 
@@ -69,6 +70,8 @@ struct _MoblinPanelPrivate
 	GtkTreeModel *chooser_model;
 
 	gchar *pincode;
+
+	gboolean connecting;
 };
 
 #define CONNECT_TIMEOUT 3.0
@@ -87,6 +90,13 @@ enum {
 	PAGE_FAILURE
 } MoblinPages;
 
+enum {
+	STATUS_CONNECTING,
+	LAST_SIGNAL
+};
+
+static guint _signals[LAST_SIGNAL] = {0, };
+
 static void
 power_switch_toggled_cb (NbtkGtkLightSwitch *light_switch,
                          gpointer            user_data)
@@ -547,6 +557,56 @@ set_device_view (GtkButton *button, MoblinPanel *self)
 	gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), PAGE_DEVICES);
 }
 
+static void
+determine_connecting (const gchar *key, gpointer value, gpointer user_data)
+{
+	BluetoothStatus status = GPOINTER_TO_INT (value);
+	BluetoothStatus *other_status = user_data;
+
+	if (status == BLUETOOTH_STATUS_CONNECTING)
+		(*other_status) = status;
+}
+
+static void
+have_connecting_device (MoblinPanel *self)
+{
+	MoblinPanelPrivate *priv = MOBLIN_PANEL_GET_PRIVATE (self);
+	GHashTable *states;
+	GtkTreeIter iter;
+	BluetoothStatus status = BLUETOOTH_STATUS_INVALID;
+	gboolean connecting = FALSE;
+
+	gtk_tree_model_get_iter_first (priv->chooser_model, &iter);
+	gtk_tree_model_get(priv->chooser_model, &iter, BLUETOOTH_COLUMN_SERVICES, &states, -1);
+
+	if (states) {
+		g_hash_table_foreach (states, (GHFunc) determine_connecting, &status);
+
+		g_hash_table_unref (states);
+	}
+
+	if (status == BLUETOOTH_STATUS_CONNECTING)
+		connecting = TRUE;
+
+	if (connecting != priv->connecting) {
+		priv->connecting = connecting;
+		g_signal_emit (self, _signals[STATUS_CONNECTING], 0,
+			priv->connecting);
+	}
+}
+
+static void
+model_changed_cb (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
+{
+	have_connecting_device (MOBLIN_PANEL (user_data));
+}
+
+static void
+row_deleted_cb (GtkTreeModel *model, GtkTreePath *path, gpointer user_data)
+{
+	have_connecting_device (MOBLIN_PANEL (user_data));
+}
+
 static GtkWidget *
 create_failure_page (MoblinPanel *self)
 {
@@ -744,6 +804,9 @@ create_devices_page (MoblinPanel *self)
 	type_column = bluetooth_chooser_get_type_column (BLUETOOTH_CHOOSER (priv->display));
 	if (!priv->chooser_model) {
 		priv->chooser_model = bluetooth_chooser_get_model (BLUETOOTH_CHOOSER (priv->display));
+		g_signal_connect (priv->chooser_model, "row-changed", G_CALLBACK (model_changed_cb), self);
+		g_signal_connect (priv->chooser_model, "row-deleted", G_CALLBACK (row_deleted_cb), self);
+		g_signal_connect (priv->chooser_model, "row-inserted", G_CALLBACK (model_changed_cb), self);
 	}
 
 	tree_view = bluetooth_chooser_get_treeview (BLUETOOTH_CHOOSER (priv->display));
@@ -837,11 +900,10 @@ create_devices_page (MoblinPanel *self)
 	/* Button for Send file */
 	priv->send_button = gtk_button_new_with_label (_("Send file from your computer"));
 	gtk_widget_show (priv->send_button);
-	gtk_widget_set_sensitive (priv->send_button, FALSE);
 	g_signal_connect (priv->send_button, "clicked",
                     G_CALLBACK (send_file_button_clicked_cb), priv->display);
 	g_signal_connect (priv->display, "selected-device-changed",
-			G_CALLBACK (selected_device_changed_cb), self);
+			G_CALLBACK (selected_device_changed_cb), priv->send_button);
 	gtk_box_pack_start (GTK_BOX (vbox), priv->send_button, FALSE, FALSE, 4);
 
 	return page;
@@ -855,6 +917,7 @@ moblin_panel_init (MoblinPanel *self)
 
 	priv = MOBLIN_PANEL_GET_PRIVATE (self);
 	priv->pincode = NULL;
+	priv->connecting = FALSE;
 
 	priv->client = bluetooth_client_new ();
 	priv->killswitch = bluetooth_killswitch_new ();
@@ -904,6 +967,12 @@ moblin_panel_class_init (MoblinPanelClass *klass)
 	GObjectClass *obj_class = G_OBJECT_CLASS (klass);
 	g_type_class_add_private (klass, sizeof (MoblinPanelPrivate));
 	obj_class->dispose = moblin_panel_dispose;
+
+	_signals[STATUS_CONNECTING] = g_signal_new ("status-connecting", MOBLIN_TYPE_PANEL,
+						G_SIGNAL_RUN_FIRST,
+						G_STRUCT_OFFSET (MoblinPanelClass, status_connecting),
+						NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
+						G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
 }
 
 /**
diff --git a/moblin/moblin-panel.h b/moblin/moblin-panel.h
index 7370f58..0cae24d 100644
--- a/moblin/moblin-panel.h
+++ b/moblin/moblin-panel.h
@@ -63,6 +63,8 @@ struct _MoblinPanelClass
 {
   GtkHBoxClass parent_class;
   MoblinPanelPrivate *priv;
+
+  void (*status_connecting) (MoblinPanel *self, gboolean connecting);
 };
 
 GType moblin_panel_get_type (void);
diff --git a/moblin/theme/bluetooth-panel.css.in b/moblin/theme/bluetooth-panel.css.in
index 166fdab..93cffb3 100644
--- a/moblin/theme/bluetooth-panel.css.in
+++ b/moblin/theme/bluetooth-panel.css.in
@@ -11,15 +11,17 @@ MnbToolbarButton:hover, MnbToolbarButton:active {
 }
 
 MnbToolbarButton#state-idle {
-  background-image: url("file://@pkgdatadir@/moblin-icons/bluetooth-not-paired.png");
+  background-image: url("file://@pkgdatadir@/moblin-icons/bluetooth-idle.png");
 }
 
 MnbToolbarButton#state-idle:hover, MnbToolbarButton#state-idle:active, MnbToolbarButton#state-idle:checked  {
-  background-image: url("file://@pkgdatadir@/moblin-icons/bluetooth-not-paired-hover.png");
+  background-image: url("file://@pkgdatadir@/moblin-icons/bluetooth-idle-hover.png");
+}
 
-MnbToolbarButton#state-paired {
-  background-image: url("file://@pkgdatadir@/moblin-icons/bluetooth-strong.png");
+MnbToolbarButton#state-connecting {
+  background-image: url("file://@pkgdatadir@/moblin-icons/bluetooth-connecting.png");
 }
 
-MnbToolbarButton#state-paired:hover, MnbToolbarButton#state-paired:active, MnbToolbarButton#state-paired:checked  {
-  background-image: url("file://@pkgdatadir@/moblin-icons/bluetooth-strong-hover.png");
+MnbToolbarButton#state-connecting:hover, MnbToolbarButton#state-connecting:active, MnbToolbarButton#state-connecting:checked  {
+  background-image: url("file://@pkgdatadir@/moblin-icons/bluetooth-connecting-hover.png");
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]