[network-manager-applet/menu-rework: 8/18] applet: add applet_menu_item_favorize_helper to applet api and use it to mark favorites in menu



commit 11560e7a82a13099c735cc9ed1207b6d6070885c
Author: Alexander Sack <asac ubuntu com>
Date:   Wed Sep 23 02:05:55 2009 +0200

    applet: add applet_menu_item_favorize_helper to applet api and use it to mark favorites in menu
    
    we favorize all connection/ap menu items so they have all the same
    indentation; for wifi aps that have a known connection configuration
    will be marked visually as a favorite (using the "favorites" icon);
    for all other devices all connections will be marked as favorites
    except the various auto connections for device classes that have
    those.

 src/applet-device-bt.c    |    2 +
 src/applet-device-cdma.c  |    2 +
 src/applet-device-gsm.c   |    2 +
 src/applet-device-wifi.c  |    5 ++++
 src/applet-device-wired.c |    2 +
 src/applet.c              |   52 +++++++++++++++++++++++++++++++++++++++++++++
 src/applet.h              |    6 +++++
 7 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/src/applet-device-bt.c b/src/applet-device-bt.c
index 5fb9e7e..401371f 100644
--- a/src/applet-device-bt.c
+++ b/src/applet-device-bt.c
@@ -127,6 +127,8 @@ add_connection_items (NMDevice *device,
 		                       info,
 		                       (GClosureNotify) bt_menu_item_info_destroy, 0);
 
+		applet_menu_item_favorize_helper (GTK_BIN (item), applet->favorites_icon, TRUE);
+
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	}
 }
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index f158ef2..b6979dc 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -210,6 +210,8 @@ add_connection_items (NMDevice *device,
 		                       info,
 		                       (GClosureNotify) cdma_menu_item_info_destroy, 0);
 
+		applet_menu_item_favorize_helper (GTK_BIN (item), applet->favorites_icon, TRUE);
+
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	}
 }
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index 293e295..433c3bc 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -211,6 +211,8 @@ add_connection_items (NMDevice *device,
 		                       info,
 		                       (GClosureNotify) gsm_menu_item_info_destroy, 0);
 
+		applet_menu_item_favorize_helper (GTK_BIN (item), applet->favorites_icon, TRUE);
+
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	}
 }
diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c
index bc8aa7c..d1dfe2e 100644
--- a/src/applet-device-wifi.c
+++ b/src/applet-device-wifi.c
@@ -474,6 +474,7 @@ add_new_ap_item (NMDeviceWifi *device,
 	GSList *ap_connections = NULL;
 	const GByteArray *ssid;
 	guint32 dev_caps;
+	gboolean is_favorite = FALSE;
 
 	ap_connections = filter_connections_for_access_point (connections, device, ap);
 
@@ -522,6 +523,7 @@ add_new_ap_item (NMDeviceWifi *device,
 			gtk_menu_shell_append (GTK_MENU_SHELL (submenu), GTK_WIDGET (subitem));
 		}
 
+		is_favorite = TRUE;
 		gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
 	} else {
 		NMConnection *connection;
@@ -534,6 +536,7 @@ add_new_ap_item (NMDeviceWifi *device,
 		if (g_slist_length (ap_connections) == 1) {
 			connection = NM_CONNECTION (g_slist_nth_data (ap_connections, 0));
 			info->connection = g_object_ref (G_OBJECT (connection));
+			is_favorite = TRUE;
 		}
 
 		g_signal_connect_data (GTK_WIDGET (item),
@@ -544,6 +547,8 @@ add_new_ap_item (NMDeviceWifi *device,
 		                       0);
 	}
 
+	applet_menu_item_favorize_helper (GTK_BIN (item), applet->favorites_icon, is_favorite);
+
 	gtk_widget_show_all (GTK_WIDGET (item));
 
 	g_slist_free (ap_connections);
diff --git a/src/applet-device-wired.c b/src/applet-device-wired.c
index f48783b..3a44789 100644
--- a/src/applet-device-wired.c
+++ b/src/applet-device-wired.c
@@ -152,6 +152,8 @@ add_connection_items (NMDevice *device,
 		                       info,
 		                       (GClosureNotify) wired_menu_item_info_destroy, 0);
 
+		applet_menu_item_favorize_helper (GTK_BIN (item), applet->favorites_icon, TRUE);
+
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	}
 }
