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
@@ -0,0 +1,140 @@
1
+
2
+ /* Generated by glib-mkenums.rb ($Id$) */
3
+
4
+ #ifndef __GLIB_ENUM_TYPES_H__
5
+ #define __GLIB_ENUM_TYPES_H__
6
+
7
+ #include <glib-object.h>
8
+
9
+ G_BEGIN_DECLS
10
+
11
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gbookmarkfile.h" */
12
+ GType g_bookmark_file_error_get_type (void);
13
+ #define G_TYPE_BOOKMARK_FILE_ERROR (g_bookmark_file_error_get_type())
14
+
15
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gchecksum.h" */
16
+ GType g_checksum_type_get_type (void);
17
+ #define G_TYPE_CHECKSUM_TYPE (g_checksum_type_get_type())
18
+
19
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gconvert.h" */
20
+ GType g_convert_error_get_type (void);
21
+ #define G_TYPE_CONVERT_ERROR (g_convert_error_get_type())
22
+
23
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gdate.h" */
24
+ GType g_date_dmy_get_type (void);
25
+ #define G_TYPE_DATE_DMY (g_date_dmy_get_type())
26
+ GType g_date_weekday_get_type (void);
27
+ #define G_TYPE_DATE_WEEKDAY (g_date_weekday_get_type())
28
+ GType g_date_month_get_type (void);
29
+ #define G_TYPE_DATE_MONTH (g_date_month_get_type())
30
+
31
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gfileutils.h" */
32
+ GType g_file_error_get_type (void);
33
+ #define G_TYPE_FILE_ERROR (g_file_error_get_type())
34
+ GType g_file_test_get_type (void);
35
+ #define G_TYPE_FILE_TEST (g_file_test_get_type())
36
+
37
+ /* enumerations from "/opt/local/include/glib-2.0/glib/ghook.h" */
38
+ GType g_hook_flag_mask_get_type (void);
39
+ #define G_TYPE_HOOK_FLAG_MASK (g_hook_flag_mask_get_type())
40
+
41
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gkeyfile.h" */
42
+ GType g_key_file_error_get_type (void);
43
+ #define G_TYPE_KEY_FILE_ERROR (g_key_file_error_get_type())
44
+ GType g_key_file_flags_get_type (void);
45
+ #define G_TYPE_KEY_FILE_FLAGS (g_key_file_flags_get_type())
46
+
47
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gmarkup.h" */
48
+ GType g_markup_error_get_type (void);
49
+ #define G_TYPE_MARKUP_ERROR (g_markup_error_get_type())
50
+ GType g_markup_parse_flags_get_type (void);
51
+ #define G_TYPE_MARKUP_PARSE_FLAGS (g_markup_parse_flags_get_type())
52
+ GType g_markup_collect_type_get_type (void);
53
+ #define G_TYPE_MARKUP_COLLECT_TYPE (g_markup_collect_type_get_type())
54
+
55
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gmessages.h" */
56
+ GType g_log_level_flags_get_type (void);
57
+ #define G_TYPE_LOG_LEVEL_FLAGS (g_log_level_flags_get_type())
58
+
59
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gnode.h" */
60
+ GType g_traverse_flags_get_type (void);
61
+ #define G_TYPE_TRAVERSE_FLAGS (g_traverse_flags_get_type())
62
+ GType g_traverse_type_get_type (void);
63
+ #define G_TYPE_TRAVERSE_TYPE (g_traverse_type_get_type())
64
+
65
+ /* enumerations from "/opt/local/include/glib-2.0/glib/goption.h" */
66
+ GType g_option_flags_get_type (void);
67
+ #define G_TYPE_OPTION_FLAGS (g_option_flags_get_type())
68
+ GType g_option_arg_get_type (void);
69
+ #define G_TYPE_OPTION_ARG (g_option_arg_get_type())
70
+ GType g_option_error_get_type (void);
71
+ #define G_TYPE_OPTION_ERROR (g_option_error_get_type())
72
+
73
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gregex.h" */
74
+ GType g_regex_error_get_type (void);
75
+ #define G_TYPE_REGEX_ERROR (g_regex_error_get_type())
76
+ GType g_regex_compile_flags_get_type (void);
77
+ #define G_TYPE_REGEX_COMPILE_FLAGS (g_regex_compile_flags_get_type())
78
+ GType g_regex_match_flags_get_type (void);
79
+ #define G_TYPE_REGEX_MATCH_FLAGS (g_regex_match_flags_get_type())
80
+
81
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gshell.h" */
82
+ GType g_shell_error_get_type (void);
83
+ #define G_TYPE_SHELL_ERROR (g_shell_error_get_type())
84
+
85
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gslice.h" */
86
+ GType g_slice_config_get_type (void);
87
+ #define G_TYPE_SLICE_CONFIG (g_slice_config_get_type())
88
+
89
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gspawn.h" */
90
+ GType g_spawn_error_get_type (void);
91
+ #define G_TYPE_SPAWN_ERROR (g_spawn_error_get_type())
92
+ GType g_spawn_flags_get_type (void);
93
+ #define G_TYPE_SPAWN_FLAGS (g_spawn_flags_get_type())
94
+
95
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gstrfuncs.h" */
96
+ GType g_ascii_type_get_type (void);
97
+ #define G_TYPE_ASCII_TYPE (g_ascii_type_get_type())
98
+
99
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gtestutils.h" */
100
+ GType g_test_trap_flags_get_type (void);
101
+ #define G_TYPE_TEST_TRAP_FLAGS (g_test_trap_flags_get_type())
102
+ GType g_test_log_type_get_type (void);
103
+ #define G_TYPE_TEST_LOG_TYPE (g_test_log_type_get_type())
104
+
105
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gthread.h" */
106
+ GType g_thread_error_get_type (void);
107
+ #define G_TYPE_THREAD_ERROR (g_thread_error_get_type())
108
+ GType g_thread_priority_get_type (void);
109
+ #define G_TYPE_THREAD_PRIORITY (g_thread_priority_get_type())
110
+ GType g_once_status_get_type (void);
111
+ #define G_TYPE_ONCE_STATUS (g_once_status_get_type())
112
+
113
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gunicode.h" */
114
+ GType g_unicode_type_get_type (void);
115
+ #define G_TYPE_UNICODE_TYPE (g_unicode_type_get_type())
116
+ GType g_unicode_break_type_get_type (void);
117
+ #define G_TYPE_UNICODE_BREAK_TYPE (g_unicode_break_type_get_type())
118
+ GType g_unicode_script_get_type (void);
119
+ #define G_TYPE_UNICODE_SCRIPT (g_unicode_script_get_type())
120
+ GType g_normalize_mode_get_type (void);
121
+ #define G_TYPE_NORMALIZE_MODE (g_normalize_mode_get_type())
122
+
123
+ /* enumerations from "/opt/local/include/glib-2.0/glib/gutils.h" */
124
+ GType g_user_directory_get_type (void);
125
+ #define G_TYPE_USER_DIRECTORY (g_user_directory_get_type())
126
+
127
+ /* enumerations from "/opt/local/include/glib-2.0/gobject/gsignal.h" */
128
+ GType g_signal_flags_get_type (void);
129
+ #define G_TYPE_SIGNAL_FLAGS (g_signal_flags_get_type())
130
+ GType g_connect_flags_get_type (void);
131
+ #define G_TYPE_CONNECT_FLAGS (g_connect_flags_get_type())
132
+ GType g_signal_match_type_get_type (void);
133
+ #define G_TYPE_SIGNAL_MATCH_TYPE (g_signal_match_type_get_type())
134
+
135
+ G_END_DECLS
136
+
137
+ #endif /* __GLIB_ENUM_TYPES_H__ */
138
+
139
+ /* Generated data ends here */
140
+
@@ -0,0 +1,199 @@
1
+ #
2
+ # glib-mkenums.rb
3
+ #
4
+ # C language enum description generation library like as glib-mkenums tool.
5
+ #
6
+ # Copyright(C) 2006-2008 Ruby-GNOME2 Project.
7
+ #
8
+ # This program is licenced under the same license of Ruby-GNOME2.
9
+ #
10
+
11
+ module GLib
12
+ class EnumDefinition
13
+ attr_accessor :EnumName, :enum_name, :ENUM_NAME, :ENUM_SHORT
14
+ attr_accessor :type, :Type
15
+ attr_accessor :g_type_prefix, :prefix
16
+
17
+ attr_reader :constants
18
+
19
+ def initialize(name, const_lines, g_type_prefix, options={})
20
+ @options = options || {}
21
+ @EnumName = name
22
+ @g_type_prefix = g_type_prefix
23
+ @constants = []
24
+ @enum_name = @EnumName.sub(/^[A-Z]/){|v| v.downcase}.gsub(/[A-Z]+/){|v| "_" + v.downcase}.sub(/(^_|_$)/, "")
25
+ @ENUM_NAME = @enum_name.upcase
26
+ @ENUM_SHORT = @ENUM_NAME.sub(/^#{@g_type_prefix.sub(/_TYPE.*$/, "")}/, "").sub(/^_/, "")
27
+
28
+ parse_const_lines(const_lines)
29
+ end
30
+
31
+ def parse_const_lines(const_lines)
32
+ ret = ""
33
+
34
+ if @options[:force_flags] or /<</ =~ const_lines
35
+ @type = "flags"
36
+ @Type = "Flags"
37
+ else
38
+ @type = "enum"
39
+ @Type = "Enum"
40
+ end
41
+ constants = []
42
+ const_lines.scan(/^\s*([^\s,]*).*\n/) do |name|
43
+ constants << name[0] unless name[0] =~ /(^[\/\*]|^$)/
44
+ end
45
+ @prefix = extract_prefix(constants)
46
+ constants.each do |name|
47
+ @constants << [name, name.sub(/#{@prefix}/, "").gsub(/_/, "-").downcase]
48
+ end
49
+ end
50
+
51
+ def extract_prefix(ary)
52
+ return [] if ary == nil
53
+ a = ary[0].split(//)
54
+ if ary.size == 1
55
+ @ENUM_NAME + "_"
56
+ else
57
+ ary[1..-1].each do |b|
58
+ b = b.split(//)
59
+ l = [a.length, b.length].min
60
+ a = a[0, (0...l).find{|i| a[i] != b[i] } || l]
61
+ end
62
+ a.join('')
63
+ end
64
+ end
65
+
66
+ def create_c
67
+ constants = "\n" + @constants.collect{|name, nick|
68
+ %Q[ { #{name}, "#{name}", "#{nick}" },\n]
69
+ }.join +
70
+ %Q[ { 0, NULL, NULL }]
71
+
72
+ ret = <<-CREATE_C
73
+
74
+ GType
75
+ #{@enum_name}_get_type (void)
76
+ {
77
+ static GType etype = 0;
78
+ if (etype == 0) {
79
+ static const G#{@Type}Value values[] = {#{constants}
80
+ };
81
+ etype = g_#{@type}_register_static ("#{@EnumName}", values);
82
+ }
83
+ return etype;
84
+ }
85
+ CREATE_C
86
+ ret
87
+ end
88
+
89
+ def create_h
90
+ %Q[
91
+ GType #{@enum_name}_get_type (void);
92
+ #define #{@g_type_prefix}#{@ENUM_SHORT} (#{@enum_name}_get_type())]
93
+ end
94
+
95
+
96
+ def self.parse(data, g_type_prefix, options={})
97
+ options ||= {}
98
+ enums = []
99
+ data.scan(/^\s*typedef\s+enum\s*
100
+ \{?\s*(.*?)
101
+ \}\s*(\w+);/mx){|constants, name|
102
+ enum_options = {}
103
+ force_flags_patterns = [(options[:force_flags] || [])].flatten
104
+ if force_flags_patterns.any? {|pattern| pattern === name}
105
+ enum_options[:force_flags] = true
106
+ end
107
+ enum = new(name, constants, g_type_prefix, enum_options)
108
+ enums << enum
109
+ }
110
+ enums
111
+ end
112
+ end
113
+
114
+ class MkEnums
115
+ # Create target_filename.c and target_filename.h from files
116
+ # with g_type_prefix and include_files.
117
+ # * target_filename: the target file name. This creates #{target_filename.c} and #{target_filename.h}.
118
+ # * files: header files to parse
119
+ # * g_type_prefix: the gtype prefix such as GTK_TYPE_
120
+ # * include_files: define #include <file> lines into target_filename.c
121
+ def self.create(target_filename, files, g_type_prefix, include_files,
122
+ options)
123
+ puts "creating #{target_filename}.c"
124
+ mkenums = MkEnums.new(target_filename, files, g_type_prefix, include_files,
125
+ options)
126
+
127
+ open("#{target_filename}.c", "w") do |out|
128
+ out.write(mkenums.create_c)
129
+ end
130
+ puts "creating #{target_filename}.h"
131
+ open("#{target_filename}.h", "w") do |out|
132
+ out.write(mkenums.create_h)
133
+ end
134
+ end
135
+
136
+ # Initialize GLib::MkEnums
137
+ #
138
+ # * target_filename: the target file name. This creates #{target_filename.c} and #{target_filename.h}.
139
+ # * files: header files to parse
140
+ # * g_type_prefix: the gtype prefix such as GTK_TYPE_
141
+ # * include_files: define #include <file> lines into target_filename.c
142
+ def initialize(target_filename, files, g_type_prefix, include_files, options)
143
+ @target_filename = target_filename
144
+ @include_files = include_files
145
+ @targets = []
146
+ files.each do |path|
147
+ data = ""
148
+ File.open(path) do |i|
149
+ data = i.read
150
+ end
151
+ @targets << [path, EnumDefinition.parse(data, g_type_prefix, options)]
152
+ end
153
+ end
154
+
155
+ def create_enums(meth) # :nodoc:
156
+ ret = ""
157
+ @targets.each do |target|
158
+ if target[1].size > 0
159
+ ret << %Q[\n\n/* enumerations from "#{target[0]}" */]
160
+ target[1].each{|enum|
161
+ ret << enum.__send__(meth)
162
+ }
163
+ end
164
+ end
165
+ ret
166
+ end
167
+
168
+ # Create a C source as a String.
169
+ def create_c
170
+ ret = "\n/* Generated by glib-mkenums.rb ($Id$) */ \n\n"
171
+ ret << %Q[#include "#{@target_filename}.h"\n]
172
+ @include_files.each do |file|
173
+ ret << "#include <#{file}>\n"
174
+ end
175
+ ret << "\n"
176
+ ret << create_enums(:create_c)
177
+ ret << "\n\n/* Generated data ends here */\n\n"
178
+ ret
179
+ end
180
+
181
+ # Create a C header as a String.
182
+ def create_h
183
+ header = "#{@target_filename}.h"
184
+ const = "__#{File.basename(header).upcase.gsub(/-|\./, '_')}__"
185
+
186
+ ret = "\n/* Generated by glib-mkenums.rb ($Id$) */ \n\n"
187
+ ret << "#ifndef #{const}\n"
188
+ ret << "#define #{const}\n\n"
189
+ ret << "#include <glib-object.h>\n\n"
190
+ ret << "G_BEGIN_DECLS"
191
+ ret << create_enums(:create_h)
192
+ ret << "\n\nG_END_DECLS\n\n"
193
+ ret << "#endif /* #{const} */\n"
194
+ ret << "\n/* Generated data ends here */\n\n"
195
+ ret
196
+ end
197
+ end
198
+ end
199
+
data/src/lib/glib2.rb ADDED
@@ -0,0 +1,220 @@
1
+ #
2
+ # glib2.rb
3
+ # Copyright(C) 2005 Ruby-GNOME2 Project.
4
+ #
5
+ # This program is licenced under the same
6
+ # license of Ruby-GNOME2.
7
+ #
8
+
9
+ require 'rbconfig'
10
+ if /mingw|mswin|mswin32/ =~ RUBY_PLATFORM
11
+ ENV['PATH'] = %w(bin lib).collect{|dir|
12
+ "#{Config::CONFIG["prefix"]}\\lib\\GTK\\#{dir};"
13
+ }.join('') + ENV['PATH']
14
+ end
15
+
16
+ require 'English'
17
+ require 'thread'
18
+
19
+ module GLib
20
+ module_function
21
+ def check_binding_version?(major, minor, micro)
22
+ BINDING_VERSION[0] > major ||
23
+ (BINDING_VERSION[0] == major &&
24
+ BINDING_VERSION[1] > minor) ||
25
+ (BINDING_VERSION[0] == major &&
26
+ BINDING_VERSION[1] == minor &&
27
+ BINDING_VERSION[2] >= micro)
28
+ end
29
+
30
+ def exit_application(exception, status)
31
+ msg = exception.message || exception.to_s
32
+ msg = exception.class.to_s if msg == ""
33
+ backtrace = exception.backtrace
34
+ $stderr.puts backtrace.shift + ": #{msg}"
35
+ backtrace.each do |v|
36
+ $stderr.puts "\t from #{v}"
37
+ end
38
+ exit(status)
39
+ end
40
+
41
+ def __add_one_arg_setter(klass)
42
+ #for Instance methods.
43
+ ary = klass.instance_methods(false)
44
+ ary.each do |m|
45
+ if /^set_(.*)/ =~ m and not ary.include? "#{$1}=" and klass.instance_method(m).arity == 1
46
+ begin
47
+ klass.module_eval("def #{$1}=(val); set_#{$1}(val); val; end\n")
48
+ rescue SyntaxError
49
+ $stderr.print "Couldn't create #{klass}\##{$1}=(v).\n" if $DEBUG
50
+ end
51
+ end
52
+ end
53
+ #for Class methods/Module functions.
54
+ if Object.method(:methods).arity == -1
55
+ ary = klass.methods(false)
56
+ else
57
+ ary = klass.methods
58
+ end
59
+ ary.each do |m|
60
+ if /^set_(.*)/ =~ m and not ary.include? "#{$1}=" and klass.method(m).arity == 1
61
+ begin
62
+ klass.module_eval("def self.#{$1}=(val); set_#{$1}(val); val; end\n")
63
+ rescue SyntaxError
64
+ $stderr.print "Couldn't create #{klass}\##{$1}=(v).\n" if $DEBUG
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ require 'glib2.so'
72
+
73
+ module GLib
74
+
75
+ class Type
76
+
77
+ def decendants
78
+ [self] + children.map{|t| t.decendants }.flatten
79
+ end
80
+
81
+ def ancestors
82
+ # ([self] + interfaces + (parent ? parent.ancestors : [])).reverse.uniq.reverse
83
+ [self] + (parent ? parent.ancestors : [])
84
+ end
85
+ end
86
+
87
+
88
+ class Enum
89
+ def _dump(limit)
90
+ Marshal.dump(to_i, limit)
91
+ end
92
+
93
+ def self._load(obj)
94
+ new(Marshal.load(obj))
95
+ end
96
+ end
97
+
98
+
99
+ class Flags
100
+ def _dump(limit)
101
+ Marshal.dump(to_i, limit)
102
+ end
103
+
104
+ def self._load(obj)
105
+ new(Marshal.load(obj))
106
+ end
107
+
108
+ # FIXME
109
+ def inspect
110
+ values = self.class.values
111
+ if values.find{|x| x == self }
112
+ body = nick
113
+ else
114
+ a = values.select{|x| self >= x }
115
+ a = a.reject{|x| a.find{|y| y > x } }
116
+ body = a.empty? ? '{}' : a.map{|x| x.nick }.join('|')
117
+ end
118
+ format('#<%s %s>', self.class.inspect, body)
119
+ end
120
+ end
121
+
122
+ module Log
123
+ DOMAIN = "Ruby/GLib"
124
+ LEVELS = {
125
+ LEVEL_ERROR => "ERROR",
126
+ LEVEL_CRITICAL => "CRITICAL",
127
+ LEVEL_WARNING => "WARNING",
128
+ LEVEL_MESSAGE => "MESSAGE",
129
+ LEVEL_INFO => "INFO",
130
+ LEVEL_DEBUG => "DEBUG"
131
+ }
132
+
133
+ module_function
134
+ def error(str)
135
+ log(DOMAIN, LEVEL_ERROR, caller(1)[0] << ": " << str)
136
+ end
137
+ def message(str)
138
+ log(DOMAIN, LEVEL_MESSAGE, caller(1)[0] << ": " << str)
139
+ end
140
+ def critical(str)
141
+ log(DOMAIN, LEVEL_CRITICAL, caller(1)[0] << ": " << str)
142
+ end
143
+ def warning(str)
144
+ log(DOMAIN, LEVEL_WARNING, caller(1)[0] << ": " << str)
145
+ end
146
+
147
+ def set_log_domain(domain)
148
+ level = GLib::Log::LEVEL_MASK
149
+ if $DEBUG
150
+ level = 255
151
+ elsif $VERBOSE
152
+ level = 127
153
+ end
154
+ GLib::Log.set_handler(domain, level)
155
+ end
156
+ end
157
+
158
+ if const_defined?(:UserDirectory)
159
+ class UserDirectory
160
+ constants.each do |name|
161
+ if /\ADIRECTORY_/ =~ name
162
+ const_set($POSTMATCH, const_get(name))
163
+ end
164
+ end
165
+ end
166
+ end
167
+
168
+ LOG_DOMAIN = "GLib"
169
+
170
+ class Object
171
+ LOG_DOMAIN = "GLib-GObject"
172
+ end
173
+
174
+ class Thread
175
+ LOG_DOMAIN = "GThread"
176
+ end
177
+
178
+ module Module
179
+ LOG_DOMAIN = "GModule"
180
+ end
181
+ end
182
+
183
+ GLib::Log.set_log_domain(nil)
184
+ GLib::Log.set_log_domain(GLib::LOG_DOMAIN)
185
+ GLib::Log.set_log_domain(GLib::Object::LOG_DOMAIN)
186
+ GLib::Log.set_log_domain(GLib::Thread::LOG_DOMAIN)
187
+ GLib::Log.set_log_domain(GLib::Module::LOG_DOMAIN)
188
+
189
+ # Ruby-GetText-Package support
190
+ begin
191
+ require 'gettext'
192
+ rescue LoadError
193
+ unless defined? GetText
194
+ module GetText
195
+ module_function
196
+ def _(msgid); msgid; end
197
+ def N_(msgid); msgid; end
198
+ def n_(msgid, msgid_plural, n)
199
+ n == 1 ? msgid : msgid_plural
200
+ end
201
+ def s_(msgid, div = '|')
202
+ if index = msgid.rindex(div)
203
+ msgid = msgid[(index + 1)..-1]
204
+ else
205
+ msgid
206
+ end
207
+ end
208
+ def bindtextdomain(domainname, path = nil, locale = nil, charset = nil)
209
+ end
210
+ end
211
+ end
212
+ end
213
+
214
+ =begin
215
+ Don't we need this?
216
+ ObjectSpace.define_finalizer(GLib) {
217
+ GLib::Log.cancel_handler
218
+ puts "GLib::Log.cancel_handler was called." if $DEBUG
219
+ }
220
+ =end