[network-manager-applet/menu-rework: 11/18] ap-menu-item: prepare AP menu items for folded menu



commit 97b9a64d54b4b7379f40b667ef6f15bf1abb653b
Author: Alexander Sack <asac ubuntu com>
Date:   Wed Sep 23 13:30:01 2009 +0200

    ap-menu-item: prepare AP menu items for folded menu
    
    add and set a sort_label and a sort_strength field to the NMNetworkMenuItem
    struct; also make "already-favorized" gobject data a integer suitable for
    sorting and rename it to "favorite"; also set the "favorite" data on the
    menu item itself rather than its child and adjust
    applet_menu_item_favorize_helper code to use the new data key accordingly.

 src/ap-menu-item.c |   21 ++++++++++++++++-----
 src/ap-menu-item.h |    2 ++
 src/applet.c       |    6 +++---
 3 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/src/ap-menu-item.c b/src/ap-menu-item.c
index 7e9968f..b074c0d 100644
--- a/src/ap-menu-item.c
+++ b/src/ap-menu-item.c
@@ -52,6 +52,7 @@ nm_network_menu_item_init (NMNetworkMenuItem * item)
 
 	item->strength = gtk_image_new ();
 	gtk_box_pack_end (GTK_BOX (item->hbox), item->strength, FALSE, TRUE, 0);
+	item->sort_label = g_strdup ("");
 
 	gtk_widget_show (item->ssid);
 	gtk_widget_show (item->strength);
@@ -98,6 +99,8 @@ nm_network_menu_item_class_dispose (GObject *object)
 	gtk_widget_destroy (item->detail);
 	gtk_widget_destroy (item->hbox);
 
+	g_free (item->sort_label);
+
 	item->destroyed = TRUE;
 	g_free (item->hash);
 
@@ -132,6 +135,8 @@ nm_network_menu_item_set_ssid (NMNetworkMenuItem * item, GByteArray * ssid)
 		gtk_label_set_text (GTK_LABEL (item->ssid), display_ssid);
 		g_free (display_ssid);
 	}
+	g_free (item->sort_label);
+	item->sort_label = g_strdup (gtk_label_get_text (GTK_LABEL (item->ssid)));
 }
 
 guint32
@@ -161,16 +166,22 @@ nm_network_menu_item_set_strength (NMNetworkMenuItem * item,
 
 	item->int_strength = strength;
 
-	if (strength > 80)
+	if (strength > 80) {
 		pixbuf = gdk_pixbuf_copy (applet->wireless_100_icon);
-	else if (strength > 55)
+		item->sort_strength = 4;
+	} else if (strength > 55) {
 		pixbuf = gdk_pixbuf_copy (applet->wireless_75_icon);
-	else if (strength > 30)
+		item->sort_strength = 3;
+	} else if (strength > 30) {
 		pixbuf = gdk_pixbuf_copy (applet->wireless_50_icon);
-	else if (strength > 5)
+		item->sort_strength = 2;
+	} else if (strength > 5) {
 		pixbuf = gdk_pixbuf_copy (applet->wireless_25_icon);
-	else
+		item->sort_strength = 1;
+	} else {
 		pixbuf = gdk_pixbuf_copy (applet->wireless_00_icon);
+		item->sort_strength = 0;
+	}
 
 	if ((ap_flags & NM_802_11_AP_FLAGS_PRIVACY)
 		|| (ap_wpa != NM_802_11_AP_SEC_NONE)
diff --git a/src/ap-menu-item.h b/src/ap-menu-item.h
index a44c2e3..b5f3e6b 100644
--- a/src/ap-menu-item.h
+++ b/src/ap-menu-item.h
@@ -53,6 +53,8 @@ struct _NMNetworkMenuItem
 	guint32     hash_len;
 	gboolean    destroyed;
 	GSList *    dupes;
+	gchar *sort_label;
+	guint32 sort_strength;
 };
 
 struct _NMNetworkMenuItemClass
diff --git a/src/applet.c b/src/applet.c
index 5ca8a01..6ae516a 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -468,7 +468,7 @@ applet_menu_item_favorize_helper (GtkBin *binitem,
 
 	child = gtk_bin_get_child (binitem);
 	box = gtk_hbox_new (FALSE, 0);
-	already_favorized_ptr = g_object_get_data (G_OBJECT (child), "already-favorized");
+	already_favorized_ptr = g_object_get_data (G_OBJECT (binitem), "favorite");
 
 	if (already_favorized_ptr)
 		goto abort;
@@ -485,6 +485,7 @@ applet_menu_item_favorize_helper (GtkBin *binitem,
 		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 (binitem), "favorite", GINT_TO_POINTER (1));
 	} else {
 		GtkWidget *image = gtk_image_new_from_pixbuf (favoritePixbuf);
 		g_assert (image);
@@ -494,10 +495,9 @@ applet_menu_item_favorize_helper (GtkBin *binitem,
 		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 (binitem), "favorite", GINT_TO_POINTER (2));
 	}
 
-	g_object_set_data (G_OBJECT (child), "already-favorized", GINT_TO_POINTER (1));
-
 	return;
 abort:
 	g_object_ref_sink (box);



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