[network-manager-openconnect/lr/libnm: 2/9] properties: port the new plugin to libnm



commit d0dda2c66ad22291909ae76f6a1e8fc8e5f7c7fc
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Thu Jul 16 15:48:37 2015 +0200

    properties: port the new plugin to libnm

 auth-dialog/Makefile.am        |    4 +-
 auth-dialog/main.c             |    2 +-
 configure.ac                   |   14 ++++--
 nm-openconnect-service.name.in |    5 ++-
 properties/Makefile.am         |    8 ++--
 properties/auth-helpers.c      |    8 ++--
 properties/auth-helpers.h      |   11 +++-
 properties/nm-openconnect.c    |  104 +++++++++++++++++++++++----------------
 src/Makefile.am                |    6 +-
 9 files changed, 96 insertions(+), 66 deletions(-)
---
diff --git a/auth-dialog/Makefile.am b/auth-dialog/Makefile.am
index c0c135d..4545bbc 100644
--- a/auth-dialog/Makefile.am
+++ b/auth-dialog/Makefile.am
@@ -1,7 +1,7 @@
 libexec_PROGRAMS = nm-openconnect-auth-dialog
 
 nm_openconnect_auth_dialog_CPPFLAGS = \
-       $(NM_CFLAGS) \
+       $(LIBNM_GLIB_CFLAGS) \
        $(GLIB_CFLAGS) \
        $(GTK_CFLAGS) \
        $(OPENCONNECT_CFLAGS) \
@@ -21,7 +21,7 @@ nm_openconnect_auth_dialog_SOURCES = \
 
 nm_openconnect_auth_dialog_LDADD = \
        $(GTK_LIBS) \
-       $(NM_LIBS) \
+       $(LIBNM_GLIB_LIBS) \
        $(OPENCONNECT_LIBS) \
        $(LIBXML_LIBS) \
        $(LIBSECRET_LIBS)
diff --git a/auth-dialog/main.c b/auth-dialog/main.c
index 83cb870..2602e2b 100644
--- a/auth-dialog/main.c
+++ b/auth-dialog/main.c
@@ -45,7 +45,7 @@
 #define SECRET_API_SUBJECT_TO_CHANGE
 #include <libsecret/secret.h>
 
-#include "../src/nm-openconnect-service.h"
+#include "../src/nm-openconnect-service-defines.h"
 
 #include "openconnect.h"
 
diff --git a/configure.ac b/configure.ac
index 654999a..efb7c2b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,11 +70,11 @@ if test x"$with_gnome" != xno; then
        fi
 fi
 
-PKG_CHECK_MODULES(NM,
-                  NetworkManager >= 0.9.10
-                  libnm-util >= 0.9.10
-                  libnm-glib  >= 0.9.10
-                  libnm-glib-vpn >= 0.9.10)
+PKG_CHECK_MODULES(LIBNM_GLIB,
+                  NetworkManager >= 1.1.0
+                  libnm-util >= 1.1.0
+                  libnm-glib  >= 1.1.0
+                  libnm-glib-vpn >= 1.1.0)
 
 dnl
 dnl Distribution version string
@@ -84,6 +84,10 @@ if ! test x"$ac_distver" = x""; then
   AC_DEFINE_UNQUOTED(DIST_VERSION, "$ac_distver", [Define the distribution version string])
 fi
 
