[network-manager-applet/th/vpn-service-info-bgo767197] c-e: allow one VPN plugin to create multiple "Add" entires



commit 906ae62dab739e507d15cf0381a7c2f2cf299c04
Author: Thomas Haller <thaller redhat com>
Date:   Fri Jun 3 17:31:48 2016 +0200

    c-e: allow one VPN plugin to create multiple "Add" entires
    
    Previously already, one VPN plugin could edit connections with different
    service-types, using aliases. That is for example used for nm-libreswan,
    which supports both libreswan and openswan types.
    
    However, in "Connection Add" one plugin could only create one entry
    in the list of supported types. Thus, the vpn.service-type could
    only be set to the main service-type, and one plugin could not create
    different types.
    
    Extend that, by allowing the VPN to specify that it supports adding
    of connections also for alias types.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=767197

 src/connection-editor/ce-new-connection.ui |   12 ++-
 src/connection-editor/connection-helpers.c |  112 +++++++++++++++++++---------
 src/connection-editor/vpn-helpers.c        |   27 +++++++
 src/connection-editor/vpn-helpers.h        |    7 ++
 4 files changed, 118 insertions(+), 40 deletions(-)
---
diff --git a/src/connection-editor/ce-new-connection.ui b/src/connection-editor/ce-new-connection.ui
index ec4a3c9..180a37e 100644
--- a/src/connection-editor/ce-new-connection.ui
+++ b/src/connection-editor/ce-new-connection.ui
@@ -4,14 +4,18 @@
   <requires lib="gtk+" version="3.0"/>
   <object class="GtkListStore" id="new_connection_combo_model">
     <columns>
-      <!-- column-name name -->
+      <!-- column-name name, COL_MARKUP -->
       <column type="gchararray"/>
-      <!-- column-name sensitive -->
+      <!-- column-name sensitive, COL_SENSITIVE -->
       <column type="gboolean"/>
-      <!-- column-name new_func -->
+      <!-- column-name new_func, COL_NEW_FUNC -->
       <column type="gpointer"/>
-      <!-- column-name vpn_plugin -->
+      <!-- column-name vpn_plugin, COL_VPN_PLUGIN -->
       <column type="GObject"/>
+      <!-- column-name vpn_service_type, COL_VPN_SERVICE_TYPE -->
+      <column type="gchararray"/>
+      <!-- column-name vpn_is_alias, COL_VPN_IS_ALIAS -->
+      <column type="gboolean"/>
     </columns>
   </object>
   <object class="GtkDialog" id="new_connection_type_dialog">
diff --git a/src/connection-editor/connection-helpers.c b/src/connection-editor/connection-helpers.c
index 9cc789c..9e67b26 100644
--- a/src/connection-editor/connection-helpers.c
+++ b/src/connection-editor/connection-helpers.c
@@ -40,6 +40,8 @@
 #define COL_SENSITIVE  1
 #define COL_NEW_FUNC   2
 #define COL_VPN_PLUGIN 3
+#define COL_VPN_SERVICE_TYPE 4
+#define COL_VPN_IS_ALIAS 5
 
 static gint
 sort_types (gconstpointer a, gconstpointer b)
@@ -141,8 +143,11 @@ combo_changed_cb (GtkComboBox *combo, gpointer user_data)
        GtkLabel *label = GTK_LABEL (user_data);
        GtkTreeModel *model;
        GtkTreeIter iter;
-       NMVpnEditorPlugin *plugin = NULL;
-       char *description, *markup;
+       gs_unref_object NMVpnEditorPlugin *plugin = NULL;
+       gs_free char *service_type = NULL;
+       gs_free char *description = NULL;
+       gs_free char *markup = NULL;
+       gboolean is_alias;
 
        if (!gtk_combo_box_get_active_iter (combo, &iter))
                goto error;
@@ -151,19 +156,24 @@ combo_changed_cb (GtkComboBox *combo, gpointer user_data)
        if (!model)
                goto error;
 
-       gtk_tree_model_get (model, &iter, COL_VPN_PLUGIN, &plugin, -1);
-       if (!plugin)
+       gtk_tree_model_get (model, &iter,
+                           COL_VPN_PLUGIN, &plugin,
+                           COL_VPN_SERVICE_TYPE, &service_type,
+                           COL_VPN_IS_ALIAS, &is_alias,
+                           -1);
+       if (!plugin || !service_type)
                goto error;
 
