[network-manager-applet/th/tmp] nm-c-e: let --create show the "Add" connection dialog



commit e0bc789fe78895d0e41a88a02928ee161749bb57
Author: Thomas Haller <thaller redhat com>
Date:   Wed Oct 19 19:17:40 2016 +0200

    nm-c-e: let --create show the "Add" connection dialog
    
    Previously, `nm-connection-editor --create` without explicit --type argument
    would directly create an ethernet connection. Now, open instead the list
    of connection types, as if the user clicks "Add" in the main menu.

 src/connection-editor/main.c               |   44 ++++++++++++---------------
 src/connection-editor/nm-connection-list.c |    8 ++++-
 src/connection-editor/nm-connection-list.h |    1 +
 3 files changed, 28 insertions(+), 25 deletions(-)
---
diff --git a/src/connection-editor/main.c b/src/connection-editor/main.c
index 185e95e..4b1de97 100644
--- a/src/connection-editor/main.c
+++ b/src/connection-editor/main.c
@@ -67,8 +67,8 @@ handle_arguments (NMConnectionList *list,
                   gboolean quit_after)
 {
        gboolean show_list = TRUE;
-       GType ctype;
-       char *type_tmp = NULL;
+       GType ctype = 0;
+       gs_free char *type_tmp = NULL;
        const char *p, *detail = NULL;
 
        if (type) {
@@ -77,36 +77,33 @@ handle_arguments (NMConnectionList *list,
                        type = type_tmp = g_strndup (type, p - type);
                        detail = p + 1;
                }
-       } else
-               type = NM_SETTING_WIRED_SETTING_NAME;
+       }
 
        /* Grab type to create or show */
-       ctype = nm_setting_lookup_type (type);
-       if (ctype == 0) {
-               g_warning ("Unknown connection type '%s'", type);
-               g_free (type_tmp);
-               return TRUE;
+       if (type) {
+               ctype = nm_setting_lookup_type (type);
+               if (ctype == 0) {
+                       g_warning ("Unknown connection type '%s'", type);
+                       return TRUE;
+               }
        }
 
        if (show) {
                /* Just show the given connection type page */
                nm_connection_list_set_type (list, ctype);
        } else if (create) {
-               if (!type) {
-                       g_warning ("'create' requested but no connection type given.");
-                       g_free (type_tmp);
-                       return TRUE;
+               if (!ctype)
+                       nm_connection_list_add (list);
+               else {
+                       /* 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);
                }
-
-               /* 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);
-
                show_list = FALSE;
        } else if (edit_uuid) {
                /* Show the edit dialog for the given UUID */
@@ -118,7 +115,6 @@ handle_arguments (NMConnectionList *list,
        if (show_list == FALSE && quit_after == TRUE)
                g_signal_connect_swapped (list, "editing-done", G_CALLBACK (g_main_loop_quit), loop);
 
-       g_free (type_tmp);
        return show_list;
 }
 
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index 3210168..bdd4bc1 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -296,7 +296,13 @@ really_add_connection (NMConnection *connection,
 static void
 add_clicked (GtkButton *button, gpointer user_data)
 {
-       NMConnectionList *list = user_data;
+       nm_connection_list_add (user_data);
+}
+
+void
+nm_connection_list_add (NMConnectionList *list)
+{
+       g_return_if_fail (NM_IS_CONNECTION_LIST (list));
 
        new_connection_dialog (GTK_WINDOW (list->dialog),
                               list->client,
diff --git a/src/connection-editor/nm-connection-list.h b/src/connection-editor/nm-connection-list.h
index 046f2e3..6d382bc 100644
--- a/src/connection-editor/nm-connection-list.h
+++ b/src/connection-editor/nm-connection-list.h
@@ -67,5 +67,6 @@ void              nm_connection_list_set_type (NMConnectionList *list, GType cty
 void              nm_connection_list_present (NMConnectionList *list);
 void              nm_connection_list_create (NMConnectionList *list, GType ctype, const char *detail);
 void              nm_connection_list_edit (NMConnectionList *list, const gchar *uuid);
+void              nm_connection_list_add (NMConnectionList *list);
 
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]