+PKG_CHECK_MODULES(LIBNM, libnm >= 1.1.0)
+LIBNM_CFLAGS="$LIBNM_CFLAGS -DNM_VERSION_MIN_REQUIRED=NM_VERSION_1_2"
+LIBNM_CFLAGS="$LIBNM_CFLAGS -DNM_VERSION_MAX_ALLOWED=NM_VERSION_1_2"
+
 NM_COMPILER_WARNINGS
 
 AC_CONFIG_FILES([
diff --git a/nm-openconnect-service.name.in b/nm-openconnect-service.name.in
index 992837a..db9bd61 100644
--- a/nm-openconnect-service.name.in
+++ b/nm-openconnect-service.name.in
@@ -3,6 +3,9 @@ name=openconnect
 service=org.freedesktop.NetworkManager.openconnect
 program= LIBEXECDIR@/nm-openconnect-service
 
+[libnm]
+plugin= PLUGINDIR@/libnm-openconnect-properties
+
 [GNOME]
 auth-dialog= LIBEXECDIR@/nm-openconnect-auth-dialog
-properties= PLUGINDIR@/libnm-openconnect-properties
+properties= PLUGINDIR@/libnm-openconnect-properties-old
diff --git a/properties/Makefile.am b/properties/Makefile.am
index a5dcaf6..aba4b1f 100644
--- a/properties/Makefile.am
+++ b/properties/Makefile.am
@@ -27,21 +27,21 @@ common_CFLAGS =                                         \
 
 libnm_openconnect_properties_la_CFLAGS =                \
        $(common_CFLAGS)                                \
-       $(NM_CFLAGS)
+       $(LIBNM_CFLAGS)
 
 libnm_openconnect_properties_old_la_CFLAGS =            \
        -DNM_OPENCONNECT_OLD                            \
        $(common_CFLAGS)                                \
-       $(NM_CFLAGS)
+       $(LIBNM_GLIB_CFLAGS)
 
 libnm_openconnect_properties_la_LIBADD = \
        $(GTK_LIBS) \
-       $(NM_LIBS) \
+       $(LIBNM_LIBS) \
        $(OPENCONNECT_LIBS)
 
 libnm_openconnect_properties_old_la_LIBADD = \
        $(GTK_LIBS) \
-       $(NM_LIBS) \
+       $(LIBNM_GLIB_LIBS) \
        $(OPENCONNECT_LIBS)
 
 libnm_openconnect_properties_la_LDFLAGS = \
diff --git a/properties/auth-helpers.c b/properties/auth-helpers.c
index 919ddfc..db47443 100644
--- a/properties/auth-helpers.c
+++ b/properties/auth-helpers.c
@@ -37,12 +37,12 @@
 
 #include "auth-helpers.h"
 #include "nm-openconnect.h"
-#include "../src/nm-openconnect-service.h"
+#include "../src/nm-openconnect-service-defines.h"
 
 void
 tls_pw_init_auth_widget (GtkBuilder *builder,
                          GtkSizeGroup *group,
-                         NMSettingVPN *s_vpn,
+                         NMSettingVpn *s_vpn,
                          ChangedCallback changed_cb,
                          gpointer user_data)
 {
@@ -113,7 +113,7 @@ static void
 update_from_filechooser (GtkBuilder *builder,
                          const char *key,
                          const char *widget_name,
-                         NMSettingVPN *s_vpn)
+                         NMSettingVpn *s_vpn)
 {
        GtkWidget *widget;
        char *filename;
@@ -143,7 +143,7 @@ update_from_filechooser (GtkBuilder *builder,
 gboolean
 auth_widget_update_connection (GtkBuilder *builder,
                                const char *contype,
-                               NMSettingVPN *s_vpn)
+                               NMSettingVpn *s_vpn)
 {
        update_from_filechooser (builder, NM_OPENCONNECT_KEY_CACERT, "ca_cert_chooser", s_vpn);
        update_from_filechooser (builder, NM_OPENCONNECT_KEY_USERCERT, "cert_user_cert_chooser", s_vpn);
diff --git a/properties/auth-helpers.h b/properties/auth-helpers.h
index f43c928..19ac773 100644
--- a/properties/auth-helpers.h
+++ b/properties/auth-helpers.h
@@ -26,20 +26,25 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 
+#ifdef NM_OPENCONNECT_OLD
+#define NM_VPN_LIBNM_COMPAT
 #include <nm-connection.h>
 #include <nm-setting-vpn.h>
+#else /* !NM_OPENCONNECT_OLD */
+#include <NetworkManager.h>
+#endif
 
 typedef void (*ChangedCallback) (GtkWidget *widget, gpointer user_data);
 
 void tls_pw_init_auth_widget (GtkBuilder *builder,
                               GtkSizeGroup *group,
-                              NMSettingVPN *s_vpn,
+                              NMSettingVpn *s_vpn,
                               ChangedCallback changed_cb,
                               gpointer user_data);
 
 void sk_init_auth_widget (GtkBuilder *builder,
                           GtkSizeGroup *group,
-                          NMSettingVPN *s_vpn,
+                          NMSettingVpn *s_vpn,
                           ChangedCallback changed_cb,
                           gpointer user_data);
 
@@ -47,7 +52,7 @@ gboolean auth_widget_check_validity (GtkBuilder *builder, GError **error);
 
 gboolean auth_widget_update_connection (GtkBuilder *builder,
                                         const char *contype,
-                                        NMSettingVPN *s_vpn);
+                                        NMSettingVpn *s_vpn);
 
 GtkFileFilter *tls_file_chooser_filter_new (void);
 
diff --git a/properties/nm-openconnect.c b/properties/nm-openconnect.c
index 478e394..f84b701 100644
--- a/properties/nm-openconnect.c
+++ b/properties/nm-openconnect.c
@@ -49,34 +49,52 @@
 #define openconnect_has_oath_support() 0
 #endif
 
+#ifdef NM_OPENCONNECT_OLD
+#define NM_VPN_LIBNM_COMPAT
 #include <nm-vpn-plugin-ui-interface.h>
 #include <nm-setting-vpn.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-ip4-config.h>
 
-#include "nm-openconnect-service-defines.h"
-#include "nm-openconnect.h"
-#include "auth-helpers.h"
+#define nm_simple_connection_new nm_connection_new
 
 #define OPENCONNECT_PLUGIN_NAME    _("Cisco AnyConnect Compatible VPN (openconnect)")
 #define OPENCONNECT_PLUGIN_DESC    _("Compatible with Cisco AnyConnect SSL VPN.")
-#define OPENCONNECT_PLUGIN_SERVICE NM_DBUS_SERVICE_OPENCONNECT 
+
+#else /* !NM_OPENCONNECT_OLD */
+
+#include <NetworkManager.h>
+
+#define OPENCONNECT_PLUGIN_NAME    _("openconnect")
+#define OPENCONNECT_PLUGIN_DESC    _("Cisco AnyConnect SSL Compatible VPN")
+#endif
+
+#include "nm-openconnect-service-defines.h"
+#include "nm-openconnect.h"
+#include "auth-helpers.h"
 
 
 /************** plugin class **************/
 
-static void openconnect_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class);
+enum {
+       PROP_0,
+       PROP_NAME,
+       PROP_DESC,
+       PROP_SERVICE
+};
+
+static void openconnect_plugin_ui_interface_init (NMVpnEditorPluginInterface *iface_class);
 
 G_DEFINE_TYPE_EXTENDED (OpenconnectPluginUi, openconnect_plugin_ui, G_TYPE_OBJECT, 0,
-                        G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_PLUGIN_UI_INTERFACE,
+                        G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR_PLUGIN,
                                                openconnect_plugin_ui_interface_init))
 
 /************** UI widget class **************/
 
-static void openconnect_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class);
+static void openconnect_plugin_ui_widget_interface_init (NMVpnEditorInterface *iface_class);
 
 G_DEFINE_TYPE_EXTENDED (OpenconnectPluginUiWidget, openconnect_plugin_ui_widget, G_TYPE_OBJECT, 0,
-                        G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_PLUGIN_UI_WIDGET_INTERFACE,
+                        G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_EDITOR,
                                                openconnect_plugin_ui_widget_interface_init))
 
 #define OPENCONNECT_PLUGIN_UI_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), 