-       g_object_get (G_OBJECT (plugin), NM_VPN_EDITOR_PLUGIN_DESCRIPTION, &description, NULL);
-       g_object_unref (plugin);
+       if (is_alias)
+               nm_vpn_editor_plugin_get_service_info (plugin, service_type, NULL, NULL, &description, NULL);
+       else
+               g_object_get (G_OBJECT (plugin), NM_VPN_EDITOR_PLUGIN_DESCRIPTION, &description, NULL);
+
        if (!description)
                goto error;
 
        markup = g_markup_printf_escaped ("<i>%s</i>", description);
        gtk_label_set_markup (label, markup);
-       g_free (markup);
-       g_free (description);
        return;
 
 error:
@@ -171,6 +181,34 @@ error:
 }
 
 static void
+_combo_entry_add_vpn (GtkListStore *model,
+                      GtkTreeIter *iter,
+                      NMVpnEditorPlugin *plugin,
+                      const char *service_type,
+                      const char *name,
+                      gboolean is_alias,
+                      gboolean show_headers,
+                      PageNewConnectionFunc new_connection_func)
+{
+       gs_free char *markup = NULL;
+
+       if (show_headers)
+               markup = g_markup_printf_escaped ("    %s", name);
+       else
+               markup = g_markup_escape_text (name, -1);
+
+       gtk_list_store_append (model, iter);
+       gtk_list_store_set (model, iter,
+                           COL_MARKUP, markup,
+                           COL_SENSITIVE, TRUE,
+                           COL_NEW_FUNC, new_connection_func,
+                           COL_VPN_PLUGIN, plugin,
+                           COL_VPN_SERVICE_TYPE, service_type,
+                           COL_VPN_IS_ALIAS, is_alias,
+                           -1);
+}
+
+static void
 set_up_connection_type_combo (GtkComboBox *combo,
                               GtkLabel *description_label,
                               NewConnectionTypeFilterFunc type_filter_func,
@@ -259,24 +297,34 @@ set_up_connection_type_combo (GtkComboBox *combo,
        }
 
        for (p = vpn_plugins; p; p = p->next) {
-               NMVpnEditorPlugin *plugin = nm_vpn_plugin_info_get_editor_plugin (p->data);
-               char *desc;
+               NMVpnPluginInfo *plugin_info = p->data;
+               NMVpnEditorPlugin *plugin = nm_vpn_plugin_info_get_editor_plugin (plugin_info);
+               const char *const*aliases = nm_vpn_plugin_info_get_aliases (plugin_info);
+               gs_free char *p_service_type = NULL;
+               gs_free char *p_desc = NULL;
 
-               g_object_get (plugin, NM_VPN_EDITOR_PLUGIN_NAME, &desc, NULL);
+               g_object_get (plugin, NM_VPN_EDITOR_PLUGIN_NAME, &p_desc, NULL);
+               g_object_get (plugin, NM_VPN_EDITOR_PLUGIN_SERVICE, &p_service_type, NULL);
 
-               if (show_headers)
-                       markup = g_markup_printf_escaped ("    %s", desc);
-               else
-                       markup = g_markup_escape_text (desc, -1);
-               gtk_list_store_append (model, &iter);
-               gtk_list_store_set (model, &iter,
-                                   COL_MARKUP, markup,
-                                   COL_SENSITIVE, TRUE,
-                                   COL_NEW_FUNC, list[vpn_index].new_connection_func,
-                                   COL_VPN_PLUGIN, plugin,
-                                   -1);
-               g_free (markup);
-               g_free (desc);
+               if (p_service_type && p_desc)
+                       _combo_entry_add_vpn (model, &iter, plugin, p_service_type, p_desc, FALSE, 
show_headers, list[vpn_index].new_connection_func);
+
+               aliases = nm_vpn_plugin_info_get_aliases (plugin_info);
+               for (; aliases && aliases[0]; aliases++) {
+                       const char *service_type = aliases[0];
+                       gs_free char *name = NULL;
+                       guint flags;
+
+                       if (!nm_vpn_editor_plugin_get_service_info (plugin, service_type, NULL, &name, NULL, 
&flags))
+                               continue;
+
+                       if (!name)
+                               continue;
+                       if (!NM_FLAGS_HAS (flags, NM_VPN_EDITOR_PLUGIN_SERVICE_FLAGS_CAN_ADD))
+                               continue;
+
+                       _combo_entry_add_vpn (model, &iter, plugin, service_type, name, TRUE, show_headers, 
list[vpn_index].new_connection_func);
+               }
 
                if (nm_vpn_editor_plugin_get_capabilities (plugin) & NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT)
                        import_supported = TRUE;
@@ -389,8 +437,7 @@ new_connection_dialog_full (GtkWindow *parent_window,
        GtkTreeIter iter;
        int response;
        PageNewConnectionFunc new_func = NULL;
-       NMVpnEditorPlugin *plugin = NULL;
-       char *vpn_type = NULL;
+       gs_free char *vpn_service_type = NULL;
        GError *error = NULL;
 
        /* load GUI */
@@ -425,24 +472,17 @@ new_connection_dialog_full (GtkWindow *parent_window,
                gtk_combo_box_get_active_iter (combo, &iter);
                gtk_tree_model_get (gtk_combo_box_get_model (combo), &iter,
                                    COL_NEW_FUNC, &new_func,
-                                   COL_VPN_PLUGIN, &plugin,
+                                   COL_VPN_SERVICE_TYPE, &vpn_service_type,
                                    -1);
-
-               if (plugin) {
-                       g_object_get (G_OBJECT (plugin), NM_VPN_EDITOR_PLUGIN_SERVICE, &vpn_type, NULL);
-                       g_object_unref (plugin);
-               }
        }
 
        gtk_widget_destroy (GTK_WIDGET (type_dialog));
        g_object_unref (gui);
 
-       if (new_func)
-               new_connection_of_type (parent_window, vpn_type, client, new_func, result_func, user_data);
+       if (new_func && vpn_service_type)
+               new_connection_of_type (parent_window, vpn_service_type, client, new_func, result_func, 
user_data);
        else
                result_func (NULL, user_data);
-
-       g_free (vpn_type);
 }
 
 typedef struct {
diff --git a/src/connection-editor/vpn-helpers.c b/src/connection-editor/vpn-helpers.c
index 35823c7..aeb42d6 100644
--- a/src/connection-editor/vpn-helpers.c
+++ b/src/connection-editor/vpn-helpers.c
@@ -334,3 +334,30 @@ vpn_supports_ipv6 (NMConnection *connection)
        capabilities = nm_vpn_editor_plugin_get_capabilities (plugin);
        return (capabilities & NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6) != 0;
 }
+
+gboolean
+nm_vpn_editor_plugin_get_service_info (NMVpnEditorPlugin *plugin,
+                                       const char *service_name,
+                                       char **out_short_name,
+                                       char **out_pretty_name,
+                                       char **out_description,
+                                       guint *out_flags)
+{
+       gs_free char *short_name_dummy = NULL;
+       gs_free char *pretty_name_dummy = NULL;
+       gs_free char *description_dummy = NULL;
+       guint flags_dummy = 0;
+
+       g_return_val_if_fail (NM_IS_VPN_EDITOR_PLUGIN (plugin), FALSE);
+       g_return_val_if_fail (service_name, FALSE);
+
+       return nm_vpn_editor_plugin_call (plugin,
+                                         NM_VPN_EDITOR_PLUGIN_CALL_GET_SERVICE_INFO,
+                                         NULL,
+                                         service_name,
+                                         out_short_name ?: &short_name_dummy,
+                                         out_pretty_name ?: &pretty_name_dummy,
+                                         out_description ?: &description_dummy,
+                                         out_flags ?: &flags_dummy);
+}
+
diff --git a/src/connection-editor/vpn-helpers.h b/src/connection-editor/vpn-helpers.h
index bc017fb..98790fe 100644
--- a/src/connection-editor/vpn-helpers.h
+++ b/src/connection-editor/vpn-helpers.h
@@ -39,4 +39,11 @@ void vpn_export (NMConnection *connection);
 
 gboolean vpn_supports_ipv6 (NMConnection *connection);
 
+gboolean nm_vpn_editor_plugin_get_service_info (NMVpnEditorPlugin *plugin,
+                                                const char *service_name,
+                                                char **out_short_name,
+                                                char **out_pretty_name,
+                                                char **out_description,
+                                                guint *out_flags);
+
 #endif  /* _VPN_HELPERS_H_ */


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