[gjs] overrides: fix gtk_container_child_set_property() for NULL values



commit 68b835ca242c2079a9703a38f06abcf0ef40ddc4
Author: Cosimo Cecchi <cosimo endlessm com>
Date:   Thu Jan 9 13:53:31 2014 -0800

    overrides: fix gtk_container_child_set_property() for NULL values
    
    Install a GTK override with a fix for
    gtk_container_chilld_set_property() not using the correct GType for NULL
    values.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721838

 Makefile-modules.am                                |   10 +++-
 Makefile.am                                        |   17 ++++++
 configure.ac                                       |   19 ++++++-
 libgjs-private/gjs-gtk-util.c                      |   61 ++++++++++++++++++++
 libgjs-private/gjs-gtk-util.h                      |   37 ++++++++++++
 ...ules.gresource.xml => modules.gresource.xml.in} |    1 +
 modules/overrides/Gtk.js                           |   10 +++
 7 files changed, 152 insertions(+), 3 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index 07860f4..90d9c35 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -14,13 +14,21 @@ JS_NATIVE_MODULE_CFLAGS =   \
 JS_NATIVE_MODULE_LIBADD =      \
         $(GJS_LIBS)
 
+if ENABLE_GTK
+gtk_override = <file>modules/overrides/Gtk.js</file>
+endif
+
+modules/modules.gresource.xml: $(srcdir)/modules/modules.gresource.xml.in Makefile
+       $(AM_V_GEN) sed -e 's|@GTK_OVERRIDE[ ]|$(gtk_override)|g' $< > $@
+
 modules_resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies 
$(srcdir)/modules/modules.gresource.xml)
 modules-resources.h: $(srcdir)/modules/modules.gresource.xml $(modules_resource_files)
        $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --sourcedir=$(builddir) 
--generate --c-name modules_resources $<
 modules-resources.c: $(srcdir)/modules/modules.gresource.xml $(modules_resource_files)
        $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --sourcedir=$(builddir) 
--generate --c-name modules_resources $<
 
-EXTRA_DIST += $(modules_resource_files) $(srcdir)/modules/modules.gresource.xml
+EXTRA_DIST += $(modules_resource_files) $(srcdir)/modules/modules.gresource.xml.in
+CLEANFILES += $(srcdir)/modules/modules.gresource.xml
 
 nodist_libmodules_resources_la_SOURCES = modules-resources.c modules-resources.h
 libmodules_resources_la_CPPFLAGS = $(JS_NATIVE_MODULE_CFLAGS)
diff --git a/Makefile.am b/Makefile.am
index 68cdd0f..e9490d6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -97,6 +97,11 @@ libgjs_la_LDFLAGS =          \
 libgjs_la_LIBADD =             \
        $(GJS_LIBS)
 
+if ENABLE_GTK
+libgjs_la_CPPFLAGS += $(GJS_GTK_CFLAGS)
+libgjs_la_LIBADD += $(GJS_GTK_LIBS)
+endif
+
 libgjs_la_SOURCES =            \
        gjs/byteArray.cpp               \
        gjs/context.cpp         \
@@ -151,6 +156,14 @@ libgjs_private_source_files = \
        libgjs-private/gjs-gdbus-wrapper.h      \
        libgjs-private/gjs-util.cpp             \
        libgjs-private/gjs-util.h
+
+if ENABLE_GTK
+libgjs_private_source_files +=                         \
+       libgjs-private/gjs-gtk-util.c           \
+       libgjs-private/gjs-gtk-util.h           \
+       $(NULL)
+endif
+
 libgjs_la_SOURCES += $(libgjs_private_source_files)
 
 GjsPrivate-1.0.gir: libgjs.la
@@ -159,6 +172,10 @@ GjsPrivate_1_0_gir_INCLUDES = GObject-2.0 Gio-2.0
 GjsPrivate_1_0_gir_FILES = $(libgjs_private_source_files)
 GjsPrivate_1_0_gir_SCANNERFLAGS = --identifier-prefix=Gjs --symbol-prefix=gjs_ --warn-all
 
+if ENABLE_GTK
+GjsPrivate_1_0_gir_INCLUDES += Gtk-3.0
+endif
+
 INTROSPECTION_GIRS += GjsPrivate-1.0.gir
 
 if ENABLE_DTRACE
diff --git a/configure.ac b/configure.ac
index 4e006a7..c8a298b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,11 +77,16 @@ common_packages="gmodule-2.0 gthread-2.0 gio-2.0 >= glib_required_version mozjs-
 gjs_packages="gobject-introspection-1.0 libffi $common_packages"
 gjs_cairo_packages="cairo cairo-gobject $common_packages"
 gjs_gdbus_packages="gobject-2.0 >= glib_required_version gio-2.0"
+gjs_gtk_packages="gtk+-3.0"
 # gjs-tests links against everything
 gjstests_packages="$gjstests_packages $gjs_packages"
 
 PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= glib_required_version])
 PKG_CHECK_MODULES([GJS], [$gjs_packages])
+PKG_CHECK_MODULES([GJS_GDBUS], [$gjs_gdbus_packages])
+PKG_CHECK_MODULES([GJSTESTS], [$gjstests_packages])
+
+# Optional cairo dep (enabled by default)
 AC_ARG_WITH(cairo,
            AS_HELP_STRING([--without-cairo], [Use cairo @<:@default=yes@:>@]),
            [], [with_cairo=yes])
