On 29/01/2012 16:51, Stephan Sokolow wrote:
> Ugh. Serves me right for sending a message shortly after not sleeping well.
>
> That's GLib.KeyFile I'm intending to use for the config file.
>
> This thing:
> http://www.valadoc.org/glib-2.0/GLib.KeyFile.html

Something like this reads a few keys from a Desktop file :

         KeyFile kf = new KeyFile ();
         kf.load_from_file (config_file, KeyFileFlags.NONE);
         string group = "Desktop Entry";
         if (kf.has_group (group) == false)
             return false;

         string key;

         string type = "";
         key = "Type";
         if (kf.has_key (group, key) == true) {
             type = kf.get_value (group, key);
             //stdout.printf ("Type: %s\n", type);
         }

         string name = "";
         key = "Name";
         if (kf.has_key (group, key) == true) {
             name = kf.get_value (group, key);
             //stdout.printf ("Name: %s\n", name);
         }

Very handy and something like this to save to a file :

         File file = File.new_for_path (config_file);

         // delete if file already exists
         if (file.query_exists ()) {
             file.delete ();
         }

         string config = "";
         DataOutputStream dos = new DataOutputStream (file.create 
(FileCreateFlags.REPLACE_DESTINATION));
         config += "key01=value1\n";
         config += "key02=value2\n";
         dos.put_string (config);

It's possible to use a fixed size buffer instead of DataOutputStream I 
think...

Anyway, it's great to write some programs in Vala, congratulations.

:)




-- 
Axel FILMORE


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Lxde-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lxde-list

Reply via email to