That's clean and a fairly obvious solution, but it's not really declarative and, in retrospect, I should have made it clear that my intent was to make it possible for the config system to write out a default config file for the user to examine.
That means that I need some mechanism which can gather all of the default key-value pairs without needing to either execute every code path first or pre-process the source the way gettext would. I'll probably take some inspiration from the Python optparse and argparse modules since they do roughly what I want but for argv instead. Thanks for taking the time to send me that link though. On 12-01-30 01:24 AM, PCMan wrote: > Source code of libfm can be reused for this purpose. > See this: > http://pcmanfm.git.sourceforge.net/git/gitweb.cgi?p=pcmanfm/libfm;a=blob;f=src/actions/utils.vala;h=2e29ae21d37153fff2e48d1879368d5063d2129a;hb=refs/heads/master > > This is what I used in libfm. > > On Mon, Jan 30, 2012 at 12:33 AM, Stephan Sokolow > <[email protected] <mailto:[email protected]>> > wrote: > > *nod* I have run across KeyFile demo code but thanks. > > The main thing holding me back is deciding on the cleanest, most > declarative way to implement default values. > > One of my main goals with gvrun has been to keep the source as clean, > concise, and reusably modular as possible. > > On 12-01-29 11:19 AM, Axel FILMORE wrote: > > 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. > > > > :) > > > > > > > > > > > > ------------------------------------------------------------------------------ > 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] <mailto:[email protected]> > https://lists.sourceforge.net/lists/listinfo/lxde-list > > > > > ------------------------------------------------------------------------------ > 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 > > > ------------------------------------------------------------------------------ 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
