[network-manager-applet/lr/import: 1/5] arg



commit a383fb257a7cf86c89a4114b2d48a1316c7fd858
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Wed Oct 19 19:23:23 2016 +0200

    arg

 src/connection-editor/main.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/src/connection-editor/main.c b/src/connection-editor/main.c
index 185e95e..d991b8d 100644
--- a/src/connection-editor/main.c
+++ b/src/connection-editor/main.c
@@ -39,6 +39,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"
@@ -64,6 +65,7 @@ handle_arguments (NMConnectionList *list,
                   gboolean create,
                   gboolean show,
                   const char *edit_uuid,
+                  const char *import,
                   gboolean quit_after)
 {
        gboolean show_list = TRUE;
@@ -77,7 +79,9 @@ handle_arguments (NMConnectionList *list,
                        type = type_tmp = g_strndup (type, p - type);
                        detail = p + 1;
                }
-       } else
+       } else if (import)
+               type = NM_SETTING_VPN_SETTING_NAME;
+       else
                type = NM_SETTING_WIRED_SETTING_NAME;
 
        /* Grab type to create or show */
@@ -133,7 +137,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) {
@@ -145,7 +149,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);
@@ -201,7 +206,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;
@@ -242,6 +248,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,
@@ -281,7 +289,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;
 
@@ -290,6 +298,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 },
@@ -321,7 +330,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;
@@ -340,7 +349,7 @@ main (int argc, char *argv[])
        owner_id = start_service (bus, list, &registration_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]