@@ -92,9 +97,18 @@ AM_CONDITIONAL(ENABLE_CAIRO, test x$have_cairo = xyes)
 AS_IF([test x$have_cairo = xyes], [
   AC_DEFINE([ENABLE_CAIRO],[1],[Define if you want to build with cairo support])
 ])
-PKG_CHECK_MODULES([GJS_GDBUS], [$gjs_gdbus_packages])
 
-PKG_CHECK_MODULES([GJSTESTS], [$gjstests_packages])
+# Optional GTK+ dep (enabled by default)
+AC_ARG_WITH(gtk,
+            AS_HELP_STRING([--without-gtk], [Use GTK+ @<:@default=yes@:>@]),
+            [], [with_gtk=yes])
+AS_IF([test x$with_gtk = xyes], [
+  PKG_CHECK_MODULES([GJS_GTK], [$gjs_gtk_packages], have_gtk=yes, have_gtk=no)
+  ], [have_gtk=no])
+AM_CONDITIONAL(ENABLE_GTK, test x$have_gtk = xyes)
+AS_IF([test x$have_gtk = xyes], [
+  AC_DEFINE([ENABLE_GTK],[1],[Define if you want to build with GTK+ support])
+])
 
 GI_DATADIR=$($PKG_CONFIG --variable=gidatadir gobject-introspection-1.0)
 AC_SUBST(GI_DATADIR)
@@ -221,6 +235,7 @@ AC_MSG_RESULT([
        GJS_LIBS:               ${GJS_LIBS}
 
        cairo:                  ${have_cairo}
+       GTK+:                   ${have_gtk}
        readline:               ${have_readline}
        dtrace:                 ${ENABLE_DTRACE}
        systemtap:              ${ENABLE_SYSTEMTAP}
diff --git a/libgjs-private/gjs-gtk-util.c b/libgjs-private/gjs-gtk-util.c
new file mode 100644
index 0000000..f15bfd5
--- /dev/null
+++ b/libgjs-private/gjs-gtk-util.c
@@ -0,0 +1,61 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/* Copyright 2014 Endless Mobile, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <config.h>
+#include <gtk/gtk.h>
+
+#include "gjs-gtk-util.h"
+
+void
+gjs_gtk_container_child_set_property (GtkContainer *container,
+                                      GtkWidget    *child,
+                                      const gchar  *property,
+                                      const GValue *value)
+{
+    GParamSpec *pspec;
+
+    pspec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (container),
+                                                     property);
+    if (pspec == NULL) {
+      g_warning ("%s does not have a property called %s",
+                 g_type_name (G_OBJECT_TYPE (container)), property);
+      return;
+    }
+
+    if ((G_VALUE_TYPE (value) == G_TYPE_POINTER) &&
+        (g_value_get_pointer (value) == NULL) &&
+        !g_value_type_transformable (G_VALUE_TYPE (value), pspec->value_type)) {
+        /* Set an empty value. This will happen when we set a NULL value from JS.
+         * Since GJS doesn't know the GParamSpec for this property, it
+         * will just put NULL into a G_TYPE_POINTER GValue, which will later
+         * fail when trying to transform it to the GParamSpec's GType.
+         */
+        GValue null_value = G_VALUE_INIT;
+        g_value_init (&null_value, pspec->value_type);
+        gtk_container_child_set_property (container, child,
+                                          property, &null_value);
+        g_value_unset (&null_value);
+    } else {
+        gtk_container_child_set_property (container, child,
+                                          property, value);
+    }
+}
diff --git a/libgjs-private/gjs-gtk-util.h b/libgjs-private/gjs-gtk-util.h
new file mode 100644
index 0000000..b47971b
--- /dev/null
+++ b/libgjs-private/gjs-gtk-util.h
@@ -0,0 +1,37 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/* Copyright 2014 Endless Mobile, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __GJS_PRIVATE_GTK_UTIL_H__
+#define __GJS_PRIVATE_GTK_UTIL_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+void gjs_gtk_container_child_set_property (GtkContainer *container,
+                                           GtkWidget    *child,
+                                           const gchar  *property,
+                                           const GValue *value);
+
+G_END_DECLS
+
+#endif /* __GJS_PRIVATE_GTK_UTIL_H__ */
diff --git a/modules/modules.gresource.xml b/modules/modules.gresource.xml.in
similarity index 97%
rename from modules/modules.gresource.xml
rename to modules/modules.gresource.xml.in
index 8f89fe8..8fccdfd 100644
--- a/modules/modules.gresource.xml
+++ b/modules/modules.gresource.xml.in
@@ -8,6 +8,7 @@
     <file>modules/overrides/GLib.js</file>
     <file>modules/overrides/Gio.js</file>
     <file>modules/overrides/GObject.js</file>
+    @GTK_OVERRIDE@
 
     <file>modules/cairo.js</file>
     <file>modules/gettext.js</file>
diff --git a/modules/overrides/Gtk.js b/modules/overrides/Gtk.js
new file mode 100644
index 0000000..c73de88
--- /dev/null
+++ b/modules/overrides/Gtk.js
@@ -0,0 +1,10 @@
+var GjsPrivate = imports.gi.GjsPrivate;
+var Gtk;
+
+function _init() {
+    Gtk = this;
+
+    Gtk.Container.prototype.child_set_property = function(child, property, value) {
+        GjsPrivate.gtk_container_child_set_property(this, child, property, value);
+    };
+}


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