[network-manager-applet] applet: prepare for appindicator patch



commit 40f052d38af9e9f3bc42c6cbbb51e9044ab73663
Author: Pavel Šimerda <psimerda redhat com>
Date:   Wed Dec 17 15:00:00 2014 +0100

    applet: prepare for appindicator patch
    
    Add an empty applet_schedule_update_menu() that would later be used
    by the appindicator code. Prepare the code for the final appindicator
    patch.

 src/ap-menu-item.c            |    2 +-
 src/applet-device-broadband.c |    2 +
 src/applet-device-wifi.c      |    4 ++-
 src/applet-device-wimax.c     |   27 ++++++++++++-------
 src/applet.c                  |   57 +++++++++++++++++++++++-----------------
 src/applet.h                  |   23 ++++++++--------
 6 files changed, 68 insertions(+), 47 deletions(-)
---
diff --git a/src/ap-menu-item.c b/src/ap-menu-item.c
index 3f18029..ec0f181 100644
--- a/src/ap-menu-item.c
+++ b/src/ap-menu-item.c
@@ -69,9 +69,9 @@ nm_network_menu_item_init (NMNetworkMenuItem *item)
 
        priv->strength = gtk_image_new ();
        gtk_box_pack_end (GTK_BOX (priv->hbox), priv->strength, FALSE, TRUE, 0);
+       gtk_widget_show (priv->strength);
 
        gtk_widget_show (priv->ssid);
-       gtk_widget_show (priv->strength);
        gtk_widget_show (priv->detail);
        gtk_widget_show (priv->hbox);
 }
diff --git a/src/applet-device-broadband.c b/src/applet-device-broadband.c
index 26d7707..df99f4c 100644
--- a/src/applet-device-broadband.c
+++ b/src/applet-device-broadband.c
@@ -812,6 +812,7 @@ signal_quality_updated (GObject *object,
                         BroadbandDeviceInfo *info)
 {
        applet_schedule_update_icon (info->applet);
+       applet_schedule_update_menu (info->applet);
 }
 
 static void
@@ -820,6 +821,7 @@ access_technologies_updated (GObject *object,
                              BroadbandDeviceInfo *info)
 {
        applet_schedule_update_icon (info->applet);
+       applet_schedule_update_menu (info->applet);
 }
 
 static void
diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c
index c67f8b6..d5a937a 100644
--- a/src/applet-device-wifi.c
+++ b/src/applet-device-wifi.c
@@ -547,12 +547,12 @@ create_new_ap_item (NMDeviceWifi *device,
 
        item = NM_NETWORK_MENU_ITEM (nm_network_menu_item_new (dup_data->hash,
                                                               !!g_slist_length (ap_connections)));
-       gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
 
        ssid = nm_access_point_get_ssid (ap);
        nm_network_menu_item_set_ssid (item, (GByteArray *) ssid);
 
        dev_caps = nm_device_wifi_get_capabilities (device);
+       gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
        nm_network_menu_item_set_detail (item, ap, nma_icon_check_and_load ("nm-adhoc", applet), dev_caps);
        nm_network_menu_item_best_strength (item, nm_access_point_get_strength (ap), applet);
        nm_network_menu_item_add_dupe (item, ap);
@@ -1078,6 +1078,7 @@ access_point_added_cb (NMDeviceWifi *device,
                          applet);
        
        queue_avail_access_point_notification (NM_DEVICE (device));
+       applet_schedule_update_menu (applet);
 }
 
 static void
@@ -1095,6 +1096,7 @@ access_point_removed_cb (NMDeviceWifi *device,
        if (old == ap) {
                g_object_set_data (G_OBJECT (device), ACTIVE_AP_TAG, NULL);
                applet_schedule_update_icon (applet);
+               applet_schedule_update_menu (applet);
        }
 }
 
