[network-manager-applet/dcbw/indicator-cleanups: 3/3] applet: don't use GtkImageMenuItems (bgo #740574)



commit be7805ec5ef4adfa51128b5c3a9c3d9804f7373f
Author: Dan Williams <dcbw redhat com>
Date:   Mon Feb 22 14:34:26 2016 -0600

    applet: don't use GtkImageMenuItems (bgo #740574)
    
    GtkImageMenuItems are deprecated and we shouldn't use them anymore.
    So don't; appindicator/dbusmenu can handle GtkImages in normal
    GtkMenuItems now with the 16.04.0 release.
    
    appindicator/dbusmenu also strips Pango markup so we can remove
    the conditionals around label text.

 configure.ac       |    1 +
 src/ap-menu-item.c |   26 +++-----------------------
 src/ap-menu-item.h |    4 ++--
 src/mb-menu-item.c |   24 +-----------------------
 src/mb-menu-item.h |    4 ++--
 5 files changed, 9 insertions(+), 50 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c5312a9..94af4b0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -106,6 +106,7 @@ GTK_CFLAGS="$GTK_CFLAGS -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_4"
 AC_ARG_WITH([appindicator], AS_HELP_STRING([--with-appindicator|--without-appindicator], [Build with 
libappindicator support instead of xembed systray support.]))
 if test "$with_appindicator" == "yes"; then
        PKG_CHECK_MODULES(APPINDICATOR, appindicator3-0.1)
+       PKG_CHECK_MODULES(DBUSMENU, dbusmenu-gtk3-0.4 >= 16.04.0)
        AC_DEFINE([ENABLE_INDICATOR], 1, [Enable using libappindicator])
 fi
 
diff --git a/src/ap-menu-item.c b/src/ap-menu-item.c
index ee997f7..6cfacd1 100644
--- a/src/ap-menu-item.c
+++ b/src/ap-menu-item.c
@@ -33,18 +33,16 @@
 #include "mobile-helpers.h"
 
 
-G_DEFINE_TYPE (NMNetworkMenuItem, nm_network_menu_item, GTK_TYPE_IMAGE_MENU_ITEM);
+G_DEFINE_TYPE (NMNetworkMenuItem, nm_network_menu_item, GTK_TYPE_MENU_ITEM);
 
 #define NM_NETWORK_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_NETWORK_MENU_ITEM, 
NMNetworkMenuItemPrivate))
 
 typedef struct {
-#ifndef ENABLE_INDICATOR
        GtkWidget * ssid;
        GtkWidget * strength;
        GtkWidget * hbox;
-#endif
 
-       char      * ssid_string;
+       char *      ssid_string;
        guint32     int_strength;
        gchar *     hash;
        GSList *    dupes;
@@ -125,18 +123,8 @@ update_icon (NMNetworkMenuItem *item, NMApplet *applet)
                icon = scaled;
        }
 
-#ifdef ENABLE_INDICATOR
-#ifdef DBUSMENU_PIXMAP_SUPPORT
-       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), gtk_image_new_from_pixbuf (icon));
-#else
-       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
-                                      gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU));
-#endif
-       /* For some reason we must always re-set always-show after setting the image */
-       gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
-#else
        gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), icon);
-#endif
+
        g_object_unref (icon);
 }
 
@@ -192,9 +180,6 @@ update_label (NMNetworkMenuItem *item, gboolean use_bold)
 {
        NMNetworkMenuItemPrivate *priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item);
 
-#ifdef ENABLE_INDICATOR
-       gtk_menu_item_set_label (GTK_MENU_ITEM (item), priv->ssid_string);
-#else
        gtk_label_set_use_markup (GTK_LABEL (priv->ssid), use_bold);
        if (use_bold) {
                char *markup = g_markup_printf_escaped ("<b>%s</b>", priv->ssid_string);
@@ -203,7 +188,6 @@ update_label (NMNetworkMenuItem *item, gboolean use_bold)
                g_free (markup);
        } else
                gtk_label_set_text (GTK_LABEL (priv->ssid), priv->ssid_string);
-#endif
 }
 
 void
@@ -316,7 +300,6 @@ nm_network_menu_item_new (NMAccessPoint *ap,
 static void
 nm_network_menu_item_init (NMNetworkMenuItem *item)
 {
-#ifndef ENABLE_INDICATOR
        NMNetworkMenuItemPrivate *priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item);
 
        priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
@@ -332,9 +315,6 @@ nm_network_menu_item_init (NMNetworkMenuItem *item)
 
        gtk_widget_show (priv->ssid);
        gtk_widget_show (priv->hbox);
-#else
-       gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
-#endif
 }
 
 static void
