[network-manager-applet/dcbw/indicator-cleanups: 2/3] applet: use fewer deprecated GtkImageMenuItems (bgo #740574)



commit a8a6d557819d9a0fcd706ca2c48031f058b06859
Author: Dan Williams <dcbw redhat com>
Date:   Mon Feb 22 14:27:03 2016 -0600

    applet: use fewer deprecated GtkImageMenuItems (bgo #740574)
    
    GtkImageMenuItem is deprecated and we should use fewer of them.  Most
    GTK-based desktop environments seem to have stopped showing icons in
    menus by default anyway.  This will allow us to simplify the code
    for both the regular applet and the appindictor version.  So:
    
    1) remove the stock icons from the static menu items so they won't
    be displayed
    2) override gtk-menu-images to TRUE for later appindicator changes,
    since we actually want our custom menu item images displayed, just
    not the stock ones (that we just removed anyway)

 src/applet.c |   49 +++++++++++++++++++++----------------------------
 1 files changed, 21 insertions(+), 28 deletions(-)
---
diff --git a/src/applet.c b/src/applet.c
index 8f46889..30491c8 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -489,7 +489,7 @@ applet_menu_item_add_complex_separator_helper (GtkWidget *menu,
 #ifdef ENABLE_INDICATOR
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
 #else
-       GtkWidget *menu_item = gtk_image_menu_item_new ();
+       GtkWidget *menu_item = gtk_menu_item_new ();
        GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
        GtkWidget *xlabel = NULL;
 
@@ -516,7 +516,7 @@ applet_new_menu_item_helper (NMConnection *connection,
                              NMConnection *active,
                              gboolean add_active)
 {
-       GtkWidget *item = gtk_image_menu_item_new_with_label ("");
+       GtkWidget *item = gtk_menu_item_new_with_label ("");
 
        if (add_active && (active == connection)) {
                char *markup;
@@ -531,7 +531,6 @@ applet_new_menu_item_helper (NMConnection *connection,
        } else
                gtk_menu_item_set_label (GTK_MENU_ITEM (item), nm_connection_get_id (connection));
 
-       gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
        return item;
 }
 
@@ -1812,16 +1811,22 @@ applet_connection_info_cb (NMApplet *applet)
 static GtkWidget *nma_context_menu_create (NMApplet *applet)
 {
        GtkMenuShell *menu;
-#ifndef ENABLE_INDICATOR
-       GtkWidget *menu_item;
-#endif
-       GtkWidget *image;
        guint id;
+       static gboolean icons_shown = FALSE;
 
        g_return_val_if_fail (applet != NULL, NULL);
 
        menu = GTK_MENU_SHELL (gtk_menu_new ());
 
+       if (G_UNLIKELY (icons_shown == FALSE)) {
+               GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (menu));
+
+               /* We always want our icons displayed */
+               if (settings)
+                       g_object_set (G_OBJECT (settings), "gtk-menu-images", TRUE, NULL);
+               icons_shown = TRUE;
+       }
+
        /* 'Enable Networking' item */
        applet->networking_enabled_item = gtk_check_menu_item_new_with_mnemonic (_("Enable _Networking"));
        id = g_signal_connect (applet->networking_enabled_item,
@@ -1865,45 +1870,33 @@ static GtkWidget *nma_context_menu_create (NMApplet *applet)
 #endif
 
        /* 'Connection Information' item */
-       applet->info_menu_item = gtk_image_menu_item_new_with_mnemonic (_("Connection _Information"));
+       applet->info_menu_item = gtk_menu_item_new_with_mnemonic (_("Connection _Information"));
        g_signal_connect_swapped (applet->info_menu_item,
                                  "activate",
                                  G_CALLBACK (applet_connection_info_cb),
                                  applet);
-       image = gtk_image_new_from_stock (GTK_STOCK_INFO, GTK_ICON_SIZE_MENU);
-       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (applet->info_menu_item), image);
        gtk_menu_shell_append (menu, applet->info_menu_item);
 
        /* 'Edit Connections...' item */
-       applet->connections_menu_item = gtk_image_menu_item_new_with_mnemonic (_("Edit Connections..."));
+       applet->connections_menu_item = gtk_menu_item_new_with_mnemonic (_("Edit Connections..."));
        g_signal_connect (applet->connections_menu_item,
                                   "activate",
                                   G_CALLBACK (nma_edit_connections_cb),
                                   applet);
-       image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
-       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (applet->connections_menu_item), image);
        gtk_menu_shell_append (menu, applet->connections_menu_item);
 
        /* Separator */
        nma_menu_add_separator_item (GTK_WIDGET (menu));
 
 #ifndef ENABLE_INDICATOR
-#if 0  /* FIXME: Implement the help callback, nma_help_cb()! */
-       /* Help item */
-       menu_item = gtk_image_menu_item_new_with_mnemonic (_("_Help"));
-       g_signal_connect (menu_item, "activate", G_CALLBACK (nma_help_cb), applet);
-       image = gtk_image_new_from_stock (GTK_STOCK_HELP, GTK_ICON_SIZE_MENU);
-       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
-       gtk_menu_shell_append (menu, menu_item);
-       gtk_widget_set_sensitive (menu_item, FALSE);
-#endif
+       {
+               /* About item */
+               GtkWidget *menu_item;
 
-       /* About item */
-       menu_item = gtk_image_menu_item_new_with_mnemonic (_("_About"));
-       g_signal_connect_swapped (menu_item, "activate", G_CALLBACK (applet_about_dialog_show), applet);
-       image = gtk_image_new_from_stock (GTK_STOCK_ABOUT, GTK_ICON_SIZE_MENU);
-       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
-       gtk_menu_shell_append (menu, menu_item);
+               menu_item = gtk_menu_item_new_with_mnemonic (_("_About"));
+               g_signal_connect_swapped (menu_item, "activate", G_CALLBACK (applet_about_dialog_show), 
applet);
+               gtk_menu_shell_append (menu, menu_item);
+       }
 #endif
 
        gtk_widget_show_all (GTK_WIDGET (menu));


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