glib2 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/ChangeLog +3023 -0
  2. data/README +28 -0
  3. data/Rakefile +87 -0
  4. data/extconf.rb +61 -0
  5. data/sample/bookmarkfile.rb +66 -0
  6. data/sample/completion.rb +45 -0
  7. data/sample/idle.rb +41 -0
  8. data/sample/iochannel.rb +44 -0
  9. data/sample/keyfile.rb +62 -0
  10. data/sample/shell.rb +36 -0
  11. data/sample/spawn.rb +25 -0
  12. data/sample/timeout.rb +28 -0
  13. data/sample/timeout2.rb +35 -0
  14. data/sample/timer.rb +40 -0
  15. data/sample/type-register.rb +103 -0
  16. data/sample/type-register2.rb +104 -0
  17. data/sample/utils.rb +54 -0
  18. data/src/glib-enum-types.c +1032 -0
  19. data/src/glib-enum-types.h +140 -0
  20. data/src/lib/glib-mkenums.rb +199 -0
  21. data/src/lib/glib2.rb +220 -0
  22. data/src/lib/mkmf-gnome2.rb +390 -0
  23. data/src/lib/pkg-config.rb +137 -0
  24. data/src/rbgcompat.h +30 -0
  25. data/src/rbglib.c +320 -0
  26. data/src/rbglib.h +96 -0
  27. data/src/rbglib_bookmarkfile.c +595 -0
  28. data/src/rbglib_completion.c +192 -0
  29. data/src/rbglib_convert.c +195 -0
  30. data/src/rbglib_error.c +95 -0
  31. data/src/rbglib_fileutils.c +83 -0
  32. data/src/rbglib_i18n.c +44 -0
  33. data/src/rbglib_int64.c +157 -0
  34. data/src/rbglib_iochannel.c +883 -0
  35. data/src/rbglib_keyfile.c +846 -0
  36. data/src/rbglib_maincontext.c +917 -0
  37. data/src/rbglib_mainloop.c +87 -0
  38. data/src/rbglib_messages.c +150 -0
  39. data/src/rbglib_pollfd.c +111 -0
  40. data/src/rbglib_shell.c +68 -0
  41. data/src/rbglib_source.c +190 -0
  42. data/src/rbglib_spawn.c +345 -0
  43. data/src/rbglib_threads.c +51 -0
  44. data/src/rbglib_timer.c +127 -0
  45. data/src/rbglib_unicode.c +611 -0
  46. data/src/rbglib_utils.c +386 -0
  47. data/src/rbglib_win32.c +136 -0
  48. data/src/rbgobj_boxed.c +251 -0
  49. data/src/rbgobj_closure.c +337 -0
  50. data/src/rbgobj_convert.c +167 -0
  51. data/src/rbgobj_enums.c +961 -0
  52. data/src/rbgobj_fundamental.c +30 -0
  53. data/src/rbgobj_object.c +892 -0
  54. data/src/rbgobj_param.c +390 -0
  55. data/src/rbgobj_paramspecs.c +305 -0
  56. data/src/rbgobj_signal.c +963 -0
  57. data/src/rbgobj_strv.c +61 -0
  58. data/src/rbgobj_type.c +851 -0
  59. data/src/rbgobj_typeinstance.c +121 -0
  60. data/src/rbgobj_typeinterface.c +148 -0
  61. data/src/rbgobj_typemodule.c +66 -0
  62. data/src/rbgobj_typeplugin.c +49 -0
  63. data/src/rbgobj_value.c +313 -0
  64. data/src/rbgobj_valuearray.c +59 -0
  65. data/src/rbgobj_valuetypes.c +298 -0
  66. data/src/rbgobject.c +406 -0
  67. data/src/rbgobject.h +265 -0
  68. data/src/rbgprivate.h +88 -0
  69. data/src/rbgutil.c +222 -0
  70. data/src/rbgutil.h +82 -0
  71. data/src/rbgutil_callback.c +231 -0
  72. data/test/glib-test-init.rb +6 -0
  73. data/test/glib-test-utils.rb +12 -0
  74. data/test/run-test.rb +25 -0
  75. data/test/test_enum.rb +99 -0
  76. data/test/test_file_utils.rb +15 -0
  77. data/test/test_glib2.rb +120 -0
  78. data/test/test_iochannel.rb +275 -0
  79. data/test/test_key_file.rb +38 -0
  80. data/test/test_mkenums.rb +25 -0
  81. data/test/test_signal.rb +20 -0
  82. data/test/test_timeout.rb +28 -0
  83. data/test/test_unicode.rb +369 -0
  84. data/test/test_utils.rb +37 -0
  85. data/test/test_win32.rb +13 -0
  86. metadata +165 -0