diff --git a/src/ap-menu-item.h b/src/ap-menu-item.h
index c538c36..2136a8f 100644
--- a/src/ap-menu-item.h
+++ b/src/ap-menu-item.h
@@ -40,11 +40,11 @@ typedef struct _NMNetworkMenuItem       NMNetworkMenuItem;
 typedef struct _NMNetworkMenuItemClass  NMNetworkMenuItemClass;
 
 struct _NMNetworkMenuItem {
-       GtkImageMenuItem parent;
+       GtkMenuItem parent;
 };
 
 struct _NMNetworkMenuItemClass {
-       GtkImageMenuItemClass parent_class;
+       GtkMenuItemClass parent_class;
 };
 
 
diff --git a/src/mb-menu-item.c b/src/mb-menu-item.c
index e1bcde5..f8645db 100644
--- a/src/mb-menu-item.c
+++ b/src/mb-menu-item.c
@@ -28,17 +28,15 @@
 
 #include "mb-menu-item.h"
 
-G_DEFINE_TYPE (NMMbMenuItem, nm_mb_menu_item, GTK_TYPE_IMAGE_MENU_ITEM);
+G_DEFINE_TYPE (NMMbMenuItem, nm_mb_menu_item, GTK_TYPE_MENU_ITEM);
 
 #define NM_MB_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MB_MENU_ITEM, 
NMMbMenuItemPrivate))
 
 typedef struct {
-#ifndef ENABLE_INDICATOR
        GtkWidget *strength;
        GtkWidget *detail;
        GtkWidget *hbox;
        GtkWidget *desc;
-#endif
 
        char *desc_string;
        guint32    int_strength;
@@ -80,9 +78,6 @@ update_label (NMMbMenuItem *item, gboolean use_bold)
 {
        NMMbMenuItemPrivate *priv = NM_MB_MENU_ITEM_GET_PRIVATE (item);
 
-#ifdef ENABLE_INDICATOR
-       gtk_menu_item_set_label (GTK_MENU_ITEM (item), priv->desc_string);
-#else
        gtk_label_set_use_markup (GTK_LABEL (priv->desc), use_bold);
        if (use_bold) {
                char *markup = g_markup_printf_escaped ("<b>%s</b>", priv->desc_string);
@@ -91,7 +86,6 @@ update_label (NMMbMenuItem *item, gboolean use_bold)
                g_free (markup);
        } else
                gtk_label_set_text (GTK_LABEL (priv->desc), priv->desc_string);
-#endif
 }
 
 GtkWidget *
@@ -188,19 +182,7 @@ nm_mb_menu_item_new (const char *connection_name,
                const char *icon_name = mobile_helper_get_quality_icon_name (strength);
                GdkPixbuf *pixbuf = nma_icon_check_and_load (icon_name, applet);
 
-#ifdef ENABLE_INDICATOR
-#ifdef DBUSMENU_PIXMAP_SUPPORT
-               gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), gtk_image_new_from_pixbuf 
(pixbuf));
-#else
-               gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
-                                              gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU));
-               pixbuf = NULL;
-#endif
-               /* For some reason we must always re-set always-show after setting the image */
-               gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
-#else
                gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), pixbuf);
-#endif
        }
 
        return GTK_WIDGET (item);
@@ -211,7 +193,6 @@ nm_mb_menu_item_new (const char *connection_name,
 static void
 nm_mb_menu_item_init (NMMbMenuItem *self)
 {
-#ifndef ENABLE_INDICATOR
        NMMbMenuItemPrivate *priv = NM_MB_MENU_ITEM_GET_PRIVATE (self);
 
        priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
@@ -227,9 +208,6 @@ nm_mb_menu_item_init (NMMbMenuItem *self)
        gtk_widget_show (priv->desc);
        gtk_widget_show (priv->strength);
        gtk_widget_show (priv->hbox);
-#else
-       gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (self), TRUE);
-#endif
 }
 
 static void
diff --git a/src/mb-menu-item.h b/src/mb-menu-item.h
index e38ed9f..a973062 100644
--- a/src/mb-menu-item.h
+++ b/src/mb-menu-item.h
@@ -36,11 +36,11 @@
 #define NM_MB_MENU_ITEM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MB_MENU_ITEM, 
NMMbMenuItemClass))
 
 typedef struct {
-       GtkImageMenuItem image_item;
+       GtkMenuItem image_item;
 } NMMbMenuItem;
 
 typedef struct {
-       GtkImageMenuItemClass parent_class;
+       GtkMenuItemClass parent_class;
 } NMMbMenuItemClass;
 
 


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