[virt-tools-list] [PATCH 7/7] Make GApplication port compatible with older glib

Eduardo Lima (Etrunko) etrunko at redhat.com
Fri Dec 11 16:40:36 UTC 2015


Signed-off-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>
---
 configure.ac           |  2 +-
 src/remote-viewer.c    |  9 +++++++++
 src/virt-glib-compat.c | 29 +++++++++++++++++++++++++++++
 src/virt-viewer-app.c  | 15 +++++++++++++++
 src/virt-viewer-app.h  |  8 ++++++++
 src/virt-viewer.c      |  9 +++++++++
 6 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index bd9524e..889c9cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@ AC_CANONICAL_HOST
 m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])
 AM_SILENT_RULES([yes])
 
-GLIB2_REQUIRED="2.40.0"
+GLIB2_REQUIRED="2.38.0"
 LIBXML2_REQUIRED="2.6.0"
 LIBVIRT_REQUIRED="0.10.0"
 GTK3_REQUIRED="3.0"
diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 036ee06..deb7288 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -233,7 +233,12 @@ remote_viewer_class_init (RemoteViewerClass *klass)
     app_class->start = remote_viewer_start;
     app_class->deactivated = remote_viewer_deactivated;
 
+#ifdef GLIB_VERSION_2_40
     g_app_class->handle_local_options = remote_viewer_handle_local_options;
+#else
+    (void) g_app_class;
+    app_class->handle_local_options = remote_viewer_handle_local_options;
+#endif
 
 #ifdef HAVE_SPICE_GTK
     app_class->activate = remote_viewer_activate;
@@ -1262,7 +1267,11 @@ remote_viewer_handle_local_options(GApplication *gapp, GVariantDict *options)
     if (title && !controller)
         g_object_set(app, "title", title, NULL);
 
+#ifdef GLIB_VERSION_2_40
     ret = G_APPLICATION_CLASS(remote_viewer_parent_class)->handle_local_options(gapp, options);
+#else
+    ret = VIRT_VIEWER_APP_CLASS(remote_viewer_parent_class)->handle_local_options(gapp, options);
+#endif
 
 end:
     if (ret == 1)
diff --git a/src/virt-glib-compat.c b/src/virt-glib-compat.c
index 0118e45..fdd85fb 100644
--- a/src/virt-glib-compat.c
+++ b/src/virt-glib-compat.c
@@ -36,6 +36,7 @@ GByteArray *g_byte_array_new_take (guint8 *data, gsize len)
 #ifndef GLIB_VERSION_2_40
 #include <glib.h>
 #include <glib/gi18n.h>
+#include "virt-viewer-app.h" /* VIRT_VIEWER_APP_GET_CLASS */
 
 typedef struct _GApplicationOptionsPrivate GApplicationOptionsPrivate;
 struct _GApplicationOptionsPrivate
