summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2018-07-23 20:33:27 +0200
committerLubomir Rintel <lkundrak@v3.sk>2018-07-24 12:35:52 +0200
commit9d79ffdb148b31c7194c66946c87b6cd57ed54a3 (patch)
tree16364d0eb611bc561ba93147fd8339cc1b41745e
parent419c459e70ac752eb9226b0db1192fb0433d5d5e (diff)
downloadnetwork-manager-applet-9d79ffdb148b31c7194c66946c87b6cd57ed54a3.tar.gz
connection-list: attempt a VPN import first
On nm-connection-editor --import, nm_connection_list_create() is called with an empty ctype (G_TYPE_INVALID). This is not good -- on a successful import the first known type (which happens to be Bluetooth) would match. Let's treat this as "any connection type" -- attempt a VPN import opportunistically and if it succeeds, continute with a ctype of NM_TYPE_SETTING_VPN. Otherwise just bail out.
-rw-r--r--src/connection-editor/nm-connection-list.c69
1 files changed, 44 insertions, 25 deletions
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index d81aaae5..c5d09328 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -1042,12 +1042,41 @@ nm_connection_list_create (NMConnectionList *list,
NMConnectionListPrivate *priv;
ConnectionTypeData *types;
ConnectionResultData *data;
- GError *error = NULL;
+ gs_unref_object NMConnection *connection = NULL;
+ gs_free_error GError *error = NULL;
int i;
g_return_if_fail (NM_IS_CONNECTION_LIST (list));
priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
+ if (import_filename) {
+ if (ctype == G_TYPE_INVALID) {
+ /* Atempt a VPN import */
+ connection = vpn_connection_from_file (import_filename, NULL);
+ if (connection)
+ ctype = NM_TYPE_SETTING_VPN;
+ else
+ g_set_error (&error, NMA_ERROR, NMA_ERROR_GENERIC, _("Unrecognized connection type"));
+ } else if (ctype == NM_TYPE_SETTING_VPN) {
+ connection = vpn_connection_from_file (import_filename, &error);
+ } else {
+ g_set_error (&error, NMA_ERROR, NMA_ERROR_GENERIC,
+ _("Don’t know how to import “%s” connections"), g_type_name (ctype));
+ }
+
+ if (!connection) {
+ nm_connection_editor_error (NULL, _("Error importing connection"), "%s", error->message);
+ callback (list, user_data);
+ return;
+ }
+ }
+
+ if (ctype == G_TYPE_INVALID) {
+ nm_connection_editor_error (NULL, _("Error creating connection"), _("Connection type not specified."));
+ callback (list, user_data);
+ return;
+ }
+
types = get_connection_type_list ();
for (i = 0; types[i].name; i++) {
if ( types[i].setting_types[0] == ctype
@@ -1066,32 +1095,22 @@ nm_connection_list_create (NMConnectionList *list,
}
callback (list, user_data);
- } else {
- gs_unref_object NMConnection *connection = NULL;
+ return;
+ }
- if (import_filename) {
- connection = vpn_connection_from_file (import_filename, &error);
- if (!connection) {
- nm_connection_editor_error (NULL, _("Error importing connection"), error->message);
- callback (list, user_data);
- return;
- }
- }
+ data = g_slice_new0 (ConnectionResultData);
+ data->list = list;
+ data->callback = callback;
+ data->user_data = user_data;
- data = g_slice_new0 (ConnectionResultData);
- data->list = list;
- data->callback = callback;
- data->user_data = user_data;
-
- new_connection_of_type (GTK_WINDOW (list),
- detail,
- NULL,
- connection,
- priv->client,
- types[i].new_connection_func,
- really_add_connection,
- data);
- }
+ new_connection_of_type (GTK_WINDOW (list),
+ detail,
+ NULL,
+ connection,
+ priv->client,
+ types[i].new_connection_func,
+ really_add_connection,
+ data);
}
void