[network-manager-applet/lr/import: 4/5] editor: add --import command line argument
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/lr/import: 4/5] editor: add --import command line argument
- Date: Thu, 10 Nov 2016 18:09:41 +0000 (UTC)
commit 0d8daa451e31ce36b2f79bb8020d6b3a2fdd3eaf
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Sun Oct 30 16:06:30 2016 +0100
editor: add --import command line argument
It currently can only import VPN connections.
src/connection-editor/main.c | 29 +++++++++++++++++++++++------
1 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/src/connection-editor/main.c b/src/connection-editor/main.c
index 745a367..60b2236 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"
@@ -65,12 +67,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;
+ NMConnection *connection = NULL;
if (type) {
p = strchr (type, ':');
@@ -102,6 +106,14 @@ handle_arguments (NMConnectionList *list,
g_strdup (detail), g_free);
}
show_list = FALSE;
+ } else if (import) {
+ connection = vpn_connection_from_file (import);
+ g_idle_add (idle_create_connection, list);
+ g_object_set_data (G_OBJECT (list), "nm-connection-editor-ctype",
+ GSIZE_TO_POINTER (NM_TYPE_SETTING_VPN));
+ g_object_set_data_full (G_OBJECT (list), "nm-connection-editor-connection",
+ nm_g_object_ref (connection), nm_g_object_unref);
+ show_list = FALSE;
} else if (edit_uuid) {
/* Show the edit dialog for the given UUID */
nm_connection_list_edit (list, edit_uuid);
@@ -126,7 +138,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) {
@@ -138,7 +150,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);
@@ -194,7 +207,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;
@@ -235,6 +249,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,
@@ -274,7 +290,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;
@@ -283,6 +299,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 },
@@ -314,7 +331,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;
@@ -333,7 +350,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));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]