@@ -232,6 +233,32 @@ g_application_parse_command_line (GApplication   *application,
 #if 0
   if (!g_option_context_parse_strv (context, arguments, error))
     goto out;
+#else
+  {
+    /* FIXME: glib code uses context->strv_mode flag that is used in the free
+     * operation. The original function is implemented like this:
+     *
+     * gboolean
+     * g_option_context_parse_strv (GOptionContext   *context,
+     *                              gchar          ***arguments,
+     *                              GError          **error)
+     * {
+     *   gboolean success;
+     *   gint argc;
+     *
+     *   context->strv_mode = TRUE;
+     *   argc = g_strv_length (*arguments);
+     *   success = g_option_context_parse (context, &argc, arguments, error);
+     *   context->strv_mode = FALSE;
+     *
+     *   return success;
+     * }
+     */
+
+    gint argc = g_strv_length (*arguments);
+    if (!g_option_context_parse (context, &argc, arguments, error))
+      goto out;
+  }
 #endif
 
   /* Check for --gapplication-service */
@@ -357,6 +384,8 @@ g_application_real_local_command_line (GApplication   *application,
 
 #if 0
   g_signal_emit (application, g_application_signals[SIGNAL_HANDLE_LOCAL_OPTIONS], 0, options, exit_status);
+#else
+  *exit_status = VIRT_VIEWER_APP_GET_CLASS(application)->handle_local_options(application, options);
 #endif
 
   if (*exit_status >= 0)
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 67cac77..fc01423 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -112,6 +112,9 @@ static gint virt_viewer_app_handle_local_options(GApplication *app,
 static void virt_viewer_app_startup_cb(GApplication *app, gpointer data);
 static void virt_viewer_app_activate_cb(GApplication *app, gpointer data);
 
+#ifndef GLIB_VERSION_2_40
+static gboolean virt_viewer_app_local_command_line(GApplication *app, gchar ***args, int *ret);
+#endif
 
 struct _VirtViewerAppPrivate {
     VirtViewerWindow *main_window;
@@ -1942,7 +1945,12 @@ virt_viewer_app_class_init (VirtViewerAppClass *klass)
     object_class->set_property = virt_viewer_app_set_property;
     object_class->dispose = virt_viewer_app_dispose;
 
+#ifdef GLIB_VERSION_2_40
     g_app_class->handle_local_options = virt_viewer_app_handle_local_options;
+#else
+    g_app_class->local_command_line = virt_viewer_app_local_command_line;
+    klass->handle_local_options = virt_viewer_app_handle_local_options;
+#endif
 
     klass->start = virt_viewer_app_default_start;
     klass->initial_connect = virt_viewer_app_default_initial_connect;
@@ -2616,6 +2624,13 @@ gboolean virt_viewer_app_get_session_cancelled(VirtViewerApp *self)
     return self->priv->cancelled;
 }
 
+#ifndef GLIB_VERSION_2_40
+static gboolean
+virt_viewer_app_local_command_line(GApplication *app, gchar ***args, int *ret)
+{
+    return g_application_real_local_command_line(app, args, ret);
+}
+#endif
 /*
  * Local variables:
  *  c-indent-level: 4
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
index 7bb22fb..2cc8f3b 100644
--- a/src/virt-viewer-app.h
+++ b/src/virt-viewer-app.h
@@ -44,6 +44,10 @@ typedef struct {
     VirtViewerAppPrivate *priv;
 } VirtViewerApp;
 
+#ifndef GLIB_VERSION_2_40
+typedef struct _GVariantDict GVariantDict;
+#endif
+
 typedef struct {
     GtkApplicationClass parent_class;
 
@@ -53,6 +57,10 @@ typedef struct {
     gboolean (*activate) (VirtViewerApp *self, GError **error);
     void (*deactivated) (VirtViewerApp *self, gboolean connect_error);
     gboolean (*open_connection)(VirtViewerApp *self, int *fd);
+
+#ifndef GLIB_VERSION_2_40
+    gint (*handle_local_options) (GApplication *gapp, GVariantDict *options);
+#endif
 } VirtViewerAppClass;
 
 GType virt_viewer_app_get_type (void);
diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index 0f870de..e1cda23 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -124,7 +124,12 @@ virt_viewer_class_init (VirtViewerClass *klass)
     app_class->open_connection = virt_viewer_open_connection;
     app_class->start = virt_viewer_start;
 
+#ifdef GLIB_VERSION_2_40
     g_app_class->handle_local_options = virt_viewer_handle_local_options;
+#else
+    (void) g_app_class;
+    app_class->handle_local_options = virt_viewer_handle_local_options;
+#endif
 }
 
 static void
@@ -1054,7 +1059,11 @@ virt_viewer_handle_local_options(GApplication *gapp, GVariantDict *options)
     if (g_variant_dict_lookup(options, OPT_CONNECT, "s", &uri))
         self->priv->uri = g_strdup(uri);
 
+#ifdef GLIB_VERSION_2_40
     ret = G_APPLICATION_CLASS(virt_viewer_parent_class)->handle_local_options(gapp, options);
+#else
+    ret = VIRT_VIEWER_APP_CLASS(virt_viewer_parent_class)->handle_local_options(gapp, options);
+#endif
 
 end:
     if (ret == 1)
-- 
2.5.0




More information about the virt-tools-list mailing list