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/rbgcompat.h ADDED
@@ -0,0 +1,30 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+ rbgcompat.h -
4
+
5
+ Copyright (C) 2007 Ruby-GNOME2 Project Team
6
+ **********************************************************************/
7
+
8
+ #ifndef __RBGCOMPAT_H__
9
+ #define __RBGCOMPAT_H__
10
+
11
+ G_BEGIN_DECLS
12
+
13
+ typedef struct {
14
+ GType type;
15
+ VALUE (*get_superclass)(void);
16
+ void (*type_init_hook)(VALUE);
17
+ void (*rvalue2gvalue)(VALUE val, GValue *result);
18
+ VALUE (*gvalue2rvalue)(const GValue *);
19
+ void (*initialize)(VALUE, gpointer);
20
+ gpointer (*robj2instance)(VALUE);
21
+ VALUE (*instance2robj)(gpointer);
22
+ } RGFundamental;
23
+
24
+ #define G_DEF_FUNDAMENTAL(f) (rbgobj_fund_define_fundamental(f))
25
+
26
+ extern void rbgobj_fund_define_fundamental(RGFundamental *fundamental);
27
+
28
+ G_END_DECLS
29
+
30
+ #endif
data/src/rbglib.c ADDED
@@ -0,0 +1,320 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+
4
+ rbglib.c -
5
+
6
+ $Author: sakai $
7
+ $Date: 2007/07/14 13:42:08 $
8
+
9
+ Copyright (C) 2002,2003 Masahiro Sakai
10
+
11
+ **********************************************************************/
12
+
13
+ #include <locale.h>
14
+ #include "rbgprivate.h"
15
+ #include "rbglib.h"
16
+
17
+ static ID id_inspect;
18
+
19
+ VALUE mGLib;
20
+
21
+ extern void Init_gutil();
22
+ extern void Init_gutil_callback();
23
+ extern void Init_glib_int64();
24
+ extern void Init_glib_error();
25
+ extern void Init_glib_threads();
26
+ extern void Init_glib_convert();
27
+ extern void Init_glib_messages();
28
+ extern void Init_glib_spawn();
29
+ extern void Init_glib_fileutils();
30
+ extern void Init_glib_utils();
31
+ extern void Init_glib_i18n();
32
+ extern void Init_glib_win32();
33
+ extern void Init_gobject();
34
+ extern void Init_glib_main_loop();
35
+ extern void Init_glib_main_context();
36
+ extern void Init_glib_source();
37
+ extern void Init_glib_poll_fd();
38
+ extern void Init_glib_io_channel();
39
+ extern void Init_glib_shell();
40
+ extern void Init_glib_completion();
41
+ extern void Init_glib_timer();
42
+ extern void Init_glib_unicode();
43
+ extern void Init_glib_keyfile();
44
+ extern void Init_glib_bookmark_file();
45
+
46
+ const gchar *
47
+ rbg_rval_inspect(VALUE object)
48
+ {
49
+ VALUE inspected;
50
+
51
+ inspected = rb_funcall(object, id_inspect, 0);
52
+ return RVAL2CSTR(inspected);
53
+ }
54
+
55
+ char *
56
+ rbg_string_value_ptr(ptr)
57
+ volatile VALUE *ptr;
58
+ {
59
+ return rb_string_value_ptr(ptr);
60
+ }
61
+
62
+ gchar *
63
+ rbg_rval2cstr_accept_nil(VALUE str)
64
+ {
65
+ return NIL_P(str) ? NULL : StringValuePtr(str);
66
+ }
67
+
68
+ VALUE
69
+ rbg_cstr2rval(const char* str)
70
+ {
71
+ return str ? rb_str_new2(str) : Qnil;
72
+ }
73
+
74
+ VALUE
75
+ rbg_cstr2rval_with_free(gchar* str)
76
+ {
77
+ VALUE ret = Qnil;
78
+ if (str) {
79
+ ret = rb_str_new2(str);
80
+ g_free(str);
81
+ }
82
+ return ret;
83
+ }
84
+
85
+ #if 0
86
+ /*
87
+ 2004-04-15 Commented out by Masao.
88
+
89
+ These functions replace g_malloc/g_realloc/g_free of GLib.
90
+ When g_malloc is called and the memory area can not reserved,
91
+ rb_gc() will be called. It makes Ruby-GNOME2 uses memory efficiently.
92
+
93
+ But rb_gc() does not work under multithread.
94
+ So they occur "cross-thread violation".
95
+ */
96
+
97
+ static gpointer
98
+ my_malloc(gsize n_bytes)
99
+ {
100
+ /* Should we rescue NoMemoryError? */
101
+ return ruby_xmalloc(n_bytes);
102
+ }
103
+
104
+ static gpointer
105
+ my_realloc(gpointer mem, gsize n_bytes)
106
+ {
107
+ /* Should we rescue NoMemoryError? */
108
+ return ruby_xrealloc(mem, n_bytes);
109
+ }
110
+
111
+ static void
112
+ my_free(gpointer mem)
113
+ {
114
+ return ruby_xfree(mem);
115
+ }
116
+
117
+ static void
118
+ Init_mem()
119
+ {
120
+ GMemVTable mem_table = {
121
+ my_malloc,
122
+ my_realloc,
123
+ my_free,
124
+ NULL,
125
+ NULL,
126
+ NULL,
127
+ };
128
+ g_mem_set_vtable(&mem_table);
129
+ }
130
+ #endif
131
+
132
+ static VALUE
133
+ rbg_s_os_win32(self)
134
+ VALUE self;
135
+ {
136
+ #ifdef G_OS_WIN32
137
+ return Qtrue;
138
+ #else
139
+ return Qfalse;
140
+ #endif
141
+ }
142
+
143
+ static VALUE
144
+ rbg_s_os_beos(self)
145
+ VALUE self;
146
+ {
147
+ #ifdef G_OS_BEOS
148
+ return Qtrue;
149
+ #else
150
+ return Qfalse;
151
+ #endif
152
+ }
153
+
154
+ static VALUE
155
+ rbg_s_os_unix(self)
156
+ VALUE self;
157
+ {
158
+ #ifdef G_OS_UNIX
159
+ return Qtrue;
160
+ #else
161
+ return Qfalse;
162
+ #endif
163
+ }
164
+
165
+ void
166
+ Init_glib2()
167
+ {
168
+ id_inspect = rb_intern("inspect");
169
+
170
+ mGLib = rb_define_module("GLib");
171
+
172
+ setlocale (LC_CTYPE, "");
173
+ #if LC_MESSAGES
174
+ setlocale (LC_MESSAGES, "");
175
+ #endif
176
+
177
+ /* Version Information */
178
+ rb_define_const(mGLib, "VERSION",
179
+ rb_ary_new3(3,
180
+ INT2FIX(glib_major_version),
181
+ INT2FIX(glib_minor_version),
182
+ INT2FIX(glib_micro_version)));
183
+ rb_define_const(mGLib, "MAJOR_VERSION", INT2FIX(glib_major_version));
184
+ rb_define_const(mGLib, "MINOR_VERSION", INT2FIX(glib_minor_version));
185
+ rb_define_const(mGLib, "MICRO_VERSION", INT2FIX(glib_micro_version));
186
+ rb_define_const(mGLib, "INTERFACE_AGE", INT2FIX(glib_interface_age));
187
+ rb_define_const(mGLib, "BINARY_AGE", INT2FIX(glib_binary_age));
188
+
189
+ rb_define_const(mGLib, "BINDING_VERSION",
190
+ rb_ary_new3(3,
191
+ INT2FIX(RBGLIB_MAJOR_VERSION),
192
+ INT2FIX(RBGLIB_MINOR_VERSION),
193
+ INT2FIX(RBGLIB_MICRO_VERSION)));
194
+
195
+ rb_define_const(mGLib, "BUILD_VERSION",
196
+ rb_ary_new3(3,
197
+ INT2FIX(GLIB_MAJOR_VERSION),
198
+ INT2FIX(GLIB_MINOR_VERSION),
199
+ INT2FIX(GLIB_MICRO_VERSION)));
200
+
201
+ /* Limits of Basic Types */
202
+ rb_define_const(mGLib, "MININT", INT2FIX(G_MININT));
203
+ rb_define_const(mGLib, "MAXINT", INT2NUM(G_MAXINT));
204
+ rb_define_const(mGLib, "MAXUINT", UINT2NUM(G_MAXUINT));
205
+
206
+ rb_define_const(mGLib, "MINSHORT", INT2FIX(G_MINSHORT));
207
+ rb_define_const(mGLib, "MAXSHORT", INT2FIX(G_MAXSHORT));
208
+ rb_define_const(mGLib, "MAXUSHORT", UINT2NUM(G_MAXUSHORT));
209
+
210
+ rb_define_const(mGLib, "MINLONG", INT2FIX(G_MINLONG));
211
+ rb_define_const(mGLib, "MAXLONG", INT2NUM(G_MAXLONG));
212
+ rb_define_const(mGLib, "MAXULONG", UINT2NUM(G_MAXULONG));
213
+
214
+ #if GLIB_CHECK_VERSION(2,4,0)
215
+ rb_define_const(mGLib, "MININT8", INT2FIX(G_MININT8));
216
+ rb_define_const(mGLib, "MAXINT8", INT2FIX(G_MAXINT8));
217
+ rb_define_const(mGLib, "MAXUINT8", UINT2NUM(G_MAXUINT8));
218
+
219
+ rb_define_const(mGLib, "MININT16", INT2FIX(G_MININT16));
220
+ rb_define_const(mGLib, "MAXINT16", INT2FIX(G_MAXINT16));
221
+ rb_define_const(mGLib, "MAXUINT16", UINT2NUM(G_MAXUINT16));
222
+
223
+ rb_define_const(mGLib, "MININT32", INT2FIX(G_MININT32));
224
+ rb_define_const(mGLib, "MAXINT32", INT2NUM(G_MAXINT32));
225
+ rb_define_const(mGLib, "MAXUINT32", UINT2NUM(G_MAXUINT32));
226
+ #endif
227
+ rb_define_const(mGLib, "MININT64", INT2FIX(G_MININT64));
228
+ rb_define_const(mGLib, "MAXINT64", LL2NUM(G_MAXINT64));
229
+ rb_define_const(mGLib, "MAXUINT64", ULL2NUM(G_MAXUINT64));
230
+ #if GLIB_CHECK_VERSION(2,4,0)
231
+ rb_define_const(mGLib, "MAXSIZE", UINT2NUM(G_MAXSIZE));
232
+ #endif
233
+ rb_define_const(mGLib, "MINFLOAT", INT2FIX(G_MINFLOAT));
234
+ rb_define_const(mGLib, "MAXFLOAT", DBL2NUM(G_MAXFLOAT));
235
+
236
+ rb_define_const(mGLib, "MINDOUBLE", INT2FIX(G_MINDOUBLE));
237
+ rb_define_const(mGLib, "MAXDOUBLE", DBL2NUM(G_MAXDOUBLE));
238
+
239
+ /* Standard Macros */
240
+ rb_define_module_function(mGLib, "os_win32?", rbg_s_os_win32, 0);
241
+ rb_define_module_function(mGLib, "os_beos?", rbg_s_os_beos, 0);
242
+ rb_define_module_function(mGLib, "os_unix?", rbg_s_os_unix, 0);
243
+
244
+ rb_define_const(mGLib, "DIR_SEPARATOR", CSTR2RVAL(G_DIR_SEPARATOR_S));
245
+ rb_define_const(mGLib, "SEARCHPATH_SEPARATOR", CSTR2RVAL(G_SEARCHPATH_SEPARATOR_S));
246
+
247
+ /* Don't implement them.
248
+ #define G_DIR_SEPARATOR_S
249
+ #define G_IS_DIR_SEPARATOR (c)
250
+ #define G_SEARCHPATH_SEPARATOR
251
+ #define TRUE
252
+ #define FALSE
253
+ #define NULL
254
+ #define MIN (a, b)
255
+ #define MAX (a, b)
256
+ #define ABS (a)
257
+ #define CLAMP (x, low, high)
258
+ #define G_STRUCT_MEMBER (member_type, struct_p, struct_offset)
259
+ #define G_STRUCT_MEMBER_P (struct_p, struct_offset)
260
+ #define G_STRUCT_OFFSET (struct_type, member)
261
+ #define G_MEM_ALIGN
262
+ #define G_CONST_RETURN
263
+ */
264
+
265
+ /* Numerical Definitions */
266
+ /* Don't implement them.
267
+ #define G_IEEE754_FLOAT_BIAS
268
+ #define G_IEEE754_DOUBLE_BIAS
269
+ union GFloatIEEE754;
270
+ union GDoubleIEEE754;
271
+ */
272
+ rb_define_const(mGLib, "E", CSTR2RVAL(G_STRINGIFY(G_E)));
273
+ rb_define_const(mGLib, "LN2", CSTR2RVAL(G_STRINGIFY(G_LN2)));
274
+ rb_define_const(mGLib, "LN10", CSTR2RVAL(G_STRINGIFY(G_LN10)));
275
+ rb_define_const(mGLib, "PI", CSTR2RVAL(G_STRINGIFY(G_PI)));
276
+ rb_define_const(mGLib, "PI_2", CSTR2RVAL(G_STRINGIFY(G_PI_2)));
277
+ rb_define_const(mGLib, "PI_4", CSTR2RVAL(G_STRINGIFY(G_PI_4)));
278
+ rb_define_const(mGLib, "SQRT2", CSTR2RVAL(G_STRINGIFY(G_SQRT2)));
279
+ rb_define_const(mGLib, "LOG_2_BASE_10", CSTR2RVAL(G_STRINGIFY(G_LOG_2_BASE_10)));
280
+
281
+ /* From "The Main Event Loop" */
282
+ rb_define_const(mGLib, "PRIORITY_HIGH", INT2FIX(G_PRIORITY_HIGH));
283
+ rb_define_const(mGLib, "PRIORITY_DEFAULT", INT2FIX(G_PRIORITY_DEFAULT));
284
+ rb_define_const(mGLib, "PRIORITY_HIGH_IDLE", INT2FIX(G_PRIORITY_HIGH_IDLE));
285
+ rb_define_const(mGLib, "PRIORITY_DEFAULT_IDLE", INT2FIX(G_PRIORITY_DEFAULT_IDLE));
286
+ rb_define_const(mGLib, "PRIORITY_LOW", INT2FIX(G_PRIORITY_LOW));
287
+
288
+
289
+ /* Init_mem(); */
290
+ Init_gutil();
291
+ Init_gutil_callback();
292
+ Init_glib_int64();
293
+ Init_glib_error();
294
+ Init_glib_threads();
295
+ Init_glib_convert();
296
+ Init_glib_messages();
297
+ Init_glib_fileutils();
298
+ Init_glib_i18n();
299
+ Init_glib_win32();
300
+
301
+ Init_gobject();
302
+
303
+ /* Require GBoxed/GObject */
304
+ Init_glib_utils();
305
+ Init_glib_spawn();
306
+ Init_glib_main_loop();
307
+ Init_glib_source();
308
+ Init_glib_main_context();
309
+ Init_glib_poll_fd();
310
+ Init_glib_io_channel();
311
+ Init_glib_shell();
312
+ Init_glib_completion();
313
+ Init_glib_timer();
314
+ Init_glib_unicode();
315
+ Init_glib_keyfile();
316
+ Init_glib_bookmark_file();
317
+
318
+ /* This is called here once. */
319
+ G_DEF_SETTERS(mGLib);
320
+ }
data/src/rbglib.h ADDED
@@ -0,0 +1,96 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+
4
+ rbglib.h -
5
+
6
+ $Author: sakai $
7
+ $Date: 2007/07/04 13:13:20 $
8
+
9
+ Copyright (C) 2002-2005 Ruby-GNOME2 Project
10
+ Copyright (C) 2002,2003 Masahiro Sakai
11
+
12
+ **********************************************************************/
13
+
14
+ #include <glib.h>
15
+ #include "ruby.h"
16
+
17
+ #ifndef __RBGLIB_H__
18
+ #define __RBGLIB_H__
19
+
20
+ #ifdef __cplusplus
21
+ extern "C" {
22
+ #endif /* __cplusplus */
23
+
24
+ #define RBGLIB_MAJOR_VERSION 0
25
+ #define RBGLIB_MINOR_VERSION 20
26
+ #define RBGLIB_MICRO_VERSION 0
27
+
28
+ #ifndef RSTRING_PTR
29
+ # define RSTRING_PTR(s) (RSTRING(s)->ptr)
30
+ # define RSTRING_LEN(s) (RSTRING(s)->len)
31
+ #endif
32
+
33
+ #ifndef RARRAY_PTR
34
+ # define RARRAY_PTR(s) (RARRAY(s)->ptr)
35
+ # define RARRAY_LEN(s) (RARRAY(s)->len)
36
+ #endif
37
+
38
+ #ifndef DBL2NUM
39
+ # define DBL2NUM(v) (rb_float_new(v))
40
+ #endif
41
+
42
+ #if ! GLIB_CHECK_VERSION(2,4,0)
43
+ typedef int GPid;
44
+ #endif
45
+
46
+ #define RBG_INSPECT(object) (rbg_rval_inspect(object))
47
+
48
+ #define RVAL2CSTR(v) (StringValuePtr(v))
49
+ #define RVAL2CSTR_ACCEPT_NIL(v) (rbg_rval2cstr_accept_nil(v))
50
+ #define RVAL2CSTR2(v) (RVAL2CSTR_ACCEPT_NIL(v))
51
+ #define CSTR2RVAL(s) (rbg_cstr2rval(s))
52
+ #define CSTR2RVAL_FREE(s) (rbg_cstr2rval_with_free(s))
53
+ #define CSTR2RVAL2(s) (CSTR2RVAL_FREE(s))
54
+
55
+ #define CBOOL2RVAL(b) ((b) ? Qtrue : Qfalse)
56
+ #define RVAL2CBOOL(b) (RTEST(b))
57
+ #define GERROR2RVAL(error) (rbgerr_gerror2exception(error))
58
+ #define RAISE_GERROR(error) rb_exc_raise(GERROR2RVAL(error))
59
+ #define G_DEF_ERROR(domain, name, module, parent, gtype) \
60
+ rbgerr_define_gerror(domain, name, module, parent, gtype)
61
+ #define G_DEF_ERROR2(domain, name, module, parent) \
62
+ rbgerr_define_gerror(domain, name, module, parent, Qnil)
63
+
64
+ #if defined(G_PLATFORM_WIN32) && !defined(RUBY_GLIB2_STATIC_COMPILATION)
65
+ # ifdef RUBY_GLIB2_COMPILATION
66
+ # define RUBY_GLIB2_VAR __declspec(dllexport)
67
+ # else
68
+ # define RUBY_GLIB2_VAR extern __declspec(dllimport)
69
+ # endif
70
+ #else
71
+ # define RUBY_GLIB2_VAR extern
72
+ #endif
73
+
74
+ RUBY_GLIB2_VAR VALUE mGLib;
75
+
76
+ extern const gchar *rbg_rval_inspect(VALUE object);
77
+
78
+ extern gchar* rbg_string_value_ptr(volatile VALUE* ptr); /* no longer used */
79
+ extern gchar *rbg_rval2cstr_accept_nil(VALUE str);
80
+ extern VALUE rbg_cstr2rval(const char* str);
81
+ extern VALUE rbg_cstr2rval_with_free(gchar* str);
82
+
83
+ /* rbgerror.h */
84
+ extern VALUE rbgerr_gerror2exception(GError *error);
85
+ extern VALUE rbgerr_define_gerror(GQuark domain, const gchar* name, VALUE module, VALUE parent, VALUE gtype);
86
+
87
+ extern VALUE rbglib_int64_to_num(guint64 val);
88
+ extern VALUE rbglib_uint64_to_num(guint64 val);
89
+ extern gint64 rbglib_num_to_int64(VALUE val);
90
+ extern guint64 rbglib_num_to_uint64(VALUE val);
91
+
92
+ #ifdef __cplusplus
93
+ }
94
+ #endif /* __cplusplus */
95
+
96
+ #endif /* __RBGLIB_H__ */
@@ -0,0 +1,595 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbglib_bookmarkfile.c -
5
+
6
+ $Author: sakai $
7
+ $Date: 2007/07/07 08:25:33 $
8
+
9
+ Copyright (C) 2006 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "rbgprivate.h"
13
+
14
+ #if GLIB_CHECK_VERSION(2,12,0)
15
+ /************************************************/
16
+ static GBookmarkFile*
17
+ bookmarkfile_copy(const GBookmarkFile* file)
18
+ {
19
+ /*
20
+ GBookmarkFile* new_file;
21
+ g_return_val_if_fail (file != NULL, NULL);
22
+ new_file = g_key_file_new();
23
+ *new_file = (GBookmarkFile*)*file;
24
+ return new_file;
25
+ */
26
+ return (GBookmarkFile*)file;
27
+ }
28
+
29
+
30
+ GType
31
+ g_bookmark_file_get_type(void)
32
+ {
33
+ static GType our_type = 0;
34
+ if (our_type == 0)
35
+ our_type = g_boxed_type_register_static("GBookmarkFile",
36
+ (GBoxedCopyFunc)bookmarkfile_copy,
37
+ (GBoxedFreeFunc)g_bookmark_file_free);
38
+ return our_type;
39
+ }
40
+ /************************************************/
41
+
42
+ #define G_TYPE_BOOKMARK_FILE (g_bookmark_file_get_type())
43
+ #define _SELF(self) ((GBookmarkFile*)(RVAL2BOXED(self, G_TYPE_BOOKMARK_FILE)))
44
+
45
+ static VALUE
46
+ bf_initialize(self)
47
+ VALUE self;
48
+ {
49
+ G_INITIALIZE(self, g_bookmark_file_new());
50
+ return Qnil;
51
+ }
52
+
53
+ static VALUE
54
+ bf_load_from_file(self, filename)
55
+ VALUE self, filename;
56
+ {
57
+ GError* error = NULL;
58
+ gboolean ret = g_bookmark_file_load_from_file(_SELF(self),
59
+ (const gchar*)RVAL2CSTR(filename),
60
+ &error);
61
+ if (!ret) RAISE_GERROR(error);
62
+ return self;
63
+ }
64
+
65
+ static VALUE
66
+ bf_load_from_data(VALUE self, VALUE data)
67
+ {
68
+ GError *error = NULL;
69
+
70
+ StringValue(data);
71
+ if (!g_bookmark_file_load_from_data(_SELF(self),
72
+ RSTRING_PTR(data),
73
+ RSTRING_LEN(data),
74
+ &error))
75
+ RAISE_GERROR(error);
76
+
77
+ return Qnil;
78
+ }
79
+
80
+ static VALUE
81
+ bf_load_from_data_dirs(self, file)
82
+ VALUE self, file;
83
+ {
84
+ GError* error = NULL;
85
+ gboolean ret;
86
+ gchar* full_path;
87
+
88
+ ret = g_bookmark_file_load_from_data_dirs(_SELF(self),
89
+ (const gchar*)RVAL2CSTR(file),
90
+ &full_path, &error);
91
+
92
+ if (! ret) RAISE_GERROR(error);
93
+
94
+ return full_path ? CSTR2RVAL(full_path) : Qnil;
95
+ }
96
+
97
+ static VALUE
98
+ bf_to_data(self)
99
+ VALUE self;
100
+ {
101
+ VALUE ret;
102
+ gsize len;
103
+ GError* error = NULL;
104
+ gchar* data = g_bookmark_file_to_data(_SELF(self), &len, &error);
105
+
106
+ if (error) RAISE_GERROR(error);
107
+
108
+ ret = rb_str_new(data, len);
109
+ g_free(data);
110
+
111
+ return ret;
112
+ }
113
+
114
+ static VALUE
115
+ bf_to_file(self, filename)
116
+ VALUE self, filename;
117
+ {
118
+ GError* error = NULL;
119
+ gboolean ret = g_bookmark_file_to_file(_SELF(self),
120
+ (const gchar *)RVAL2CSTR(filename),
121
+ &error);
122
+ if (!ret) RAISE_GERROR(error);
123
+ return self;
124
+ }
125
+
126
+ static VALUE
127
+ bf_has_item(self, uri)
128
+ VALUE self, uri;
129
+ {
130
+ return CBOOL2RVAL(g_bookmark_file_has_item(_SELF(self),
131
+ (const gchar *)RVAL2CSTR(uri)));
132
+ }
133
+
134
+ static VALUE
135
+ bf_has_group(self, uri, group)
136
+ VALUE self, uri, group;
137
+ {
138
+ GError* error = NULL;
139
+ return CBOOL2RVAL(g_bookmark_file_has_group(_SELF(self),
140
+ (const gchar *)RVAL2CSTR(uri),
141
+ (const gchar *)RVAL2CSTR(group),
142
+ &error));
143
+ }
144
+
145
+ static VALUE
146
+ bf_has_application(self, uri, name)
147
+ VALUE self, uri, name;
148
+ {
149
+ GError* error = NULL;
150
+ return CBOOL2RVAL(g_bookmark_file_has_application(_SELF(self),
151
+ (const gchar *)RVAL2CSTR(uri),
152
+ (const gchar *)RVAL2CSTR(name),
153
+ &error));
154
+ }
155
+
156
+ static VALUE
157
+ bf_get_size(self)
158
+ VALUE self;
159
+ {
160
+ return INT2NUM(g_bookmark_file_get_size(_SELF(self)));
161
+ }
162
+
163
+ static VALUE
164
+ bf_get_uris(self)
165
+ VALUE self;
166
+ {
167
+ int i;
168
+ gsize len;
169
+ VALUE ary = rb_ary_new();
170
+ gchar** ret = g_bookmark_file_get_uris(_SELF(self), &len);
171
+
172
+ for (i = 0; i < len; i++){
173
+ rb_ary_push(ary, CSTR2RVAL(ret[i]));
174
+ }
175
+
176
+ g_strfreev(ret);
177
+
178
+ return ary;
179
+ }
180
+
181
+ static VALUE
182
+ bf_get_title(self, uri)
183
+ VALUE self, uri;
184
+ {
185
+ GError *error = NULL;
186
+ gchar* ret = g_bookmark_file_get_title(_SELF(self),
187
+ (const gchar *)RVAL2CSTR(uri),
188
+ &error);
189
+ if (error) RAISE_GERROR(error);
190
+ return CSTR2RVAL2(ret);
191
+ }
192
+
193
+ static VALUE
194
+ bf_get_description(self, uri)
195
+ VALUE self, uri;
196
+ {
197
+ GError *error = NULL;
198
+ gchar* ret = g_bookmark_file_get_description(_SELF(self),
199
+ (const gchar *)RVAL2CSTR(uri),
200
+ &error);
201
+ if (error) RAISE_GERROR(error);
202
+ return CSTR2RVAL2(ret);
203
+ }
204
+
205
+ static VALUE
206
+ bf_get_mime_type(self, uri)
207
+ VALUE self, uri;
208
+ {
209
+ GError *error = NULL;
210
+ gchar* ret = g_bookmark_file_get_mime_type(_SELF(self),
211
+ (const gchar *)RVAL2CSTR(uri),
212
+ &error);
213
+ if (error) RAISE_GERROR(error);
214
+ return CSTR2RVAL2(ret);
215
+ }
216
+
217
+ static VALUE
218
+ bf_get_is_private(self, uri)
219
+ VALUE self, uri;
220
+ {
221
+ GError *error = NULL;
222
+ gboolean ret = g_bookmark_file_get_is_private(_SELF(self),
223
+ (const gchar *)RVAL2CSTR(uri),
224
+ &error);
225
+ if (error) RAISE_GERROR(error);
226
+ return CBOOL2RVAL(ret);
227
+ }
228
+
229
+ static VALUE
230
+ bf_get_icon(self, uri)
231
+ VALUE self, uri;
232
+ {
233
+ gchar* href;
234
+ gchar* mime_type;
235
+ GError *error = NULL;
236
+ gboolean ret = g_bookmark_file_get_icon(_SELF(self),
237
+ (const gchar *)RVAL2CSTR(uri),
238
+ &href, &mime_type,
239
+ &error);
240
+ if (!ret){
241
+ if (error) RAISE_GERROR(error);
242
+ return Qnil;
243
+ }
244
+ return rb_assoc_new(CSTR2RVAL2(href), CSTR2RVAL2(mime_type));
245
+ }
246
+
247
+ static VALUE
248
+ bf_get_added(self, uri)
249
+ VALUE self, uri;
250
+ {
251
+ GError *error = NULL;
252
+ time_t ret = g_bookmark_file_get_added(_SELF(self),
253
+ (const gchar *)RVAL2CSTR(uri),
254
+ &error);
255
+ if (!ret) RAISE_GERROR(error);
256
+
257
+ return rb_time_new(ret, 0);
258
+ }
259
+
260
+ static VALUE
261
+ bf_get_modified(self, uri)
262
+ VALUE self, uri;
263
+ {
264
+ GError *error = NULL;
265
+ time_t ret = g_bookmark_file_get_modified(_SELF(self),
266
+ (const gchar *)RVAL2CSTR(uri),
267
+ &error);
268
+ if (!ret) RAISE_GERROR(error);
269
+
270
+ return rb_time_new(ret, 0);
271
+ }
272
+
273
+ static VALUE
274
+ bf_get_visited(self, uri)
275
+ VALUE self, uri;
276
+ {
277
+ GError *error = NULL;
278
+ time_t ret = g_bookmark_file_get_visited(_SELF(self),
279
+ (const gchar *)RVAL2CSTR(uri),
280
+ &error);
281
+ if (!ret) RAISE_GERROR(error);
282
+
283
+ return rb_time_new(ret, 0);
284
+ }
285
+
286
+ static VALUE
287
+ bf_get_groups(self, uri)
288
+ VALUE self, uri;
289
+ {
290
+ gsize length;
291
+ VALUE ary;
292
+ gint i;
293
+ GError* error = NULL;
294
+ gchar** ret = g_bookmark_file_get_groups(_SELF(self),
295
+ (const gchar *)RVAL2CSTR(uri),
296
+ &length, &error);
297
+ if (error) RAISE_GERROR(error);
298
+
299
+
300
+ ary = rb_ary_new();
301
+ for(i = 0; i < length; i++){
302
+ rb_ary_push(ary, CSTR2RVAL(ret[i]));
303
+ }
304
+
305
+ g_strfreev(ret);
306
+ return ary;
307
+ }
308
+
309
+ static VALUE
310
+ bf_get_applications(self, uri)
311
+ VALUE self, uri;
312
+ {
313
+ gsize length;
314
+ VALUE ary;
315
+ gint i;
316
+ GError* error = NULL;
317
+ gchar** ret = g_bookmark_file_get_applications(_SELF(self),
318
+ (const gchar *)RVAL2CSTR(uri),
319
+ &length, &error);
320
+ if (error) RAISE_GERROR(error);
321
+
322
+
323
+ ary = rb_ary_new();
324
+ for(i = 0; i < length; i++){
325
+ rb_ary_push(ary, CSTR2RVAL(ret[i]));
326
+ }
327
+
328
+ g_strfreev(ret);
329
+ return ary;
330
+ }
331
+
332
+ static VALUE
333
+ bf_get_app_info(self, uri, name)
334
+ VALUE self, uri, name;
335
+ {
336
+ gchar* exec;
337
+ guint count;
338
+ time_t stamp;
339
+ GError* error = NULL;
340
+
341
+ gboolean ret = g_bookmark_file_get_app_info(_SELF(self),
342
+ (const gchar *)RVAL2CSTR(uri),
343
+ (const gchar *)RVAL2CSTR(name),
344
+ &exec, &count, &stamp, &error);
345
+ if (!ret) RAISE_GERROR(error);
346
+
347
+ return rb_ary_new3(3, CSTR2RVAL(exec), UINT2NUM(count), rb_time_new(stamp, 0));
348
+ }
349
+
350
+ static VALUE
351
+ bf_set_title(self, uri, title)
352
+ VALUE self, uri, title;
353
+ {
354
+ g_bookmark_file_set_title(_SELF(self),
355
+ (const gchar *)RVAL2CSTR(uri),
356
+ (const gchar *)RVAL2CSTR(title));
357
+ return self;
358
+ }
359
+
360
+ static VALUE
361
+ bf_set_description(self, uri, description)
362
+ VALUE self, uri, description;
363
+ {
364
+ g_bookmark_file_set_description(_SELF(self),
365
+ (const gchar *)RVAL2CSTR(uri),
366
+ (const gchar *)RVAL2CSTR(description));
367
+ return self;
368
+ }
369
+
370
+ static VALUE
371
+ bf_set_mime_type(self, uri, mime_type)
372
+ VALUE self, uri, mime_type;
373
+ {
374
+ g_bookmark_file_set_mime_type(_SELF(self),
375
+ (const gchar *)RVAL2CSTR(uri),
376
+ (const gchar *)RVAL2CSTR(mime_type));
377
+ return self;
378
+ }
379
+
380
+ static VALUE
381
+ bf_set_is_private(self, uri, is_private)
382
+ VALUE self, uri, is_private;
383
+ {
384
+ g_bookmark_file_set_is_private(_SELF(self),
385
+ (const gchar *)RVAL2CSTR(uri),
386
+ RVAL2CBOOL(is_private));
387
+ return self;
388
+ }
389
+
390
+ static VALUE
391
+ bf_set_icon(self, uri, href, mime_type)
392
+ VALUE self, uri, href, mime_type;
393
+ {
394
+ g_bookmark_file_set_icon(_SELF(self),
395
+ (const gchar *)RVAL2CSTR(uri),
396
+ (const gchar *)RVAL2CSTR(href),
397
+ (const gchar *)RVAL2CSTR(mime_type));
398
+ return self;
399
+ }
400
+
401
+ static VALUE
402
+ bf_set_added(self, uri, time)
403
+ VALUE self, uri, time;
404
+ {
405
+ g_bookmark_file_set_added(_SELF(self),
406
+ (const gchar *)RVAL2CSTR(uri),
407
+ (time_t)NUM2LONG(rb_Integer(time)));
408
+ return self;
409
+ }
410
+
411
+ static VALUE
412
+ bf_set_groups(self, uri, groups)
413
+ VALUE self, uri, groups;
414
+ {
415
+ gint len = RARRAY_LEN(groups);
416
+ gchar** glist = ALLOCA_N(gchar*, len);
417
+ gint i;
418
+
419
+ for (i = 0; i < len; i++){
420
+ glist[i] = RVAL2CSTR(RARRAY_PTR(groups)[i]);
421
+ }
422
+
423
+ g_bookmark_file_set_groups(_SELF(self),
424
+ (const gchar *)RVAL2CSTR(uri),
425
+ (const gchar **)glist, len);
426
+ return self;
427
+ }
428
+
429
+ static VALUE
430
+ bf_set_modified(self, uri, time)
431
+ VALUE self, uri, time;
432
+ {
433
+ g_bookmark_file_set_modified(_SELF(self),
434
+ (const gchar *)RVAL2CSTR(uri),
435
+ (time_t)NUM2LONG(rb_Integer(time)));
436
+ return self;
437
+ }
438
+
439
+ static VALUE
440
+ bf_set_visited(self, uri, time)
441
+ VALUE self, uri, time;
442
+ {
443
+ g_bookmark_file_set_visited(_SELF(self),
444
+ (const gchar *)RVAL2CSTR(uri),
445
+ (time_t)NUM2LONG(rb_Integer(time)));
446
+ return self;
447
+ }
448
+
449
+ static VALUE
450
+ bf_set_app_info(self, uri, name, exec, count, stamp)
451
+ VALUE self,uri, name, exec, count, stamp;
452
+ {
453
+ GError* error = NULL;
454
+ gboolean ret = g_bookmark_file_set_app_info(_SELF(self),
455
+ (const gchar *)RVAL2CSTR(uri),
456
+ (const gchar *)RVAL2CSTR(name),
457
+ (const gchar *)RVAL2CSTR(exec),
458
+ NUM2INT(count),
459
+ (time_t)NUM2LONG(rb_Integer(stamp)),
460
+ &error);
461
+
462
+ if (! ret) RAISE_GERROR(error);
463
+
464
+ return self;
465
+ }
466
+
467
+ static VALUE
468
+ bf_add_group(self, uri, group)
469
+ VALUE self, uri, group;
470
+ {
471
+ g_bookmark_file_add_group(_SELF(self),
472
+ (const gchar *)RVAL2CSTR(uri),
473
+ (const gchar *)RVAL2CSTR(group));
474
+ return self;
475
+ }
476
+
477
+ static VALUE
478
+ bf_add_application(self, uri, name, exec)
479
+ VALUE self, uri, name, exec;
480
+ {
481
+ g_bookmark_file_add_application(_SELF(self),
482
+ (const gchar *)RVAL2CSTR(uri),
483
+ (const gchar *)RVAL2CSTR(name),
484
+ (const gchar *)RVAL2CSTR(exec));
485
+ return self;
486
+ }
487
+
488
+ static VALUE
489
+ bf_remove_group(self, uri, group)
490
+ VALUE self, uri, group;
491
+ {
492
+ GError* error = NULL;
493
+ gboolean ret = g_bookmark_file_remove_group(_SELF(self),
494
+ (const gchar *)RVAL2CSTR(uri),
495
+ (const gchar *)RVAL2CSTR(group),
496
+ &error);
497
+ if (! ret) RAISE_GERROR(error);
498
+
499
+ return self;
500
+ }
501
+
502
+ static VALUE
503
+ bf_remove_application(self, uri, name)
504
+ VALUE self, uri, name;
505
+ {
506
+ GError *error = NULL;
507
+ gboolean ret = g_bookmark_file_remove_application(_SELF(self),
508
+ (const gchar *)RVAL2CSTR(uri),
509
+ (const gchar *)RVAL2CSTR(name),
510
+ &error);
511
+ if (! ret) RAISE_GERROR(error);
512
+
513
+ return self;
514
+ }
515
+
516
+
517
+ static VALUE
518
+ bf_remove_item(self, uri)
519
+ VALUE self, uri;
520
+ {
521
+ GError *error = NULL;
522
+ gboolean ret = g_bookmark_file_remove_item(_SELF(self),
523
+ (const gchar *)RVAL2CSTR(uri),
524
+ &error);
525
+ if (! ret) RAISE_GERROR(error);
526
+
527
+ return self;
528
+ }
529
+
530
+ static VALUE
531
+ bf_move_item(self, old_uri, new_uri)
532
+ VALUE self, old_uri, new_uri;
533
+ {
534
+ GError *error = NULL;
535
+ gboolean ret = g_bookmark_file_move_item(_SELF(self),
536
+ (const gchar *)RVAL2CSTR(old_uri),
537
+ (const gchar *)RVAL2CSTR(new_uri),
538
+ &error);
539
+ if (! ret) RAISE_GERROR(error);
540
+
541
+ return self;
542
+ }
543
+
544
+ #endif
545
+
546
+ void
547
+ Init_glib_bookmark_file()
548
+ {
549
+ #if GLIB_CHECK_VERSION(2,12,0)
550
+ VALUE bf = G_DEF_CLASS(G_TYPE_BOOKMARK_FILE, "BookmarkFile", mGLib);
551
+
552
+ G_DEF_ERROR(G_BOOKMARK_FILE_ERROR, "BookmarkFileError", mGLib,
553
+ rb_eRuntimeError, G_TYPE_BOOKMARK_FILE_ERROR);
554
+
555
+ rb_define_method(bf, "initialize", bf_initialize, 0);
556
+ rb_define_method(bf, "load_from_file", bf_load_from_file, 1);
557
+ rb_define_method(bf, "load_from_data", bf_load_from_data, 1);
558
+ rb_define_method(bf, "load_from_data_dirs", bf_load_from_data_dirs, 1);
559
+ rb_define_method(bf, "to_data", bf_to_data, 0);
560
+ rb_define_method(bf, "to_file", bf_to_file, 1);
561
+ rb_define_method(bf, "has_item?", bf_has_item, 1);
562
+ rb_define_method(bf, "has_group?", bf_has_group, 2);
563
+ rb_define_method(bf, "has_application?", bf_has_application, 2);
564
+ rb_define_method(bf, "size", bf_get_size, 0);
565
+ rb_define_method(bf, "uris", bf_get_uris, 0);
566
+ rb_define_method(bf, "get_title", bf_get_title, 1);
567
+ rb_define_method(bf, "get_description", bf_get_description, 1);
568
+ rb_define_method(bf, "get_mime_type", bf_get_mime_type, 1);
569
+ rb_define_method(bf, "private?", bf_get_is_private, 1);
570
+ rb_define_method(bf, "get_icon", bf_get_icon, 1);
571
+ rb_define_method(bf, "get_added", bf_get_added, 1);
572
+ rb_define_method(bf, "get_modified", bf_get_modified, 1);
573
+ rb_define_method(bf, "get_visited", bf_get_visited, 1);
574
+ rb_define_method(bf, "get_groups", bf_get_groups, 1);
575
+ rb_define_method(bf, "get_applications", bf_get_applications, 1);
576
+ rb_define_method(bf, "get_app_info", bf_get_app_info, 2);
577
+ rb_define_method(bf, "set_title", bf_set_title, 2);
578
+ rb_define_method(bf, "set_description", bf_set_description, 2);
579
+ rb_define_method(bf, "set_mime_type", bf_set_mime_type, 2);
580
+ rb_define_method(bf, "set_private", bf_set_is_private, 2);
581
+ rb_define_method(bf, "set_icon", bf_set_icon, 3);
582
+ rb_define_method(bf, "set_added", bf_set_added, 2);
583
+ rb_define_method(bf, "set_groups", bf_set_groups, 2);
584
+ rb_define_method(bf, "set_modified", bf_set_modified, 2);
585
+ rb_define_method(bf, "set_visited", bf_set_visited, 2);
586
+ rb_define_method(bf, "set_app_info", bf_set_app_info, 5);
587
+ rb_define_method(bf, "add_group", bf_add_group, 2);
588
+ rb_define_method(bf, "add_application", bf_add_application, 3);
589
+ rb_define_method(bf, "remove_group", bf_remove_group, 2);
590
+ rb_define_method(bf, "remove_application", bf_remove_application, 2);
591
+ rb_define_method(bf, "remove_item", bf_remove_item, 1);
592
+ rb_define_method(bf, "move_item", bf_move_item, 2);
593
+ #endif
594
+ }
595
+