[gjs: 3/7] gjs-private: Move GTK override into util
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 3/7] gjs-private: Move GTK override into util
- Date: Sat, 17 Aug 2019 01:21:06 +0000 (UTC)
commit adcc1d98ea0f7afb79b5687d4f652fbc1f7cb7ee
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Aug 13 00:49:47 2019 +0200
gjs-private: Move GTK override into util
Now that the function no longer uses GTK directly, there is no reason
for keeping it separate from other utility functions.
https://gitlab.gnome.org/GNOME/gjs/issues/99
Makefile.am | 4 --
gjs-srcs.mk | 5 --
libgjs-private/gjs-gtk-util.c | 109 ------------------------------------------
libgjs-private/gjs-gtk-util.h | 42 ----------------
libgjs-private/gjs-util.c | 81 +++++++++++++++++++++++++++++++
libgjs-private/gjs-util.h | 6 +++
win32/config-msvc.mak | 2 +-
7 files changed, 88 insertions(+), 161 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 1b3b6d9d..dfb36dd4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -94,10 +94,6 @@ endif
# Also, these files used to be a separate library
libgjs_private_source_files = $(gjs_private_srcs)
-if ENABLE_GTK
-libgjs_private_source_files += $(gjs_gtk_private_srcs)
-endif
-
libgjs_la_SOURCES += $(libgjs_private_source_files)
# The built-in modules also used to be compiled separately
diff --git a/gjs-srcs.mk b/gjs-srcs.mk
index 389c3d02..95022596 100644
--- a/gjs-srcs.mk
+++ b/gjs-srcs.mk
@@ -103,11 +103,6 @@ gjs_private_srcs = \
libgjs-private/gjs-gdbus-wrapper.h \
libgjs-private/gjs-util.c \
libgjs-private/gjs-util.h \
- libgjs-private/gjs-gtk-util.h \
- $(NULL)
-
-gjs_gtk_private_srcs = \
- libgjs-private/gjs-gtk-util.c \
$(NULL)
gjs_console_srcs = \
diff --git a/libgjs-private/gjs-util.c b/libgjs-private/gjs-util.c
index f27e4c76..00e3f6d1 100644
--- a/libgjs-private/gjs-util.c
+++ b/libgjs-private/gjs-util.c
@@ -28,6 +28,7 @@
#include <gio/gio.h>
#include <glib-object.h>
+#include <girepository.h>
#include <glib.h>
#include <glib/gi18n.h> /* for bindtextdomain, bind_textdomain_codeset, textdomain */
@@ -204,3 +205,83 @@ int gjs_open_bytes(GBytes* bytes, GError** error) {
g_error("%s is currently supported on UNIX only", __func__);
#endif
}
+
+static GParamSpec* gjs_gtk_container_class_find_child_property(
+ GIObjectInfo* container_info, GObject* container, const char* property) {
+ GIBaseInfo* class_info = NULL;
+ GIBaseInfo* find_child_property_fun = NULL;
+
+ GIArgument ret;
+ GIArgument find_child_property_args[2];
+
+ class_info = g_object_info_get_class_struct(container_info);
+ find_child_property_fun =
+ g_struct_info_find_method(class_info, "find_child_property");
+
+ find_child_property_args[0].v_pointer = G_OBJECT_GET_CLASS(container);
+ find_child_property_args[1].v_string = (char*)property;
+
+ g_function_info_invoke(find_child_property_fun, find_child_property_args, 2,
+ NULL, 0, &ret, NULL);
+
+ g_clear_pointer(&class_info, g_base_info_unref);
+ g_clear_pointer(&find_child_property_fun, g_base_info_unref);
+
+ return (GParamSpec*)ret.v_pointer;
+}
+
+void gjs_gtk_container_child_set_property(GObject* container, GObject* child,
+ const char* property,
+ const GValue* value) {
+ GParamSpec* pspec = NULL;
+ GIBaseInfo* base_info = NULL;
+ GIBaseInfo* child_set_property_fun = NULL;
+ GIObjectInfo* container_info;
+ GValue value_arg = G_VALUE_INIT;
+ GIArgument ret;
+
+ GIArgument child_set_property_args[4];
+
+ base_info = g_irepository_find_by_name(NULL, "Gtk", "Container");
+ container_info = (GIObjectInfo*)base_info;
+
+ pspec = gjs_gtk_container_class_find_child_property(container_info,
+ container, property);
+ if (pspec == NULL) {
+ g_warning("%s does not have a property called %s",
+ g_type_name(G_OBJECT_TYPE(container)), property);
+ goto out;
+ }
+
+ 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.
+ */
+ g_value_init(&value_arg, pspec->value_type);
+ } else {
+ g_value_init(&value_arg, G_VALUE_TYPE(value));
+ g_value_copy(value, &value_arg);
+ }
+
+ child_set_property_fun =
+ g_object_info_find_method(container_info, "child_set_property");
+
+ child_set_property_args[0].v_pointer = container;
+ child_set_property_args[1].v_pointer = child;
+ child_set_property_args[2].v_string = (char*)property;
+ child_set_property_args[3].v_pointer = &value_arg;
+
+ g_function_info_invoke(child_set_property_fun, child_set_property_args, 4,
+ NULL, 0, &ret, NULL);
+
+ g_value_unset(&value_arg);
+
+out:
+ g_clear_pointer(&pspec, g_param_spec_unref);
+ g_clear_pointer(&base_info, g_base_info_unref);
+ g_clear_pointer(&child_set_property_fun, g_base_info_unref);
+}
diff --git a/libgjs-private/gjs-util.h b/libgjs-private/gjs-util.h
index a1c907c1..945dc8ad 100644
--- a/libgjs-private/gjs-util.h
+++ b/libgjs-private/gjs-util.h
@@ -67,6 +67,12 @@ GType gjs_param_spec_get_value_type (GParamSpec *pspec);
GJS_EXPORT
GType gjs_param_spec_get_owner_type (GParamSpec *pspec);
+/* For imports.overrides.Gtk */
+GJS_EXPORT
+void gjs_gtk_container_child_set_property(GObject* container, GObject* child,
+ const char* property,
+ const GValue* value);
+
/* For tests */
GJS_EXPORT
int gjs_open_bytes(GBytes* bytes, GError** error);
diff --git a/win32/config-msvc.mak b/win32/config-msvc.mak
index 29cfee90..3572c9b6 100644
--- a/win32/config-msvc.mak
+++ b/win32/config-msvc.mak
@@ -90,7 +90,7 @@ INTROSPECTION_INCLUDE_PACKAGES = --include=Gio-2.0 --include=GObject-2.0
# Enable GTK+
!if "$(NO_GTK)" != "1"
GJS_DEFINES = $(GJS_DEFINES) /DENABLE_GTK
-LIBGJS_PRIVATE_SOURCES = $(LIBGJS_PRIVATE_SOURCES) $(gjs_gtk_private_srcs)
+LIBGJS_PRIVATE_SOURCES = $(LIBGJS_PRIVATE_SOURCES)
GJS_INTROSPECTION_CHECK_PACKAGE = gtk+-3.0
INTROSPECTION_INCLUDE_PACKAGES = $(INTROSPECTION_INCLUDE_PACKAGES) --include=Gtk-3.0
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]