Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 64 lines (50 sloc) 1.465 kb
b1302c5 Christian Hergert Initial commit.
authored
1 #include <gtk/gtk.h>
2 #include <gjs/gjs-module.h>
3
4 #include "g-script-js.h"
5
6 static void
7 connect_func (GtkBuilder *builder,
8 GObject *object,
9 const gchar *signal_name,
10 const gchar *handler_name,
11 GObject *connect_object,
12 GConnectFlags flags,
13 gpointer user_data)
14 {
15 const gchar *script_name = user_data;
16 GScriptJs *script;
17 GClosure *closure;
18
19 g_return_if_fail(script_name != NULL);
20 g_return_if_fail(connect_object == NULL); /* TODO */
21
22 script = G_SCRIPT_JS(gtk_builder_get_object(builder, script_name));
23 if (!script) {
24 g_critical("Cannot locate script %s", script_name);
25 return;
26 }
27
28 closure = g_script_js_get_function(script, handler_name);
29 if (!closure) {
30 g_critical("Cannot locate function %s", handler_name);
31 return;
32 }
33
34 g_signal_connect_closure(object, signal_name, closure,
35 !!(flags & G_CONNECT_AFTER));
36 }
37
38 gint
39 main (gint argc,
40 gchar *argv[])
41 {
42 GtkBuilder *builder;
43 GtkWidget *window;
44 GError *error = NULL;
45
46 gtk_init(&argc, &argv);
47
48 /* linker hack */
49 g_debug("Registering type: %s", g_type_name(G_TYPE_SCRIPT_JS));
50
51 builder = gtk_builder_new();
52 gtk_builder_add_from_file(builder, "script.ui", &error);
53 gtk_builder_connect_signals_full(builder, connect_func, "script");
54 g_assert_no_error(error);
55
56 window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
57 g_assert(window);
58
59 gtk_window_present(GTK_WINDOW(window));
60 gtk_main();
61
62 return 0;
63 }
Something went wrong with that request. Please try again.