diff --git a/src/applet-device-wimax.c b/src/applet-device-wimax.c
index 1741b2f..a23cecd 100644
--- a/src/applet-device-wimax.c
+++ b/src/applet-device-wimax.c
@@ -296,7 +296,10 @@ wimax_add_menu_item (NMDevice *device,
 static void
 nsp_quality_changed (NMWimaxNsp *nsp, GParamSpec *pspec, gpointer user_data)
 {
-       applet_schedule_update_icon (NM_APPLET (user_data));
+       NMApplet *applet = NM_APPLET (user_data);
+
+       applet_schedule_update_icon (applet);
+       applet_schedule_update_menu (applet);
 }
 
 static NMWimaxNsp *
@@ -358,8 +361,11 @@ active_nsp_changed_cb (NMDeviceWimax *device,
        if (!s_wimax)
                return;
 
-       if (g_strcmp0 (nm_wimax_nsp_get_name (new), nm_setting_wimax_get_network_name (s_wimax)) != 0)
-               applet_schedule_update_icon (applet);
+       if (g_strcmp0 (nm_wimax_nsp_get_name (new), nm_setting_wimax_get_network_name (s_wimax)) == 0)
+               return;
+
+       applet_schedule_update_icon (applet);
+       applet_schedule_update_menu (applet);
 }
 
 static void
@@ -367,15 +373,16 @@ nsp_removed_cb (NMDeviceWimax *device,
                 NMWimaxNsp *nsp,
                 gpointer user_data)
 {
-       NMApplet *applet = NM_APPLET  (user_data);
-       NMWimaxNsp *old;
+       NMApplet *applet = NM_APPLET (user_data);
+
+       /* Ignore unkown nsp */
+       if (g_object_get_data (G_OBJECT (device), ACTIVE_NSP_TAG) != nsp)
+               return;
 
        /* Clear the ACTIVE_NSP_TAG if the active NSP just got removed */
-       old = g_object_get_data (G_OBJECT (device), ACTIVE_NSP_TAG);
-       if (old == nsp) {
-               g_object_set_data (G_OBJECT (device), ACTIVE_NSP_TAG, NULL);
-               applet_schedule_update_icon (applet);
-       }
+       g_object_set_data (G_OBJECT (device), ACTIVE_NSP_TAG, NULL);
+       applet_schedule_update_icon (applet);
+       applet_schedule_update_menu (applet);
 }
 
 static void
diff --git a/src/applet.c b/src/applet.c
index b400fef..f15d463 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -537,6 +537,8 @@ add_and_activate_cb (NMClient *client,
                      GError *error,
                      gpointer user_data)
 {
+       NMApplet *applet = NM_APPLET (user_data);
+
        if (error) {
                const char *text = _("Failed to add/activate connection");
                char *err_text = g_strdup_printf ("(%d) %s", error->code,
@@ -547,7 +549,8 @@ add_and_activate_cb (NMClient *client,
                g_free (err_text);
        }
 
-       applet_schedule_update_icon (NM_APPLET (user_data));
+       applet_schedule_update_icon (applet);
+       applet_schedule_update_menu (applet);
 }
 
 static void
@@ -581,6 +584,8 @@ applet_menu_item_activate_helper_new_connection (NMConnection *connection,
 static void
 disconnect_cb (NMDevice *device, GError *error, gpointer user_data)
 {
+       NMApplet *applet = NM_APPLET (user_data);
+
        if (error) {
                const char *text = _("Device disconnect failed");
                char *err_text = g_strdup_printf ("(%d) %s", error->code,
@@ -590,6 +595,9 @@ disconnect_cb (NMDevice *device, GError *error, gpointer user_data)
                utils_show_error_dialog (_("Disconnect failure"), text, err_text, FALSE, NULL);
                g_free (err_text);
        }
+
+       applet_schedule_update_icon (applet);
+       applet_schedule_update_menu (applet);
 }
 
 void
@@ -598,7 +606,7 @@ applet_menu_item_disconnect_helper (NMDevice *device,
 {
        g_return_if_fail (NM_IS_DEVICE (device));
 
-       nm_device_disconnect (device, disconnect_cb, NULL);
+       nm_device_disconnect (device, disconnect_cb, applet);
 }
 
 static void
@@ -694,13 +702,11 @@ applet_new_menu_item_helper (NMConnection *connection,
                              NMConnection *active,
                              gboolean add_active)
 {
-       GtkWidget *item;
-       NMSettingConnection *s_con;
+       NMSettingConnection *s_con = nm_connection_get_setting_connection (connection);
+       GtkWidget *item = gtk_image_menu_item_new_with_label ("");
        char *markup;
        GtkWidget *label;
 
-       s_con = nm_connection_get_setting_connection (connection);
-       item = gtk_image_menu_item_new_with_label ("");
        if (add_active && (active == connection)) {
                /* Pure evil */
                label = gtk_bin_get_child (GTK_BIN (item));
@@ -1126,6 +1132,7 @@ vpn_connection_state_changed (NMVPNConnection *vpn,
                clear_animation_timeout (applet);
 
        applet_schedule_update_icon (applet);
+       applet_schedule_update_menu (applet);
 }
 
 static const char *
@@ -1181,6 +1188,7 @@ activate_vpn_cb (NMClient *client,
        }
 
        applet_schedule_update_icon (info->applet);
+       applet_schedule_update_menu (info->applet);
        g_free (info->vpn_name);
        g_free (info);
 }
@@ -1207,9 +1215,10 @@ nma_menu_vpn_item_clicked (GtkMenuItem *item, gpointer user_data)
                return;
        }
 
-       if (applet_get_active_for_connection (applet, connection))
+       if (applet_get_active_for_connection (applet, connection)) {
                /* Connection already active; do nothing */
                return;
+       }
 
        s_con = nm_connection_get_setting_connection (connection);
        info = g_malloc0 (sizeof (VPNActivateInfo));
@@ -1769,7 +1778,6 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet)
                NMConnection *connection = NM_CONNECTION (iter->data);
                NMActiveConnection *active;
                const char *name;
-               GtkWidget *image;
                NMState state;
 
                name = get_connection_id (connection);
@@ -1794,7 +1802,8 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet)
                        gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
 
                if (active) {
-                       image = gtk_image_new_from_stock (GTK_STOCK_CONNECT, GTK_ICON_SIZE_MENU);
+                       GtkWidget *image = gtk_image_new_from_stock (GTK_STOCK_CONNECT, GTK_ICON_SIZE_MENU);
+
                        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
                }
 
@@ -2344,6 +2353,10 @@ applet_add_default_connection_item (NMDevice *device,
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 }
 
+void
+applet_schedule_update_menu (NMApplet *applet)
+{
+}
 
 /*****************************************************************************/
 
@@ -2496,6 +2509,7 @@ foo_device_state_changed_cb (NMDevice *device,
        }
 
        applet_schedule_update_icon (applet);
+       applet_schedule_update_menu (applet);
 }
 
 static void
@@ -2539,6 +2553,7 @@ foo_client_state_changed_cb (NMClient *client, GParamSpec *pspec, gpointer user_
        }
 
        applet_schedule_update_icon (applet);
+       applet_schedule_update_menu (applet);
 }
 
 static void
@@ -2556,6 +2571,7 @@ foo_manager_running_cb (NMClient *client,
        }
 
        applet_schedule_update_icon (applet);
+       applet_schedule_update_menu (applet);
 }
 
 #define VPN_STATE_ID_TAG "vpn-state-id"
@@ -2585,6 +2601,7 @@ foo_active_connections_changed_cb (NMClient *client,
        }
 
        applet_schedule_update_icon (applet);
+       applet_schedule_update_menu (applet);
 }
 
 static void
