glib2 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/README
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Ruby/GLib2
|
2
|
+
==========
|
3
|
+
Ruby/GLib2 is a Ruby binding of GLib-2.x.
|
4
|
+
|
5
|
+
Requirements
|
6
|
+
------------
|
7
|
+
Ruby: http://www.ruby-lang.org/
|
8
|
+
GLib: http://www.gtk.org/
|
9
|
+
|
10
|
+
Install
|
11
|
+
-------
|
12
|
+
0. install ruby-1.6.x or later, GLib.
|
13
|
+
1. ruby extconf.rb
|
14
|
+
2. make
|
15
|
+
3. su
|
16
|
+
4. make install
|
17
|
+
|
18
|
+
Copying
|
19
|
+
-------
|
20
|
+
Copyright (c) 2002-2005 Ruby-GNOME2 Project Team
|
21
|
+
|
22
|
+
This program is free software.
|
23
|
+
You can distribute/modify this program under the terms of
|
24
|
+
the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
|
25
|
+
|
26
|
+
Project Website
|
27
|
+
---------------
|
28
|
+
http://ruby-gnome2.sourceforge.jp/
|
data/Rakefile
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
CLEAN.include '**/*.o'
|
3
|
+
CLEAN.include "**/*.#{Config::MAKEFILE_CONFIG['DLEXT']}"
|
4
|
+
CLOBBER.include 'doc'
|
5
|
+
CLOBBER.include '**/*.log'
|
6
|
+
CLOBBER.include '**/Makefile'
|
7
|
+
CLOBBER.include '**/extconf.h'
|
8
|
+
|
9
|
+
# Determine the current version of the software
|
10
|
+
def ruby_glib_version
|
11
|
+
buf = File.read('src/rbglib.h')
|
12
|
+
if buf =~ /\s*RBGLIB_MAJOR_VERSION\s*(\d.+)/
|
13
|
+
major = $1
|
14
|
+
else
|
15
|
+
major = 0
|
16
|
+
end
|
17
|
+
if buf =~ /\s*RBGLIB_MINOR_VERSION\s*(\d.+)/
|
18
|
+
minor = $1
|
19
|
+
else
|
20
|
+
minor = 0
|
21
|
+
end
|
22
|
+
if buf =~ /\s*RBGLIB_MICRO_VERSION\s*(\d.+)/
|
23
|
+
micro = $1
|
24
|
+
else
|
25
|
+
micro = 0
|
26
|
+
end
|
27
|
+
"#{major}.#{minor}.#{micro}"
|
28
|
+
end
|
29
|
+
|
30
|
+
CURRENT_VERSION = ruby_glib_version
|
31
|
+
|
32
|
+
desc "Default Task (Test project)"
|
33
|
+
task :default => :test
|
34
|
+
|
35
|
+
# Make tasks -----------------------------------------------------
|
36
|
+
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
|
37
|
+
MAKECMD = ENV['MAKE_CMD'] || make_program
|
38
|
+
MAKEOPTS = ENV['MAKE_OPTS'] || ''
|
39
|
+
|
40
|
+
GLIB_SO = "src/glib2.#{Config::MAKEFILE_CONFIG['DLEXT']}"
|
41
|
+
|
42
|
+
file 'Makefile' => 'extconf.rb' do
|
43
|
+
sh "ruby extconf.rb #{ENV['EXTCONF_OPTS']}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def make(target = '')
|
47
|
+
pid = system("#{MAKECMD} #{MAKEOPTS} #{target}")
|
48
|
+
$?.exitstatus
|
49
|
+
end
|
50
|
+
|
51
|
+
# Let make handle dependencies between c/o/so - we'll just run it.
|
52
|
+
file GLIB_SO => (['Makefile'] + Dir['src/*.c'] + Dir['src/*.h']) do
|
53
|
+
m = make
|
54
|
+
fail "Make failed (status #{m})" unless m == 0
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "Configure Glib2"
|
58
|
+
task :configure => ['Makefile']
|
59
|
+
|
60
|
+
desc "Compile the shared object"
|
61
|
+
task :compile => [GLIB_SO]
|
62
|
+
|
63
|
+
desc "Run glib tests"
|
64
|
+
task :test => :compile do
|
65
|
+
sh "ruby test/run-test.rb"
|
66
|
+
end
|
67
|
+
|
68
|
+
desc 'Generate gem specification'
|
69
|
+
task :gemspec do
|
70
|
+
require 'erb'
|
71
|
+
tspec = ERB.new(File.read(File.join(File.dirname(__FILE__),'src','glib2.gemspec.erb')))
|
72
|
+
File.open(File.join(File.dirname(__FILE__),'glib2.gemspec'),'wb') do|f|
|
73
|
+
f << tspec.result
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
desc 'Build gem'
|
78
|
+
task :package => :gemspec do
|
79
|
+
require 'rubygems/specification'
|
80
|
+
spec_source = File.read File.join(File.dirname(__FILE__),'glib2.gemspec')
|
81
|
+
spec = nil
|
82
|
+
# see: http://gist.github.com/16215
|
83
|
+
Thread.new { spec = eval("$SAFE = 3\n#{spec_source}") }.join
|
84
|
+
spec.validate
|
85
|
+
Gem::Builder.new(spec).build
|
86
|
+
end
|
87
|
+
|
data/extconf.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
=begin
|
2
|
+
extconf.rb for Ruby/GLib extention library
|
3
|
+
=end
|
4
|
+
|
5
|
+
TOPDIR = File.expand_path(File.dirname(__FILE__))
|
6
|
+
MKMF_GNOME2_DIR = TOPDIR + '/src/lib'
|
7
|
+
SRCDIR = TOPDIR + '/src'
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift MKMF_GNOME2_DIR
|
10
|
+
|
11
|
+
PACKAGE_NAME = "glib2"
|
12
|
+
PACKAGE_ID = "gobject-2.0"
|
13
|
+
|
14
|
+
require 'mkmf-gnome2'
|
15
|
+
|
16
|
+
PKGConfig.have_package(PACKAGE_ID) or exit 1
|
17
|
+
PKGConfig.have_package('gthread-2.0')
|
18
|
+
|
19
|
+
setup_win32(PACKAGE_NAME)
|
20
|
+
|
21
|
+
have_header("unistd.h")
|
22
|
+
have_header("io.h")
|
23
|
+
|
24
|
+
glib_header = "glib.h"
|
25
|
+
have_func("g_spawn_close_pid", glib_header)
|
26
|
+
have_func("g_thread_init", glib_header)
|
27
|
+
have_func("g_main_depth", glib_header)
|
28
|
+
have_func("g_listenv", glib_header)
|
29
|
+
|
30
|
+
ruby_header = "ruby.h"
|
31
|
+
have_func("rb_check_array_type", ruby_header)
|
32
|
+
have_func("rb_exec_recursive", ruby_header)
|
33
|
+
have_func("rb_errinfo", ruby_header)
|
34
|
+
have_func("rb_sourcefile", ruby_header)
|
35
|
+
have_func("rb_sourceline", ruby_header)
|
36
|
+
have_func("ruby_set_current_source", ruby_header)
|
37
|
+
have_func("rb_thread_blocking_region", ruby_header)
|
38
|
+
have_func("ruby_native_thread_p", ruby_header)
|
39
|
+
have_func("rb_str_encode", ruby_header)
|
40
|
+
|
41
|
+
have_var("curr_thread", [ruby_header, "node.h"])
|
42
|
+
have_var("rb_curr_thread", [ruby_header, "node.h"])
|
43
|
+
|
44
|
+
create_pkg_config_file("Ruby/GLib2", PACKAGE_ID)
|
45
|
+
|
46
|
+
create_makefile_at_srcdir(PACKAGE_NAME, SRCDIR, "-DRUBY_GLIB2_COMPILATION") do
|
47
|
+
enum_type_prefix = "glib-enum-types"
|
48
|
+
include_paths = PKGConfig.cflags_only_I("glib-2.0")
|
49
|
+
headers = include_paths.split.inject([]) do |result, path|
|
50
|
+
result + Dir.glob(File.join(path.sub(/^-I/, ""), "glib", "*.h"))
|
51
|
+
end.reject do |file|
|
52
|
+
/g(iochannel|scanner)\.h/ =~ file
|
53
|
+
end
|
54
|
+
include_paths = PKGConfig.cflags_only_I("gobject-2.0")
|
55
|
+
headers = include_paths.split.inject(headers) do |result, path|
|
56
|
+
result + Dir.glob(File.join(path.sub(/^-I/, ""), "gobject", "gsignal.h"))
|
57
|
+
end
|
58
|
+
glib_mkenums(enum_type_prefix, headers, "G_TYPE_", ["glib-object.h"])
|
59
|
+
end
|
60
|
+
|
61
|
+
create_top_makefile
|
@@ -0,0 +1,66 @@
|
|
1
|
+
=begin
|
2
|
+
bookmarkfile.rb - Sample for GLib::BookmarkFile
|
3
|
+
|
4
|
+
Copyright (C) 2006 Ruby-GNOME2 Project Team
|
5
|
+
This program is licenced under the same licence as Ruby-GNOME2.
|
6
|
+
|
7
|
+
$Id: bookmarkfile.rb,v 1.1 2006/12/26 09:59:51 mutoh Exp $
|
8
|
+
=end
|
9
|
+
|
10
|
+
require 'glib2'
|
11
|
+
|
12
|
+
$KCODE = "U"
|
13
|
+
|
14
|
+
#
|
15
|
+
# Create bookmarkfile data.
|
16
|
+
#
|
17
|
+
URI = "http://ruby-gnome2.sourceforge.jp/"
|
18
|
+
bf = GLib::BookmarkFile.new
|
19
|
+
bf.set_title(URI, "Ruby-GNOME2 sample")
|
20
|
+
bf.set_description(URI, "Ruby-GNOME2 Sampe for GLib::BookmarkFile")
|
21
|
+
bf.set_mime_type(URI, "text/html")
|
22
|
+
bf.set_private(URI, false)
|
23
|
+
bf.set_icon(URI, "http://ruby-gnome2.sourceforge.jp/logo-gy.png", "image/png")
|
24
|
+
bf.set_added(URI, Time.now)
|
25
|
+
bf.set_modified(URI, Time.now)
|
26
|
+
bf.set_visited(URI, Time.now)
|
27
|
+
bf.set_groups(URI, ["Ruby", "GTK+"])
|
28
|
+
bf.set_app_info(URI, "WWW Browser", "firefox %u", 1, Time.now)
|
29
|
+
bf.add_group(URI, "GNOME")
|
30
|
+
bf.add_application(URI, "Ruby VM", "ruby %u")
|
31
|
+
|
32
|
+
#bf.remove_group(URI, "GTK+")
|
33
|
+
#bf.remove_application(URI, "Ruby VM")
|
34
|
+
#bf.remove_item(URI)
|
35
|
+
#bf.move_item(URI, "http://gtk.org/")
|
36
|
+
|
37
|
+
# Save as "bookmarkfile.xml"
|
38
|
+
bf.to_file("bookmarkfile.xml")
|
39
|
+
|
40
|
+
#
|
41
|
+
# Load from "bookmarkfile.xml"
|
42
|
+
#
|
43
|
+
bf2 = GLib::BookmarkFile.new
|
44
|
+
bf2.load_from_file("bookmarkfile.xml")
|
45
|
+
|
46
|
+
puts "size = #{bf2.size}"
|
47
|
+
puts "uris = #{bf2.uris.inspect}"
|
48
|
+
bf2.uris.each do |uri|
|
49
|
+
puts "uri: [#{uri}]"
|
50
|
+
puts " * title: [#{bf2.get_title(uri)}]"
|
51
|
+
puts " * description: [#{bf2.get_description(uri)}]"
|
52
|
+
puts " * mime_type: [#{bf2.get_mime_type(uri)}]"
|
53
|
+
puts " * private?: [#{bf2.private?(uri)}]"
|
54
|
+
puts " * icon: [#{bf2.get_icon(uri).inspect}]"
|
55
|
+
puts " * added: [#{bf2.get_added(uri)}]"
|
56
|
+
puts " * modified: [#{bf2.get_modified(uri)}]"
|
57
|
+
puts " * visited: [#{bf2.get_visited(uri)}]"
|
58
|
+
puts " * groups: #{bf2.get_groups(uri).inspect}"
|
59
|
+
puts " * applications: #{bf2.get_applications(uri).inspect}"
|
60
|
+
begin
|
61
|
+
puts " * app_info: #{bf2.get_app_info(uri, "WWW Browser").inspect}"
|
62
|
+
rescue
|
63
|
+
puts $!
|
64
|
+
end
|
65
|
+
puts
|
66
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
=begin
|
2
|
+
completion.rb - Sample for GLib::Completion
|
3
|
+
|
4
|
+
Copyright (C) 2005 Ruby-GNOME2 Project Team
|
5
|
+
This program is licenced under the same licence as Ruby-GNOME2.
|
6
|
+
|
7
|
+
$Id: completion.rb,v 1.1 2005/10/14 19:10:07 mutoh Exp $
|
8
|
+
=end
|
9
|
+
|
10
|
+
require 'glib2'
|
11
|
+
|
12
|
+
###########################
|
13
|
+
# Simple String completion
|
14
|
+
###########################
|
15
|
+
ary = ["a_", "a_ab", "aac", "aabc", "aabcd"]
|
16
|
+
comp = GLib::Completion.new
|
17
|
+
comp.add_items(ary)
|
18
|
+
p comp.complete("a_")
|
19
|
+
p comp.complete("aab")
|
20
|
+
|
21
|
+
puts "-----------"
|
22
|
+
|
23
|
+
|
24
|
+
############################
|
25
|
+
# Class completion and UTF-8
|
26
|
+
############################
|
27
|
+
class Test
|
28
|
+
def initialize(str)
|
29
|
+
@str = str
|
30
|
+
end
|
31
|
+
def value
|
32
|
+
@str
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ary2 = [Test.new("あ_"), Test.new("あ_あい"),
|
37
|
+
Test.new("ああab"), Test.new("ああabc"), Test.new("ああbcd")]
|
38
|
+
|
39
|
+
comp2 = GLib::Completion.new {|data|
|
40
|
+
data.value
|
41
|
+
}
|
42
|
+
|
43
|
+
comp2.add_items(ary2)
|
44
|
+
puts %Q$["#{comp2.complete("あ_").join(', "')}"]$
|
45
|
+
puts %Q$["#{comp2.complete("ああa").join(', "')}"]$
|
data/sample/idle.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
=begin
|
2
|
+
idle.rb - Sample for GLib::Idle, GLib::MainLoop.
|
3
|
+
|
4
|
+
Copyright (C) 2005 Ruby-GNOME2 Project Team
|
5
|
+
This program is licenced under the same licence as Ruby-GNOME2.
|
6
|
+
|
7
|
+
$Date: 2005/03/13 14:39:58 $
|
8
|
+
$Id: idle.rb,v 1.1 2005/03/13 14:39:58 mutoh Exp $
|
9
|
+
=end
|
10
|
+
|
11
|
+
require 'glib2'
|
12
|
+
|
13
|
+
mainloop = GLib::MainLoop.new(nil, true)
|
14
|
+
|
15
|
+
i = 0
|
16
|
+
GLib::Idle.add {
|
17
|
+
i += 1
|
18
|
+
p "timeout1-#{i}"
|
19
|
+
if i > 9
|
20
|
+
mainloop.quit
|
21
|
+
false # the source is removed.
|
22
|
+
else
|
23
|
+
true # continue ...
|
24
|
+
end
|
25
|
+
}
|
26
|
+
|
27
|
+
j = 0
|
28
|
+
GLib::Idle.add {
|
29
|
+
j += 1
|
30
|
+
p "timeout2-#{i}"
|
31
|
+
if j > 9
|
32
|
+
mainloop.quit
|
33
|
+
false # the source is removed.
|
34
|
+
else
|
35
|
+
true # continue ...
|
36
|
+
end
|
37
|
+
}
|
38
|
+
|
39
|
+
mainloop.run
|
40
|
+
|
41
|
+
p "quit..."
|
data/sample/iochannel.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
=begin
|
2
|
+
iochannel.rb - Sample for GLib::IOChannel.
|
3
|
+
|
4
|
+
Copyright (C) 2005 Ruby-GNOME2 Project Team
|
5
|
+
This program is licenced under the same licence as Ruby-GNOME2.
|
6
|
+
|
7
|
+
$Id: iochannel.rb,v 1.3 2006/12/20 18:08:20 mutoh Exp $
|
8
|
+
=end
|
9
|
+
|
10
|
+
require 'glib2'
|
11
|
+
|
12
|
+
path = ARGV[0] || __FILE__
|
13
|
+
|
14
|
+
GLib::IOChannel.open(path) {|io|
|
15
|
+
puts io.read
|
16
|
+
}
|
17
|
+
|
18
|
+
stdout = GLib::IOChannel.new(path, "r")
|
19
|
+
stdout.add_watch(GLib::IOChannel::IN
|
20
|
+
) {|io, condition|
|
21
|
+
puts "condition = #{condition}"
|
22
|
+
false
|
23
|
+
}
|
24
|
+
|
25
|
+
context = GLib::MainContext.default
|
26
|
+
mainloop = GLib::MainLoop.new(context, true)
|
27
|
+
|
28
|
+
|
29
|
+
Thread.new{
|
30
|
+
num = 0
|
31
|
+
loop {
|
32
|
+
num += 1
|
33
|
+
str = stdout.gets
|
34
|
+
puts "line #{num}: #{str}"
|
35
|
+
unless str
|
36
|
+
mainloop.quit
|
37
|
+
break
|
38
|
+
end
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
mainloop.run
|
43
|
+
|
44
|
+
stdout.close
|
data/sample/keyfile.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
=begin
|
2
|
+
keyfile.rb - Sample for GLib::KeyFile
|
3
|
+
|
4
|
+
Copyright (C) 2006 Ruby-GNOME2 Project Team
|
5
|
+
This program is licenced under the same licence as Ruby-GNOME2.
|
6
|
+
|
7
|
+
$Id: keyfile.rb,v 1.2 2006/12/23 17:43:03 mutoh Exp $
|
8
|
+
=end
|
9
|
+
|
10
|
+
require 'glib2'
|
11
|
+
|
12
|
+
$KCODE = "U"
|
13
|
+
|
14
|
+
#
|
15
|
+
# Create a GLib::KeyFile
|
16
|
+
#
|
17
|
+
kf = GLib::KeyFile.new
|
18
|
+
kf.set_value("Group 1", "value", "Hello World")
|
19
|
+
kf.set_comment("Group 1", nil, "This file is generated by keyfile.rb")
|
20
|
+
kf.set_string("Group 1", "string", "Hello World\nRuby-GNOME2")
|
21
|
+
kf.set_locale_string("Group 1", "locale_string", "ja", "こんにちわ世界")
|
22
|
+
kf.set_locale_string("Group 1", "locale_string", "en", "Hello World")
|
23
|
+
kf.set_boolean("Group 1", "boolean", true)
|
24
|
+
kf.set_integer("Group 1", "integer", 1)
|
25
|
+
kf.set_double("Group 1", "double", 1.0)
|
26
|
+
kf.set_string_list("Group 2", "string_list", ["foo", "bar"])
|
27
|
+
kf.set_locale_string_list("Group 2", "locale_string_list", "ja", ["こんにちわ", "世界"])
|
28
|
+
kf.set_locale_string_list("Group 2", "locale_string_list", "en", ["Hellow", "World"])
|
29
|
+
kf.set_boolean_list("Group 2", "boolean_list", [true, false])
|
30
|
+
kf.set_integer_list("Group 2", "integer_list", [1, 2, 3])
|
31
|
+
kf.set_double_list("Group 2", "double_list", [1.2, 1.3, 1.45])
|
32
|
+
kf.set_comment("Group 2", "string_list", "comment of string_list")
|
33
|
+
|
34
|
+
# Save as "keyfile.ini"
|
35
|
+
File.open("keyfile.ini", "w") do |out|
|
36
|
+
out.write kf.to_data
|
37
|
+
end
|
38
|
+
|
39
|
+
#kf.remove_comment("Group 2", "string_list")
|
40
|
+
#kf.remove_key("Group 2", "string_list")
|
41
|
+
#kf.remove_group("Group 2")
|
42
|
+
|
43
|
+
#
|
44
|
+
# Load from "keyfile.ini"
|
45
|
+
#
|
46
|
+
kf2 = GLib::KeyFile.new
|
47
|
+
kf2.load_from_file("keyfile.ini")
|
48
|
+
|
49
|
+
puts "Group 1: value = #{kf2.get_value("Group 1", "value")}"
|
50
|
+
puts "Group 1: string = #{kf2.get_string("Group 1", "string")}"
|
51
|
+
puts "Group 1: locale_string[ja] = #{kf2.get_locale_string("Group 1", "locale_string", "ja")}"
|
52
|
+
puts "Group 1: locale_string[en] = #{kf2.get_locale_string("Group 1", "locale_string", "en")}"
|
53
|
+
puts "Group 1: boolean = #{kf2.get_boolean("Group 1", "boolean")}"
|
54
|
+
puts "Group 1: integer = #{kf2.get_integer("Group 1", "integer")}"
|
55
|
+
puts "Group 1: double = #{kf2.get_double("Group 1", "double")}"
|
56
|
+
puts "Group 2: string_list = #{kf2.get_string_list("Group 2", "string_list").inspect}"
|
57
|
+
puts "Group 2: locale_string_list[ja] = #{kf2.get_locale_string_list("Group 2", "locale_string_list", "ja").inspect}"
|
58
|
+
puts "Group 2: locale_string_list[en] = #{kf2.get_locale_string_list("Group 2", "locale_string_list", "en").inspect}"
|
59
|
+
puts "Group 2: boolean_list = #{kf2.get_boolean_list("Group 2", "boolean_list").inspect}"
|
60
|
+
puts "Group 2: integer_list = #{kf2.get_integer_list("Group 2", "integer_list").inspect}"
|
61
|
+
puts "Group 2: double_list = #{kf2.get_double_list("Group 2", "double_list").inspect}"
|
62
|
+
puts "Group 2: comment = #{kf2.get_comment("Group 2", "string_list")}"
|
data/sample/shell.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
=begin
|
2
|
+
shell.rb - Sample for GLib::Shell
|
3
|
+
|
4
|
+
Copyright (C) 2005 Ruby-GNOME2 Project Team
|
5
|
+
This program is licenced under the same licence as Ruby-GNOME2.
|
6
|
+
|
7
|
+
$Id: shell.rb,v 1.1 2005/10/14 19:10:07 mutoh Exp $
|
8
|
+
=end
|
9
|
+
|
10
|
+
require 'glib2'
|
11
|
+
|
12
|
+
cmd = "ls *.c *.o"
|
13
|
+
|
14
|
+
p GLib::Shell.parse(cmd)
|
15
|
+
|
16
|
+
puts quote = GLib::Shell.quote(cmd)
|
17
|
+
puts GLib::Shell.unquote(quote)
|
18
|
+
|
19
|
+
puts "----"
|
20
|
+
|
21
|
+
#Samples to catch an Exception
|
22
|
+
begin
|
23
|
+
GLib::Shell.parse('foooo "bar')
|
24
|
+
rescue GLib::ShellError => e
|
25
|
+
puts "domain = #{e.domain}"
|
26
|
+
puts "code = #{e.code}"
|
27
|
+
puts "message = #{e.message}"
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
GLib::Shell.unquote('foooo "bar')
|
32
|
+
rescue GLib::ShellError => e
|
33
|
+
puts "domain = #{e.domain}"
|
34
|
+
puts "code = #{e.code}"
|
35
|
+
puts "message = #{e.message}"
|
36
|
+
end
|