[network-manager-applet/lr/import] x
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/lr/import] x
- Date: Tue, 25 Oct 2016 12:54:16 +0000 (UTC)
commit c8bbb740e9625d9851f6b5c1fe675eee0ce0e9fb
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Mon Oct 24 11:30:59 2016 +0200
x
src/connection-editor/ce-page.c | 22 +++--
src/connection-editor/connection-helpers.c | 159 ++++++++++++++++++++++++++++
src/connection-editor/page-vpn.c | 79 +++-----------
src/connection-editor/page-vpn.h | 7 --
4 files changed, 187 insertions(+), 80 deletions(-)
---
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index de111a5..a1a0d36 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -819,23 +819,27 @@ ce_page_complete_connection (NMConnection *connection,
char *uuid, *id;
const GPtrArray *connections;
- s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
- nm_connection_add_setting (connection, NM_SETTING (s_con));
-
- uuid = nm_utils_uuid_generate ();
+ s_con = nm_connection_get_setting_connection (connection);
+ if (!s_con) {
+ s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+ nm_connection_add_setting (connection, NM_SETTING (s_con));
+ }
- connections = nm_client_get_connections (client);
- id = ce_page_get_next_available_name (connections, format);
+ id = nm_setting_connection_get_id (s_con);
+ if (!id) {
+ connections = nm_client_get_connections (client);
+ id = ce_page_get_next_available_name (connections, format);
+ g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL);
+ g_free (id);
+ }
+ uuid = nm_utils_uuid_generate ();
g_object_set (s_con,
NM_SETTING_CONNECTION_UUID, uuid,
- NM_SETTING_CONNECTION_ID, id,
NM_SETTING_CONNECTION_TYPE, ctype,
NM_SETTING_CONNECTION_AUTOCONNECT, autoconnect,
NULL);
-
g_free (uuid);
- g_free (id);
}
CEPage *
diff --git a/src/connection-editor/connection-helpers.c b/src/connection-editor/connection-helpers.c
index 85261ef..c6570e1 100644
--- a/src/connection-editor/connection-helpers.c
+++ b/src/connection-editor/connection-helpers.c
@@ -170,6 +170,165 @@ no_description:
gtk_label_set_text (label, "");
}
+
+
+
+
+
+
+
+
+
+
+static NMConnection *
+vpn_import_from_file (const char *filename, NMClient *client)
+{
+ NMConnection *connection = NULL;
+ const char *service_type;
+ NMSettingConnection *s_con;
+ NMSettingVpn *s_vpn;
+ GError *error = NULL;
+ GSList *iter;
+ char *s;
+
+ for (iter = vpn_get_plugin_infos (); !connection && iter; iter = iter->next) {
+ NMVpnEditorPlugin *plugin;
+
+ plugin = nm_vpn_plugin_info_get_editor_plugin (iter->data);
+ g_clear_error (&error);
+ connection = nm_vpn_editor_plugin_import (plugin, filename, &error);
+ if (connection)
+ break;
+ }
+
+ if (connection) {
+ /* Sanity check the connection. */
+ s_vpn = nm_connection_get_setting_vpn (connection);
+ service_type = s_vpn ? nm_setting_vpn_get_service_type (s_vpn) : NULL;
+
+ if (!service_type || !strlen (service_type)) {
+ g_object_unref (connection);
+ connection = NULL;
+
+ error = g_error_new_literal (NMA_ERROR, NMA_ERROR_GENERIC,
+ _("The VPN plugin failed to import the VPN connection
correctly\n\nError: no VPN service type."));
+ }
+ }
+
+ if (!connection) {
+ GtkWidget *err_dialog;
+ char *bname = g_path_get_basename (filename);
+
+ err_dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Cannot import VPN connection"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (err_dialog),
+ _("The file ā%sā could not be read or does not contain
recognized VPN connection information\n\nError: %s."),
+ bname, error ? error->message : _("unknown error"));
+ g_free (bname);
+ g_signal_connect (err_dialog, "delete-event", G_CALLBACK (gtk_widget_destroy), NULL);
+ g_signal_connect (err_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+ gtk_widget_show_all (err_dialog);
+ gtk_window_present (GTK_WINDOW (err_dialog));
+ }
+
+ g_clear_error (&error);
+
+ return connection;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ NMClient *client;
+ PageNewConnectionResultFunc result_func;
+ gpointer user_data;
+} NewVpnInfo;
+
+
+
+
+static void
+import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data)
+{
+ char *filename = NULL;
+ NewVpnInfo *info = (NewVpnInfo *) user_data;
+ NMConnection *connection = NULL;
+
+ if (response != GTK_RESPONSE_ACCEPT)
+ goto out;
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ if (!filename) {
+ g_warning ("%s: didn't get a filename back from the chooser!", __func__);
+ goto out;
+ }
+
+ connection = vpn_import_from_file (filename, info->client);
+//g_printerr ("CAN HAS 1 %p\n", connection);
+//nm_connection_dump (connection);
+ if (connection)
+ info->result_func (connection, FALSE, NULL, info->user_data);
+//g_printerr ("CAN HAS 2 %p\n", connection);
+
+ g_free (filename);
+out:
+ gtk_widget_hide (dialog);
+ gtk_widget_destroy (dialog);
+ g_object_unref (info->client);
+ g_slice_free (NewVpnInfo, info);
+}
+
+
+
+
+
+
+static void
+vpn_connection_import (GtkWindow *parent,
+ const char *detail,
+ gpointer detail_data,
+ NMClient *client,
+ PageNewConnectionResultFunc result_func,
+ gpointer user_data)
+{
+ NewVpnInfo *info;
+ GtkWidget *dialog;
+ const char *home_folder;
+
+ info = g_slice_new (NewVpnInfo);
+ info->result_func = result_func;
+ info->client = g_object_ref (client);
+ info->user_data = user_data;
+
+ dialog = gtk_file_chooser_dialog_new (_("Select file to import"),
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ home_folder = g_get_home_dir ();
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), home_folder);
+
+ g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (import_vpn_from_file_cb), info);
+ gtk_widget_show_all (dialog);
+ gtk_window_present (GTK_WINDOW (dialog));
+}
+
+
+
+
static void
set_up_connection_type_combo (GtkComboBox *combo,
GtkLabel *description_label,
diff --git a/src/connection-editor/page-vpn.c b/src/connection-editor/page-vpn.c
index 1a519e4..9b9cc30 100644
--- a/src/connection-editor/page-vpn.c
+++ b/src/connection-editor/page-vpn.c
@@ -198,6 +198,18 @@ typedef struct {
gpointer user_data;
} ActionInfo;
+static void
+complete_vpn_connection (NMConnection *connection, NMClient *client)
+{
+ ce_page_complete_connection (connection,
+ _("VPN connection %d"),
+ NM_SETTING_VPN_SETTING_NAME,
+ FALSE,
+ client);
+}
+
+
+#if 0
static NMConnection *
vpn_import_from_file (const char *filename, NMClient *client)
{
@@ -281,65 +293,7 @@ vpn_import_from_file (const char *filename, NMClient *client)
return connection;
}
-
-static void
-import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data)
-{
- char *filename = NULL;
- NewVpnInfo *info = (NewVpnInfo *) user_data;
- NMConnection *connection = NULL;
-
- if (response != GTK_RESPONSE_ACCEPT)
- goto out;
-
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- if (!filename) {
- g_warning ("%s: didn't get a filename back from the chooser!", __func__);
- goto out;
- }
-
- connection = vpn_import_from_file (filename, info->client);
- if (connection)
- info->result_func (connection, FALSE, NULL, info->user_data);
-
- g_free (filename);
-out:
- gtk_widget_hide (dialog);
- gtk_widget_destroy (dialog);
- g_object_unref (info->client);
- g_slice_free (NewVpnInfo, info);
-}
-
-void
-vpn_connection_import (GtkWindow *parent,
- const char *detail,
- gpointer detail_data,
- NMClient *client,
- PageNewConnectionResultFunc result_func,
- gpointer user_data)
-{
- NewVpnInfo *info;
- GtkWidget *dialog;
- const char *home_folder;
-
- info = g_slice_new (NewVpnInfo);
- info->result_func = result_func;
- info->client = g_object_ref (client);
- info->user_data = user_data;
-
- dialog = gtk_file_chooser_dialog_new (_("Select file to import"),
- NULL,
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
- home_folder = g_get_home_dir ();
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), home_folder);
-
- g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (import_vpn_from_file_cb), info);
- gtk_widget_show_all (dialog);
- gtk_window_present (GTK_WINDOW (dialog));
-}
+#endif
#define NEW_VPN_CONNECTION_PRIMARY_LABEL _("Choose a VPN Connection Type")
#define NEW_VPN_CONNECTION_SECONDARY_LABEL _("Select the type of VPN you wish to use for the new connection.
If the type of VPN connection you wish to create does not appear in the list, you may not have the correct
VPN plugin installed.")
@@ -440,11 +394,8 @@ vpn_connection_new (GtkWindow *parent,
service_type = detail;
connection = nm_simple_connection_new ();
- ce_page_complete_connection (connection,
- _("VPN connection %d"),
- NM_SETTING_VPN_SETTING_NAME,
- FALSE,
- client);
+ complete_vpn_connection (connection, client);
+
s_vpn = nm_setting_vpn_new ();
g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, service_type, NULL);
diff --git a/src/connection-editor/page-vpn.h b/src/connection-editor/page-vpn.h
index 18994c9..6e7ba9a 100644
--- a/src/connection-editor/page-vpn.h
+++ b/src/connection-editor/page-vpn.h
@@ -66,11 +66,4 @@ void vpn_connection_new (GtkWindow *parent,
PageNewConnectionResultFunc result_func,
gpointer user_data);
-void vpn_connection_import (GtkWindow *parent,
- const char *detail,
- gpointer detail_data,
- NMClient *client,
- PageNewConnectionResultFunc result_func,
- gpointer user_data);
-
#endif /* __PAGE_VPN_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]