@@ -3242,13 +3259,13 @@ GdkPixbuf *
 nma_icon_check_and_load (const char *name, NMApplet *applet)
 {
        GError *error = NULL;
-       GdkPixbuf *icon = g_hash_table_lookup (applet->icon_cache, name);
+       GdkPixbuf *icon;
 
        g_assert (name != NULL);
        g_assert (applet != NULL);
 
        /* icon already loaded successfully */
-       if (icon)
+       if ((icon = g_hash_table_lookup (applet->icon_cache, name)))
                return icon;
 
        /* Try to load the icon; if the load fails, log the problem, and set
@@ -3312,11 +3329,6 @@ error:
        return FALSE;
 }
 
-static void nma_icon_theme_changed (GtkIconTheme *icon_theme, NMApplet *applet)
-{
-       nma_icons_reload (applet);
-}
-
 static void nma_icons_init (NMApplet *applet)
 {
        GdkScreen *screen;
@@ -3324,7 +3336,7 @@ static void nma_icons_init (NMApplet *applet)
 
        if (applet->icon_theme) {
                g_signal_handlers_disconnect_by_func (applet->icon_theme,
-                                                     G_CALLBACK (nma_icon_theme_changed),
+                                                     G_CALLBACK (nma_icons_reload),
                                                      applet);
                g_object_unref (G_OBJECT (applet->icon_theme));
        }
@@ -3343,7 +3355,7 @@ static void nma_icons_init (NMApplet *applet)
                                   GINT_TO_POINTER (TRUE));
        }
 
-       g_signal_connect (applet->icon_theme, "changed", G_CALLBACK (nma_icon_theme_changed), applet);
+       g_signal_connect (applet->icon_theme, "changed", G_CALLBACK (nma_icons_reload), applet);
 }
 
 static void
@@ -3352,7 +3364,7 @@ status_icon_screen_changed_cb (GtkStatusIcon *icon,
                                NMApplet *applet)
 {
        nma_icons_init (applet);
-       nma_icon_theme_changed (NULL, applet);
+       nma_icons_reload (applet);
 }
 
 static gboolean
@@ -3421,11 +3433,9 @@ status_icon_popup_menu_cb (GtkStatusIcon *icon,
 static gboolean
 setup_widgets (NMApplet *applet)
 {
-       g_return_val_if_fail (NM_IS_APPLET (applet), FALSE);
 
        applet->status_icon = gtk_status_icon_new ();
-       if (!applet->status_icon)
-               return FALSE;
+
        if (shell_debug)
                gtk_status_icon_set_name (applet->status_icon, "adsfasdfasdfadfasdf");
 
@@ -3646,9 +3656,8 @@ static void finalize (GObject *object)
        g_clear_object (&applet->menu);
        g_clear_pointer (&applet->icon_cache, g_hash_table_destroy);
        g_clear_object (&applet->fallback_icon);
-       nma_icons_free (applet);
-
        g_free (applet->tip);
+       nma_icons_free (applet);
 
        while (g_slist_length (applet->secrets_reqs))
                applet_secrets_request_free ((SecretsRequest *) applet->secrets_reqs->data);
diff --git a/src/applet.h b/src/applet.h
index 95bc287..cf729af 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -118,28 +118,31 @@ typedef struct
 
        /* Data model elements */
        guint                   update_icon_id;
+       char *                  tip;
 
-       GtkIconTheme *  icon_theme;
-       GHashTable *    icon_cache;
+       /* Animation stuff */
+       int                             animation_step;
+       guint                   animation_id;
 #define NUM_CONNECTING_FRAMES 11
 #define NUM_VPN_CONNECTING_FRAMES 14
+
+       GtkIconTheme *  icon_theme;
+       GHashTable *    icon_cache;
        GdkPixbuf *             fallback_icon;
 
        /* Active status icon pixbufs */
        GdkPixbuf *             icon_layers[ICON_LAYER_MAX + 1];
 
-       /* Animation stuff */
-       int                             animation_step;
-       guint                   animation_id;
-
        /* Direct UI elements */
        GtkStatusIcon * status_icon;
        int             icon_size;
 
        GtkWidget *             menu;
-       char *          tip;
-
        GtkWidget *             context_menu;
+
+       GtkWidget *             notifications_enabled_item;
+       guint                   notifications_enabled_toggled_id;
+
        GtkWidget *             networking_enabled_item;
        guint           networking_enabled_toggled_id;
        GtkWidget *             wifi_enabled_item;
@@ -149,9 +152,6 @@ typedef struct
        GtkWidget *             wimax_enabled_item;
        guint           wimax_enabled_toggled_id;
 
-       GtkWidget *     notifications_enabled_item;
-       guint           notifications_enabled_toggled_id;
-
        GtkWidget *             info_menu_item;
        GtkWidget *             connections_menu_item;
 
@@ -242,6 +242,7 @@ GType nma_get_type (void);
 NMApplet *nm_applet_new (void);
 
 void applet_schedule_update_icon (NMApplet *applet);
+void applet_schedule_update_menu (NMApplet *applet);
 
 NMRemoteSettings *applet_get_settings (NMApplet *applet);
 


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