[network-manager-applet/lr/import: 3/5] import



commit ff1b3613a047dd6d8d4296b4c2e3dbf96866e782
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Thu Oct 20 18:30:05 2016 +0200

    import

 src/connection-editor/page-vpn.c    |   89 +++++++++++++++++++++++++++++++++++
 src/connection-editor/vpn-helpers.c |   86 ---------------------------------
 src/connection-editor/vpn-helpers.h |    3 -
 3 files changed, 89 insertions(+), 89 deletions(-)
---
diff --git a/src/connection-editor/page-vpn.c b/src/connection-editor/page-vpn.c
index 90fda53..91bd47d 100644
--- a/src/connection-editor/page-vpn.c
+++ b/src/connection-editor/page-vpn.c
@@ -246,6 +246,95 @@ import_cb (NMConnection *connection, gpointer user_data)
        g_slice_free (NewVpnInfo, info);
 }
 
+typedef void (*VpnImportSuccessCallback) (NMConnection *connection, gpointer user_data);
+
+typedef struct {
+       VpnImportSuccessCallback callback;
+       gpointer user_data;
+} ActionInfo;
+
+static void
+import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data)
+{
+       char *filename = NULL;
+       ActionInfo *info = (ActionInfo *) user_data;
+       GSList *iter;
+       NMConnection *connection = NULL;
+       GError *error = 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;
+       }
+
+       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)
+               info->callback (connection, info->user_data);
+       else {
+               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);
+       g_free (filename);
+
+out:
+       gtk_widget_hide (dialog);
+       gtk_widget_destroy (dialog);
+       g_free (info);
+}
+
+static void
+vpn_import (VpnImportSuccessCallback callback, gpointer user_data)
+{
+       GtkWidget *dialog;
+       ActionInfo *info;
+       const char *home_folder;
+
+       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);
+
+       info = g_malloc0 (sizeof (ActionInfo));
+       info->callback = callback;
+       info->user_data = user_data;
+
+       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));
+}
+
+
 void
 vpn_connection_import (GtkWindow *parent,
                        const char *detail,
diff --git a/src/connection-editor/vpn-helpers.c b/src/connection-editor/vpn-helpers.c
index 0d81247..0835e08 100644
--- a/src/connection-editor/vpn-helpers.c
+++ b/src/connection-editor/vpn-helpers.c
@@ -97,92 +97,6 @@ vpn_get_plugin_infos (void)
        return plugins;
 }
 
-typedef struct {
-       VpnImportSuccessCallback callback;
-       gpointer user_data;
-} ActionInfo;
-
-static void
-import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data)
-{
-       char *filename = NULL;
-       ActionInfo *info = (ActionInfo *) user_data;
-       GSList *iter;
-       NMConnection *connection = NULL;
-       GError *error = 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;
-       }
-
-       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)
-               info->callback (connection, info->user_data);
-       else {
-               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);
-       g_free (filename);
-
-out:
-       gtk_widget_hide (dialog);
-       gtk_widget_destroy (dialog);
-       g_free (info);
-}
-
-void
-vpn_import (VpnImportSuccessCallback callback, gpointer user_data)
-{
-       GtkWidget *dialog;
-       ActionInfo *info;
-       const char *home_folder;
-
-       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);
-
-       info = g_malloc0 (sizeof (ActionInfo));
-       info->callback = callback;
-       info->user_data = user_data;
-
-       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));
-}
-
 gboolean
 vpn_supports_ipv6 (NMConnection *connection)
 {
diff --git a/src/connection-editor/vpn-helpers.h b/src/connection-editor/vpn-helpers.h
index 2b180ce..2fc62ab 100644
--- a/src/connection-editor/vpn-helpers.h
+++ b/src/connection-editor/vpn-helpers.h
@@ -32,9 +32,6 @@ GSList *vpn_get_plugin_infos (void);
 
 NMVpnEditorPlugin *vpn_get_plugin_by_service (const char *service);
 
-typedef void (*VpnImportSuccessCallback) (NMConnection *connection, gpointer user_data);
-void vpn_import (VpnImportSuccessCallback callback, gpointer user_data);
-
 gboolean vpn_supports_ipv6 (NMConnection *connection);
 
 #endif  /* _VPN_HELPERS_H_ */


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