diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2016-10-30 16:06:30 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2016-11-11 15:34:48 +0100 |
commit | 735fa6e6fabf40f34c24f32ecc73d91fd536339f (patch) | |
tree | bfb36b7fe82b3a43fd2dd2aa38af98c872cd15be | |
parent | 3c9933b546af87273316d57edfd8242ca9030c7f (diff) | |
download | network-manager-applet-lr/import.tar.gz |
editor: add --import command line argumentlr/import
It currently can only import VPN connections.
-rw-r--r-- | src/connection-editor/main.c | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/src/connection-editor/main.c b/src/connection-editor/main.c index 5c1c3e2e..48cb4bda 100644 --- a/src/connection-editor/main.c +++ b/src/connection-editor/main.c @@ -30,6 +30,7 @@ #include "nm-connection-list.h" #include "nm-connection-editor.h" +#include "connection-helpers.h" gboolean nm_ce_keep_above; @@ -39,6 +40,7 @@ static GMainLoop *loop = NULL; #define ARG_CREATE "create" #define ARG_SHOW "show" #define ARG_UUID "uuid" +#define ARG_IMPORT "import" #define NM_CE_DBUS_SERVICE "org.gnome.nm_connection_editor" #define NM_CE_DBUS_INTERFACE "org.gnome.nm_connection_editor" @@ -47,14 +49,27 @@ static GDBusNodeInfo *introspection_data = NULL; /*************************************************/ +typedef struct { + NMConnectionList *list; + GType ctype; + char *detail; + NMConnection *connection; +} CreateConnectionInfo; + static gboolean idle_create_connection (gpointer user_data) { - NMConnectionList *list = user_data; - GType ctype = (GType) GPOINTER_TO_SIZE (g_object_get_data (G_OBJECT (list), "nm-connection-editor-ctype")); - char *detail = g_object_get_data (G_OBJECT (list), "nm-connection-editor-detail"); + CreateConnectionInfo *info = user_data; + + if (!info->connection) + info->connection = nm_simple_connection_new (); + nm_connection_list_create (info->list, info->ctype, + info->detail, info->connection); - nm_connection_list_create (list, ctype, detail, nm_simple_connection_new ()); + g_object_unref (info->list); + g_free (info->detail); + g_object_unref (info->connection); + g_slice_free (CreateConnectionInfo, info); return FALSE; } @@ -64,12 +79,14 @@ handle_arguments (NMConnectionList *list, gboolean create, gboolean show, const char *edit_uuid, + const char *import, gboolean quit_after) { gboolean show_list = TRUE; GType ctype = 0; gs_free char *type_tmp = NULL; const char *p, *detail = NULL; + CreateConnectionInfo *info; if (type) { p = strchr (type, ':'); @@ -94,13 +111,20 @@ handle_arguments (NMConnectionList *list, /* If type is "vpn" and the user cancels the "vpn type" dialog, we need * to quit. But we haven't even started yet. So postpone this to an idle. */ - g_idle_add (idle_create_connection, list); - g_object_set_data (G_OBJECT (list), "nm-connection-editor-ctype", - GSIZE_TO_POINTER (ctype)); - g_object_set_data_full (G_OBJECT (list), "nm-connection-editor-detail", - g_strdup (detail), g_free); + info = g_slice_new0 (CreateConnectionInfo); + info->list = g_object_ref (list); + info->ctype = ctype; + info->detail = g_strdup (detail); + g_idle_add (idle_create_connection, info); } show_list = FALSE; + } else if (import) { + info = g_slice_new0 (CreateConnectionInfo); + info->list = g_object_ref (list); + info->ctype = NM_TYPE_SETTING_VPN; + info->connection = vpn_connection_from_file (import); + g_idle_add (idle_create_connection, info); + show_list = FALSE; } else if (edit_uuid) { /* Show the edit dialog for the given UUID */ nm_connection_list_edit (list, edit_uuid); @@ -125,7 +149,7 @@ handle_method_call (GDBusConnection *connection, gpointer user_data) { NMConnectionList *list = NM_CONNECTION_LIST (user_data); - char *type = NULL, *uuid = NULL; + char *type = NULL, *uuid = NULL, *import = NULL; gboolean create = FALSE, show = FALSE; if (g_strcmp0 (method_name, "Start") == 0) { @@ -137,7 +161,8 @@ handle_method_call (GDBusConnection *connection, g_variant_lookup (dict, ARG_UUID, "s", &uuid); g_variant_lookup (dict, ARG_CREATE, "b", &create); g_variant_lookup (dict, ARG_SHOW, "b", &show); - if (handle_arguments (list, type, create, show, uuid, FALSE)) + g_variant_lookup (dict, ARG_IMPORT, "s", &import); + if (handle_arguments (list, type, create, show, uuid, import, FALSE)) nm_connection_list_present (list); g_dbus_method_invocation_return_value (invocation, NULL); @@ -193,7 +218,8 @@ try_existing_instance (GDBusConnection *bus, const char *type, gboolean create, gboolean show, - const char *uuid) + const char *uuid, + const char *import) { gs_free char *owner = NULL; gs_free_error GError *error = NULL; @@ -234,6 +260,8 @@ try_existing_instance (GDBusConnection *bus, g_variant_builder_add (&builder, "{sv}", ARG_SHOW, g_variant_new_boolean (TRUE)); if (uuid) g_variant_builder_add (&builder, "{sv}", ARG_UUID, g_variant_new_string (uuid)); + if (import) + g_variant_builder_add (&builder, "{sv}", ARG_IMPORT, g_variant_new_string (import)); reply = g_dbus_connection_call_sync (bus, NM_CE_DBUS_SERVICE, @@ -273,7 +301,7 @@ main (int argc, char *argv[]) NMConnectionList *list = NULL; guint owner_id = 0, registration_id = 0; GDBusConnection *bus = NULL; - gs_free char *type = NULL, *uuid = NULL; + gs_free char *type = NULL, *uuid = NULL, *import = NULL; gboolean create = FALSE, show = FALSE; int ret = 1; @@ -282,6 +310,7 @@ main (int argc, char *argv[]) { ARG_CREATE, 'c', 0, G_OPTION_ARG_NONE, &create, "Create a new connection", NULL }, { ARG_SHOW, 's', 0, G_OPTION_ARG_NONE, &show, "Show a given connection type page", NULL }, { "edit", 'e', 0, G_OPTION_ARG_STRING, &uuid, "Edit an existing connection with a given UUID", "UUID" }, + { ARG_IMPORT, 'i', 0, G_OPTION_ARG_STRING, &import, "Import a VPN connection from given file", NULL }, /* This is not passed over D-Bus. */ { "keep-above", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &nm_ce_keep_above, NULL, NULL }, @@ -313,7 +342,7 @@ main (int argc, char *argv[]) * is one, send the arguments to it and exit instead of opening * a second instance of the connection editor. */ - if (try_existing_instance (bus, type, create, show, uuid)) { + if (try_existing_instance (bus, type, create, show, uuid, import)) { /* success */ ret = 0; goto out; @@ -332,7 +361,7 @@ main (int argc, char *argv[]) owner_id = start_service (bus, list, ®istration_id); /* Figure out what page or editor window we'll show initially */ - if (handle_arguments (list, type, create, show, uuid, (create || show || uuid))) + if (handle_arguments (list, type, create, show, uuid, import, (create || show || uuid || import))) nm_connection_list_present (list); g_unix_signal_add (SIGTERM, signal_handler, GINT_TO_POINTER (SIGTERM)); |