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



commit efaf40f81e4062e7afe12db2edb4159c4b4e8316
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 |   25 ++-----------------------
 src/ap-menu-item.h |    4 ++--
 src/mb-menu-item.c |   29 ++---------------------------
 src/mb-menu-item.h |    4 ++--
 5 files changed, 9 insertions(+), 54 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7b44085..7e39955 100644
--- a/configure.ac
+++ b/configure.ac
@@ -104,6 +104,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 1a1ba75..b37b4ec 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;
@@ -128,18 +126,7 @@ update_icon (NMNetworkMenuItem *item, NMApplet *applet)
                        icon = icon_free2 = gdk_pixbuf_scale_simple (icon, 24, 24, GDK_INTERP_BILINEAR);
        }
 
-#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
 }
 
 void
@@ -194,9 +181,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);
@@ -205,7 +189,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
@@ -318,7 +301,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);
@@ -334,9 +316,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 b370d05..d2168e2 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 *
@@ -187,22 +181,7 @@ nm_mb_menu_item_new (const char *connection_name,
        if (enabled && strength) {
                const char *icon_name = mobile_helper_get_quality_icon_name (strength);
 
-#ifdef ENABLE_INDICATOR
-
-               gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
-#ifdef DBUSMENU_PIXMAP_SUPPORT
-                                              gtk_image_new_from_pixbuf (nma_icon_check_and_load (icon_name, 
applet))
-#else
-                                              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),
-                                          nma_icon_check_and_load (icon_name, applet));
-#endif
+               gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), nma_icon_check_and_load (icon_name, 
applet));
        }
 
        return GTK_WIDGET (item);
@@ -213,7 +192,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);
@@ -229,9 +207,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]