summaryrefslogtreecommitdiff
path: root/libgjs-private
diff options
context:
space:
mode:
authorFlorian Müllner <fmuellner@gnome.org>2019-08-13 00:49:47 +0200
committerFlorian Müllner <fmuellner@gnome.org>2019-08-15 00:58:04 +0000
commitadcc1d98ea0f7afb79b5687d4f652fbc1f7cb7ee (patch)
treed45df84ecdeca923792035e44443582b0244fb32 /libgjs-private
parenta14df4996edc15b3cff2a182980679678532b481 (diff)
downloadgjs-adcc1d98ea0f7afb79b5687d4f652fbc1f7cb7ee.tar.gz
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
Diffstat (limited to 'libgjs-private')
-rw-r--r--libgjs-private/gjs-gtk-util.c109
-rw-r--r--libgjs-private/gjs-gtk-util.h42
-rw-r--r--libgjs-private/gjs-util.c81
-rw-r--r--libgjs-private/gjs-util.h6
4 files changed, 87 insertions, 151 deletions
diff --git a/libgjs-private/gjs-gtk-util.c b/libgjs-private/gjs-gtk-util.c
deleted file mode 100644
index 2b4ab563..00000000
--- a/libgjs-private/gjs-gtk-util.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/* -*- 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 <stddef.h> // for NULL
-
-#include <girepository.h>
-#include <glib-object.h>
-#include <glib.h>
-
-#include "libgjs-private/gjs-gtk-util.h"
-
-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-gtk-util.h b/libgjs-private/gjs-gtk-util.h
deleted file mode 100644
index 20492aa5..00000000
--- a/libgjs-private/gjs-gtk-util.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- 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 LIBGJS_PRIVATE_GJS_GTK_UTIL_H_
-#define LIBGJS_PRIVATE_GJS_GTK_UTIL_H_
-
-#include <config.h> /* for ENABLE_GTK */
-
-#include <glib-object.h>
-#include <glib.h>
-
-#include "gjs/macros.h"
-
-G_BEGIN_DECLS
-
-GJS_EXPORT
-void gjs_gtk_container_child_set_property(GObject* container, GObject* child,
- const char* property,
- const GValue* value);
-
-G_END_DECLS
-
-#endif /* LIBGJS_PRIVATE_GJS_GTK_UTIL_H_ */
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);