[network-manager-applet/menu-rework: 10/18] applet: add helper function for partly folded menus
- From: Dan Williams <dcbw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [network-manager-applet/menu-rework: 10/18] applet: add helper function for partly folded menus
- Date: Fri, 25 Sep 2009 05:48:44 +0000 (UTC)
commit 7902f0fc4c21b007dbd2f454dbd438b9e0e220e9
Author: Alexander Sack <asac ubuntu com>
Date: Wed Sep 23 13:22:17 2009 +0200
applet: add helper function for partly folded menus
helper function adds a GList* of menu items to a GtkMenu in a way
that displays most important N menu items on the top level and
fold the rest to a submenu
The algorithm first sorts the list using the prio_cmp_func to create
a list of most N important items; this list is again sorted using
the generic_cmp_func before being added to the top level of the menu;
all items not among the N most important ones are added to a submenu
passed as parameter to the menu; the submenu items are sorted using
the generic_cmp_func.
src/applet.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/applet.h | 7 ++++++
2 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/src/applet.c b/src/applet.c
index 02156f8..5ca8a01 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -503,6 +503,69 @@ abort:
g_object_ref_sink (box);
}
+void
+applet_menu_add_items_top_and_fold_sorted_helper (GtkMenu *menu,
+ GList *items,
+ guint top_count,
+ GtkWidget *submenu_item,
+ GCompareFunc prio_cmp_func,
+ GCompareFunc generic_cmp_func)
+{
+ GList *iter = items;
+ GList *clone_top = NULL;
+ GList *clone_top_filtered = NULL;
+ GList *clone_folded = NULL;
+ GtkWidget *submenu;
+ int i;
+
+ g_assert (menu);
+ g_assert (items);
+ g_assert (top_count > 0);
+ g_assert (submenu_item);
+ g_assert (prio_cmp_func);
+ g_assert (generic_cmp_func);
+
+ submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (submenu_item));
+ g_assert (submenu_item);
+
+ while (iter) {
+ clone_top = g_list_append (clone_top, iter->data);
+ clone_folded = g_list_append (clone_folded, iter->data);
+ iter = iter->next;
+ }
+
+ clone_top = g_list_sort (clone_top, prio_cmp_func);
+ clone_folded = g_list_sort (clone_folded, generic_cmp_func);
+
+ iter = clone_top;
+ for (i = 0; !!iter && i < top_count; i++, iter = iter->next) {
+ clone_folded = g_list_remove (clone_folded, iter->data);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), iter->data);
+ clone_top_filtered = g_list_append (clone_top_filtered, iter->data);
+ }
+
+
+ clone_top_filtered = g_list_sort (clone_top_filtered, generic_cmp_func);
+ iter = clone_top_filtered;
+ while (iter) {
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), iter->data);
+ iter = iter->next;
+ }
+
+ iter = clone_folded;
+ if (iter)
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), submenu_item);
+ while (iter) {
+ gtk_menu_shell_append (GTK_MENU_SHELL (submenu), iter->data);
+ iter = iter->next;
+ }
+
+ g_list_free(clone_top);
+ g_list_free(clone_top_filtered);
+ g_list_free(clone_folded);
+}
+
+
static void
applet_clear_notify (NMApplet *applet)
{
diff --git a/src/applet.h b/src/applet.h
index a9850ce..13be72c 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -233,6 +233,13 @@ void applet_menu_item_favorize_helper (GtkBin *binitem,
GdkPixbuf *favoritePixbuf,
gboolean is_favorite);
+void applet_menu_add_items_top_and_fold_sorted_helper (GtkMenu *menu,
+ GList *items,
+ guint top_count,
+ GtkWidget *submenu_item,
+ GCompareFunc prio_cmp_func,
+ GCompareFunc generic_cmp_func);
+
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]