[sword-devel] finding conf file for module
Dmitrijs Ledkovs
dmitrij.ledkov at ubuntu.com
Sat May 22 18:28:34 MST 2010
On 23 May 2010 01:06, Matthew Talbert <ransom1982 at gmail.com> wrote:
> So, my first question is, "what is the best way to get the conf file
> for a given module?" and the second is, "could we please add this to
> the engine?"
>
The best way is probably to store sword configurations according to
XDG base-dir spec.[1]
It allows to store system-wide and per-user config files, user-data
(actual modules) & cache (search index).
If you look into your ~/.config ~/.local & ~/.cache you will notice
that a lot of programs already use it =)
On Windows gtk maps these locations to Application Data / All Users
for system & per user Application Data (or something like that, sorry
I don't use Windows)
In terms of API gtk, at least on *nix like systems, parses environment
XDG_* variables & has some defaults. The return from those functions
is semicolon separated list of paths which you then interate over to
get all the information you need.
Ofcourse if we go this route some decisions will have to be made as to
how to split it.
1) Everything is user data so we move ~/.sword -> ~/.local/sword and
coordinate with all apps to use XDG API's in their language/toolkit to
find system & user modules / configuration files
2) Split config, actual modules & search index into ~/.config/sword/,
~/.local/sword/ & ~/.cache/sword and do changes in sword where it
finds all the pieces. The idea here is that you can wipe ~/.cache and
everything will still work and cache can be regenerated, ~/.local
should store user created data (e.g. personal commentary and
downloaded modules) while ~/.config should store preferences only
(which can be wiped out to go back to default options). Read the spec
for more details.
I'm pretty sure there are ready made api's / libraries to deal with
this. Some duplication might be necessary in sword =)
e.g. I have this in my GtkBuilder branch already for xiphos for find
system data files:
1458 gchar** dir_collection;
1459 guint dir_collection_length;
1460 guint dir_i;
1461 gchar * full_fname;
1462
1463 dir_collection = g_strdupv ((gchar **) g_get_system_data_dirs ());
1464 dir_collection_length = g_strv_length (dir_collection);
1465
1466 for (dir_i = 0; dir_i < dir_collection_length; dir_i++) {
1467 full_fname = g_build_filename
(dir_collection[dir_i], PACKAGE, fname, NULL);
1468 if (g_file_test (full_fname, G_FILE_TEST_EXISTS)) {
1469 return full_fname;
1470 }
1471
1472 }
[1] http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
More information about the sword-devel
mailing list