OPENCONNECT_TYPE_PLUGIN_UI_WIDGET, OpenconnectPluginUiWidgetPrivate))
@@ -114,11 +132,11 @@ nm_openconnect_import_export_error_quark (void)
 }
 
 static NMConnection *
-import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
+import (NMVpnEditorPlugin *iface, const char *path, GError **error)
 {
        NMConnection *connection;
        NMSettingConnection *s_con;
-       NMSettingVPN *s_vpn;
+       NMSettingVpn *s_vpn;
        NMSettingIP4Config *s_ip4;
        GKeyFile *keyfile;
        GKeyFileFlags flags;
@@ -137,7 +155,7 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
                return NULL;
        }
 
-       connection = nm_connection_new ();
+       connection = nm_simple_connection_new ();
        s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
        nm_connection_add_setting (connection, NM_SETTING (s_con));
 
@@ -218,13 +236,13 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
 }
 
 static gboolean
-export (NMVpnPluginUiInterface *iface,
+export (NMVpnEditorPlugin *iface,
         const char *path,
         NMConnection *connection,
         GError **error)
 {
        NMSettingConnection *s_con;
-       NMSettingVPN *s_vpn;
+       NMSettingVpn *s_vpn;
        const char *value;
        const char *gateway = NULL;
        const char *cacert = NULL;
@@ -447,7 +465,7 @@ init_token_mode_options (GtkComboBox *token_mode)
 static gboolean
 init_token_ui (OpenconnectPluginUiWidget *self,
                OpenconnectPluginUiWidgetPrivate *priv,
-               NMSettingVPN *s_vpn)
+               NMSettingVpn *s_vpn)
 {
        GtkWidget *widget;
        GtkComboBox *token_mode;
@@ -513,7 +531,7 @@ static gboolean
 init_plugin_ui (OpenconnectPluginUiWidget *self, NMConnection *connection, GError **error)
 {
        OpenconnectPluginUiWidgetPrivate *priv = OPENCONNECT_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
-       NMSettingVPN *s_vpn;
+       NMSettingVpn *s_vpn;
        GtkWidget *widget;
        const char *value;
 
@@ -582,7 +600,7 @@ init_plugin_ui (OpenconnectPluginUiWidget *self, NMConnection *connection, GErro
 }
 
 static GObject *
-get_widget (NMVpnPluginUiWidgetInterface *iface)
+get_widget (NMVpnEditor *iface)
 {
        OpenconnectPluginUiWidget *self = OPENCONNECT_PLUGIN_UI_WIDGET (iface);
        OpenconnectPluginUiWidgetPrivate *priv = OPENCONNECT_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
@@ -591,13 +609,13 @@ get_widget (NMVpnPluginUiWidgetInterface *iface)
 }
 
 static gboolean
-update_connection (NMVpnPluginUiWidgetInterface *iface,
+update_connection (NMVpnEditor *iface,
                    NMConnection *connection,
                    GError **error)
 {
        OpenconnectPluginUiWidget *self = OPENCONNECT_PLUGIN_UI_WIDGET (iface);
        OpenconnectPluginUiWidgetPrivate *priv = OPENCONNECT_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
-       NMSettingVPN *s_vpn;
+       NMSettingVpn *s_vpn;
        GtkWidget *widget;
        char *str;
        GtkTreeModel *model;
@@ -698,17 +716,17 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
        return TRUE;
 }
 
-static NMVpnPluginUiWidgetInterface *
+static NMVpnEditor *
 nm_vpn_plugin_ui_widget_interface_new (NMConnection *connection, GError **error)
 {
-       NMVpnPluginUiWidgetInterface *object;
+       NMVpnEditor *object;
        OpenconnectPluginUiWidgetPrivate *priv;
        char *ui_file;
 
        if (error)
                g_return_val_if_fail (*error == NULL, NULL);
 
-       object = NM_VPN_PLUGIN_UI_WIDGET_INTERFACE (g_object_new (OPENCONNECT_TYPE_PLUGIN_UI_WIDGET, NULL));
+       object = g_object_new (OPENCONNECT_TYPE_PLUGIN_UI_WIDGET, NULL);
        if (!object) {
                g_set_error (error, OPENCONNECT_PLUGIN_UI_ERROR, 0, "could not create openconnect object");
                return NULL;
@@ -788,7 +806,7 @@ openconnect_plugin_ui_widget_init (OpenconnectPluginUiWidget *plugin)
 }
 
 static void
-openconnect_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class)
+openconnect_plugin_ui_widget_interface_init (NMVpnEditorInterface *iface_class)
 {
        /* interface implementation */
        iface_class->get_widget = get_widget;
@@ -796,15 +814,15 @@ openconnect_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface
 }
 
 static guint32
-get_capabilities (NMVpnPluginUiInterface *iface)
+get_capabilities (NMVpnEditorPlugin *iface)
 {
-       return (NM_VPN_PLUGIN_UI_CAPABILITY_IMPORT |
-               NM_VPN_PLUGIN_UI_CAPABILITY_EXPORT |
-               NM_VPN_PLUGIN_UI_CAPABILITY_IPV6);
+       return (NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT |
+               NM_VPN_EDITOR_PLUGIN_CAPABILITY_EXPORT |
+               NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6);
 }
 
-static NMVpnPluginUiWidgetInterface *
-ui_factory (NMVpnPluginUiInterface *iface, NMConnection *connection, GError **error)
+static NMVpnEditor *
+get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
 {
        return nm_vpn_plugin_ui_widget_interface_new (connection, error);
 }
@@ -814,14 +832,14 @@ get_property (GObject *object, guint prop_id,
               GValue *value, GParamSpec *pspec)
 {
        switch (prop_id) {
-       case NM_VPN_PLUGIN_UI_INTERFACE_PROP_NAME:
+       case PROP_NAME:
                g_value_set_string (value, OPENCONNECT_PLUGIN_NAME);
                break;
-       case NM_VPN_PLUGIN_UI_INTERFACE_PROP_DESC:
+       case PROP_DESC:
                g_value_set_string (value, OPENCONNECT_PLUGIN_DESC);
                break;
-       case NM_VPN_PLUGIN_UI_INTERFACE_PROP_SERVICE:
-               g_value_set_string (value, OPENCONNECT_PLUGIN_SERVICE);
+       case PROP_SERVICE:
+               g_value_set_string (value, NM_DBUS_SERVICE_OPENCONNECT);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -837,16 +855,16 @@ openconnect_plugin_ui_class_init (OpenconnectPluginUiClass *req_class)
        object_class->get_property = get_property;
 
        g_object_class_override_property (object_class,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_PROP_NAME,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_NAME);
+                                         PROP_NAME,
+                                         NM_VPN_EDITOR_PLUGIN_NAME);
 
        g_object_class_override_property (object_class,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_PROP_DESC,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_DESC);
+                                         PROP_DESC,
+                                         NM_VPN_EDITOR_PLUGIN_DESCRIPTION);
 
        g_object_class_override_property (object_class,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_PROP_SERVICE,
-                                         NM_VPN_PLUGIN_UI_INTERFACE_SERVICE);
+                                         PROP_SERVICE,
+                                         NM_VPN_EDITOR_PLUGIN_SERVICE);
 }
 
 static void
@@ -855,17 +873,17 @@ openconnect_plugin_ui_init (OpenconnectPluginUi *plugin)
 }
 
 static void
-openconnect_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class)
+openconnect_plugin_ui_interface_init (NMVpnEditorPluginInterface *iface_class)
 {
        /* interface implementation */
-       iface_class->ui_factory = ui_factory;
+       iface_class->get_editor = get_editor;
        iface_class->get_capabilities = get_capabilities;
        iface_class->import_from_file = import;
        iface_class->export_to_file = export;
 }
 
