summaryrefslogtreecommitdiff
path: root/src/applet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/applet.c')
-rw-r--r--src/applet.c114
1 files changed, 53 insertions, 61 deletions
diff --git a/src/applet.c b/src/applet.c
index 0fe14e75..72ac5c96 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -1007,8 +1007,6 @@ activate_vpn_cb (GObject *client,
g_free (info);
}
-static void nma_menu_disconnect_vpn_item_activate (GtkMenuItem *item, gpointer user_data);
-
static void
nma_menu_vpn_item_clicked (GtkMenuItem *item, gpointer user_data)
{
@@ -1018,23 +1016,22 @@ nma_menu_vpn_item_clicked (GtkMenuItem *item, gpointer user_data)
NMActiveConnection *active;
NMDevice *device = NULL;
- active = applet_get_default_active_connection (applet, &device);
- if (!active || !device) {
- g_warning ("%s: no active connection or device.", __func__);
- return;
- }
-
connection = NM_CONNECTION (g_object_get_data (G_OBJECT (item), "connection"));
if (!connection) {
g_warning ("%s: no connection associated with menu item!", __func__);
return;
}
- if (applet_get_active_for_connection (applet, connection)) {
- if (INDICATOR_ENABLED (applet))
- nma_menu_disconnect_vpn_item_activate (item, applet);
+ active = applet_get_active_for_connection (applet, connection);
+ if (active) {
+ /* Connection already active; disconnect it */
+ nm_client_deactivate_connection (applet->nm_client, active, NULL, NULL);
+ return;
+ }
- /* Connection already active; do nothing */
+ active = applet_get_default_active_connection (applet, &device);
+ if (!active || !device) {
+ g_warning ("%s: no active connection or device.", __func__);
return;
}
@@ -1072,11 +1069,34 @@ nma_menu_configure_vpn_item_activate (GtkMenuItem *item, gpointer user_data)
// nmi_dbus_signal_user_interface_activated (applet->connection);
}
+/*
+ * nma_menu_add_vpn_item_activate
+ *
+ * Signal function called when user clicks "Add a VPN connection..."
+ *
+ */
+static void
+nma_menu_add_vpn_item_activate (GtkMenuItem *item, gpointer user_data)
+{
+ const char *argv[] = { BINDIR "/nm-connection-editor", "--create", "--type", NM_SETTING_VPN_SETTING_NAME, NULL};
+
+ g_spawn_async (NULL, (gchar **) argv, NULL, 0, NULL, NULL, NULL, NULL);
+}
+
+/*
+ * applet_get_active_vpn_connection:
+ *
+ * Gets a VPN connection along with its state. If there are more, ones that
+ * are not yet fully activated are preferred.
+ *
+ */
static NMActiveConnection *
-applet_get_first_active_vpn_connection (NMApplet *applet,
+applet_get_active_vpn_connection (NMApplet *applet,
NMVpnConnectionState *out_state)
{
const GPtrArray *active_list;
+ NMActiveConnection *ret = NULL;
+ NMVpnConnectionState state;
int i;
active_list = nm_client_get_active_connections (applet->nm_client);
@@ -1095,34 +1115,18 @@ applet_get_first_active_vpn_connection (NMApplet *applet,
g_assert (s_con);
if (!strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_VPN_SETTING_NAME)) {
- if (out_state)
- *out_state = nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (candidate));
- return candidate;
+ ret = candidate;
+ state = nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (candidate));
+
+ if (state != NM_VPN_CONNECTION_STATE_ACTIVATED)
+ break;
}
}
- return NULL;
-}
-
-/*
- * nma_menu_disconnect_vpn_item_activate
- *
- * Signal function called when user clicks "Disconnect VPN"
- *
- */
-static void
-nma_menu_disconnect_vpn_item_activate (GtkMenuItem *item, gpointer user_data)
-{
- NMApplet *applet = NM_APPLET (user_data);
- NMActiveConnection *active_vpn = NULL;
- NMVpnConnectionState state = NM_VPN_CONNECTION_STATE_UNKNOWN;
+ if (ret && out_state)
+ *out_state = state;
- active_vpn = applet_get_first_active_vpn_connection (applet, &state);
- if (active_vpn)
- nm_client_deactivate_connection (applet->nm_client, active_vpn, NULL, NULL);
- else
- g_warning ("%s: deactivate clicked but no active VPN connection could be found.", __func__);
-// nmi_dbus_signal_user_interface_activated (applet->connection);
+ return ret;
}
/*
@@ -1440,7 +1444,7 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet)
GtkMenu *vpn_menu;
GtkMenuItem *item;
GPtrArray *list;
- int i, num_vpn_active = 0;
+ int i;
nma_menu_add_separator_item (menu);
@@ -1454,13 +1458,6 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet)
list = get_vpn_connections (applet);
for (i = 0; i < list->len; i++) {
NMConnection *connection = NM_CONNECTION (list->pdata[i]);
-
- if (applet_get_active_for_connection (applet, connection))
- num_vpn_active++;
- }
-
- for (i = 0; i < list->len; i++) {
- NMConnection *connection = NM_CONNECTION (list->pdata[i]);
NMActiveConnection *active;
const char *name;
NMState state;
@@ -1480,10 +1477,8 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet)
&& state != NM_STATE_CONNECTED_SITE
&& state != NM_STATE_CONNECTED_GLOBAL)
gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
- else if ((num_vpn_active == 0) || active)
- gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
else
- gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
+ gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), !!active);
@@ -1497,19 +1492,15 @@ nma_menu_add_vpn_submenu (GtkWidget *menu, NMApplet *applet)
}
/* Draw a separator, but only if we have VPN connections above it */
- if (list->len)
+ if (list->len) {
nma_menu_add_separator_item (GTK_WIDGET (vpn_menu));
-
- 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);
+ 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);
+ } else {
+ item = GTK_MENU_ITEM (gtk_menu_item_new_with_mnemonic (_("_Add a VPN connection...")));
+ g_signal_connect (item, "activate", G_CALLBACK (nma_menu_add_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_ptr_array_unref (list);
@@ -2563,7 +2554,7 @@ get_tip_for_vpn (NMActiveConnection *active, NMVpnConnectionState state, NMApple
tip = g_strdup_printf (_("Requesting a VPN address for '%s'..."), id);
break;
case NM_VPN_CONNECTION_STATE_ACTIVATED:
- tip = g_strdup_printf (_("VPN connection '%s' active"), id);
+ tip = g_strdup_printf (_("VPN connection active"));
break;
default:
break;
@@ -2628,7 +2619,7 @@ applet_update_icon (gpointer user_data)
g_clear_pointer (&icon_name_free, g_free);
/* VPN state next */
- active_vpn = applet_get_first_active_vpn_connection (applet, &vpn_state);
+ active_vpn = applet_get_active_vpn_connection (applet, &vpn_state);
if (active_vpn) {
switch (vpn_state) {
case NM_VPN_CONNECTION_STATE_ACTIVATED:
@@ -2904,6 +2895,7 @@ applet_agent_cancel_secrets_cb (AppletAgent *agent,
if (req->reqid == request_id) {
/* cancel and free this password request */
applet_secrets_request_free (req);
+ break;
}
}
}