diff --git a/src/applet.c b/src/applet.c
index f121bfb..265b32a 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -454,6 +454,54 @@ applet_menu_item_add_complex_separator_helper (GtkWidget *menu,
 	return;
 }
 
+void
+applet_menu_item_favorize_helper (GtkBin *binitem,
+                                  GdkPixbuf *favoritePixbuf,
+                                  gboolean is_favorite)
+{
+	GtkWidget *child;
+	GtkWidget *box;
+	gpointer already_favorized_ptr;
+
+	g_assert (binitem);
+	g_assert (favoritePixbuf);
+
+	child = gtk_bin_get_child (binitem);
+	box = gtk_hbox_new (FALSE, 0);
+	already_favorized_ptr = g_object_get_data (G_OBJECT (child), "already-favorized");
+
+	if (already_favorized_ptr)
+		goto abort;
+
+	if (!is_favorite) {
+		int image_width, image_height;
+		GtkWidget *placeholder = gtk_alignment_new (0,0,0,0);
+		g_object_ref (child);
+		image_width = gdk_pixbuf_get_width (favoritePixbuf);
+		image_height = gdk_pixbuf_get_height (favoritePixbuf);
+		gtk_container_remove (GTK_CONTAINER (binitem), child);
+		gtk_widget_set_size_request (placeholder, image_width, image_height);
+		gtk_box_pack_start (GTK_BOX (box), placeholder, FALSE, FALSE, 0);
+		gtk_box_pack_start (GTK_BOX (box), child, TRUE, TRUE, 4);
+		gtk_container_add (GTK_CONTAINER (binitem), box);
+		g_object_unref (child);
+	} else {
+		GtkWidget *image = gtk_image_new_from_pixbuf (favoritePixbuf);
+		g_assert (image);
+		g_object_ref (child);
+		gtk_container_remove (GTK_CONTAINER (binitem), child);
+		gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
+		gtk_box_pack_start (GTK_BOX (box), child, TRUE, TRUE, 4);
+		gtk_container_add (GTK_CONTAINER (binitem), box);
+		g_object_unref (child);
+	}
+
+	g_object_set_data (G_OBJECT (child), "already-favorized", GINT_TO_POINTER (1));
+
+	return;
+abort:
+	g_object_ref_sink (box);
+}
 
 static void
 applet_clear_notify (NMApplet *applet)
@@ -1200,6 +1248,7 @@ nma_menu_device_get_menu_item (NMDevice *device,
 		                       info,
 		                       (GClosureNotify) applet_device_info_destroy, 0);
 		gtk_widget_set_sensitive (item, TRUE);
+		applet_menu_item_favorize_helper (GTK_BIN (item), applet->favorites_icon, FALSE);
 		break;
 	}
 	default:
@@ -2410,6 +2459,7 @@ static void nma_icons_free (NMApplet *applet)
 	CLEAR_ICON(applet->wireless_75_icon);
 	CLEAR_ICON(applet->wireless_100_icon);
 	CLEAR_ICON(applet->secure_lock_icon);
+	CLEAR_ICON(applet->favorites_icon);
 
 	for (i = 0; i < NUM_CONNECTING_STAGES; i++) {
 		for (j = 0; j < NUM_CONNECTING_FRAMES; j++)
@@ -2480,6 +2530,8 @@ nma_icons_load (NMApplet *applet)
 		g_free (name);
 	}
 
+	ICON_LOAD(applet->favorites_icon, "favorites");
+
 	applet->icons_loaded = TRUE;
 
 out:
diff --git a/src/applet.h b/src/applet.h
index 395722e..a9850ce 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -121,6 +121,8 @@ typedef struct
 	GdkPixbuf *		vpn_connecting_icons[NUM_VPN_CONNECTING_FRAMES];
 	GdkPixbuf *		vpn_lock_icon;
 
+	GdkPixbuf *		favorites_icon;
+
 	/* Active status icon pixbufs */
 	GdkPixbuf *		icon_layers[ICON_LAYER_MAX + 1];
 
@@ -227,6 +229,10 @@ void applet_menu_item_add_complex_separator_helper (GtkWidget *menu,
                                                     GdkPixbuf *favicon,
                                                     int pos);
 
+void applet_menu_item_favorize_helper (GtkBin *binitem,
+                                       GdkPixbuf *favoritePixbuf,
+                                       gboolean is_favorite);
+
 NMSettingsConnectionInterface *applet_get_exported_connection_for_device (NMDevice *device, NMApplet *applet);
 
 void applet_do_notify (NMApplet *applet,



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