[network-manager-applet/bg/menu-wifi-scan-bgo774848: 2/2] applet: update AP list while the menu is open (wip)



commit 36e7ddfe57392ccc9ebc6c3b647c2b313d5230e3
Author: Beniamino Galvani <bgalvani redhat com>
Date:   Fri Jan 6 15:38:30 2017 +0100

    applet: update AP list while the menu is open (wip)

 src/applet.c |   60 +++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 41 insertions(+), 19 deletions(-)
---
diff --git a/src/applet.c b/src/applet.c
index 9a05be6..23c9a5f 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -1811,15 +1811,25 @@ applet_connection_info_cb (NMApplet *applet)
  * Generate the contextual popup menu.
  *
  */
-static GtkWidget *nma_context_menu_create (NMApplet *applet)
+static GtkWidget *nma_context_menu_create (NMApplet *applet, GtkMenu *orig)
 {
        GtkMenuShell *menu;
        guint id;
        static gboolean icons_shown = FALSE;
+       GList *children, *elt;
 
        g_return_val_if_fail (applet != NULL, NULL);
 
-       menu = GTK_MENU_SHELL (gtk_menu_new ());
+       if (orig) {
+               menu = GTK_MENU_SHELL (orig);
+
+               children = gtk_container_get_children (GTK_CONTAINER (menu));
+               for (elt = children; elt; elt = g_list_next (elt))
+                       gtk_container_remove (GTK_CONTAINER (menu), GTK_WIDGET (elt->data));
+               g_list_free (children);
+       } else {
+               menu = GTK_MENU_SHELL (gtk_menu_new ());
+       }
 
        if (G_UNLIKELY (icons_shown == FALSE)) {
                GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (menu));
@@ -2003,25 +2013,39 @@ applet_add_default_connection_item (NMDevice *device,
 }
 
 static gboolean
-applet_update_indicator_menu (gpointer user_data)
+applet_update_menu (gpointer user_data)
 {
        NMApplet *applet = NM_APPLET (user_data);
+
+       if (INDICATOR_ENABLED (applet)) {
 #ifdef WITH_APPINDICATOR
-       GtkWidget *menu;
+               GtkWidget *menu;
+               static gboolean inited;
 
-       menu = (GtkWidget *) app_indicator_get_menu (applet->app_indicator);
-       if (menu)
-               g_signal_handlers_disconnect_by_func (menu, applet_request_wifi_scan, applet);
+               menu = (GtkWidget *) app_indicator_get_menu (applet->app_indicator);
+               menu = nma_context_menu_create (applet, (GtkMenu *) menu);
+               nma_menu_show_cb (menu, applet);
+               nma_menu_add_separator_item (menu);
+               nma_context_menu_update (applet);
 
-       menu = nma_context_menu_create (applet);
-       nma_menu_show_cb (menu, applet);
-       nma_menu_add_separator_item (menu);
-       nma_context_menu_update (applet);
+               if (!inited) {
+                       app_indicator_set_menu (applet->app_indicator, GTK_MENU (menu));
+                       g_signal_connect_swapped (menu, "show", G_CALLBACK (applet_request_wifi_scan), 
applet);
+                       inited = TRUE;
+               }
+#endif /* WITH_APPINDICATOR */
+       } else {
+               if (applet->menu) {
+                       GList *children, *elt;
 
-       app_indicator_set_menu (applet->app_indicator, GTK_MENU (menu));
+                       children = gtk_container_get_children (GTK_CONTAINER (applet->menu));
+                       for (elt = children; elt; elt = g_list_next (elt))
+                               gtk_container_remove (GTK_CONTAINER (applet->menu), GTK_WIDGET (elt->data));
+                       g_list_free (children);
 
-       g_signal_connect_swapped (menu, "show", G_CALLBACK (applet_request_wifi_scan), applet);
-#endif /* WITH_APPINDICATOR */
+                       nma_menu_show_cb (applet->menu, applet);
+               }
+       }
 
        applet->update_menu_id = 0;
        return G_SOURCE_REMOVE;
@@ -2030,10 +2054,8 @@ applet_update_indicator_menu (gpointer user_data)
 void
 applet_schedule_update_menu (NMApplet *applet)
 {
-       if (INDICATOR_ENABLED (applet)) {
-               if (!applet->update_menu_id)
-                       applet->update_menu_id = g_idle_add (applet_update_indicator_menu, applet);
-       }
+       if (!applet->update_menu_id)
+               applet->update_menu_id = g_idle_add (applet_update_menu, applet);
 }
 
 /*****************************************************************************/
@@ -3177,7 +3199,7 @@ setup_widgets (NMApplet *applet)
                g_signal_connect (applet->status_icon, "popup-menu",
                                  G_CALLBACK (status_icon_popup_menu_cb), applet);
 
-               applet->context_menu = nma_context_menu_create (applet);
+               applet->context_menu = nma_context_menu_create (applet, NULL);
                if (!applet->context_menu)
                        return FALSE;
        }


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