diff options
author | Dan Williams <dcbw@redhat.com> | 2015-02-17 14:05:33 -0600 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2015-02-17 14:05:33 -0600 |
commit | 39c0868faf3374f6358d7282cad79cb7de71fdfa (patch) | |
tree | 88479cdc048906a7701e24bd0174efce112d60d5 | |
parent | 55c39272f5f66c5127799833464a9f498179de22 (diff) | |
parent | 756b3cc9527f9cd24d8a7db5b6c951d1b00a2d63 (diff) | |
download | network-manager-applet-39c0868faf3374f6358d7282cad79cb7de71fdfa.tar.gz |
merge: add compile-time support for libappindicator (bgo #740574)
For the moment only pixmaps are passed for WiFi/WWAN menu items
are passed instead of the icon name. Not all implementations
of appindicator/dbusmenu support pixmap data (Enlightenment is
one that does not) but we'll work on that.
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ap-menu-item.c | 367 | ||||
-rw-r--r-- | src/ap-menu-item.h | 18 | ||||
-rw-r--r-- | src/applet-device-wifi.c | 25 | ||||
-rw-r--r-- | src/applet.c | 163 | ||||
-rw-r--r-- | src/applet.h | 11 | ||||
-rw-r--r-- | src/mb-menu-item.c | 59 |
9 files changed, 428 insertions, 224 deletions
diff --git a/configure.ac b/configure.ac index 5452784b..639810b4 100644 --- a/configure.ac +++ b/configure.ac @@ -145,6 +145,12 @@ case "${with_bluetooth}" in ;; esac +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) + AC_DEFINE([ENABLE_INDICATOR], 1, [Enable using libappindicator]) +fi + AM_CONDITIONAL(HAVE_GBT, test x"$have_gbt" = "xyes") dnl ModemManager1 with libmm-glib for WWAN support diff --git a/po/POTFILES.in b/po/POTFILES.in index 768b18b4..5df683ab 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,6 +5,7 @@ nm-applet.desktop.in nm-connection-editor.desktop.in org.gnome.nm-applet.gschema.xml.in [type: gettext/glade]src/8021x.ui +src/ap-menu-item.c src/applet.c src/applet-device-bond.c src/applet-device-bridge.c diff --git a/src/Makefile.am b/src/Makefile.am index 903102cf..c0407a60 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,7 @@ nm_applet_CPPFLAGS = \ $(LIBSECRET_CFLAGS) \ $(NOTIFY_CFLAGS) \ $(MM_GLIB_CFLAGS) \ + $(APPINDICATOR_CFLAGS) \ -DNM_VERSION_MIN_REQUIRED=NM_VERSION_0_9_10 \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_0_9_10 \ -DICONDIR=\""$(datadir)/icons"\" \ @@ -82,6 +83,7 @@ nm_applet_LDADD = \ $(LIBSECRET_LIBS) \ $(NOTIFY_LIBS) \ $(MM_GLIB_LIBS) \ + $(APPINDICATOR_LIBS) \ ${top_builddir}/src/marshallers/libmarshallers.la \ ${top_builddir}/src/utils/libutils.la \ ${top_builddir}/src/wireless-security/libwireless-security.la \ diff --git a/src/ap-menu-item.c b/src/ap-menu-item.c index ec0f1816..a622eb2b 100644 --- a/src/ap-menu-item.c +++ b/src/ap-menu-item.c @@ -39,12 +39,15 @@ G_DEFINE_TYPE (NMNetworkMenuItem, nm_network_menu_item, GTK_TYPE_IMAGE_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; - char * ssid_string; GtkWidget * strength; - guint32 int_strength; GtkWidget * detail; GtkWidget * hbox; +#endif + + char * ssid_string; + guint32 int_strength; gchar * hash; GSList * dupes; gboolean has_connections; @@ -52,86 +55,7 @@ typedef struct { gboolean is_encrypted; } NMNetworkMenuItemPrivate; -static void -nm_network_menu_item_init (NMNetworkMenuItem *item) -{ - NMNetworkMenuItemPrivate *priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item); - - priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - priv->ssid = gtk_label_new (NULL); - gtk_misc_set_alignment (GTK_MISC (priv->ssid), 0.0, 0.5); - - priv->detail = gtk_image_new (); - - gtk_container_add (GTK_CONTAINER (item), priv->hbox); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->ssid, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->detail, FALSE, FALSE, 0); - - 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->detail); - gtk_widget_show (priv->hbox); -} - -GtkWidget* -nm_network_menu_item_new (const char *hash, gboolean has_connections) -{ - NMNetworkMenuItem *item; - - item = g_object_new (NM_TYPE_NETWORK_MENU_ITEM, NULL); - g_assert (item); - NM_NETWORK_MENU_ITEM_GET_PRIVATE (item)->has_connections = has_connections; - NM_NETWORK_MENU_ITEM_GET_PRIVATE (item)->hash = g_strdup (hash); - return GTK_WIDGET (item); -} - -static void -finalize (GObject *object) -{ - NMNetworkMenuItemPrivate *priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (object); - - g_free (priv->hash); - g_free (priv->ssid_string); - - g_slist_foreach (priv->dupes, (GFunc) g_free, NULL); - g_slist_free (priv->dupes); - - G_OBJECT_CLASS (nm_network_menu_item_parent_class)->finalize (object); -} - -static void -nm_network_menu_item_class_init (NMNetworkMenuItemClass * klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (NMNetworkMenuItemPrivate)); - - /* virtual methods */ - object_class->finalize = finalize; -} - -void -nm_network_menu_item_set_ssid (NMNetworkMenuItem *item, GByteArray *ssid) -{ - NMNetworkMenuItemPrivate *priv; - - g_return_if_fail (NM_IS_NETWORK_MENU_ITEM (item)); - g_return_if_fail (ssid != NULL); - - priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item); - - g_free (priv->ssid_string); - - priv->ssid_string = nm_utils_ssid_to_utf8 (ssid); - if (!priv->ssid_string) { - // FIXME: shouldn't happen; always coerce the SSID to _something_ - priv->ssid_string = g_strdup ("<unknown>"); - } - gtk_label_set_text (GTK_LABEL (priv->ssid), priv->ssid_string); -} +/******************************************************************/ const char * nm_network_menu_item_get_ssid (NMNetworkMenuItem *item) @@ -149,37 +73,48 @@ nm_network_menu_item_get_strength (NMNetworkMenuItem *item) return NM_NETWORK_MENU_ITEM_GET_PRIVATE (item)->int_strength; } -void -nm_network_menu_item_best_strength (NMNetworkMenuItem *item, - guint8 strength, - NMApplet *applet) +static void +update_atk_desc (NMNetworkMenuItem *item) { - NMNetworkMenuItemPrivate *priv; - GdkPixbuf *icon = NULL, *pixbuf, *top; - - g_return_if_fail (NM_IS_NETWORK_MENU_ITEM (item)); - - priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item); - - strength = MIN (strength, 100); - - /* Just do nothing if the new strength is less */ - if (strength < priv->int_strength) - return; + NMNetworkMenuItemPrivate *priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item); + GString *desc = NULL; + + desc = g_string_new (""); + g_string_append_printf (desc, "%s: ", priv->ssid_string); + + if (priv->is_adhoc) + g_string_append (desc, _("ad-hoc")); + else { + g_string_append_printf (desc, "%d%%", priv->int_strength); + if (priv->is_encrypted) { + g_string_append (desc, ", "); + g_string_append (desc, _("secure.")); + } + } - priv->int_strength = strength; + atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (item)), desc->str); + g_string_free (desc, TRUE); +} - if (strength > 80) - icon = nma_icon_check_and_load ("nm-signal-100", applet); - else if (strength > 55) - icon = nma_icon_check_and_load ("nm-signal-75", applet); - else if (strength > 30) - icon = nma_icon_check_and_load ("nm-signal-50", applet); - else if (strength > 5) - icon = nma_icon_check_and_load ("nm-signal-25", applet); +static void +update_icon (NMNetworkMenuItem *item, NMApplet *applet) +{ + NMNetworkMenuItemPrivate *priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item); + GdkPixbuf *icon = NULL, *pixbuf, *top, *scaled; + const char *icon_name = NULL; + + if (priv->int_strength > 80) + icon_name = "nm-signal-100"; + else if (priv->int_strength > 55) + icon_name = "nm-signal-75"; + else if (priv->int_strength > 30) + icon_name = "nm-signal-50"; + else if (priv->int_strength > 5) + icon_name = "nm-signal-25"; else - icon = nma_icon_check_and_load ("nm-signal-00", applet); + icon_name = "nm-signal-00"; + icon = nma_icon_check_and_load (icon_name, applet); pixbuf = gdk_pixbuf_copy (icon); /* If the AP is "secure", composite the lock icon on top of the signal bars */ @@ -193,71 +128,57 @@ nm_network_menu_item_best_strength (NMNetworkMenuItem *item, /* Scale to menu size if larger so the menu doesn't look awful */ if (gdk_pixbuf_get_height (pixbuf) > 24 || gdk_pixbuf_get_width (pixbuf) > 24) { - GdkPixbuf *scaled; - scaled = gdk_pixbuf_scale_simple (pixbuf, 24, 24, GDK_INTERP_BILINEAR); g_object_unref (pixbuf); pixbuf = scaled; } +#ifdef ENABLE_INDICATOR + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), gtk_image_new_from_pixbuf (pixbuf)); + /* 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 g_object_unref (pixbuf); -} - -const char * -nm_network_menu_item_get_hash (NMNetworkMenuItem *item) -{ - g_return_val_if_fail (NM_IS_NETWORK_MENU_ITEM (item), NULL); - return NM_NETWORK_MENU_ITEM_GET_PRIVATE (item)->hash; +#ifndef ENABLE_INDICATOR + if (priv->is_adhoc && !gtk_image_get_pixbuf (GTK_IMAGE (priv->detail))) { + scaled = NULL; + pixbuf = nma_icon_check_and_load ("nm-adhoc", applet); + if (gdk_pixbuf_get_height (pixbuf) > 24 || gdk_pixbuf_get_width (pixbuf) > 24) + scaled = gdk_pixbuf_scale_simple (pixbuf, 24, 24, GDK_INTERP_BILINEAR); + gtk_image_set_from_pixbuf (GTK_IMAGE (priv->detail), scaled ? scaled : pixbuf); + g_clear_object (&scaled); + } +#endif } void -nm_network_menu_item_set_detail (NMNetworkMenuItem *item, - NMAccessPoint *ap, - GdkPixbuf *adhoc_icon, - guint32 dev_caps) +nm_network_menu_item_set_strength (NMNetworkMenuItem *item, + guint8 strength, + NMApplet *applet) { NMNetworkMenuItemPrivate *priv; - gboolean is_adhoc = FALSE; - guint32 ap_flags, ap_wpa, ap_rsn; g_return_if_fail (NM_IS_NETWORK_MENU_ITEM (item)); priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item); - ap_flags = nm_access_point_get_flags (ap); - ap_wpa = nm_access_point_get_wpa_flags (ap); - ap_rsn = nm_access_point_get_rsn_flags (ap); - - if ((ap_flags & NM_802_11_AP_FLAGS_PRIVACY) || ap_wpa || ap_rsn) - priv->is_encrypted = TRUE; - - if (nm_access_point_get_mode (ap) == NM_802_11_MODE_ADHOC) { - GdkPixbuf *scaled = NULL; - - priv->is_adhoc = is_adhoc = TRUE; - - if (gdk_pixbuf_get_height (adhoc_icon) > 24 || gdk_pixbuf_get_width (adhoc_icon) > 24) - scaled = gdk_pixbuf_scale_simple (adhoc_icon, 24, 24, GDK_INTERP_BILINEAR); - - gtk_image_set_from_pixbuf (GTK_IMAGE (priv->detail), scaled ? scaled : adhoc_icon); + strength = MIN (strength, 100); + if (strength > priv->int_strength) { + priv->int_strength = strength; + update_icon (item, applet); + update_atk_desc (item); + } +} - g_clear_object (&scaled); - } else - gtk_image_set_from_stock (GTK_IMAGE (priv->detail), NULL, GTK_ICON_SIZE_MENU); +const char * +nm_network_menu_item_get_hash (NMNetworkMenuItem *item) +{ + g_return_val_if_fail (NM_IS_NETWORK_MENU_ITEM (item), NULL); - /* Don't enable the menu item the device can't even connect to the AP */ - if ( !nm_utils_security_valid (NMU_SEC_NONE, dev_caps, TRUE, is_adhoc, ap_flags, ap_wpa, ap_rsn) - && !nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, TRUE, is_adhoc, ap_flags, ap_wpa, ap_rsn) - && !nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, TRUE, is_adhoc, ap_flags, ap_wpa, ap_rsn) - && !nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, TRUE, is_adhoc, ap_flags, ap_wpa, ap_rsn) - && !nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, TRUE, is_adhoc, ap_flags, ap_wpa, ap_rsn) - && !nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, TRUE, is_adhoc, ap_flags, ap_wpa, ap_rsn) - && !nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, TRUE, is_adhoc, ap_flags, ap_wpa, ap_rsn) - && !nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, TRUE, is_adhoc, ap_flags, ap_wpa, ap_rsn)) { - gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); - } + return NM_NETWORK_MENU_ITEM_GET_PRIVATE (item)->hash; } gboolean @@ -280,23 +201,31 @@ nm_network_menu_item_find_dupe (NMNetworkMenuItem *item, NMAccessPoint *ap) return FALSE; } -void -nm_network_menu_item_set_active (NMNetworkMenuItem *item, gboolean active) +static void +update_label (NMNetworkMenuItem *item, gboolean use_bold) { - NMNetworkMenuItemPrivate *priv; - char *markup; - - g_return_if_fail (NM_IS_NETWORK_MENU_ITEM (item)); + NMNetworkMenuItemPrivate *priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item); - 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); - gtk_label_set_use_markup (GTK_LABEL (priv->ssid), active); - if (active) { - markup = g_markup_printf_escaped ("<b>%s</b>", priv->ssid_string); gtk_label_set_markup (GTK_LABEL (priv->ssid), markup); g_free (markup); } else gtk_label_set_text (GTK_LABEL (priv->ssid), priv->ssid_string); +#endif +} + +void +nm_network_menu_item_set_active (NMNetworkMenuItem *item, gboolean active) +{ + g_return_if_fail (NM_IS_NETWORK_MENU_ITEM (item)); + + update_label (item, active); } void @@ -337,3 +266,115 @@ nm_network_menu_item_get_is_encrypted (NMNetworkMenuItem *item) return NM_NETWORK_MENU_ITEM_GET_PRIVATE (item)->is_encrypted; } +/******************************************************************/ + +GtkWidget * +nm_network_menu_item_new (NMAccessPoint *ap, + guint32 dev_caps, + const char *hash, + gboolean has_connections, + NMApplet *applet) +{ + NMNetworkMenuItem *item; + NMNetworkMenuItemPrivate *priv; + guint32 ap_flags, ap_wpa, ap_rsn; + const GByteArray *ssid; + + item = g_object_new (NM_TYPE_NETWORK_MENU_ITEM, NULL); + g_assert (item); + + priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (item); + + nm_network_menu_item_add_dupe (item, ap); + + ssid = nm_access_point_get_ssid (ap); + if (ssid) + priv->ssid_string = nm_utils_ssid_to_utf8 (ssid); + if (!priv->ssid_string) + priv->ssid_string = g_strdup ("<unknown>"); + + priv->has_connections = has_connections; + priv->hash = g_strdup (hash); + priv->int_strength = nm_access_point_get_strength (ap); + + if (nm_access_point_get_mode (ap) == NM_802_11_MODE_ADHOC) + priv->is_adhoc = TRUE; + + ap_flags = nm_access_point_get_flags (ap); + ap_wpa = nm_access_point_get_wpa_flags (ap); + ap_rsn = nm_access_point_get_rsn_flags (ap); + if ((ap_flags & NM_802_11_AP_FLAGS_PRIVACY) || ap_wpa || ap_rsn) + priv->is_encrypted = TRUE; + + /* Don't enable the menu item the device can't even connect to the AP */ + if ( !nm_utils_security_valid (NMU_SEC_NONE, dev_caps, TRUE, priv->is_adhoc, ap_flags, ap_wpa, ap_rsn) + && !nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, TRUE, priv->is_adhoc, ap_flags, ap_wpa, ap_rsn) + && !nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, TRUE, priv->is_adhoc, ap_flags, ap_wpa, ap_rsn) + && !nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, TRUE, priv->is_adhoc, ap_flags, ap_wpa, ap_rsn) + && !nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, TRUE, priv->is_adhoc, ap_flags, ap_wpa, ap_rsn) + && !nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, TRUE, priv->is_adhoc, ap_flags, ap_wpa, ap_rsn) + && !nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, TRUE, priv->is_adhoc, ap_flags, ap_wpa, ap_rsn) + && !nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, TRUE, priv->is_adhoc, ap_flags, ap_wpa, ap_rsn)) { + gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); + } + + update_label (item, FALSE); + update_icon (item, applet); + update_atk_desc (item); + + return GTK_WIDGET (item); +} + +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); + priv->ssid = gtk_label_new (NULL); + gtk_misc_set_alignment (GTK_MISC (priv->ssid), 0.0, 0.5); + + priv->detail = gtk_image_new (); + + gtk_container_add (GTK_CONTAINER (item), priv->hbox); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->ssid, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->detail, FALSE, FALSE, 0); + + 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->detail); + gtk_widget_show (priv->hbox); +#else + gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE); +#endif +} + +static void +finalize (GObject *object) +{ + NMNetworkMenuItemPrivate *priv = NM_NETWORK_MENU_ITEM_GET_PRIVATE (object); + + g_free (priv->hash); + g_free (priv->ssid_string); + + g_slist_foreach (priv->dupes, (GFunc) g_free, NULL); + g_slist_free (priv->dupes); + + G_OBJECT_CLASS (nm_network_menu_item_parent_class)->finalize (object); +} + +static void +nm_network_menu_item_class_init (NMNetworkMenuItemClass * klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (NMNetworkMenuItemPrivate)); + + /* virtual methods */ + object_class->finalize = finalize; +} + diff --git a/src/ap-menu-item.h b/src/ap-menu-item.h index a8871d1f..c538c364 100644 --- a/src/ap-menu-item.h +++ b/src/ap-menu-item.h @@ -49,24 +49,22 @@ struct _NMNetworkMenuItemClass { GType nm_network_menu_item_get_type (void) G_GNUC_CONST; -GtkWidget* nm_network_menu_item_new (const char *hash, gboolean has_connections); +GtkWidget* nm_network_menu_item_new (NMAccessPoint *ap, + guint32 dev_caps, + const char *hash, + gboolean has_connections, + NMApplet *applet); -void nm_network_menu_item_set_ssid (NMNetworkMenuItem *item, - GByteArray *ssid); const char *nm_network_menu_item_get_ssid (NMNetworkMenuItem *item); gboolean nm_network_menu_item_get_is_adhoc (NMNetworkMenuItem *item); gboolean nm_network_menu_item_get_is_encrypted (NMNetworkMenuItem *item); guint32 nm_network_menu_item_get_strength (NMNetworkMenuItem *item); -void nm_network_menu_item_best_strength (NMNetworkMenuItem *item, - guint8 strength, - NMApplet *applet); +void nm_network_menu_item_set_strength (NMNetworkMenuItem *item, + guint8 strength, + NMApplet *applet); const char *nm_network_menu_item_get_hash (NMNetworkMenuItem * item); -void nm_network_menu_item_set_detail (NMNetworkMenuItem * item, - NMAccessPoint * ap, - GdkPixbuf * adhoc_icon, - guint32 dev_caps); gboolean nm_network_menu_item_find_dupe (NMNetworkMenuItem *item, NMAccessPoint *ap); diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c index d5a937a0..2bcd42bb 100644 --- a/src/applet-device-wifi.c +++ b/src/applet-device-wifi.c @@ -534,29 +534,20 @@ create_new_ap_item (NMDeviceWifi *device, { WifiMenuItemInfo *info; GSList *iter; - NMNetworkMenuItem *item = NULL; + GtkWidget *item; GSList *dev_connections = NULL; GSList *ap_connections = NULL; - const GByteArray *ssid; - guint32 dev_caps; dev_connections = nm_device_filter_connections (NM_DEVICE (device), connections); ap_connections = nm_access_point_filter_connections (ap, dev_connections); g_slist_free (dev_connections); dev_connections = NULL; - item = NM_NETWORK_MENU_ITEM (nm_network_menu_item_new (dup_data->hash, - !!g_slist_length (ap_connections))); - - 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); - + item = nm_network_menu_item_new (ap, + nm_device_wifi_get_capabilities (device), + dup_data->hash, + !!g_slist_length (ap_connections), + applet); g_object_set_data (G_OBJECT (item), "device", NM_DEVICE (device)); /* If there's only one connection, don't show the submenu */ @@ -610,7 +601,7 @@ create_new_ap_item (NMDeviceWifi *device, } g_slist_free (ap_connections); - return item; + return NM_NETWORK_MENU_ITEM (item); } static NMNetworkMenuItem * @@ -643,7 +634,7 @@ get_menu_item_for_ap (NMDeviceWifi *device, g_slist_foreach (menu_list, find_duplicate, &dup_data); if (dup_data.found) { - nm_network_menu_item_best_strength (dup_data.found, nm_access_point_get_strength (ap), applet); + nm_network_menu_item_set_strength (dup_data.found, nm_access_point_get_strength (ap), applet); nm_network_menu_item_add_dupe (dup_data.found, ap); return NULL; } diff --git a/src/applet.c b/src/applet.c index ee027a5f..a7b4ffc3 100644 --- a/src/applet.c +++ b/src/applet.c @@ -677,6 +677,9 @@ applet_menu_item_add_complex_separator_helper (GtkWidget *menu, NMApplet *applet, const gchar* label) { +#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 *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); GtkWidget *xlabel = NULL; @@ -696,6 +699,7 @@ applet_menu_item_add_complex_separator_helper (GtkWidget *menu, "sensitive", FALSE, NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); +#endif } GtkWidget * @@ -705,10 +709,12 @@ applet_new_menu_item_helper (NMConnection *connection, { NMSettingConnection *s_con = nm_connection_get_setting_connection (connection); GtkWidget *item = gtk_image_menu_item_new_with_label (""); - char *markup; - GtkWidget *label; +#ifndef ENABLE_INDICATOR if (add_active && (active == connection)) { + char *markup; + GtkWidget *label; + /* Pure evil */ label = gtk_bin_get_child (GTK_BIN (item)); gtk_label_set_use_markup (GTK_LABEL (label), TRUE); @@ -716,12 +722,14 @@ applet_new_menu_item_helper (NMConnection *connection, gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); } else +#endif gtk_menu_item_set_label (GTK_MENU_ITEM (item), nm_setting_connection_get_id (s_con)); gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE); return item; } +#ifndef ENABLE_INDICATOR #define TITLE_TEXT_R ((double) 0x5e / 255.0 ) #define TITLE_TEXT_G ((double) 0x5e / 255.0 ) #define TITLE_TEXT_B ((double) 0x5e / 255.0 ) @@ -785,6 +793,7 @@ menu_title_item_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data) menu_item_draw_generic (widget, cr); return TRUE; } +#endif /* ENABLE_INDICATOR */ GtkWidget * applet_menu_item_create_device_item_helper (NMDevice *device, @@ -795,7 +804,9 @@ applet_menu_item_create_device_item_helper (NMDevice *device, item = gtk_menu_item_new_with_label (text); gtk_widget_set_sensitive (item, FALSE); +#ifndef ENABLE_INDICATOR g_signal_connect (item, "draw", G_CALLBACK (menu_title_item_draw), NULL); +#endif return item; } @@ -853,8 +864,13 @@ applet_do_notify (NMApplet *applet, g_return_if_fail (summary != NULL); g_return_if_fail (message != NULL); +#ifdef ENABLE_INDICATOR + if (app_indicator_get_status (applet->app_indicator) == APP_INDICATOR_STATUS_PASSIVE) + return; +#else if (!gtk_status_icon_is_embedded (applet->status_icon)) return; +#endif /* if we're not acting as a secret agent, don't notify either */ if (!applet->agent) @@ -1194,6 +1210,10 @@ activate_vpn_cb (NMClient *client, g_free (info); } +#ifdef ENABLE_INDICATOR +static void nma_menu_disconnect_vpn_item_activate (GtkMenuItem *item, gpointer user_data); +#endif + static void nma_menu_vpn_item_clicked (GtkMenuItem *item, gpointer user_data) { @@ -1217,6 +1237,9 @@ nma_menu_vpn_item_clicked (GtkMenuItem *item, gpointer user_data) } if (applet_get_active_for_connection (applet, connection)) { +#ifdef ENABLE_INDICATOR + nma_menu_disconnect_vpn_item_activate (item, applet); +#endif /* Connection already active; do nothing */ return; } @@ -1766,6 +1789,7 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet) item = GTK_MENU_ITEM (gtk_menu_item_new_with_mnemonic (_("_VPN Connections"))); gtk_menu_item_set_submenu (item, GTK_WIDGET (vpn_menu)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item)); + gtk_widget_show (GTK_WIDGET (item)); list = get_vpn_connections (applet); for (iter = list; iter; iter = g_slist_next (iter)) { @@ -1783,8 +1807,7 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet) name = get_connection_id (connection); - item = GTK_MENU_ITEM (gtk_image_menu_item_new_with_label (name)); - gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(item), TRUE); + item = GTK_MENU_ITEM (gtk_check_menu_item_new_with_label (name)); /* If no VPN connections are active, draw all menu items enabled. If * >= 1 VPN connections are active, only the active VPN menu item is @@ -1802,11 +1825,7 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet) else gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); - if (active) { - 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); - } + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), !!active); g_object_set_data_full (G_OBJECT (item), "connection", g_object_ref (connection), @@ -1814,6 +1833,7 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet) g_signal_connect (item, "activate", G_CALLBACK (nma_menu_vpn_item_clicked), applet); gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item)); + gtk_widget_show (GTK_WIDGET (item)); } /* Draw a seperator, but only if we have VPN connections above it */ @@ -1823,12 +1843,14 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet) item = GTK_MENU_ITEM (gtk_menu_item_new_with_mnemonic (_("_Configure VPN..."))); g_signal_connect (item, "activate", G_CALLBACK (nma_menu_configure_vpn_item_activate), applet); gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item)); + gtk_widget_show (GTK_WIDGET (item)); item = GTK_MENU_ITEM (gtk_menu_item_new_with_mnemonic (_("_Disconnect VPN"))); g_signal_connect (item, "activate", G_CALLBACK (nma_menu_disconnect_vpn_item_activate), applet); gtk_menu_shell_append (GTK_MENU_SHELL (vpn_menu), GTK_WIDGET (item)); if (num_vpn_active == 0) gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); + gtk_widget_show (GTK_WIDGET (item)); g_slist_free (list); } @@ -1879,6 +1901,7 @@ nma_set_networking_enabled_cb (GtkWidget *widget, NMApplet *applet) } +#ifndef ENABLE_INDICATOR static void nma_set_notifications_enabled_cb (GtkWidget *widget, NMApplet *applet) { @@ -1901,6 +1924,7 @@ nma_set_notifications_enabled_cb (GtkWidget *widget, NMApplet *applet) PREF_SUPPRESS_WIFI_NETWORKS_AVAILABLE, !state); } +#endif /* ENABLE_INDICATOR */ static gboolean has_usable_wifi (NMApplet *applet) @@ -1937,7 +1961,9 @@ static void nma_menu_show_cb (GtkWidget *menu, NMApplet *applet) g_return_if_fail (menu != NULL); g_return_if_fail (applet != NULL); +#ifndef ENABLE_INDICATOR gtk_status_icon_set_tooltip_text (applet->status_icon, NULL); +#endif if (!nm_client_get_manager_running (applet->nm_client)) { nma_menu_add_text_item (menu, _("NetworkManager is not running...")); @@ -1959,11 +1985,14 @@ static void nma_menu_show_cb (GtkWidget *menu, NMApplet *applet) nma_menu_add_create_network_item (menu, applet); } +#ifndef ENABLE_INDICATOR gtk_widget_show_all (menu); +#endif // nmi_dbus_signal_user_interface_activated (applet->connection); } +#ifndef ENABLE_INDICATOR static gboolean destroy_old_menu (gpointer user_data) { @@ -1985,6 +2014,7 @@ nma_menu_deactivate_cb (GtkWidget *widget, NMApplet *applet) /* Re-set the tooltip */ gtk_status_icon_set_tooltip_text (applet->status_icon, applet->tip); } +#endif static gboolean is_permission_yes (NMApplet *applet, NMClientPermission perm) @@ -2010,7 +2040,9 @@ nma_context_menu_update (NMApplet *applet) gboolean wifi_hw_enabled; gboolean wwan_hw_enabled; gboolean wimax_hw_enabled; +#ifndef ENABLE_INDICATOR gboolean notifications_enabled = TRUE; +#endif gboolean sensitive = FALSE; state = nm_client_get_state (applet->nm_client); @@ -2070,6 +2102,7 @@ nma_context_menu_update (NMApplet *applet) gtk_widget_set_sensitive (GTK_WIDGET (applet->wimax_enabled_item), wimax_hw_enabled && is_permission_yes (applet, NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX)); +#ifndef ENABLE_INDICATOR /* Enabled notifications */ g_signal_handler_block (G_OBJECT (applet->notifications_enabled_item), applet->notifications_enabled_toggled_id); @@ -2081,6 +2114,7 @@ nma_context_menu_update (NMApplet *applet) gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (applet->notifications_enabled_item), notifications_enabled); g_signal_handler_unblock (G_OBJECT (applet->notifications_enabled_item), applet->notifications_enabled_toggled_id); +#endif /* Don't show wifi-specific stuff if wifi is off */ if (state != NM_STATE_ASLEEP) { @@ -2156,7 +2190,9 @@ 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; @@ -2202,6 +2238,7 @@ static GtkWidget *nma_context_menu_create (NMApplet *applet) nma_menu_add_separator_item (GTK_WIDGET (menu)); +#ifndef ENABLE_INDICATOR /* Toggle notifications item */ applet->notifications_enabled_item = gtk_check_menu_item_new_with_mnemonic (_("Enable N_otifications")); id = g_signal_connect (applet->notifications_enabled_item, @@ -2212,6 +2249,7 @@ static GtkWidget *nma_context_menu_create (NMApplet *applet) gtk_menu_shell_append (menu, applet->notifications_enabled_item); nma_menu_add_separator_item (GTK_WIDGET (menu)); +#endif /* 'Connection Information' item */ applet->info_menu_item = gtk_image_menu_item_new_with_mnemonic (_("Connection _Information")); @@ -2236,6 +2274,7 @@ static GtkWidget *nma_context_menu_create (NMApplet *applet) /* 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")); @@ -2252,6 +2291,7 @@ static GtkWidget *nma_context_menu_create (NMApplet *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); +#endif gtk_widget_show_all (GTK_WIDGET (menu)); @@ -2354,9 +2394,31 @@ applet_add_default_connection_item (NMDevice *device, gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); } +#ifdef ENABLE_INDICATOR +static gboolean +applet_update_indicator_menu (gpointer user_data) +{ + NMApplet *applet = NM_APPLET (user_data); + GtkWidget *menu = nma_context_menu_create (applet); + + nma_menu_show_cb (menu, applet); + nma_menu_add_separator_item (menu); + nma_context_menu_update (applet); + + app_indicator_set_menu (applet->app_indicator, GTK_MENU (menu)); + + applet->update_menu_id = 0; + return FALSE; +} +#endif /* ENABLE_INDICATOR */ + void applet_schedule_update_menu (NMApplet *applet) { +#ifdef ENABLE_INDICATOR + if (!applet->update_menu_id) + applet->update_menu_id = g_idle_add (applet_update_indicator_menu, applet); +#endif } /*****************************************************************************/ @@ -2366,6 +2428,16 @@ foo_set_icon (NMApplet *applet, guint32 layer, GdkPixbuf *pixbuf, char *icon_nam { g_return_if_fail (layer == ICON_LAYER_LINK || layer == ICON_LAYER_VPN); +#ifdef ENABLE_INDICATOR + /* FIXME: We rely on the fact that VPN icon gets drawn later and therefore + * wins but we cannot currently set a combined pixmap made of both the link + * icon and the VPN icon. + */ + if (icon_name == NULL && layer == ICON_LAYER_LINK) + icon_name = g_strdup ("nm-no-connection"); + if (icon_name != NULL && g_strcmp0 (app_indicator_get_icon (applet->app_indicator), icon_name) != 0) + app_indicator_set_icon_full (applet->app_indicator, icon_name, applet->tip); +#else /* Load the pixbuf by icon name */ if (icon_name && !pixbuf) pixbuf = nma_icon_check_and_load (icon_name, applet); @@ -2403,6 +2475,7 @@ foo_set_icon (NMApplet *applet, guint32 layer, GdkPixbuf *pixbuf, char *icon_nam gtk_status_icon_set_from_pixbuf (applet->status_icon, pixbuf); g_object_unref (pixbuf); +#endif } NMRemoteConnection * @@ -2557,6 +2630,17 @@ foo_client_state_changed_cb (NMClient *client, GParamSpec *pspec, gpointer user_ applet_schedule_update_menu (applet); } +#ifdef ENABLE_INDICATOR +static void +foo_device_removed_cb (NMClient *client, NMDevice *device, gpointer user_data) +{ + NMApplet *applet = NM_APPLET (user_data); + + applet_schedule_update_icon (applet); + applet_schedule_update_menu (applet); +} +#endif + static void foo_manager_running_cb (NMClient *client, GParamSpec *pspec, @@ -2653,6 +2737,11 @@ foo_client_setup (NMApplet *applet) g_signal_connect (applet->nm_client, "device-added", G_CALLBACK (foo_device_added_cb), applet); +#ifdef ENABLE_INDICATOR + g_signal_connect (applet->nm_client, "device-removed", + G_CALLBACK (foo_device_removed_cb), + applet); +#endif g_signal_connect (applet->nm_client, "notify::manager-running", G_CALLBACK (foo_manager_running_cb), applet); @@ -2925,7 +3014,11 @@ applet_update_icon (gpointer user_data) if (!nm_running) state = NM_STATE_UNKNOWN; +#ifdef ENABLE_INDICATOR + app_indicator_set_status (applet->app_indicator, nm_running ? APP_INDICATOR_STATUS_ACTIVE : APP_INDICATOR_STATUS_PASSIVE); +#else gtk_status_icon_set_visible (applet->status_icon, applet->visible); +#endif switch (state) { case NM_STATE_UNKNOWN: @@ -2986,7 +3079,13 @@ applet_update_icon (gpointer user_data) /* update tooltip */ g_free (applet->tip); applet->tip = g_strdup (vpn_tip ? vpn_tip : dev_tip); +#ifdef ENABLE_INDICATOR + /* FIXME: The applet->tip attribute seems to only be picked up by + * the next call to foo_set_icon() which is not particularly nice. + */ +#else gtk_status_icon_set_tooltip_text (applet->status_icon, applet->tip); +#endif g_free (vpn_tip); g_free (dev_tip); @@ -3332,7 +3431,6 @@ error: static void nma_icons_init (NMApplet *applet) { - GdkScreen *screen; gboolean path_appended; if (applet->icon_theme) { @@ -3342,9 +3440,11 @@ static void nma_icons_init (NMApplet *applet) g_object_unref (G_OBJECT (applet->icon_theme)); } - screen = gtk_status_icon_get_screen (applet->status_icon); - g_assert (screen); - applet->icon_theme = gtk_icon_theme_get_for_screen (screen); +#ifdef ENABLE_INDICATOR + applet->icon_theme = gtk_icon_theme_get_default (); +#else + applet->icon_theme = gtk_icon_theme_get_for_screen (gtk_status_icon_get_screen (applet->status_icon)); +#endif /* If not done yet, append our search path */ path_appended = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (applet->icon_theme), @@ -3359,6 +3459,7 @@ static void nma_icons_init (NMApplet *applet) g_signal_connect (applet->icon_theme, "changed", G_CALLBACK (nma_icons_reload), applet); } +#ifndef ENABLE_INDICATOR static void status_icon_screen_changed_cb (GtkStatusIcon *icon, GParamSpec *pspec, @@ -3430,11 +3531,18 @@ status_icon_popup_menu_cb (GtkStatusIcon *icon, gtk_status_icon_position_menu, icon, button, activate_time); } +#endif /* ENABLE_INDICATOR */ static gboolean setup_widgets (NMApplet *applet) { - +#ifdef ENABLE_INDICATOR + applet->app_indicator = app_indicator_new + ("nm-applet", "nm-no-connection", + APP_INDICATOR_CATEGORY_SYSTEM_SERVICES); + app_indicator_set_title(applet->app_indicator, _("Network")); + applet_schedule_update_menu (applet); +#else applet->status_icon = gtk_status_icon_new (); if (shell_debug) @@ -3452,10 +3560,20 @@ setup_widgets (NMApplet *applet) applet->context_menu = nma_context_menu_create (applet); if (!applet->context_menu) return FALSE; +#endif return TRUE; } +#ifdef ENABLE_INDICATOR +static void +new_connection_cb (NMRemoteSettings *settings, NMRemoteConnection *connection, gpointer user_data) +{ + NMApplet *applet = NM_APPLET (user_data); + + applet_schedule_update_menu (applet); +} +#else static void applet_embedded_cb (GObject *object, GParamSpec *pspec, gpointer user_data) { @@ -3464,6 +3582,7 @@ applet_embedded_cb (GObject *object, GParamSpec *pspec, gpointer user_data) g_debug ("applet now %s the notification area", embedded ? "embedded in" : "removed from"); } +#endif static void register_agent (NMApplet *applet) @@ -3476,6 +3595,12 @@ register_agent (NMApplet *applet) G_CALLBACK (applet_agent_get_secrets_cb), applet); g_signal_connect (applet->agent, APPLET_AGENT_CANCEL_SECRETS, G_CALLBACK (applet_agent_cancel_secrets_cb), applet); +#ifdef ENABLE_INDICATOR + /* Watch for new connections */ + g_signal_connect (applet->settings, "new-connection", + G_CALLBACK (new_connection_cb), + applet); +#endif } static gboolean @@ -3520,7 +3645,9 @@ applet_gsettings_show_changed (GSettings *settings, applet->visible = g_settings_get_boolean (settings, key); +#ifndef ENABLE_INDICATOR gtk_status_icon_set_visible (applet->status_icon, applet->visible); +#endif } static gboolean @@ -3621,12 +3748,14 @@ initable_init (GInitable *initable, GCancellable *cancellable, GError **error) mm1_client_setup (applet); #endif +#ifndef ENABLE_INDICATOR /* Track embedding to help debug issues where user has removed the * notification area applet from the panel, and thus nm-applet too. */ g_signal_connect (applet->status_icon, "notify::embedded", G_CALLBACK (applet_embedded_cb), NULL); applet_embedded_cb (G_OBJECT (applet->status_icon), NULL, NULL); +#endif if (with_agent) register_agent (applet); @@ -3654,12 +3783,18 @@ static void finalize (GObject *object) if (applet->update_icon_id) g_source_remove (applet->update_icon_id); +#ifdef ENABLE_INDICATOR + g_clear_object (&applet->app_indicator); + if (applet->update_menu_id) + g_source_remove (applet->update_menu_id); +#else g_clear_object (&applet->status_icon); g_clear_object (&applet->menu); g_clear_pointer (&applet->icon_cache, g_hash_table_destroy); g_clear_object (&applet->fallback_icon); g_free (applet->tip); nma_icons_free (applet); +#endif 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 cf729afa..b8228142 100644 --- a/src/applet.h +++ b/src/applet.h @@ -36,6 +36,10 @@ #include <libnotify/notify.h> +#ifdef ENABLE_INDICATOR +#include <libappindicator/app-indicator.h> +#endif + #include <nm-connection.h> #include <nm-client.h> #include <nm-access-point.h> @@ -129,19 +133,24 @@ typedef struct GtkIconTheme * icon_theme; GHashTable * icon_cache; GdkPixbuf * fallback_icon; + int icon_size; /* Active status icon pixbufs */ GdkPixbuf * icon_layers[ICON_LAYER_MAX + 1]; /* Direct UI elements */ +#ifdef ENABLE_INDICATOR + AppIndicator * app_indicator; + guint update_menu_id; +#else GtkStatusIcon * status_icon; - int icon_size; GtkWidget * menu; GtkWidget * context_menu; GtkWidget * notifications_enabled_item; guint notifications_enabled_toggled_id; +#endif GtkWidget * networking_enabled_item; guint networking_enabled_toggled_id; diff --git a/src/mb-menu-item.c b/src/mb-menu-item.c index 4f204f17..216f7b6f 100644 --- a/src/mb-menu-item.c +++ b/src/mb-menu-item.c @@ -36,12 +36,15 @@ G_DEFINE_TYPE (NMMbMenuItem, nm_mb_menu_item, GTK_TYPE_IMAGE_MENU_ITEM); #define NM_MB_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MB_MENU_ITEM, NMMbMenuItemPrivate)) typedef struct { - GtkWidget *desc; - char *desc_string; +#ifndef ENABLE_INDICATOR GtkWidget *strength; - guint32 int_strength; GtkWidget *detail; GtkWidget *hbox; + GtkWidget *desc; +#endif + + char *desc_string; + guint32 int_strength; } NMMbMenuItemPrivate; static const char * @@ -78,6 +81,25 @@ get_tech_name (guint32 tech) return NULL; } +static void +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); + + gtk_label_set_markup (GTK_LABEL (priv->desc), markup); + g_free (markup); + } else + gtk_label_set_text (GTK_LABEL (priv->desc), priv->desc_string); +#endif +} + GtkWidget * nm_mb_menu_item_new (const char *connection_name, guint32 strength, @@ -93,8 +115,7 @@ nm_mb_menu_item_new (const char *connection_name, const char *tech_name = NULL; item = g_object_new (NM_TYPE_MB_MENU_ITEM, NULL); - if (!item) - return NULL; + g_assert (item); priv = NM_MB_MENU_ITEM_GET_PRIVATE (item); priv->int_strength = strength; @@ -168,24 +189,20 @@ nm_mb_menu_item_new (const char *connection_name, break; } - if (enabled && connection_name && active) { - char *markup; - - gtk_label_set_use_markup (GTK_LABEL (priv->desc), TRUE); - markup = g_markup_printf_escaped ("<b>%s</b>", priv->desc_string); - gtk_label_set_markup (GTK_LABEL (priv->desc), markup); - g_free (markup); - } else { - /* Disconnected and disabled states */ - gtk_label_set_use_markup (GTK_LABEL (priv->desc), FALSE); - gtk_label_set_text (GTK_LABEL (priv->desc), priv->desc_string); - } + update_label (item, (enabled && connection_name && active)); /* And the strength icon, if we have strength information at all */ if (enabled && strength) { - GdkPixbuf *pixbuf = nma_icon_check_and_load (mobile_helper_get_quality_icon_name (strength), applet); - + const char *icon_name = mobile_helper_get_quality_icon_name (strength); + GdkPixbuf *pixbuf = nma_icon_check_and_load (icon_name, applet); + +#ifdef ENABLE_INDICATOR + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), gtk_image_new_from_pixbuf (pixbuf)); + /* 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); @@ -196,6 +213,7 @@ 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); @@ -211,6 +229,9 @@ 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 |