[ruby-gnome2-doc-cvs] [Hiki] update - tips_gconf

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2003年 9月 11日 (木) 01:04:58 JST


-------------------------
REMOTE_ADDR = 218.231.205.39
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/?tips_gconf
-------------------------
  = How to use Ruby/GConf2
  GConf is a configuration data storage mechanism. It's one of the easiest way to store configuration data. And the feature is so cool and elegant.
  If you think to add customization function to your application, check it out!
  
  See ((<Introduction to the GConf library|URL:http://developer.gnome.org/feature/archive/gconf/gconf.html>)). It's nice introduction for GConf.
  
  == First step
  This is an easiest 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.
  
  At second, it returns 1 and "hoge".
  
- # If you execute once more, you get 1 and "fuga".
+ (('#')) If you execute once more, you get 1 and "fuga".
  
  That's all! 
  You do nothing anymore. You can serialize the data and read/write anytime!
  
  === Where are the data?
  Data are managed by gconfd which is a per-user daemon. And they 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 is as String, Numeric, true/false.
  
  == The notice of change
  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 follow sample in 2 terminal and execute them on each terminal.
  
   require 'gconf2'
   require 'gtk2'
   
   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
  :2003-09-11 ((<Masao>))
   Translate to English.
  
  :2003-06-19 ((<Masao>))
   Initial release(Japanese)





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