summaryrefslogtreecommitdiff
path: root/src/applet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/applet.c')
-rw-r--r--src/applet.c140
1 files changed, 139 insertions, 1 deletions
diff --git a/src/applet.c b/src/applet.c
index 2b42002c..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 *
@@ -706,6 +710,7 @@ 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 ("");
+#ifndef ENABLE_INDICATOR
if (add_active && (active == connection)) {
char *markup;
GtkWidget *label;
@@ -717,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 )
@@ -786,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,
@@ -796,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;
}
@@ -854,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)
@@ -1195,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)
{
@@ -1218,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;
}
@@ -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);
@@ -3341,7 +3440,11 @@ static void nma_icons_init (NMApplet *applet)
g_object_unref (G_OBJECT (applet->icon_theme));
}
+#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),
@@ -3356,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,
@@ -3427,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)
@@ -3449,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)
{
@@ -3461,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)
@@ -3473,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
@@ -3517,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
@@ -3618,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);
@@ -3651,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);