glib2 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +3023 -0
- data/README +28 -0
- data/Rakefile +87 -0
- data/extconf.rb +61 -0
- data/sample/bookmarkfile.rb +66 -0
- data/sample/completion.rb +45 -0
- data/sample/idle.rb +41 -0
- data/sample/iochannel.rb +44 -0
- data/sample/keyfile.rb +62 -0
- data/sample/shell.rb +36 -0
- data/sample/spawn.rb +25 -0
- data/sample/timeout.rb +28 -0
- data/sample/timeout2.rb +35 -0
- data/sample/timer.rb +40 -0
- data/sample/type-register.rb +103 -0
- data/sample/type-register2.rb +104 -0
- data/sample/utils.rb +54 -0
- data/src/glib-enum-types.c +1032 -0
- data/src/glib-enum-types.h +140 -0
- data/src/lib/glib-mkenums.rb +199 -0
- data/src/lib/glib2.rb +220 -0
- data/src/lib/mkmf-gnome2.rb +390 -0
- data/src/lib/pkg-config.rb +137 -0
- data/src/rbgcompat.h +30 -0
- data/src/rbglib.c +320 -0
- data/src/rbglib.h +96 -0
- data/src/rbglib_bookmarkfile.c +595 -0
- data/src/rbglib_completion.c +192 -0
- data/src/rbglib_convert.c +195 -0
- data/src/rbglib_error.c +95 -0
- data/src/rbglib_fileutils.c +83 -0
- data/src/rbglib_i18n.c +44 -0
- data/src/rbglib_int64.c +157 -0
- data/src/rbglib_iochannel.c +883 -0
- data/src/rbglib_keyfile.c +846 -0
- data/src/rbglib_maincontext.c +917 -0
- data/src/rbglib_mainloop.c +87 -0
- data/src/rbglib_messages.c +150 -0
- data/src/rbglib_pollfd.c +111 -0
- data/src/rbglib_shell.c +68 -0
- data/src/rbglib_source.c +190 -0
- data/src/rbglib_spawn.c +345 -0
- data/src/rbglib_threads.c +51 -0
- data/src/rbglib_timer.c +127 -0
- data/src/rbglib_unicode.c +611 -0
- data/src/rbglib_utils.c +386 -0
- data/src/rbglib_win32.c +136 -0
- data/src/rbgobj_boxed.c +251 -0
- data/src/rbgobj_closure.c +337 -0
- data/src/rbgobj_convert.c +167 -0
- data/src/rbgobj_enums.c +961 -0
- data/src/rbgobj_fundamental.c +30 -0
- data/src/rbgobj_object.c +892 -0
- data/src/rbgobj_param.c +390 -0
- data/src/rbgobj_paramspecs.c +305 -0
- data/src/rbgobj_signal.c +963 -0
- data/src/rbgobj_strv.c +61 -0
- data/src/rbgobj_type.c +851 -0
- data/src/rbgobj_typeinstance.c +121 -0
- data/src/rbgobj_typeinterface.c +148 -0
- data/src/rbgobj_typemodule.c +66 -0
- data/src/rbgobj_typeplugin.c +49 -0
- data/src/rbgobj_value.c +313 -0
- data/src/rbgobj_valuearray.c +59 -0
- data/src/rbgobj_valuetypes.c +298 -0
- data/src/rbgobject.c +406 -0
- data/src/rbgobject.h +265 -0
- data/src/rbgprivate.h +88 -0
- data/src/rbgutil.c +222 -0
- data/src/rbgutil.h +82 -0
- data/src/rbgutil_callback.c +231 -0
- data/test/glib-test-init.rb +6 -0
- data/test/glib-test-utils.rb +12 -0
- data/test/run-test.rb +25 -0
- data/test/test_enum.rb +99 -0
- data/test/test_file_utils.rb +15 -0
- data/test/test_glib2.rb +120 -0
- data/test/test_iochannel.rb +275 -0
- data/test/test_key_file.rb +38 -0
- data/test/test_mkenums.rb +25 -0
- data/test/test_signal.rb +20 -0
- data/test/test_timeout.rb +28 -0
- data/test/test_unicode.rb +369 -0
- data/test/test_utils.rb +37 -0
- data/test/test_win32.rb +13 -0
- metadata +165 -0
@@ -0,0 +1,192 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/************************************************
|
3
|
+
|
4
|
+
rbglib_completion.c -
|
5
|
+
|
6
|
+
$Author: sakai $
|
7
|
+
$Date: 2007/07/08 02:40:12 $
|
8
|
+
|
9
|
+
Copyright (C) 2005,2006 Masao Mutoh
|
10
|
+
************************************************/
|
11
|
+
|
12
|
+
#include "rbgprivate.h"
|
13
|
+
|
14
|
+
static ID id_compfunc;
|
15
|
+
static ID id_call;
|
16
|
+
static ID id_to_s;
|
17
|
+
static ID id_clear;
|
18
|
+
static ID id_items_internal;
|
19
|
+
|
20
|
+
/*****************************************/
|
21
|
+
static GCompletion*
|
22
|
+
completion_copy(comp)
|
23
|
+
GCompletion* comp;
|
24
|
+
{
|
25
|
+
GCompletion* new_comp;
|
26
|
+
g_return_val_if_fail (comp != NULL, NULL);
|
27
|
+
|
28
|
+
new_comp = g_new(GCompletion, 1);
|
29
|
+
*new_comp = *comp;
|
30
|
+
return new_comp;
|
31
|
+
}
|
32
|
+
|
33
|
+
GType
|
34
|
+
g_completion_get_type(void)
|
35
|
+
{
|
36
|
+
static GType our_type = 0;
|
37
|
+
if (our_type == 0)
|
38
|
+
our_type = g_boxed_type_register_static ("GCompletion",
|
39
|
+
(GBoxedCopyFunc)completion_copy,
|
40
|
+
(GBoxedFreeFunc)g_completion_free);
|
41
|
+
return our_type;
|
42
|
+
}
|
43
|
+
/*****************************************/
|
44
|
+
|
45
|
+
#define G_TYPE_COMPLETION (g_completion_get_type())
|
46
|
+
|
47
|
+
#define _SELF(s) ((GCompletion*)RVAL2BOXED(s, G_TYPE_COMPLETION))
|
48
|
+
|
49
|
+
/* data should be [self, data] */
|
50
|
+
static gchar*
|
51
|
+
comp_func(compdata)
|
52
|
+
gpointer compdata;
|
53
|
+
{
|
54
|
+
VALUE ret;
|
55
|
+
VALUE self = RARRAY_PTR((VALUE)compdata)[0];
|
56
|
+
VALUE data = RARRAY_PTR((VALUE)compdata)[1];
|
57
|
+
|
58
|
+
VALUE func = rb_ivar_get(self, id_compfunc);
|
59
|
+
|
60
|
+
if (NIL_P(func)){
|
61
|
+
ret = rb_funcall(data, id_to_s, 0);
|
62
|
+
} else {
|
63
|
+
ret = rb_funcall(func, id_call, 1, data);
|
64
|
+
}
|
65
|
+
return RVAL2CSTR(ret);
|
66
|
+
}
|
67
|
+
|
68
|
+
static VALUE
|
69
|
+
comp_initialize(self)
|
70
|
+
VALUE self;
|
71
|
+
{
|
72
|
+
VALUE block = Qnil;
|
73
|
+
|
74
|
+
if (rb_block_given_p()) {
|
75
|
+
block = rb_block_proc();
|
76
|
+
}
|
77
|
+
|
78
|
+
rb_ivar_set(self, id_compfunc, block);
|
79
|
+
/* This is used for memory management(GC) */
|
80
|
+
rb_ivar_set(self, id_items_internal, rb_hash_new());
|
81
|
+
|
82
|
+
G_INITIALIZE(self, g_completion_new((GCompletionFunc)comp_func));
|
83
|
+
|
84
|
+
return Qnil;
|
85
|
+
}
|
86
|
+
|
87
|
+
static VALUE
|
88
|
+
comp_add_items(self, items)
|
89
|
+
VALUE self, items;
|
90
|
+
{
|
91
|
+
gint i, len;
|
92
|
+
GList* list = (GList*)NULL;
|
93
|
+
VALUE items_internal = rb_ivar_get(self, id_items_internal);
|
94
|
+
|
95
|
+
Check_Type(items, T_ARRAY);
|
96
|
+
len = RARRAY_LEN(items);
|
97
|
+
for (i = 0; i < len; i ++){
|
98
|
+
VALUE data = RARRAY_PTR(items)[i];
|
99
|
+
VALUE item = rb_assoc_new(self, data);
|
100
|
+
list = g_list_append(list, (gpointer)item);
|
101
|
+
rb_hash_aset(items_internal, data, item);
|
102
|
+
}
|
103
|
+
g_completion_add_items(_SELF(self), list);
|
104
|
+
|
105
|
+
return self;
|
106
|
+
}
|
107
|
+
|
108
|
+
static VALUE
|
109
|
+
comp_remove_items(self, items)
|
110
|
+
VALUE self, items;
|
111
|
+
{
|
112
|
+
gint i, len;
|
113
|
+
GList* list = (GList*)NULL;
|
114
|
+
VALUE items_internal = rb_ivar_get(self, id_items_internal);
|
115
|
+
|
116
|
+
Check_Type(items, T_ARRAY);
|
117
|
+
len = RARRAY_LEN(items);
|
118
|
+
for (i = 0; i < len; i ++){
|
119
|
+
VALUE data = RARRAY_PTR(items)[i];
|
120
|
+
VALUE item = rb_hash_aref(items_internal, data);
|
121
|
+
list = g_list_append(list, (gpointer)item);
|
122
|
+
rb_hash_delete(items_internal, data);
|
123
|
+
}
|
124
|
+
g_completion_remove_items(_SELF(self), list);
|
125
|
+
|
126
|
+
return self;
|
127
|
+
}
|
128
|
+
|
129
|
+
static VALUE
|
130
|
+
comp_clear_items(self)
|
131
|
+
VALUE self;
|
132
|
+
{
|
133
|
+
VALUE items_internal = rb_ivar_get(self, id_items_internal);
|
134
|
+
rb_funcall(items_internal, id_clear, 0);
|
135
|
+
g_completion_clear_items(_SELF(self));
|
136
|
+
return self;
|
137
|
+
}
|
138
|
+
|
139
|
+
static VALUE
|
140
|
+
comp_items(self)
|
141
|
+
VALUE self;
|
142
|
+
{
|
143
|
+
return rb_ivar_get(self, id_items_internal);
|
144
|
+
}
|
145
|
+
|
146
|
+
static VALUE
|
147
|
+
comp_complete(self, prefix)
|
148
|
+
VALUE self, prefix;
|
149
|
+
{
|
150
|
+
gchar* new_prefix;
|
151
|
+
VALUE ary = rb_ary_new();
|
152
|
+
#if GLIB_CHECK_VERSION(2,4,0)
|
153
|
+
GList* list = g_completion_complete_utf8(_SELF(self),
|
154
|
+
(const gchar*)RVAL2CSTR(prefix),
|
155
|
+
&new_prefix);
|
156
|
+
#else
|
157
|
+
GList* list = g_completion_complete(_SELF(self),
|
158
|
+
RVAL2CSTR(prefix),
|
159
|
+
&new_prefix);
|
160
|
+
#endif
|
161
|
+
while (list) {
|
162
|
+
rb_ary_push(ary, RARRAY_PTR((VALUE)list->data)[1]);
|
163
|
+
list = list->next;
|
164
|
+
}
|
165
|
+
|
166
|
+
return rb_assoc_new(ary, new_prefix ? CSTR2RVAL(new_prefix) : Qnil);
|
167
|
+
}
|
168
|
+
|
169
|
+
/* We don't use this.
|
170
|
+
void g_completion_set_compare (GCompletion *cmp,
|
171
|
+
GCompletionStrncmpFunc strncmp_func);
|
172
|
+
*/
|
173
|
+
|
174
|
+
void
|
175
|
+
Init_glib_completion()
|
176
|
+
{
|
177
|
+
VALUE comp = G_DEF_CLASS(G_TYPE_COMPLETION, "Completion", mGLib);
|
178
|
+
|
179
|
+
id_call = rb_intern("call");
|
180
|
+
id_to_s = rb_intern("to_s");
|
181
|
+
id_clear = rb_intern("clear");
|
182
|
+
id_compfunc = rb_intern("completion_proc");
|
183
|
+
id_items_internal = rb_intern("items_internal");
|
184
|
+
|
185
|
+
rb_define_method(comp, "initialize", comp_initialize, 0);
|
186
|
+
rb_define_method(comp, "add_items", comp_add_items, 1);
|
187
|
+
rb_define_method(comp, "remove_items", comp_remove_items, 1);
|
188
|
+
rb_define_method(comp, "clear_items", comp_clear_items, 0);
|
189
|
+
rb_define_method(comp, "complete", comp_complete, 1);
|
190
|
+
|
191
|
+
rb_define_method(comp, "items", comp_items, 0);
|
192
|
+
}
|
@@ -0,0 +1,195 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbglib_convert.c -
|
5
|
+
|
6
|
+
$Author: sakai $
|
7
|
+
$Date: 2007/06/16 02:46:28 $
|
8
|
+
|
9
|
+
Copyright (C) 2002,2003 KUBO Takehiro
|
10
|
+
Copyright (C) 2009 Ruby-GNOME2 Project Team
|
11
|
+
|
12
|
+
**********************************************************************/
|
13
|
+
#include "rbgprivate.h"
|
14
|
+
#include "rbglib.h"
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
rbglib_m_convert(self, str, to, from)
|
18
|
+
VALUE self, str, to, from;
|
19
|
+
{
|
20
|
+
GError *err = NULL;
|
21
|
+
gchar* ret;
|
22
|
+
gsize written;
|
23
|
+
VALUE s = Qnil;
|
24
|
+
|
25
|
+
StringValue(str);
|
26
|
+
ret = g_convert(RSTRING_PTR(str), RSTRING_LEN(str),
|
27
|
+
StringValuePtr(to), StringValuePtr(from),
|
28
|
+
NULL, &written, &err);
|
29
|
+
|
30
|
+
if (err != NULL)
|
31
|
+
RAISE_GERROR(err);
|
32
|
+
s = rb_str_new(ret, written);
|
33
|
+
g_free(ret);
|
34
|
+
return s;
|
35
|
+
}
|
36
|
+
|
37
|
+
static VALUE
|
38
|
+
rbglib_m_locale_to_utf8(self, str)
|
39
|
+
VALUE self, str;
|
40
|
+
{
|
41
|
+
GError *err = NULL;
|
42
|
+
VALUE s = Qnil;
|
43
|
+
gchar* ret;
|
44
|
+
gsize written;
|
45
|
+
|
46
|
+
StringValue(str);
|
47
|
+
ret = g_locale_to_utf8(RSTRING_PTR(str), RSTRING_LEN(str),
|
48
|
+
NULL, &written, &err);
|
49
|
+
|
50
|
+
if (err != NULL)
|
51
|
+
RAISE_GERROR(err);
|
52
|
+
s = rb_str_new(ret, written);
|
53
|
+
g_free(ret);
|
54
|
+
return s;
|
55
|
+
}
|
56
|
+
|
57
|
+
static VALUE
|
58
|
+
rbglib_m_locale_from_utf8(self, str)
|
59
|
+
VALUE self, str;
|
60
|
+
{
|
61
|
+
GError *err = NULL;
|
62
|
+
VALUE s = Qnil;
|
63
|
+
gchar* ret;
|
64
|
+
gsize written;
|
65
|
+
|
66
|
+
StringValue(str);
|
67
|
+
ret = g_locale_from_utf8(RSTRING_PTR(str), RSTRING_LEN(str),
|
68
|
+
NULL, &written, &err);
|
69
|
+
|
70
|
+
if (err != NULL)
|
71
|
+
RAISE_GERROR(err);
|
72
|
+
s = rb_str_new(ret, written);
|
73
|
+
g_free(ret);
|
74
|
+
return s;
|
75
|
+
}
|
76
|
+
|
77
|
+
static VALUE
|
78
|
+
rbglib_m_filename_to_utf8(self, str)
|
79
|
+
VALUE self, str;
|
80
|
+
{
|
81
|
+
GError *err = NULL;
|
82
|
+
VALUE s = Qnil;
|
83
|
+
gchar* ret;
|
84
|
+
gsize written;
|
85
|
+
|
86
|
+
StringValue(str);
|
87
|
+
ret = g_filename_to_utf8(RSTRING_PTR(str), RSTRING_LEN(str),
|
88
|
+
NULL, &written, &err);
|
89
|
+
|
90
|
+
if (err != NULL)
|
91
|
+
RAISE_GERROR(err);
|
92
|
+
s = rb_str_new(ret, written);
|
93
|
+
g_free(ret);
|
94
|
+
return s;
|
95
|
+
}
|
96
|
+
|
97
|
+
static VALUE
|
98
|
+
rbglib_m_filename_from_utf8(self, str)
|
99
|
+
VALUE self, str;
|
100
|
+
{
|
101
|
+
GError *err = NULL;
|
102
|
+
VALUE s = Qnil;
|
103
|
+
gchar* ret;
|
104
|
+
gsize written;
|
105
|
+
|
106
|
+
StringValue(str);
|
107
|
+
ret = g_filename_from_utf8(RSTRING_PTR(str), RSTRING_LEN(str),
|
108
|
+
NULL, &written, &err);
|
109
|
+
|
110
|
+
if (err != NULL)
|
111
|
+
RAISE_GERROR(err);
|
112
|
+
s = rb_str_new(ret, written);
|
113
|
+
g_free(ret);
|
114
|
+
return s;
|
115
|
+
}
|
116
|
+
|
117
|
+
static VALUE
|
118
|
+
rbglib_m_filename_to_uri(argc, argv, self)
|
119
|
+
int argc;
|
120
|
+
VALUE *argv;
|
121
|
+
VALUE self;
|
122
|
+
{
|
123
|
+
VALUE filename, hostname, s;
|
124
|
+
GError *err = NULL;
|
125
|
+
gchar* ret;
|
126
|
+
|
127
|
+
rb_scan_args(argc, argv, "11", &filename, &hostname);
|
128
|
+
|
129
|
+
ret = g_filename_to_uri(StringValuePtr(filename),
|
130
|
+
NIL_P(hostname) ? NULL : StringValuePtr(hostname),
|
131
|
+
&err);
|
132
|
+
|
133
|
+
if (err)
|
134
|
+
RAISE_GERROR(err);
|
135
|
+
s = rb_str_new2(ret);
|
136
|
+
g_free(ret);
|
137
|
+
return s;
|
138
|
+
}
|
139
|
+
|
140
|
+
static VALUE
|
141
|
+
rbglib_m_filename_from_uri(self, str)
|
142
|
+
VALUE self, str;
|
143
|
+
{
|
144
|
+
GError *err = NULL;
|
145
|
+
VALUE s;
|
146
|
+
gchar* filename;
|
147
|
+
char* hostname;
|
148
|
+
|
149
|
+
filename = g_filename_from_uri(StringValuePtr(str), &hostname, &err);
|
150
|
+
|
151
|
+
if (err)
|
152
|
+
RAISE_GERROR(err);
|
153
|
+
s = rb_ary_new3(2, rb_str_new2(filename),
|
154
|
+
hostname ? rb_str_new2(hostname) : Qnil);
|
155
|
+
g_free(filename);
|
156
|
+
g_free(hostname);
|
157
|
+
return s;
|
158
|
+
}
|
159
|
+
|
160
|
+
static VALUE
|
161
|
+
rbglib_m_utf8_validate(self, str)
|
162
|
+
VALUE self, str;
|
163
|
+
{
|
164
|
+
rb_warning("GLib.utf8_validate is deprecated. Use GLib::UTF8.validate instead.");
|
165
|
+
StringValue(str);
|
166
|
+
return CBOOL2RVAL(g_utf8_validate(RSTRING_PTR(str), RSTRING_LEN(str), NULL));
|
167
|
+
}
|
168
|
+
|
169
|
+
void
|
170
|
+
Init_glib_convert()
|
171
|
+
{
|
172
|
+
VALUE cCharError = G_DEF_ERROR2(G_CONVERT_ERROR, "ConvertError", mGLib, rb_eIOError);
|
173
|
+
|
174
|
+
rb_define_const(cCharError, "NO_CONVERSION", INT2NUM(G_CONVERT_ERROR_NO_CONVERSION));
|
175
|
+
rb_define_const(cCharError, "ILLEGAL_SEQUENCE", INT2NUM(G_CONVERT_ERROR_ILLEGAL_SEQUENCE));
|
176
|
+
rb_define_const(cCharError, "FAILED", INT2NUM(G_CONVERT_ERROR_FAILED));
|
177
|
+
rb_define_const(cCharError, "PARTIAL_INPUT", INT2NUM(G_CONVERT_ERROR_PARTIAL_INPUT));
|
178
|
+
rb_define_const(cCharError, "BAD_URI", INT2NUM(G_CONVERT_ERROR_BAD_URI));
|
179
|
+
rb_define_const(cCharError, "NOT_ABSOLUTE_PATH", INT2NUM(G_CONVERT_ERROR_NOT_ABSOLUTE_PATH));
|
180
|
+
|
181
|
+
/* glib/gunicode.h */
|
182
|
+
/* just for backward compatibility.
|
183
|
+
Use GLib::UTF8.validate instead. */
|
184
|
+
rb_define_module_function(mGLib, "utf8_validate", rbglib_m_utf8_validate, 1);
|
185
|
+
|
186
|
+
/* glib/gconvert.h */
|
187
|
+
rb_define_module_function(mGLib, "convert", rbglib_m_convert, 3);
|
188
|
+
rb_define_module_function(mGLib, "locale_to_utf8", rbglib_m_locale_to_utf8, 1);
|
189
|
+
rb_define_module_function(mGLib, "locale_from_utf8", rbglib_m_locale_from_utf8, 1);
|
190
|
+
rb_define_module_function(mGLib, "filename_to_utf8", rbglib_m_filename_to_utf8, 1);
|
191
|
+
rb_define_module_function(mGLib, "filename_from_utf8", rbglib_m_filename_from_utf8, 1);
|
192
|
+
|
193
|
+
rb_define_module_function(mGLib, "filename_to_uri", rbglib_m_filename_to_uri, -1);
|
194
|
+
rb_define_module_function(mGLib, "filename_from_uri", rbglib_m_filename_from_uri, 1);
|
195
|
+
}
|
data/src/rbglib_error.c
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/************************************************
|
3
|
+
|
4
|
+
rbgerror.c -
|
5
|
+
|
6
|
+
$Author: mutoh $
|
7
|
+
$Date: 2004/08/22 13:27:47 $
|
8
|
+
|
9
|
+
Copyright (C) 2004 Masao Mutoh
|
10
|
+
************************************************/
|
11
|
+
|
12
|
+
#include "rbgprivate.h"
|
13
|
+
#include <ctype.h>
|
14
|
+
|
15
|
+
static ID id_code;
|
16
|
+
static ID id_domain;
|
17
|
+
static VALUE gerror_table;
|
18
|
+
static VALUE generic_error;
|
19
|
+
|
20
|
+
VALUE
|
21
|
+
rbgerr_gerror2exception(error)
|
22
|
+
GError *error;
|
23
|
+
{
|
24
|
+
VALUE exc = Qnil;
|
25
|
+
VALUE klass = Qnil;
|
26
|
+
|
27
|
+
if (! error){
|
28
|
+
return rb_exc_new2(rb_eRuntimeError, "GError parameter doesn't have a value.");
|
29
|
+
}
|
30
|
+
|
31
|
+
klass = rb_hash_aref(gerror_table, UINT2NUM(error->domain));
|
32
|
+
if NIL_P(klass){
|
33
|
+
exc = rb_exc_new2(generic_error, error->message);
|
34
|
+
rb_ivar_set(exc, id_domain, CSTR2RVAL(g_quark_to_string(error->domain)));
|
35
|
+
rb_ivar_set(exc, id_code, INT2NUM(error->code));
|
36
|
+
} else {
|
37
|
+
exc = rb_exc_new2(klass, error->message);
|
38
|
+
rb_ivar_set(exc, id_domain, CSTR2RVAL(g_quark_to_string(error->domain)));
|
39
|
+
rb_ivar_set(exc, id_code, INT2NUM(error->code));
|
40
|
+
}
|
41
|
+
g_error_free(error);
|
42
|
+
return exc;
|
43
|
+
}
|
44
|
+
|
45
|
+
VALUE
|
46
|
+
rbgerr_define_gerror(domain, name, module, parent, gtype)
|
47
|
+
GQuark domain;
|
48
|
+
const gchar* name;
|
49
|
+
VALUE module;
|
50
|
+
VALUE parent;
|
51
|
+
VALUE gtype;
|
52
|
+
{
|
53
|
+
VALUE klass = rb_define_class_under(module, name, parent);
|
54
|
+
rb_funcall(klass, rbgutil_id_module_eval, 1, CSTR2RVAL("def code; @code; end\n"));
|
55
|
+
rb_funcall(klass, rbgutil_id_module_eval, 1, CSTR2RVAL("def domain; @domain; end\n"));
|
56
|
+
|
57
|
+
rb_hash_aset(gerror_table, UINT2NUM(domain), klass);
|
58
|
+
|
59
|
+
if (! NIL_P(gtype)){
|
60
|
+
GEnumClass* gclass = g_type_class_ref(gtype);
|
61
|
+
int i;
|
62
|
+
|
63
|
+
for (i = 0; i < gclass->n_values; i++) {
|
64
|
+
GEnumValue* entry = &(gclass->values[i]);
|
65
|
+
gchar* nick = g_strdup(entry->value_nick);
|
66
|
+
gchar* p;
|
67
|
+
|
68
|
+
for (p = nick; *p; p++) {
|
69
|
+
if (*p == '-')
|
70
|
+
*p = '_';
|
71
|
+
else
|
72
|
+
*p = g_ascii_toupper(*p);
|
73
|
+
}
|
74
|
+
rbgobj_define_const(klass, nick, INT2NUM(i));
|
75
|
+
g_free(nick);
|
76
|
+
}
|
77
|
+
|
78
|
+
g_type_class_unref(gclass);
|
79
|
+
}
|
80
|
+
|
81
|
+
return klass;
|
82
|
+
}
|
83
|
+
|
84
|
+
void
|
85
|
+
Init_glib_error()
|
86
|
+
{
|
87
|
+
id_code = rb_intern("@code");
|
88
|
+
id_domain = rb_intern("@domain");
|
89
|
+
gerror_table = rb_hash_new();
|
90
|
+
rb_global_variable(&gerror_table);
|
91
|
+
|
92
|
+
generic_error = rb_define_class_under(mGLib, "Error", rb_eRuntimeError);
|
93
|
+
rb_funcall(generic_error, rbgutil_id_module_eval, 1, CSTR2RVAL("def code; @code; end\n"));
|
94
|
+
rb_funcall(generic_error, rbgutil_id_module_eval, 1, CSTR2RVAL("def domain; @domain; end\n"));
|
95
|
+
}
|