data/src/rbgobject.h ADDED
@@ -0,0 +1,265 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+
4
+ rbgobject.h -
5
+
6
+ $Author: sakai $
7
+ $Date: 2007/07/19 22:03:44 $
8
+
9
+ Copyright (C) 2003,2006 Ruby-GNOME2 Project Team
10
+ Copyright (C) 2002,2003 Masahiro Sakai
11
+
12
+ **********************************************************************/
13
+
14
+ #ifndef __RBGOBJECT_H__
15
+ #define __RBGOBJECT_H__
16
+
17
+ #include <glib-object.h>
18
+ #include "ruby.h"
19
+ #include "rbglib.h"
20
+ #include "rbgutil.h"
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif /* __cplusplus */
25
+
26
+ /* macros */
27
+
28
+ #define G_INITIALIZE(obj, cobj)\
29
+ (rbgobj_initialize_object(obj, (gpointer)cobj))
30
+
31
+ #define G_DEF_CLASS(gtype, name, module)\
32
+ (rbgobj_define_class(gtype, name, module, 0, 0, Qnil))
33
+ #define G_DEF_CLASS_WITH_GC_FUNC(gtype, name, module, mark, free) \
34
+ (rbgobj_define_class(gtype, name, module, mark, free, Qnil))
35
+ #define G_DEF_CLASS2(gtype, name, module, mark, free) \
36
+ G_DEF_CLASS_WITH_GC_FUNC(gtype, name, module, mark, free)
37
+ #define G_DEF_CLASS3(gtype_name, name, module)\
38
+ (rbgobj_define_class_dynamic(gtype_name, name, module, 0, 0))
39
+ #define G_DEF_CLASS4(gtype, name, module, parent) \
40
+ (rbgobj_define_class(gtype, name, module, 0, 0, parent))
41
+
42
+ #define G_DEF_INTERFACE(gtype, name, module)\
43
+ (rbgobj_define_class(gtype, name, module, 0, 0, Qnil))
44
+ #define G_DEF_INTERFACE2(gtype, name, module, mark, free)\
45
+ (rbgobj_define_class(gtype, name, module, mark, free, Qnil))
46
+
47
+ #define RG_DEF_CONVERSION(table) (rbgobj_convert_define(table))
48
+
49
+ #define G_RELATIVE(obj, rel) (rbgobj_add_relative(obj, rel))
50
+
51
+ /* G_RELATIVE2 is useless now. Try G_CHILD_ADD/REMOVE first. */
52
+ #define G_RELATIVE2(obj, rel, id, hash_key)\
53
+ (rbgobj_add_relative_removable(obj, rel, id, hash_key))
54
+ #define G_GET_RELATIVE(obj, id, hash_key)\
55
+ (rbgobj_get_relative_removable(obj, id, hash_key))
56
+ #define G_REMOVE_RELATIVE(obj, id, hash_key)\
57
+ (rbgobj_remove_relative(obj, id, hash_key))
58
+
59
+ RUBY_GLIB2_VAR ID rbgobj_id_children;
60
+ #define G_CHILD_SET(self, id, child) (rb_ivar_set(self, id, child))
61
+ #define G_CHILD_UNSET(self, id) (rb_ivar_set(self, id, Qnil))
62
+
63
+ /* G_CHILD_ADD is same as G_RELATIVE, but the macro name is more obviously
64
+ to use than G_RELATIVE, and also support "remove" operation with the key
65
+ which is the object itself.
66
+ */
67
+ #define G_CHILD_ADD(self, child) \
68
+ (rbgobj_add_relative_removable(self, Qnil, rbgobj_id_children, child))
69
+ #define G_CHILD_REMOVE(self, child) \
70
+ (rbgobj_remove_relative(self, rbgobj_id_children, child))
71
+ #define G_CHILD_REMOVE_ALL(self) \
72
+ (rbgobj_remove_relative_all(self, rbgobj_id_children))
73
+
74
+ #define G_DEF_SIGNAL_FUNC(klass, sig_name, func)\
75
+ (rbgobj_set_signal_func(klass, sig_name, func))
76
+
77
+ #define CLASS2CINFO(klass) (rbgobj_lookup_class(klass))
78
+ #define GTYPE2CINFO(gtype) (rbgobj_lookup_class_by_gtype(gtype, Qnil))
79
+ #define GTYPE2CINFO_NO_CREATE(gtype) (rbgobj_lookup_class_by_gtype_full(gtype, Qnil, FALSE))
80
+ #define RVAL2CINFO(obj) (rbgobj_lookup_class(CLASS_OF(obj)))
81
+ #define GTYPE2CLASS(gtype) (rbgobj_gtype_to_ruby_class(gtype))
82
+ #define CLASS2GTYPE(klass) (rbgobj_lookup_class(klass)->gtype)
83
+ #define RVAL2GTYPE(obj) (CLASS2GTYPE(CLASS_OF(obj)))
84
+
85
+ #define RVAL2GOBJ(obj) (rbgobj_instance_from_ruby_object(obj))
86
+ #define GOBJ2RVAL(gobj) (rbgobj_ruby_object_from_instance(gobj))
87
+ #define GOBJ2RVAL_UNREF(gobj) (rbgobj_ruby_object_from_instance_with_unref(gobj))
88
+ #define GOBJ2RVALU(gobj) GOBJ2RVAL_UNREF(gobj)
89
+ #define GVAL2RVAL(v) (rbgobj_gvalue_to_rvalue(v))
90
+
91
+ #define RVAL2BOXED(obj, gtype) (rbgobj_boxed_get(obj, gtype))
92
+ #define BOXED2RVAL(cobj, gtype) (rbgobj_make_boxed(cobj, gtype))
93
+
94
+ #define RVAL2GENUM(obj, gtype) (rbgobj_get_enum(obj, gtype))
95
+ #define RVAL2GFLAGS(obj, gtype) (rbgobj_get_flags(obj, gtype))
96
+ #define GENUM2RVAL(n, gtype) (rbgobj_make_enum(n, gtype))
97
+ #define GFLAGS2RVAL(n, gtype) (rbgobj_make_flags(n, gtype))
98
+
99
+ #define RVAL2GPTR(object) (rbgobj_ptr2cptr(object))
100
+ #define GPTR2RVAL(ptr, gtype) (rbgobj_ptr_new(gtype, ptr))
101
+
102
+ #define G_DEF_CONSTANTS(mod, type, strip_prefix) \
103
+ rbgobj_add_constants(mod, type, strip_prefix)
104
+ #define G_RENAME_CONSTANT(orig, alt) \
105
+ rbgobj_constant_remap(orig, alt)
106
+ #define G_RENAME_NICK(orig, alt) \
107
+ rbgobj_constant_remap(orig, alt)
108
+
109
+ typedef enum
110
+ {
111
+ RBGOBJ_ABSTRACT_BUT_CREATABLE = 1 << 0, /* deprecated */
112
+ RBGOBJ_BOXED_NOT_COPY = 1 << 1,
113
+ RBGOBJ_DEFINED_BY_RUBY = 1 << 2,
114
+ } RGObjClassFlag;
115
+
116
+ typedef struct {
117
+ VALUE klass;
118
+ GType gtype;
119
+ void (*mark)(gpointer);
120
+ void (*free)(gpointer);
121
+ int flags; /* RGObjClassFlag */
122
+ } RGObjClassInfo;
123
+
124
+ /* rbgobject.c */
125
+
126
+ extern void rbgobj_initialize_object(VALUE obj, gpointer cobj);
127
+ extern gpointer rbgobj_instance_from_ruby_object(VALUE obj);
128
+ extern VALUE rbgobj_ruby_object_from_instance(gpointer instance);
129
+ extern VALUE rbgobj_ruby_object_from_instance2(gpointer instance, gboolean alloc);
130
+ extern VALUE rbgobj_ruby_object_from_instance_with_unref(gpointer instance);
131
+
132
+ extern void rbgobj_add_relative(VALUE obj, VALUE relative);
133
+ extern void rbgobj_invalidate_relatives(VALUE obj);
134
+ extern void rbgobj_add_relative_removable(VALUE obj, VALUE relative,
135
+ ID obj_ivar_id, VALUE hash_key);
136
+ extern VALUE rbgobj_get_relative_removable(VALUE obj, ID obj_ivar_id,
137
+ VALUE hash_key);
138
+ extern void rbgobj_remove_relative(VALUE obj, ID obj_ivar_id, VALUE hash_key);
139
+ extern void rbgobj_remove_relative_all(VALUE obj, ID obj_ivar_id);
140
+
141
+ extern GObject* rbgobj_gobject_new(GType type, VALUE params_hash);
142
+ extern VALUE rbgobj_create_object(VALUE klass); /* deprecated */
143
+
144
+ extern VALUE rbgobj_get_ruby_object_from_gobject(GObject* gobj, gboolean alloc);
145
+
146
+ /* deprecated */
147
+ extern void rbgobj_add_abstract_but_create_instance_class(GType gtype);
148
+
149
+ /* rbgobj_typeinstance.c */
150
+ extern void rbgobj_gc_mark_instance(gpointer instance);
151
+
152
+
153
+ /* rbgobj_type.c */
154
+ extern const RGObjClassInfo *rbgobj_lookup_class(VALUE klass);
155
+ extern const RGObjClassInfo *rbgobj_lookup_class_by_gtype(GType gtype, VALUE parent);
156
+ extern const RGObjClassInfo *rbgobj_lookup_class_by_gtype_full(GType gtype,
157
+ VALUE parent,
158
+ gboolean create_object);
159
+ extern VALUE rbgobj_gtype_to_ruby_class(GType gtype);
160
+ extern VALUE rbgobj_define_class(GType gtype, const gchar* name, VALUE module,
161
+ void* mark, void* free, VALUE parent);
162
+ extern VALUE rbgobj_define_class_dynamic(const gchar* gtype_name,
163
+ const gchar* name, VALUE module,
164
+ void* mark, void* free);
165
+ extern void rbgobj_register_class(VALUE klass,
166
+ GType gtype,
167
+ gboolean klass2gtype,
168
+ gboolean gtype2klass);
169
+ extern VALUE rbgobj_cType;
170
+ extern VALUE rbgobj_gtype_new(GType gtype);
171
+ extern GType rbgobj_gtype_get(VALUE obj);
172
+
173
+ /* rbgobj_signal.c */
174
+ typedef VALUE (*GValToRValSignalFunc)(guint num,const GValue* values);
175
+ extern void rbgobj_set_signal_func(VALUE klass, gchar* sig_name, GValToRValSignalFunc func);
176
+ extern GValToRValSignalFunc rbgobj_get_signal_func(guint signal_id);
177
+ extern VALUE rbgobj_signal_wrap(guint sig_id);
178
+
179
+
180
+ /* rbgobj_closure.c */
181
+ extern GClosure* g_rclosure_new(VALUE callback_proc, VALUE extra_args,
182
+ GValToRValSignalFunc func);
183
+ extern void g_rclosure_attach(GClosure *closure, VALUE object);
184
+ extern void g_rclosure_set_tag(GClosure *closure, const gchar *tag);
185
+
186
+ /* rbgobj_value.c */
187
+ extern VALUE rbgobj_gvalue_to_rvalue(const GValue* value);
188
+ extern void rbgobj_rvalue_to_gvalue(VALUE val, GValue* result);
189
+ extern void rbgobj_initialize_gvalue(GValue *result, VALUE value);
190
+
191
+ typedef void (*RValueToGValueFunc)(VALUE from, GValue* to);
192
+ typedef VALUE (*GValueToRValueFunc)(const GValue* from);
193
+ extern void rbgobj_register_r2g_func(GType gtype, RValueToGValueFunc func);
194
+ extern void rbgobj_register_g2r_func(GType gtype, GValueToRValueFunc func);
195
+
196
+ extern void rbgobj_gc_mark_gvalue(GValue* value);
197
+
198
+ /* rbgobj_valuetypes.c */
199
+ extern VALUE rbgobj_ptr_new(GType type, gpointer ptr);
200
+ extern gpointer rbgobj_ptr2cptr(VALUE ptr);
201
+
202
+ #define RBGOBJ_TYPE_RUBY_VALUE (rbgobj_ruby_value_get_type())
203
+ extern GType rbgobj_ruby_value_get_type();
204
+ extern VALUE g_value_get_ruby_value(const GValue* value);
205
+ extern void g_value_set_ruby_value(GValue* value, VALUE ruby);
206
+
207
+ /* rbgobj_object.c */
208
+ extern void rbgobj_register_property_setter(GType gtype, const char* prop_name, RValueToGValueFunc func);
209
+ extern void rbgobj_register_property_getter(GType gtype, const char* prop_name, GValueToRValueFunc func);
210
+
211
+ /* rbgobj_boxed.c */
212
+ extern VALUE rbgobj_boxed_create(VALUE klass); /* deprecated */
213
+ extern gpointer rbgobj_boxed_get(VALUE obj, GType gtype);
214
+ extern VALUE rbgobj_make_boxed(gpointer data, GType gtype);
215
+ extern void rbgobj_boxed_not_copy_obj(GType gtype);
216
+
217
+ /* rbgobj_enums.c */
218
+ extern void rbgobj_constant_remap(const char *original, const char *replacement);
219
+ extern void rbgobj_add_constants(VALUE mod, GType type, const gchar *strip_prefix);
220
+ extern VALUE rbgobj_make_enum(gint n, GType gtype);
221
+ extern gint rbgobj_get_enum(VALUE obj, GType gtype);
222
+ extern VALUE rbgobj_make_flags(guint n, GType gtype);
223
+ extern guint rbgobj_get_flags(VALUE obj, GType gtype);
224
+ extern void rbgobj_define_const(VALUE mod, const char *name, VALUE value);
225
+
226
+
227
+ /* rbglib_mainloop.c */
228
+ #define G_TYPE_MAIN_LOOP (g_main_loop_get_type())
229
+ extern GType g_main_loop_get_type(void);
230
+
231
+ /* rbglib_maincontext.c */
232
+ #define G_TYPE_MAIN_CONTEXT (g_main_context_get_type())
233
+ #define G_TYPE_SOURCE (g_source_get_type())
234
+ #define G_TYPE_POLL_FD (g_poll_fd_get_type())
235
+ extern GType g_main_context_get_type(void);
236
+ extern GType g_source_get_type(void);
237
+ extern GType g_poll_fd_get_type(void);
238
+
239
+ /* rbglib_keyfile.c */
240
+ #define G_TYPE_KEY_FILE (g_key_file_get_type())
241
+ extern GType g_key_file_get_type(void);
242
+
243
+ /* rbgobj_convert.c */
244
+ typedef struct {
245
+ GType type;
246
+ VALUE klass;
247
+ VALUE (*get_superclass)(void);
248
+ void (*type_init_hook)(VALUE);
249
+ void (*rvalue2gvalue)(VALUE val, GValue *result);
250
+ VALUE (*gvalue2rvalue)(const GValue *);
251
+ void (*initialize)(VALUE, gpointer);
252
+ gpointer (*robj2instance)(VALUE);
253
+ VALUE (*instance2robj)(gpointer);
254
+ void (*unref)(gpointer instance);
255
+ } RGConvertTable;
256
+
257
+ extern void rbgobj_convert_define(RGConvertTable *table);
258
+
259
+ #ifdef __cplusplus
260
+ }
261
+ #endif /* __cplusplus */
262
+
263
+ #endif /* __RBGOBJECT_H__ */
264
+
265
+ #include "rbgcompat.h"
data/src/rbgprivate.h ADDED
@@ -0,0 +1,88 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+ rbgprivate.h -
4
+
5
+ Copyright (C) 2007 Ruby-GNOME2 Project Team
6
+ **********************************************************************/
7
+
8
+ #ifndef __RBGPRIVATE_H__
9
+ #define __RBGPRIVATE_H__
10
+
11
+ #include "rbgobject.h"
12
+ #include "glib-enum-types.h"
13
+
14
+ G_BEGIN_DECLS
15
+
16
+ typedef struct {
17
+ VALUE self;
18
+ GObject* gobj;
19
+ const RGObjClassInfo* cinfo;
20
+ gboolean destroyed;
21
+ } gobj_holder;
22
+
23
+ typedef struct {
24
+ gpointer boxed;
25
+ gboolean own;
26
+ GType type;
27
+ } boxed_holder;
28
+
29
+ extern VALUE rbgobj_cEnum;
30
+ extern VALUE rbgobj_cFlags;
31
+ extern VALUE rbgobj_cBoxed;
32
+ extern VALUE rbgobj_cParam;
33
+ extern VALUE rbgobj_mInterface;
34
+ extern VALUE rbgobj_cObject;
35
+
36
+ extern VALUE rbgobj_cInstantiatable;
37
+ extern VALUE rbgobj_mMetaInterface;
38
+ #define cInstantiatable rbgobj_cInstantiatable
39
+ #define mMetaInterface rbgobj_mMetaInterface
40
+
41
+ extern void rbgobj_define_property_accessors(VALUE klass);
42
+ extern void rbgobj_define_action_methods(VALUE klass);
43
+
44
+ extern void rbgobj_param_spec_initialize(VALUE self, GParamSpec* pspec);
45
+ extern void rbgobj_boxed_initialize(VALUE obj, gpointer boxed);
46
+ extern void rbgobj_gobject_initialize(VALUE obj, gpointer cobj);
47
+
48
+ extern GParamSpec* rbgobj_get_param_spec(VALUE obj);
49
+ extern GObject* rbgobj_get_gobject(VALUE obj);
50
+
51
+ extern VALUE rbgobj_get_ruby_object_from_param_spec(GParamSpec* pspec, gboolean alloc);
52
+
53
+ extern void rbgobj_init_object_class(VALUE klass);
54
+ extern void rbgobj_init_flags_class(VALUE klass);
55
+ extern void rbgobj_init_enum_class(VALUE klass);
56
+ extern void rbgobj_init_interface(VALUE interf);
57
+
58
+ /* FIXME: should have better name */
59
+ extern void rbgobj_instance_call_cinfo_mark(gpointer instance);
60
+ extern void rbgobj_instance_call_cinfo_free(gpointer instance);
61
+
62
+ VALUE rbgutil_generic_s_gtype(VALUE klass);
63
+ VALUE rbgutil_generic_gtype(VALUE self);
64
+ #define generic_s_gtype rbgutil_generic_s_gtype
65
+ #define generic_gtype rbgutil_generic_gtype
66
+
67
+ extern gboolean rbgobj_convert_has_type(GType type);
68
+ extern RGConvertTable *rbgobj_convert_lookup(GType type);
69
+
70
+ extern gboolean rbgobj_convert_get_superclass(GType type, VALUE *result);
71
+ extern gboolean rbgobj_convert_type_init_hook(GType type, VALUE klass);
72
+ extern gboolean rbgobj_convert_gvalue2rvalue(GType type, const GValue *value,
73
+ VALUE *result);
74
+ extern gboolean rbgobj_convert_rvalue2gvalue(GType type, VALUE val,
75
+ GValue *result);
76
+ extern GType rbgobj_convert_rvalue2gtype(VALUE val);
77
+ extern gboolean rbgobj_convert_initialize(GType type, VALUE obj, gpointer cobj);
78
+ extern gboolean rbgobj_convert_robj2instance(GType type, VALUE obj,
79
+ gpointer *result);
80
+ extern gboolean rbgobj_convert_instance2robj(GType type, gpointer instance,
81
+ VALUE *result);
82
+ extern gboolean rbgobj_convert_unref(GType type, gpointer instance);
83
+
84
+ #define RubyGObjectHookModule "RubyGObjectHook__"
85
+
86
+ G_END_DECLS
87
+
88
+ #endif
data/src/rbgutil.c ADDED
@@ -0,0 +1,222 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbgutil.c -
5
+
6
+ $Author: sakai $
7
+ $Date: 2007/07/07 08:15:26 $
8
+
9
+ Copyright (C) 2002-2004 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbgprivate.h"
13
+
14
+ ID rbgutil_id_module_eval;
15
+
16
+ static ID id_add_one_arg_setter;
17
+ static ID id_set_property;
18
+ static ID id_to_a;
19
+ static ID id_allocate;
20
+
21
+ void
22
+ rbgutil_set_properties(self, hash)
23
+ VALUE self, hash;
24
+ {
25
+ int i;
26
+ VALUE ary;
27
+ GObject* obj;
28
+
29
+ Check_Type(hash, T_HASH);
30
+ ary = rb_funcall(hash, id_to_a, 0);
31
+ obj = RVAL2GOBJ(self);
32
+
33
+ g_object_freeze_notify(obj);
34
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
35
+ rb_funcall(self, id_set_property, 2,
36
+ RARRAY_PTR(RARRAY_PTR(ary)[i])[0],
37
+ RARRAY_PTR(RARRAY_PTR(ary)[i])[1]);
38
+ }
39
+ g_object_thaw_notify(obj);
40
+ }
41
+
42
+ VALUE
43
+ rbgutil_glist2ary(list)
44
+ GList *list;
45
+ {
46
+ VALUE ary = rb_ary_new();
47
+ while (list) {
48
+ rb_ary_push(ary, GOBJ2RVAL(list->data));
49
+ list = list->next;
50
+ }
51
+ return ary;
52
+ }
53
+
54
+ VALUE
55
+ rbgutil_glist2ary_and_free(list)
56
+ GList *list;
57
+ {
58
+ VALUE ary = rb_ary_new();
59
+ while (list) {
60
+ rb_ary_push(ary, GOBJ2RVAL(list->data));
61
+ list = list->next;
62
+ }
63
+ g_list_free(list);
64
+ return ary;
65
+ }
66
+
67
+ VALUE
68
+ rbgutil_glist2ary_boxed(list, gtype)
69
+ GList *list;
70
+ GType gtype;
71
+ {
72
+ VALUE ary = rb_ary_new();
73
+ while (list) {
74
+ rb_ary_push(ary, BOXED2RVAL(list->data, gtype));
75
+ list = list->next;
76
+ }
77
+ return ary;
78
+ }
79
+
80
+ VALUE
81
+ rbgutil_glist2ary_boxed_and_free(list, gtype)
82
+ GList *list;
83
+ GType gtype;
84
+ {
85
+ VALUE ary = rb_ary_new();
86
+ while (list) {
87
+ rb_ary_push(ary, BOXED2RVAL(list->data, gtype));
88
+ list = list->next;
89
+ }
90
+ g_list_free(list);
91
+ return ary;
92
+ }
93
+
94
+ VALUE
95
+ rbgutil_glist2ary_string(GList *list)
96
+ {
97
+ VALUE array;
98
+
99
+ array = rb_ary_new();
100
+ while (list) {
101
+ rb_ary_push(array, CSTR2RVAL(list->data));
102
+ list = g_list_next(list);
103
+ }
104
+ return array;
105
+ }
106
+
107
+ VALUE
108
+ rbgutil_glist2ary_string_and_free(GList *list)
109
+ {
110
+ VALUE array;
111
+ GList *node;
112
+
113
+ array = rb_ary_new();
114
+ for (node = list; node; node = g_list_next(node)) {
115
+ gchar *string = node->data;
116
+
117
+ rb_ary_push(array, CSTR2RVAL(string));
118
+ g_free(string);
119
+ }
120
+ g_list_free(list);
121
+ return array;
122
+ }
123
+
124
+ VALUE
125
+ rbgutil_gslist2ary(list)
126
+ GSList *list;
127
+ {
128
+ VALUE ary = rb_ary_new();
129
+ while (list) {
130
+ rb_ary_push(ary, GOBJ2RVAL(list->data));
131
+ list = list->next;
132
+ }
133
+ return ary;
134
+ }
135
+
136
+ VALUE
137
+ rbgutil_gslist2ary_boxed(list, gtype)
138
+ GSList *list;
139
+ GType gtype;
140
+ {
141
+ VALUE ary = rb_ary_new();
142
+ while (list) {
143
+ rb_ary_push(ary, BOXED2RVAL(list->data, gtype));
144
+ list = list->next;
145
+ }
146
+ return ary;
147
+ }
148
+
149
+ VALUE
150
+ rbgutil_gslist2ary_and_free(GSList *list)
151
+ {
152
+ GSList *node;
153
+ VALUE ary;
154
+
155
+ ary = rb_ary_new();
156
+ for (node = list; node; node = g_slist_next(node)) {
157
+ rb_ary_push(ary, GOBJ2RVAL(node->data));
158
+ }
159
+ g_slist_free(list);
160
+ return ary;
161
+ }
162
+
163
+ VALUE
164
+ rbgutil_gslist2ary_boxed_and_free(GSList *list, GType gtype)
165
+ {
166
+ GSList *node;
167
+ VALUE ary;
168
+
169
+ ary = rb_ary_new();
170
+ for (node = list; node; node = g_slist_next(node)) {
171
+ rb_ary_push(ary, BOXED2RVAL(node->data, gtype));
172
+ }
173
+ g_slist_free(list);
174
+ return ary;
175
+ }
176
+
177
+ VALUE
178
+ rbgutil_def_setters(klass)
179
+ VALUE klass;
180
+ {
181
+ return rb_funcall(mGLib, id_add_one_arg_setter, 1, klass);
182
+ }
183
+
184
+ VALUE
185
+ rbgutil_sym_g2r_func(from)
186
+ const GValue *from;
187
+ {
188
+ const gchar *str = g_value_get_string(from);
189
+ return str ? ID2SYM(rb_intern(str)) : Qnil;
190
+ }
191
+
192
+ VALUE
193
+ rbgutil_generic_s_gtype(VALUE klass)
194
+ {
195
+ return rbgobj_gtype_new(CLASS2GTYPE(klass));
196
+ }
197
+
198
+ VALUE
199
+ rbgutil_generic_gtype(VALUE self)
200
+ {
201
+ return generic_s_gtype(CLASS_OF(self));
202
+ }
203
+
204
+ VALUE
205
+ rbgutil_string_set_utf8_encoding(VALUE string)
206
+ {
207
+ #ifdef HAVE_RB_STR_ENCODE
208
+ if (!NIL_P(string))
209
+ rb_enc_associate(string, rb_utf8_encoding());
210
+ #endif
211
+ return string;
212
+ }
213
+
214
+ void
215
+ Init_gutil()
216
+ {
217
+ rbgutil_id_module_eval = rb_intern("module_eval");
218
+ id_set_property = rb_intern("set_property");
219
+ id_to_a = rb_intern("to_a");
220
+ id_add_one_arg_setter = rb_intern("__add_one_arg_setter");
221
+ id_allocate = rb_intern("allocate");
222
+ }