[ruby-gnome2-doc-cvs] [Hiki] update - tut-gconf

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2004年 3月 23日 (火) 21:19:16 JST


-------------------------
REMOTE_ADDR = 218.231.161.247
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/?tut-gconf
-------------------------
  = Ruby/GConf2 Tutorial
  GConf is a configuration data storage mechanism. It's one of the easiest way to store configuration data. And its features are so cool and elegant.
  If you are thinking of adding customization functionality to your application, check it out!
  
  See ((<Introduction to the GConf library|URL:http://developer.gnome.org/feature/archive/gconf/gconf.html>)). It's a nice introduction for GConf.
  
  == First step
  This is an easy but complete sample.
  
   require 'gconf2'
   client = GConf::Client.new
   
   #Read data
   p client["/apps/hoge/stage"]
   p client["/apps/hoge/name"] 
   
   #Write data
   client["/apps/hoge/stage"] = 1
   client["/apps/hoge/name"] = ARGV[0]
  
  Save this sample as "test.rb" and execute twice.
  
   $ruby test.rb "hoge"
   $ruby test.rb "fuga"
  
  At first, it returns nils because no data is stored.
  
  Second time around, it returns 1 and "hoge".
  
  (('#')) If you execute it once more, you get 1 and "fuga".
  
  That's all!
  You do nothing anymore. You can serialize the data and read/write data anytime!
  
  === Where's the data stored?
  Data is managed by gconfd, which is a per-user daemon. And they are saved to $HOME/.gconf/apps/hoge/%gconf.xml asynchronously. In this case, both of "/apps/hoge/stage" and "/apps/hoge/name" are keys. And the values are String, Numeric, true/false.
  
  == Notification of changes
  GConf::Client uses the GTK signal system. Instead of using GConf's custom callback API for notification, you can simply connect to a "value_changed" signal.
  Try to follow sample in 2 terminal and execute them on each terminal.
  
   require 'gconf2'
-  require 'gtk2'
-   
-  Gtk.init
+ 
   client = GConf::Client.new
   client.add_dir("/apps/hoge")
   client.notify_add("/apps/hoge/name") do |client, entry|
     p entry.value
   end
   
   Gtk.main
  
  == ChangeLog
  :2004-03-14 ((<Masao>))
   Add Gtk.init to the sample of "Notification of changes".
  :2003-09-11 ((<lone-star>))
   Small language fixes.
  :2003-09-11 ((<Masao>))
   Translate to English.
  
  :2003-06-19 ((<Masao>))
   Initial release(Japanese)





ruby-gnome2-cvs メーリングリストの案内
Back to archive index