-G_MODULE_EXPORT NMVpnPluginUiInterface *
-nm_vpn_plugin_ui_factory (GError **error)
+G_MODULE_EXPORT NMVpnEditorPlugin *
+nm_vpn_editor_plugin_factory (GError **error)
 {
        if (error)
                g_return_val_if_fail (*error == NULL, NULL);
@@ -873,6 +891,6 @@ nm_vpn_plugin_ui_factory (GError **error)
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
-       return NM_VPN_PLUGIN_UI_INTERFACE (g_object_new (OPENCONNECT_TYPE_PLUGIN_UI, NULL));
+       return g_object_new (OPENCONNECT_TYPE_PLUGIN_UI, NULL);
 }
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 2a222a0..532970d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
 AM_CPPFLAGS = \
        $(DBUS_CFLAGS) \
        $(GLIB_CFLAGS) \
-       $(NM_CFLAGS) \
+       $(LIBNM_GLIB_CFLAGS) \
        -DG_DISABLE_DEPRECATED \
        -DBINDIR=\"$(bindir)\" \
        -DPREFIX=\""$(prefix)"\" \
@@ -25,7 +25,7 @@ nm_openconnect_service_SOURCES = \
 nm_openconnect_service_LDADD = \
        $(DBUS_LIBS) \
        $(GLIB_LIBS) \
-       $(NM_LIBS)
+       $(LIBNM_GLIB_LIBS)
 
 
 nm_openconnect_service_openconnect_helper_SOURCES = \
@@ -34,6 +34,6 @@ nm_openconnect_service_openconnect_helper_SOURCES = \
 nm_openconnect_service_openconnect_helper_LDADD = \
        $(DBUS_LIBS) \
        $(GTHREAD_LIBS) \
-       $(NM_LIBS)
+       $(LIBNM_GLIB_LIBS)
 
 CLEANFILES = *~


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