Ubuntu's network-manager-applet indicator patch
- From: Mathieu Trudel-Lapierre <mathieu tl gmail com>
- To: ML NetworkManager <networkmanager-list gnome org>
- Subject: Ubuntu's network-manager-applet indicator patch
- Date: Wed, 16 Feb 2011 12:27:42 -0500
Hi,
I started some work a few weeks ago to support showing nm-applet as an
application indicator in Ubuntu.
Here's the current patch as it is in use. I know there's probably
quite a few issues with it, hence why I'm submitting it here for
review, comments, flames, and potential inclusion ;)
Regards,
Mathieu Trudel-Lapierre <mathieu tl gmail com>
Freenode: cyphermox, Jabber: mathieu tl gmail com
4096R/EE018C93 1967 8F7D 03A1 8F38 732E FF82 C126 33E1 EE01 8C93
----
From: Mathieu Trudel-Lapierre <mathieu trudel-lapierre canonical com>
Subject: Implement conditional support for libappindicator
To get better integration with Unity (and actually have nm-applet show up at
all with Unity / compiz), implement drawing the applet using libappindicator.
To play well with others, this patch actually implements libappindicator
conditionally to running configure with --enable-indicator.
=== modified file 'configure.ac'
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/configure.ac
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/configure.ac 2011-02-10
10:09:52.000000000 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/configure.ac 2011-02-11
13:10:51.979541421 -0500
@@ -114,6 +114,14 @@
;;
esac
+AC_ARG_ENABLE([indicator],
+[ --enable-appindicator Enables using libappindicator to draw the applet
+ on the screen, instead of the standard
status icons.],
+[
+ PKG_CHECK_MODULES(APPINDICATOR, appindicator-0.1)
+ AC_DEFINE([ENABLE_INDICATOR], 1, [Enable using libappindicator])
+])
+
AM_CONDITIONAL(HAVE_GBT, test x"$have_gbt" = "xyes")
# Check for libnotify >= 0.7
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/Makefile.am
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/Makefile.am 2011-02-10
10:09:52.000000000 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/Makefile.am 2011-02-11
13:10:51.979541421 -0500
@@ -5,6 +5,7 @@
nm_applet_CPPFLAGS = \
$(NMA_CFLAGS) \
$(NOTIFY_CFLAGS) \
+ $(APPINDICATOR_CFLAGS) \
-DICONDIR=\""$(datadir)/icons"\" \
-DUIDIR=\""$(uidir)"\" \
-DBINDIR=\""$(bindir)"\" \
@@ -56,6 +57,7 @@
-lm \
$(NMA_LIBS) \
$(NOTIFY_LIBS) \
+ $(APPINDICATOR_LIBS) \
${top_builddir}/src/marshallers/libmarshallers.la \
${top_builddir}/src/utils/libutils.la \
${top_builddir}/src/gconf-helpers/libgconf-helpers.la \
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet-device-bt.c
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/applet-device-bt.c 2011-02-10
10:09:52.000000000 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet-device-bt.c 2011-02-11
13:10:51.979541421 -0500
@@ -154,7 +154,9 @@
item = applet_menu_item_create_device_item_helper (device, applet, text);
+#ifndef ENABLE_INDICATOR
gtk_widget_set_sensitive (item, FALSE);
+#endif
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
@@ -209,7 +211,11 @@
}
}
+#ifndef ENABLE_INDICATOR
static GdkPixbuf *
+#else
+static gboolean
+#endif
bt_get_icon (NMDevice *device,
NMDeviceState state,
NMConnection *connection,
@@ -217,7 +223,11 @@
NMApplet *applet)
{
NMSettingConnection *s_con;
+#ifndef ENABLE_INDICATOR
GdkPixbuf *pixbuf = NULL;
+#else
+ gboolean icon_is_set = FALSE;
+#endif
const char *id;
id = nm_device_get_iface (NM_DEVICE (device));
@@ -240,14 +250,23 @@
*tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
break;
case NM_DEVICE_STATE_ACTIVATED:
+#ifndef ENABLE_INDICATOR
pixbuf = nma_icon_check_and_load ("nm-device-wwan",
&applet->wwan_icon, applet);
+#else
+ app_indicator_set_icon (applet->status_icon, "nm-device-wwan");
+ icon_is_set = TRUE;
+#endif
*tip = g_strdup_printf (_("Mobile broadband connection '%s' active"), id);
break;
default:
break;
}
+#ifndef ENABLE_INDICATOR
return pixbuf;
+#else
+ return icon_is_set;
+#endif
}
typedef struct {
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet-device-cdma.c
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/applet-device-cdma.c 2011-02-10
10:09:52.000000000 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet-device-cdma.c 2011-02-11
13:10:51.989541444 -0500
@@ -263,6 +263,9 @@
char *text;
GtkWidget *item;
GSList *connections, *all, *iter;
+#ifdef ENABLE_INDICATOR
+ GtkWidget *signal_icon;
+#endif
info = g_object_get_data (G_OBJECT (device), "devinfo");
@@ -284,7 +287,9 @@
}
item = applet_menu_item_create_device_item_helper (device, applet, text);
+#ifndef ENABLE_INDICATOR
gtk_widget_set_sensitive (item, FALSE);
+#endif
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
g_free (text);
@@ -296,6 +301,7 @@
s_con = (NMSettingConnection *) nm_connection_get_setting (active,
NM_TYPE_SETTING_CONNECTION);
g_assert (s_con);
+#ifndef ENABLE_INDICATOR
item = nm_mb_menu_item_new (nm_setting_connection_get_id (s_con),
info->quality_valid ? info->quality : 0,
info->provider_name,
@@ -303,6 +309,19 @@
cdma_state_to_mb_state (info),
info->modem_enabled,
applet);
+#else
+ text = mobile_helper_get_connection_label
(nm_setting_connection_get_id (s_con),
+
info->provider_name,
+
cdma_act_to_mb_act (info),
+
cdma_state_to_mb_state (info));
+ item = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+ text = mobile_helper_get_quality_icon (info->quality, applet);
+ signal_icon = gtk_image_new_from_icon_name (text,
GTK_ICON_SIZE_LARGE_TOOLBAR);
+ g_free (text);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM
(item), signal_icon);
+ gtk_image_menu_item_set_always_show_image
(GTK_IMAGE_MENU_ITEM (item), TRUE);
+#endif
add_connection_item (device, active, item, menu, applet);
}
@@ -316,6 +335,7 @@
}
} else {
/* Otherwise show idle registration state or disabled */
+#ifndef ENABLE_INDICATOR
item = nm_mb_menu_item_new (NULL,
info->quality_valid ? info->quality : 0,
info->provider_name,
@@ -323,6 +343,20 @@
cdma_state_to_mb_state (info),
info->modem_enabled,
applet);
+#else
+ text = mobile_helper_get_connection_label (NULL,
+
info->provider_name,
+
cdma_act_to_mb_act (info),
+
cdma_state_to_mb_state (info));
+ item = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+ text = mobile_helper_get_quality_icon (info->quality, applet);
+ signal_icon = gtk_image_new_from_icon_name (text,
GTK_ICON_SIZE_LARGE_TOOLBAR);
+ g_free (text);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM
(item), signal_icon);
+ gtk_image_menu_item_set_always_show_image
(GTK_IMAGE_MENU_ITEM (item), TRUE);
+ gtk_widget_set_sensitive (item, FALSE);
+#endif
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
@@ -387,7 +421,11 @@
check_start_polling (info);
}
+#ifndef ENABLE_INDICATOR
static GdkPixbuf *
+#else
+static gboolean
+#endif
cdma_get_icon (NMDevice *device,
NMDeviceState state,
NMConnection *connection,
@@ -395,7 +433,11 @@
NMApplet *applet)
{
NMSettingConnection *s_con;
+#ifndef ENABLE_INDICATOR
GdkPixbuf *pixbuf = NULL;
+#else
+ gboolean icon_is_set = FALSE;
+#endif
const char *id;
CdmaDeviceInfo *info;
gboolean mb_state;
@@ -424,11 +466,17 @@
break;
case NM_DEVICE_STATE_ACTIVATED:
mb_state = cdma_state_to_mb_state (info);
+#ifndef ENABLE_INDICATOR
pixbuf = mobile_helper_get_status_pixbuf (info->quality,
info->quality_valid,
mb_state,
cdma_act_to_mb_act (info),
applet);
+#else
+ /* FIXME: handle different signal levels with indicator icons. */
+ app_indicator_set_icon (applet->status_icon, "nm-device-wwan");
+ icon_is_set = TRUE;
+#endif
if ((mb_state != MB_STATE_UNKNOWN) && info->quality_valid) {
gboolean roaming = (mb_state == MB_STATE_ROAMING);
@@ -444,7 +492,11 @@
break;
}
+#ifndef ENABLE_INDICATOR
return pixbuf;
+#else
+ return icon_is_set;
+#endif
}
typedef struct {
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet-device-gsm.c
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/applet-device-gsm.c 2011-02-11
13:10:51.689540744 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet-device-gsm.c 2011-02-11
13:10:51.989541444 -0500
@@ -41,6 +41,7 @@
#include "applet-device-gsm.h"
#include "utils.h"
#include "mobile-wizard.h"
+#include "mobile-helpers.h"
#include "applet-dialogs.h"
#include "mb-menu-item.h"
#include "nma-marshal.h"
@@ -307,6 +308,9 @@
char *text;
GtkWidget *item;
GSList *connections, *all, *iter;
+#ifdef ENABLE_INDICATOR
+ GtkWidget *signal_icon;
+#endif
info = g_object_get_data (G_OBJECT (device), "devinfo");
@@ -328,7 +332,9 @@
}
item = applet_menu_item_create_device_item_helper (device, applet, text);
+#ifndef ENABLE_INDICATOR
gtk_widget_set_sensitive (item, FALSE);
+#endif
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
g_free (text);
@@ -340,6 +346,7 @@
s_con = (NMSettingConnection *) nm_connection_get_setting (active,
NM_TYPE_SETTING_CONNECTION);
g_assert (s_con);
+#ifndef ENABLE_INDICATOR
item = nm_mb_menu_item_new (nm_setting_connection_get_id (s_con),
info->quality_valid ? info->quality : 0,
info->op_name,
@@ -347,6 +354,19 @@
gsm_state_to_mb_state (info),
info->modem_enabled,
applet);
+#else
+ text = mobile_helper_get_connection_label
(nm_setting_connection_get_id (s_con),
+ info->op_name,
+ gsm_act_to_mb_act (info),
+ gsm_state_to_mb_state (info));
+ item = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+ text = mobile_helper_get_quality_icon (info->quality, applet);
+ signal_icon = gtk_image_new_from_icon_name (text,
GTK_ICON_SIZE_LARGE_TOOLBAR);
+ g_free (text);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), signal_icon);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
+#endif
add_connection_item (device, active, item, menu, applet);
}
@@ -359,6 +379,7 @@
gtk_widget_show (item);
}
} else {
+#ifndef ENABLE_INDICATOR
item = nm_mb_menu_item_new (NULL,
info->quality_valid ? info->quality : 0,
info->op_name,
@@ -366,6 +387,21 @@
gsm_state_to_mb_state (info),
info->modem_enabled,
applet);
+#else
+ text = mobile_helper_get_connection_label (NULL,
+ info->op_name,
+ gsm_act_to_mb_act (info),
+ gsm_state_to_mb_state (info));
+ item = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+ text = mobile_helper_get_quality_icon (info->quality, applet);
+ signal_icon = gtk_image_new_from_icon_name (text,
GTK_ICON_SIZE_LARGE_TOOLBAR);
+ g_free (text);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), signal_icon);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
+ gtk_widget_set_sensitive (item, FALSE);
+#endif
+
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
@@ -425,7 +461,11 @@
check_start_polling (info);
}
+#ifndef ENABLE_INDICATOR
static GdkPixbuf *
+#else
+static gboolean
+#endif
gsm_get_icon (NMDevice *device,
NMDeviceState state,
NMConnection *connection,
@@ -433,7 +473,11 @@
NMApplet *applet)
{
NMSettingConnection *s_con;
+#ifndef ENABLE_INDICATOR
GdkPixbuf *pixbuf = NULL;
+#else
+ gboolean icon_is_set = FALSE;
+#endif
const char *id;
GsmDeviceInfo *info;
guint32 mb_state;
@@ -462,11 +506,17 @@
break;
case NM_DEVICE_STATE_ACTIVATED:
mb_state = gsm_state_to_mb_state (info);
+#ifndef ENABLE_INDICATOR
pixbuf = mobile_helper_get_status_pixbuf (info->quality,
info->quality_valid,
mb_state,
gsm_act_to_mb_act (info),
applet);
+#else
+ /* FIXME: handle different signal levels for indicator icon */
+ app_indicator_set_icon (applet->status_icon, "nm-device-wwan");
+ icon_is_set = TRUE;
+#endif
if ((mb_state != MB_STATE_UNKNOWN) && info->quality_valid) {
gboolean roaming = (mb_state == MB_STATE_ROAMING);
@@ -482,7 +532,11 @@
break;
}
+#ifndef ENABLE_INDICATOR
return pixbuf;
+#else
+ return icon_is_set;
+#endif
}
typedef struct {
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet-device-wifi.c
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/applet-device-wifi.c 2011-02-11
13:10:51.819541047 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet-device-wifi.c 2011-02-11
13:10:51.989541444 -0500
@@ -323,6 +323,51 @@
return NULL;
}
+#ifdef ENABLE_INDICATOR
+static char *
+get_best_icon_name_for_ap (NMAccessPoint *ap, gboolean need_sec,
gboolean encrypted)
+{
+ char *icon_name = NULL;
+ guint32 strength;
+
+ g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
+
+ strength = nm_access_point_get_strength (ap);
+ strength = CLAMP (strength, 0, 100);
+
+ if (strength > 80)
+ icon_name = g_strdup_printf ("nm-signal-100");
+ else if (strength > 55)
+ icon_name = g_strdup_printf ("nm-signal-75");
+ else if (strength > 30)
+ icon_name = g_strdup_printf ("nm-signal-50");
+ else if (strength > 5)
+ icon_name = g_strdup_printf ("nm-signal-25");
+ else
+ icon_name = g_strdup_printf ("nm-signal-00");
+
+ if (nm_access_point_get_mode (ap) == NM_802_11_MODE_ADHOC) {
+ icon_name = g_strdup_printf ("nm-adhoc");
+ return icon_name;
+ }
+
+ if (need_sec && encrypted)
+ icon_name = g_strdup_printf ("%s-secure", icon_name);
+
+ return icon_name;
+}
+
+static char *
+escape_mnemonics (const char *ssid)
+{
+ gchar **split_ssid = g_strsplit (ssid, "_", 0);
+ gchar *clean_ssid = g_strjoinv ("__", split_ssid);
+ g_strfreev (split_ssid);
+
+ return clean_ssid;
+}
+#endif
+
static void
check_common_ssid (NMAccessPoint *ap, NMSettingWireless *s_wifi)
{
@@ -560,6 +605,10 @@
info->ap = g_object_ref (G_OBJECT (ap));
info->connection = g_object_ref (G_OBJECT (connection));
+#ifdef ENABLE_INDICATOR
+ g_object_set_data_full (G_OBJECT (subitem), "connection", G_OBJECT
(connection), (GDestroyNotify) g_free);
+#endif
+
g_signal_connect_data (subitem, "activate",
G_CALLBACK (wireless_menu_item_activate),
info,
@@ -580,6 +629,9 @@
if (g_slist_length (ap_connections) == 1) {
connection = NM_CONNECTION (g_slist_nth_data (ap_connections, 0));
info->connection = g_object_ref (G_OBJECT (connection));
+#ifdef ENABLE_INDICATOR
+ g_object_set_data_full (G_OBJECT (item), "connection", G_OBJECT
(connection), (GDestroyNotify) g_free);
+#endif
}
g_signal_connect_data (GTK_WIDGET (item),
@@ -616,13 +668,21 @@
*/
dup_data.found = NULL;
dup_data.hash = g_object_get_data (G_OBJECT (ap), "hash");
+#ifndef ENABLE_INDICATOR
g_return_val_if_fail (dup_data.hash != NULL, NULL);
+#else
+ /* heh, not much choice here, otherwise on startup we get tons of errors
+ * because g_return_val_if_fail prints assertion errors.
+ */
+ if (dup_data.hash == NULL)
+ return NULL;
+#endif
dup_data.device = NM_DEVICE (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_best_strength (dup_data.found,
nm_access_point_get_strength (ap), applet);
nm_network_menu_item_add_dupe (dup_data.found, ap);
return NULL;
}
@@ -733,6 +793,11 @@
gboolean wireless_hw_enabled = TRUE;
GSList *menu_items = NULL; /* All menu items we'll be adding */
NMNetworkMenuItem *item, *active_item = NULL;
+#if ENABLE_INDICATOR
+ GtkWidget *imi, *icon_image;
+ WirelessMenuItemInfo *info;
+ gboolean is_encrypted;
+#endif
GtkWidget *widget;
wdev = NM_DEVICE_WIFI (device);
@@ -756,7 +821,9 @@
widget = applet_menu_item_create_device_item_helper (device, applet, text);
g_free (text);
+#ifndef ENABLE_INDICATOR
gtk_widget_set_sensitive (widget, FALSE);
+#endif
gtk_menu_shell_append (GTK_MENU_SHELL (menu), widget);
gtk_widget_show (widget);
@@ -773,8 +840,36 @@
nm_network_menu_item_set_active (item, TRUE);
menu_items = g_slist_append (menu_items, item);
+#if ENABLE_INDICATOR
+ text = escape_mnemonics (nm_network_menu_item_get_ssid (item));
+ imi = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+
+ is_encrypted = nm_network_menu_item_get_is_encrypted(item);
+
+ icon_image = gtk_image_new_from_icon_name
(get_best_icon_name_for_ap (active_ap, TRUE, is_encrypted),
+ GTK_ICON_SIZE_LARGE_TOOLBAR);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (imi), icon_image);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM
(imi), TRUE);
+
+ info = g_slice_new0 (WirelessMenuItemInfo);
+ info->applet = applet;
+ info->device = g_object_ref (G_OBJECT (device));
+ info->ap = g_object_ref (G_OBJECT (active_ap));
+ info->connection = g_object_get_data (G_OBJECT (item), "connection");
+
+ g_signal_connect_data (GTK_WIDGET (imi),
+ "activate",
+ G_CALLBACK (wireless_menu_item_activate),
+ info,
+ (GClosureNotify) wireless_menu_item_info_destroy,
+ 0);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (imi));
+#else
gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item));
gtk_widget_show_all (GTK_WIDGET (item));
+#endif
}
}
}
@@ -801,7 +896,38 @@
item = get_menu_item_for_ap (wdev, ap, connections, menu_items, applet);
if (item)
+#if ENABLE_INDICATOR
+ {
+ text = escape_mnemonics (nm_network_menu_item_get_ssid (item));
+ imi = gtk_image_menu_item_new_with_label (text);
+ g_free (text);
+
+ is_encrypted = nm_network_menu_item_get_is_encrypted(item);
+
+ icon_image = gtk_image_new_from_icon_name
(get_best_icon_name_for_ap (ap, TRUE, is_encrypted),
+ GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (imi), icon_image);
+ gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (imi), TRUE);
+
+ info = g_slice_new0 (WirelessMenuItemInfo);
+ info->applet = applet;
+ info->device = g_object_ref (G_OBJECT (device));
+ info->ap = g_object_ref (G_OBJECT (ap));
+ info->connection = g_object_get_data (G_OBJECT (item), "connection");
+
+ g_signal_connect_data (GTK_WIDGET (imi),
+ "activate",
+ G_CALLBACK (wireless_menu_item_activate),
+ info,
+ (GClosureNotify) wireless_menu_item_info_destroy,
+ 0);
+
+ g_object_set_data_full (G_OBJECT (item), "nm-network-menu-item",
imi, (GDestroyNotify) g_free);
+ menu_items = g_slist_append (menu_items, item);
+ }
+#else
menu_items = g_slist_append (menu_items, item);
+#endif
}
/* Now remove the active AP item from the list, as we've already dealt with
@@ -835,8 +961,12 @@
topmenu_items = g_slist_sort (topmenu_items, sort_by_name);
for (iter = topmenu_items; iter; iter = g_slist_next (iter)) {
+#if ENABLE_INDICATOR
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET
(g_object_get_data(iter->data, "nm-network-menu-item")));
+#else
gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (iter->data));
gtk_widget_show_all (GTK_WIDGET (iter->data));
+#endif
}
g_slist_free (topmenu_items);
topmenu_items = NULL;
@@ -856,7 +986,11 @@
/* And add the rest to the submenu */
for (iter = sorted_subitems; iter; iter = g_slist_next (iter))
+#if ENABLE_INDICATOR
+ gtk_menu_shell_append (GTK_MENU_SHELL (submenu), GTK_WIDGET
(g_object_get_data(iter->data, "nm-network-menu-item")));
+#else
gtk_menu_shell_append (GTK_MENU_SHELL (submenu), GTK_WIDGET (iter->data));
+#endif
g_slist_free (sorted_subitems);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), subitem);
@@ -1093,6 +1227,12 @@
applet);
queue_avail_access_point_notification (NM_DEVICE (device));
+#ifdef ENABLE_INDICATOR
+ if (!applet->menu_update_id)
+ applet->menu_update_id = g_idle_add_full (G_PRIORITY_LOW,
+
(GSourceFunc) status_icon_activate_cb,
+ applet, NULL);
+#endif
}
static void
@@ -1111,6 +1251,12 @@
g_object_set_data (G_OBJECT (device), ACTIVE_AP_TAG, NULL);
applet_schedule_update_icon (applet);
}
+#ifdef ENABLE_INDICATOR
+ if (!applet->menu_update_id)
+ applet->menu_update_id = g_idle_add_full (G_PRIORITY_LOW,
+
(GSourceFunc) status_icon_activate_cb,
+ applet, NULL);
+#endif
}
static void
@@ -1269,7 +1415,11 @@
g_free (esc_ssid);
}
+#ifndef ENABLE_INDICATOR
static GdkPixbuf *
+#else
+static gboolean
+#endif
wireless_get_icon (NMDevice *device,
NMDeviceState state,
NMConnection *connection,
@@ -1278,7 +1428,11 @@
{
NMSettingConnection *s_con;
NMAccessPoint *ap;
+#ifndef ENABLE_INDICATOR
GdkPixbuf *pixbuf = NULL;
+#else
+ gboolean icon_is_set = FALSE;
+#endif
const char *id;
char *ssid = NULL;
@@ -1320,6 +1474,7 @@
strength = nm_access_point_get_strength (ap);
strength = CLAMP (strength, 0, 100);
+#ifndef ENABLE_INDICATOR
if (strength > 80)
pixbuf = nma_icon_check_and_load ("nm-signal-100",
&applet->wireless_100_icon, applet);
else if (strength > 55)
@@ -1330,11 +1485,20 @@
pixbuf = nma_icon_check_and_load ("nm-signal-25",
&applet->wireless_25_icon, applet);
else
pixbuf = nma_icon_check_and_load ("nm-signal-00",
&applet->wireless_00_icon, applet);
+#else
+ // here we don't care whether or not the ap has security, just
want to show signal strength
+ app_indicator_set_icon (applet->status_icon,
get_best_icon_name_for_ap (ap, FALSE, FALSE));
+ icon_is_set = TRUE;
+#endif
*tip = g_strdup_printf (_("Wireless network connection '%s'
active: %s (%d%%)"),
id, ssid, strength);
} else {
+#ifndef ENABLE_INDICATOR
pixbuf = nma_icon_check_and_load ("nm-signal-00",
&applet->wireless_00_icon, applet);
+#else
+ app_indicator_set_icon (applet->status_icon, "nm-signal-00");
+#endif
*tip = g_strdup_printf (_("Wireless network connection '%s' active"), id);
}
break;
@@ -1343,7 +1507,11 @@
}
g_free (ssid);
+#ifndef ENABLE_INDICATOR
return pixbuf;
+#else
+ return icon_is_set;
+#endif
}
static void
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet-device-wired.c
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/applet-device-wired.c 2011-02-11
13:10:51.689540744 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet-device-wired.c 2011-02-11
13:10:51.989541444 -0500
@@ -222,7 +222,9 @@
if (nm_device_get_capabilities (device) & NM_DEVICE_CAP_CARRIER_DETECT)
carrier = nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (device));
+#ifndef ENABLE_INDICATOR
gtk_widget_set_sensitive (item, FALSE);
+#endif
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
@@ -275,7 +277,11 @@
}
}
+#ifndef ENABLE_INDICATOR
static GdkPixbuf *
+#else
+static gboolean
+#endif
wired_get_icon (NMDevice *device,
NMDeviceState state,
NMConnection *connection,
@@ -283,7 +289,11 @@
NMApplet *applet)
{
NMSettingConnection *s_con;
+#ifndef ENABLE_INDICATOR
GdkPixbuf *pixbuf = NULL;
+#else
+ gboolean icon_is_set = FALSE;
+#endif
const char *id;
id = nm_device_get_iface (NM_DEVICE (device));
@@ -306,14 +316,23 @@
*tip = g_strdup_printf (_("Requesting a wired network address for
'%s'..."), id);
break;
case NM_DEVICE_STATE_ACTIVATED:
+#ifndef ENABLE_INDICATOR
pixbuf = nma_icon_check_and_load ("nm-device-wired",
&applet->wired_icon, applet);
+#else
+ app_indicator_set_icon (applet->status_icon, "nm-device-wired");
+ icon_is_set = TRUE;
+#endif
*tip = g_strdup_printf (_("Wired network connection '%s' active"), id);
break;
default:
break;
}
+#ifndef ENABLE_INDICATOR
return pixbuf;
+#else
+ return icon_is_set;
+#endif
}
/* PPPoE */
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet.c
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/applet.c 2011-02-11
13:10:51.909541258 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet.c 2011-02-11
13:12:10.159722733 -0500
@@ -438,6 +438,7 @@
int pos)
{
GtkWidget *menu_item = gtk_image_menu_item_new ();
+#ifndef ENABLE_INDICATOR
GtkWidget *box = gtk_hbox_new (FALSE, 0);
GtkWidget *xlabel = NULL;
@@ -455,6 +456,9 @@
"child", box,
"sensitive", FALSE,
NULL);
+#else
+ menu_item = gtk_separator_menu_item_new ();
+#endif
if (pos < 0)
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
else
@@ -469,10 +473,13 @@
{
GtkWidget *item;
NMSettingConnection *s_con;
+#ifndef ENABLE_INDICATOR
char *markup;
GtkWidget *label;
+#endif
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting
(connection, NM_TYPE_SETTING_CONNECTION));
+#ifndef ENABLE_INDICATOR
item = gtk_image_menu_item_new_with_label ("");
if (add_active && (active == connection)) {
/* Pure evil */
@@ -485,9 +492,13 @@
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);
+#else
+ item = gtk_menu_item_new_with_label (nm_setting_connection_get_id (s_con));
+#endif
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 )
@@ -567,7 +578,7 @@
gtk_widget_set_size_request (widget, width + 2 * xpadding, height +
ypadding + postpadding);
return TRUE;
}
-
+#endif
GtkWidget *
applet_menu_item_create_device_item_helper (NMDevice *device,
@@ -578,7 +589,9 @@
item = gtk_menu_item_new_with_mnemonic (text);
gtk_widget_set_sensitive (item, FALSE);
+#ifndef ENABLE_INDICATOR
g_signal_connect (item, "expose-event", G_CALLBACK
(menu_title_item_expose), NULL);
+#endif
return item;
}
@@ -620,7 +633,11 @@
g_return_if_fail (summary != NULL);
g_return_if_fail (message != NULL);
+#ifndef ENABLE_INDICATOR
if (!gtk_status_icon_is_embedded (applet->status_icon))
+#else
+ if (app_indicator_get_status (applet->status_icon) ==
APP_INDICATOR_STATUS_PASSIVE)
+#endif
return;
escaped = utils_escape_notify_message (message);
@@ -646,9 +663,11 @@
g_free (escaped);
+#ifndef ENABLE_INDICATOR
#if !HAVE_LIBNOTIFY_07
notify_notification_attach_to_status_icon (notify, applet->status_icon);
#endif
+#endif
notify_notification_set_urgency (notify, urgency);
notify_notification_set_timeout (notify, NOTIFY_EXPIRES_DEFAULT);
@@ -929,6 +948,12 @@
else
clear_animation_timeout (applet);
+#ifdef ENABLE_INDICATOR
+ if (!applet->menu_update_id)
+ applet->menu_update_id = g_idle_add_full (G_PRIORITY_LOW,
+ (GSourceFunc) status_icon_activate_cb,
+ applet, NULL);
+#endif
applet_schedule_update_icon (applet);
}
@@ -986,6 +1011,11 @@
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)
{
@@ -1009,9 +1039,14 @@
return;
}
- if (applet_get_active_for_connection (applet, connection))
+ if (applet_get_active_for_connection (applet, connection)) {
+#ifndef ENABLE_INDICATOR
/* Connection already active; do nothing */
+#else
+ nma_menu_disconnect_vpn_item_activate (item, applet);
+#endif
return;
+ }
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting
(connection, NM_TYPE_SETTING_CONNECTION));
info = g_malloc0 (sizeof (VPNActivateInfo));
@@ -1429,6 +1464,10 @@
dclass = get_device_class (device, applet);
if (dclass)
dclass->add_menu_item (device, n_devices, active, menu, applet);
+
+#ifdef ENABLE_INDICATOR
+ nma_menu_add_separator_item (menu);
+#endif
}
out:
@@ -1486,7 +1525,9 @@
GSList *list, *iter;
int num_vpn_active = 0;
+#ifndef ENABLE_INDICATOR
nma_menu_add_separator_item (menu);
+#endif
vpn_menu = GTK_MENU (gtk_menu_new ());
@@ -1506,12 +1547,18 @@
NMConnection *connection = NM_CONNECTION (iter->data);
NMActiveConnection *active;
const char *name;
+#ifndef ENABLE_INDICATOR
GtkWidget *image;
+#endif
name = get_connection_id (connection);
+#ifndef ENABLE_INDICATOR
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);
+#else
+ item = GTK_MENU_ITEM (gtk_check_menu_item_new_with_label (name));
+#endif
/* If no VPN connections are active, draw all menu items enabled. If
* >= 1 VPN connections are active, only the active VPN menu item is
@@ -1527,9 +1574,17 @@
gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
if (active) {
+#ifndef ENABLE_INDICATOR
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);
+#else
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(item), TRUE);
+#endif
}
+#ifdef ENABLE_INDICATOR
+ else
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(item), FALSE);
+#endif
g_object_set_data_full (G_OBJECT (item), "connection",
g_object_ref (connection),
@@ -1556,7 +1611,6 @@
g_slist_free (list);
}
-
static void
nma_set_wireless_enabled_cb (GtkWidget *widget, NMApplet *applet)
{
@@ -1574,6 +1628,7 @@
gboolean state;
g_return_if_fail (applet != NULL);
+ g_return_if_fail (widget != NULL);
state = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
nm_client_wwan_set_enabled (applet->nm_client, state);
@@ -1585,12 +1640,13 @@
gboolean state;
g_return_if_fail (applet != NULL);
+ g_return_if_fail (widget != NULL);
state = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
nm_client_networking_set_enabled (applet->nm_client, state);
}
-
+#ifndef ENABLE_INDICATOR
static void
nma_set_notifications_enabled_cb (GtkWidget *widget, NMApplet *applet)
{
@@ -1617,6 +1673,7 @@
!state,
NULL);
}
+#endif
/*
* nma_menu_show_cb
@@ -1631,11 +1688,13 @@
g_return_if_fail (menu != NULL);
g_return_if_fail (applet != NULL);
+#ifndef ENABLE_INDICATOR
#if GTK_CHECK_VERSION(2, 15, 0)
gtk_status_icon_set_tooltip_text (applet->status_icon, NULL);
#else
gtk_status_icon_set_tooltip (applet->status_icon, NULL);
#endif
+#endif
if (!nm_client_get_manager_running (applet->nm_client)) {
nma_menu_add_text_item (menu, _("NetworkManager is not running..."));
@@ -1665,6 +1724,7 @@
static gboolean nma_menu_clear (NMApplet *applet);
+#ifndef ENABLE_INDICATOR
static void
nma_menu_deactivate_cb (GtkWidget *widget, NMApplet *applet)
{
@@ -1681,6 +1741,7 @@
gtk_status_icon_set_tooltip (applet->status_icon, applet->tip);
#endif
}
+#endif
/*
* nma_menu_create
@@ -1697,8 +1758,10 @@
menu = gtk_menu_new ();
gtk_container_set_border_width (GTK_CONTAINER (menu), 0);
+#ifndef ENABLE_INDICATOR
g_signal_connect (menu, "show", G_CALLBACK (nma_menu_show_cb), applet);
g_signal_connect (menu, "deactivate", G_CALLBACK
(nma_menu_deactivate_cb), applet);
+#endif
return menu;
}
@@ -1735,12 +1798,14 @@
nma_context_menu_update (NMApplet *applet)
{
NMState state;
+ gboolean wireless_hw_enabled;
gboolean net_enabled = TRUE;
gboolean have_wireless = FALSE;
gboolean have_wwan = FALSE;
- gboolean wireless_hw_enabled;
gboolean wwan_hw_enabled;
+#ifndef ENABLE_INDICATOR
gboolean notifications_enabled = TRUE;
+#endif
state = nm_client_get_state (applet->nm_client);
@@ -1785,6 +1850,7 @@
gtk_widget_set_sensitive (GTK_WIDGET (applet->wwan_enabled_item),
wwan_hw_enabled && is_permission_yes
(applet, NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN));
+#ifndef ENABLE_INDICATOR
/* Enabled notifications */
g_signal_handler_block (G_OBJECT (applet->notifications_enabled_item),
applet->notifications_enabled_toggled_id);
@@ -1796,6 +1862,7 @@
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 wireless is off */
if (state != NM_STATE_ASLEEP) {
@@ -1822,6 +1889,12 @@
gtk_widget_show_all (applet->wwan_enabled_item);
else
gtk_widget_hide (applet->wwan_enabled_item);
+#if 0
+ if (applet->wifi_enabled_item)
+ gtk_widget_show_all (applet->wifi_enabled_item);
+ if (applet->wwan_enabled_item)
+ gtk_widget_show_all (applet->wwan_enabled_item);
+#endif
}
static void
@@ -1861,16 +1934,24 @@
* Generate the contextual popup menu.
*
*/
+#ifndef ENABLE_INDICATOR
static GtkWidget *nma_context_menu_create (NMApplet *applet)
+#else
+static GtkWidget *nma_context_menu_create (NMApplet *applet,
GtkMenuShell *menu)
+#endif
{
+#ifndef ENABLE_INDICATOR
GtkMenuShell *menu;
GtkWidget *menu_item;
+#endif
GtkWidget *image;
guint id;
g_return_val_if_fail (applet != NULL, NULL);
+#ifndef ENABLE_INDICATOR
menu = GTK_MENU_SHELL (gtk_menu_new ());
+#endif
/* 'Enable Networking' item */
applet->networking_enabled_item =
gtk_check_menu_item_new_with_mnemonic (_("Enable _Networking"));
@@ -1901,6 +1982,7 @@
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,
@@ -1911,6 +1993,7 @@
gtk_menu_shell_append (menu, applet->notifications_enabled_item);
nma_menu_add_separator_item (GTK_WIDGET (menu));
+#endif /* ifndef ENABLE_INDICATOR */
/* 'Connection Information' item */
applet->info_menu_item = gtk_image_menu_item_new_with_mnemonic
(_("Connection _Information"));
@@ -1932,6 +2015,7 @@
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM
(applet->connections_menu_item), image);
gtk_menu_shell_append (menu, applet->connections_menu_item);
+#ifndef ENABLE_INDICATOR
/* Separator */
nma_menu_add_separator_item (GTK_WIDGET (menu));
@@ -1951,6 +2035,7 @@
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));
@@ -1960,6 +2045,7 @@
/*****************************************************************************/
+#ifndef ENABLE_INDICATOR
static void
foo_set_icon (NMApplet *applet, GdkPixbuf *pixbuf, guint32 layer)
{
@@ -2004,6 +2090,7 @@
gtk_status_icon_set_from_pixbuf (applet->status_icon, pixbuf);
g_object_unref (pixbuf);
}
+#endif
NMSettingsConnectionInterface *
@@ -2206,6 +2293,13 @@
applet_common_device_state_changed (device, new_state, old_state,
reason, applet);
applet_schedule_update_icon (applet);
+
+#ifdef ENABLE_INDICATOR
+ if (!applet->menu_update_id)
+ applet->menu_update_id = g_idle_add_full (G_PRIORITY_LOW,
+ (GSourceFunc) status_icon_activate_cb,
+ applet, NULL);
+#endif
}
static void
@@ -2260,6 +2354,12 @@
break;
}
+#ifdef ENABLE_INDICATOR
+ if (!applet->menu_update_id)
+ applet->menu_update_id = g_idle_add_full (G_PRIORITY_LOW,
+ (GSourceFunc) status_icon_activate_cb,
+ applet, NULL);
+#endif
applet_schedule_update_icon (applet);
}
@@ -2374,10 +2474,18 @@
applet_schedule_update_icon (applet);
}
+#ifndef ENABLE_INDICATOR
static GdkPixbuf *
+#else
+static gboolean
+#endif
applet_common_get_device_icon (NMDeviceState state, NMApplet *applet)
{
+#ifndef ENABLE_INDICATOR
GdkPixbuf *pixbuf = NULL;
+#else
+ char *name;
+#endif
int stage = -1;
switch (state) {
@@ -2395,6 +2503,7 @@
break;
}
+#ifndef ENABLE_INDICATOR
if (stage >= 0) {
int i, j;
@@ -2409,12 +2518,23 @@
}
pixbuf = applet->network_connecting_icons[stage][applet->animation_step];
+#endif
applet->animation_step++;
if (applet->animation_step >= NUM_CONNECTING_FRAMES)
applet->animation_step = 0;
+#ifdef ENABLE_INDICATOR
+ name = g_strdup_printf ("nm-stage%02d-connecting%02d", stage+1,
applet->animation_step+1);
+ app_indicator_set_icon (applet->status_icon, name);
+ g_free (name);
+#else
}
+#endif
+#ifndef ENABLE_INDICATOR
return pixbuf;
+#else
+ return TRUE;
+#endif
}
static char *
@@ -2453,12 +2573,20 @@
return tip;
}
+#ifndef ENABLE_INDICATOR
static GdkPixbuf *
+#else
+static void
+#endif
applet_get_device_icon_for_state (NMApplet *applet, char **tip)
{
NMActiveConnection *active;
NMDevice *device = NULL;
+#ifndef ENABLE_INDICATOR
GdkPixbuf *pixbuf = NULL;
+#else
+ gboolean got_icon = FALSE;
+#endif
NMDeviceState state = NM_DEVICE_STATE_UNKNOWN;
NMADeviceClass *dclass;
@@ -2482,17 +2610,27 @@
NMConnection *connection;
connection = applet_find_active_connection_for_device (device, applet, NULL);
+#ifndef ENABLE_INDICATOR
pixbuf = dclass->get_icon (device, state, connection, tip, applet);
+#else
+ got_icon = dclass->get_icon (device, state, connection, tip, applet);
+#endif
if (!*tip)
*tip = get_tip_for_device_state (device, state, connection);
}
out:
- if (!pixbuf)
- pixbuf = applet_common_get_device_icon (state, applet);
+#ifndef ENABLE_INDICATOR
+ if (!pixbuf)
+ pixbuf = applet_common_get_device_icon (state, applet);
if (!pixbuf)
pixbuf = applet->no_connection_icon;
- return pixbuf;
+ return pixbuf;
+#else
+ if (!got_icon)
+ applet_common_get_device_icon (state, applet);
+ return;
+#endif
}
static char *
@@ -2566,49 +2704,89 @@
if (!nm_running)
state = NM_STATE_UNKNOWN;
+#ifdef ENABLE_INDICATOR
+ if (nm_running)
+ app_indicator_set_status (applet->status_icon, APP_INDICATOR_STATUS_ACTIVE);
+ else
+ app_indicator_set_status (applet->status_icon, APP_INDICATOR_STATUS_PASSIVE);
+#endif
+
switch (state) {
case NM_STATE_UNKNOWN:
case NM_STATE_ASLEEP:
+#ifndef ENABLE_INDICATOR
pixbuf = nma_icon_check_and_load ("nm-no-connection",
&applet->no_connection_icon, applet);
+#else
+ app_indicator_set_icon (applet->status_icon, "nm-no-connection");
+#endif
dev_tip = g_strdup (_("Networking disabled"));
break;
case NM_STATE_DISCONNECTED:
+#ifndef ENABLE_INDICATOR
pixbuf = nma_icon_check_and_load ("nm-no-connection",
&applet->no_connection_icon, applet);
+#else
+ app_indicator_set_icon (applet->status_icon, "nm-no-connection");
+#endif
dev_tip = g_strdup (_("No network connection"));
break;
default:
+#ifdef ENABLE_INDICATOR
+ applet_get_device_icon_for_state (applet, &dev_tip);
+#else
pixbuf = applet_get_device_icon_for_state (applet, &dev_tip);
+#endif
break;
}
+#ifndef ENABLE_INDICATOR
foo_set_icon (applet, pixbuf, ICON_LAYER_LINK);
+#endif
/* VPN state next */
pixbuf = NULL;
active_vpn = applet_get_first_active_vpn_connection (applet, &vpn_state);
if (active_vpn) {
- int i;
-
switch (vpn_state) {
case NM_VPN_CONNECTION_STATE_ACTIVATED:
+#ifndef ENABLE_INDICATOR
pixbuf = nma_icon_check_and_load ("nm-vpn-active-lock",
&applet->vpn_lock_icon, applet);
+#else
+ {
+ char *icon_name_with_vpn = NULL;
+ const gchar *cur_icon_name = app_indicator_get_icon (applet->status_icon);
+
+ icon_name_with_vpn = g_strdup_printf ("%s-secure", cur_icon_name);
+ app_indicator_set_icon (applet->status_icon, icon_name_with_vpn);
+ g_free (icon_name_with_vpn);
+ }
+#endif
break;
case NM_VPN_CONNECTION_STATE_PREPARE:
case NM_VPN_CONNECTION_STATE_NEED_AUTH:
case NM_VPN_CONNECTION_STATE_CONNECT:
case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET:
- for (i = 0; i < NUM_VPN_CONNECTING_FRAMES; i++) {
+#ifndef ENABLE_INDICATOR
+ for (int i = 0; i < NUM_VPN_CONNECTING_FRAMES; i++) {
char *name;
name = g_strdup_printf ("nm-vpn-connecting%02d", i+1);
nma_icon_check_and_load (name, &applet->vpn_connecting_icons[i], applet);
g_free (name);
}
+#endif
pixbuf = applet->vpn_connecting_icons[applet->animation_step];
applet->animation_step++;
if (applet->animation_step >= NUM_VPN_CONNECTING_FRAMES)
applet->animation_step = 0;
+#ifdef ENABLE_INDICATOR
+ {
+ char *name;
+ name = g_strdup_printf ("nm-vpn-connecting%02d", applet->animation_step+1);
+ app_indicator_set_icon (applet->status_icon, name);
+ g_free (name);
+ }
+#endif
break;
default:
break;
@@ -2616,7 +2794,9 @@
vpn_tip = get_tip_for_vpn (active_vpn, vpn_state, applet);
}
+#ifndef ENABLE_INDICATOR
foo_set_icon (applet, pixbuf, ICON_LAYER_VPN);
+#endif
if (applet->tip) {
g_free (applet->tip);
@@ -2639,11 +2819,13 @@
g_string_free (tip, FALSE);
}
+#ifndef ENABLE_INDICATOR
#if GTK_CHECK_VERSION(2, 15, 0)
gtk_status_icon_set_tooltip_text (applet->status_icon, applet->tip);
#else
gtk_status_icon_set_tooltip (applet->status_icon, applet->tip);
#endif
+#endif
return FALSE;
}
@@ -2974,7 +3156,11 @@
g_object_unref (G_OBJECT (applet->icon_theme));
}
+#ifdef ENABLE_INDICATOR
+ screen = gdk_screen_get_default();
+#else
screen = gtk_status_icon_get_screen (applet->status_icon);
+#endif
g_assert (screen);
applet->icon_theme = gtk_icon_theme_get_for_screen (screen);
@@ -3000,6 +3186,7 @@
nma_icon_theme_changed (NULL, applet);
}
+#ifndef ENABLE_INDICATOR
static gboolean
status_icon_size_changed_cb (GtkStatusIcon *icon,
gint size,
@@ -3016,20 +3203,36 @@
return TRUE;
}
+#endif
+#ifdef ENABLE_INDICATOR
+gboolean
+status_icon_activate_cb (NMApplet *applet)
+#else
static void
status_icon_activate_cb (GtkStatusIcon *icon, NMApplet *applet)
+#endif
{
/* Have clicking on the applet act also as acknowledgement
* of the notification.
*/
-
nma_menu_clear (applet);
+#ifdef ENABLE_INDICATOR
+ nma_menu_show_cb (applet->menu, applet);
+ nma_menu_add_separator_item (applet->menu);
+ applet->menu = nma_context_menu_create (applet, GTK_MENU_SHELL(applet->menu));
+ nma_context_menu_update (applet);
+ app_indicator_set_menu (applet->status_icon, GTK_MENU(applet->menu));
+ applet->menu_update_id = 0;
+ return FALSE;
+#else
gtk_menu_popup (GTK_MENU (applet->menu), NULL, NULL,
gtk_status_icon_position_menu, icon,
1, gtk_get_current_event_time ());
+#endif
}
+#ifndef ENABLE_INDICATOR
static void
status_icon_popup_menu_cb (GtkStatusIcon *icon,
guint button,
@@ -3045,32 +3248,48 @@
gtk_status_icon_position_menu, icon,
button, activate_time);
}
+#endif
static gboolean
setup_widgets (NMApplet *applet)
{
g_return_val_if_fail (NM_IS_APPLET (applet), FALSE);
+#ifdef ENABLE_INDICATOR
+ applet->status_icon = app_indicator_new
+ ("nm-applet", "nm-no-connection",
+ APP_INDICATOR_CATEGORY_SYSTEM_SERVICES);
+#else
applet->status_icon = gtk_status_icon_new ();
+#endif
if (!applet->status_icon)
return FALSE;
g_signal_connect (applet->status_icon, "notify::screen",
G_CALLBACK (status_icon_screen_changed_cb), applet);
+#ifndef ENABLE_INDICATOR
g_signal_connect (applet->status_icon, "size-changed",
G_CALLBACK (status_icon_size_changed_cb), applet);
g_signal_connect (applet->status_icon, "activate",
G_CALLBACK (status_icon_activate_cb), applet);
g_signal_connect (applet->status_icon, "popup-menu",
G_CALLBACK (status_icon_popup_menu_cb), applet);
+#endif
applet->menu = nma_menu_create (applet);
if (!applet->menu)
return FALSE;
+#ifdef ENABLE_INDICATOR
+ applet->menu = nma_context_menu_create (applet, GTK_MENU_SHELL(applet->menu));
+ nma_context_menu_update(applet);
+
+ app_indicator_set_menu(applet->status_icon, GTK_MENU(applet->menu));
+#else
applet->context_menu = nma_context_menu_create (applet);
if (!applet->context_menu)
return FALSE;
+#endif
return TRUE;
}
@@ -3139,6 +3358,7 @@
g_main_loop_quit (applet->loop);
}
+#ifndef ENABLE_INDICATOR
static void
applet_embedded_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
{
@@ -3147,6 +3367,7 @@
g_message ("applet now %s the notification area",
embedded ? "embedded in" : "removed from");
}
+#endif
static GObject *
constructor (GType type,
@@ -3189,11 +3410,6 @@
GCONF_CLIENT_PRELOAD_ONELEVEL,
NULL);
- /* Load pixmaps and create applet widgets */
- if (!setup_widgets (applet))
- goto error;
- nma_icons_init (applet);
-
if (!notify_is_initted ())
notify_init ("NetworkManager");
@@ -3238,18 +3454,25 @@
foo_client_setup (applet);
+ /* Load pixmaps and create applet widgets */
+ if (!setup_widgets (applet))
+ goto error;
+ nma_icons_init (applet);
+
/* timeout to update connection timestamps every 5 minutes */
applet->update_timestamps_id = g_timeout_add_seconds (300,
(GSourceFunc) periodic_update_active_connection_timestamps, applet);
nm_gconf_set_pre_keyring_callback (applet_pre_keyring_callback, applet);
+#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
applet->notify_actions = applet_notify_server_has_actions ();
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet.h
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/applet.h 2011-02-11
13:10:51.829541070 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/applet.h 2011-02-11
13:10:51.999541467 -0500
@@ -38,6 +38,10 @@
#include <libnotify/notify.h>
+#if ENABLE_INDICATOR
+#include <libappindicator/app-indicator.h>
+#endif
+
#include <nm-connection.h>
#include <nm-client.h>
#include <nm-access-point.h>
@@ -144,7 +148,12 @@
guint animation_id;
/* Direct UI elements */
+#if ENABLE_INDICATOR
+ AppIndicator *status_icon;
+ guint menu_update_id;
+#else
GtkStatusIcon * status_icon;
+#endif
int icon_size;
GtkWidget * menu;
@@ -197,7 +206,11 @@
NMDeviceStateReason reason,
NMApplet *applet);
+#if ENABLE_INDICATOR
+ gboolean (*get_icon) (NMDevice *device,
+#else
GdkPixbuf * (*get_icon) (NMDevice *device,
+#endif
NMDeviceState state,
NMConnection *connection,
char **tip,
@@ -225,6 +238,10 @@
void applet_schedule_update_icon (NMApplet *applet);
+#ifdef ENABLE_INDICATOR
+gboolean status_icon_activate_cb (NMApplet *applet);
+#endif
+
NMSettingsInterface *applet_get_settings (NMApplet *applet);
GSList *applet_get_all_connections (NMApplet *applet);
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/gconf-helpers/Makefile.am
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/gconf-helpers/Makefile.am 2011-02-10
10:09:52.000000000 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/gconf-helpers/Makefile.am 2011-02-11
13:10:51.999541467 -0500
@@ -12,6 +12,7 @@
libgconf_helpers_la_CPPFLAGS = \
$(NMA_CFLAGS) \
+ $(APPINDICATOR_CFLAGS) \
$(DISABLE_DEPRECATED) \
-I${top_srcdir}/src \
-I${top_builddir}/src/marshallers \
@@ -19,6 +20,7 @@
libgconf_helpers_la_LIBADD = \
$(NMA_LIBS) \
+ $(APPINDICATOR_LIBS) \
${top_builddir}/src/marshallers/libmarshallers.la \
${top_builddir}/src/utils/libutils.la
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/mobile-helpers.c
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/mobile-helpers.c 2011-02-10
10:09:52.000000000 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/mobile-helpers.c 2011-02-11
13:10:52.009541490 -0500
@@ -21,6 +21,7 @@
*/
#include "mobile-helpers.h"
+#include <glib/gi18n.h>
GdkPixbuf *
mobile_helper_get_status_pixbuf (guint32 quality,
@@ -35,7 +36,11 @@
if (!quality_valid)
quality = 0;
+#ifndef ENABLE_INDICATOR
qual_pixbuf = mobile_helper_get_quality_icon (quality, applet);
+#else
+ qual_pixbuf = wwan_pixbuf;
+#endif
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
TRUE,
@@ -80,9 +85,14 @@
return pixbuf;
}
+#ifndef ENABLE_INDICATOR
GdkPixbuf *
+#else
+char *
+#endif
mobile_helper_get_quality_icon (guint32 quality, NMApplet *applet)
{
+#ifndef ENABLE_INDICATOR
if (quality > 80)
return nma_icon_check_and_load ("nm-signal-100",
&applet->wireless_100_icon, applet);
else if (quality > 55)
@@ -93,7 +103,132 @@
return nma_icon_check_and_load ("nm-signal-25",
&applet->wireless_25_icon, applet);
return nma_icon_check_and_load ("nm-signal-00",
&applet->wireless_00_icon, applet);
+#else
+ char *icon_name;
+
+ if (quality > 80)
+ icon_name = g_strdup_printf ("gsm-3g-full");
+ else if (quality > 55)
+ icon_name = g_strdup_printf ("gsm-3g-high");
+ else if (quality > 30)
+ icon_name = g_strdup_printf ("gsm-3g-medium");
+ else if (quality > 5)
+ icon_name = g_strdup_printf ("gsm-3g-low");
+ else
+ icon_name = g_strdup_printf ("gsm-3g-none");
+
+ return icon_name;
+#endif
+}
+
+#ifdef ENABLE_INDICATOR
+static const char *
+get_tech_name (guint32 tech)
+{
+ switch (tech) {
+ case MB_TECH_1XRTT:
+ return _("CDMA");
+ case MB_TECH_EVDO_REV0:
+ case MB_TECH_EVDO_REVA:
+ return _("EVDO");
+ case MB_TECH_GSM:
+ return _("GSM");
+ case MB_TECH_GPRS:
+ return _("GPRS");
+ case MB_TECH_EDGE:
+ return _("EDGE");
+ case MB_TECH_UMTS:
+ return _("UMTS");
+ case MB_TECH_HSDPA:
+ return _("HSDPA");
+ case MB_TECH_HSUPA:
+ return _("HSUPA");
+ case MB_TECH_HSPA:
+ return _("HSPA");
+ default:
+ break;
+ }
+ return NULL;
+}
+
+char *
+mobile_helper_get_connection_label (const char *connection_name,
+ const char *provider,
+ guint32 technology,
+ guint32 state)
+{
+ const char *tech_name;
+ char *desc_string;
+
+ /* Construct the description string */
+ tech_name = get_tech_name (technology);
+ switch (state) {
+ default:
+ case MB_STATE_UNKNOWN:
+ desc_string = g_strdup (_("not enabled"));
+ break;
+ case MB_STATE_IDLE:
+ if (connection_name)
+ desc_string = g_strdup (connection_name);
+ else
+ desc_string = g_strdup (_("not registered"));
+ break;
+ case MB_STATE_HOME:
+ if (connection_name) {
+ if (provider && tech_name)
+ desc_string = g_strdup_printf ("%s
(%s %s)", connection_name, provider, tech_name);
+ else if (provider || tech_name)
+ desc_string = g_strdup_printf ("%s
(%s)", connection_name, provider ? provider : tech_name);
+ else
+ desc_string = g_strdup_printf ("%s",
connection_name);
+ } else {
+ if (provider) {
+ if (tech_name)
+ desc_string = g_strdup_printf
("%s %s", provider, tech_name);
+ else
+ desc_string = g_strdup_printf
("%s", provider);
+ } else {
+ if (tech_name)
+ desc_string = g_strdup_printf
(_("Home network (%s)"), tech_name);
+ else
+ desc_string = g_strdup_printf
(_("Home network"));
+ }
+ }
+ break;
+ case MB_STATE_SEARCHING:
+ if (connection_name)
+ desc_string = g_strdup (connection_name);
+ else
+ desc_string = g_strdup (_("searching"));
+ break;
+ case MB_STATE_DENIED:
+ desc_string = g_strdup (_("registration denied"));
+ break;
+ case MB_STATE_ROAMING:
+ if (connection_name) {
+ if (tech_name)
+ desc_string = g_strdup_printf (_("%s
(%s roaming)"), connection_name, tech_name);
+ else
+ desc_string = g_strdup_printf (_("%s
(roaming)"), connection_name);
+ } else {
+ if (provider) {
+ if (tech_name)
+ desc_string = g_strdup_printf
(_("%s (%s roaming)"), provider, tech_name);
+ else
+ desc_string = g_strdup_printf
(_("%s (roaming)"), provider);
+ } else {
+ if (tech_name)
+ desc_string = g_strdup_printf
(_("Roaming network (%s)"), tech_name);
+ else
+ desc_string = g_strdup_printf
(_("Roaming network"));
+ }
+ }
+ break;
+ }
+
+ return desc_string;
}
+#endif
GdkPixbuf *
mobile_helper_get_tech_icon (guint32 tech, NMApplet *applet)
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/mobile-helpers.h
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/mobile-helpers.h 2011-02-10
10:09:52.000000000 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/mobile-helpers.h 2011-02-11
13:10:52.009541490 -0500
@@ -55,9 +55,20 @@
guint32 access_tech,
NMApplet *applet);
+#ifndef ENABLE_INDICATOR
GdkPixbuf *mobile_helper_get_quality_icon (guint32 quality, NMApplet *applet);
+#else
+char *mobile_helper_get_quality_icon (guint32 quality, NMApplet *applet);
+#endif
GdkPixbuf *mobile_helper_get_tech_icon (guint32 tech, NMApplet *applet);
+#ifdef ENABLE_INDICATOR
+char *mobile_helper_get_connection_label (const char *connection_name,
+ const char *provider,
+ guint32 technology,
+ guint32 state);
+#endif
+
#endif /* APPLET_MOBILE_HELPERS_H */
Index: network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/mb-menu-item.c
===================================================================
--- network-manager-applet-0.8.3+git.20110203t003354.9bf0b98.orig/src/mb-menu-item.c 2011-02-10
10:09:52.000000000 -0500
+++ network-manager-applet-0.8.3+git.20110203t003354.9bf0b98/src/mb-menu-item.c 2011-02-11
13:10:52.009541490 -0500
@@ -178,11 +178,14 @@
gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
}
+/* Disabling this for indicators only because it won't build otherwise. */
+#ifndef ENABLE_INDICATOR
/* And the strength icon, if we have strength information at all */
if (enabled && strength) {
gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength),
mobile_helper_get_quality_icon
(strength, applet));
}
+#endif
return GTK_WIDGET (item);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]