Adding env setting datadir support.
This commit is contained in:
parent
59d2b38357
commit
4ecd8c2a14
@ -1,9 +1,6 @@
|
||||
const string S = Config.WS;
|
||||
const string SQLITE_PATH = ".config" + S + "recuento.sqlite";
|
||||
const string PRELOADED_IMAGES_PATH = Config.DATADIR + S + "recuento" + S + "preloaded_images";
|
||||
const string PSOE_IMAGE = PRELOADED_IMAGES_PATH + S + "psoe.jpg";
|
||||
const string PP_IMAGE = PRELOADED_IMAGES_PATH + S + "pp.jpg";
|
||||
const string VOX_IMAGE = PRELOADED_IMAGES_PATH + S + "vox.jpg";
|
||||
const string ENVIRONMENT_VARIABLE_DATADIR = "DATADIR_RECUENTO";
|
||||
const string[] MIGRATIONS = {
|
||||
"CREATE TABLE options (key TEXT PRIMARY KEY, value TEXT);",
|
||||
"CREATE TABLE parties (" +
|
||||
@ -13,6 +10,14 @@ const string[] MIGRATIONS = {
|
||||
");"
|
||||
};
|
||||
|
||||
string datadir_maybe_env () {
|
||||
string datadir_env = GLib.Environment.get_variable(ENVIRONMENT_VARIABLE_DATADIR);
|
||||
if (datadir_env != null) {
|
||||
return datadir_env;
|
||||
}
|
||||
return Config.DATADIR;
|
||||
}
|
||||
|
||||
class Party {
|
||||
public string name;
|
||||
public string image;
|
||||
@ -25,9 +30,17 @@ class Party {
|
||||
}
|
||||
|
||||
GLib.List<Gtk.Widget> list_party_widgets;
|
||||
string preloaded_images_path;
|
||||
string psoe_image;
|
||||
string pp_image;
|
||||
string vox_image;
|
||||
|
||||
void main () {
|
||||
var app = new Adw.Application ("me.sergiotarxz.recuento", 0);
|
||||
preloaded_images_path = datadir_maybe_env () + S + "recuento" + S + "preloaded_images";
|
||||
psoe_image = preloaded_images_path + S + "psoe.jpg";
|
||||
pp_image = preloaded_images_path + S + "pp.jpg";
|
||||
vox_image = preloaded_images_path + S + "vox.jpg";
|
||||
app.activate.connect ( () => {
|
||||
activate (app);
|
||||
});
|
||||
@ -135,9 +148,9 @@ void load_inital_data (Sqlite.Database db) {
|
||||
if (check_if_loaded_initial_data (db)) {
|
||||
return;
|
||||
}
|
||||
insert_party (db, "PSOE", PSOE_IMAGE);
|
||||
insert_party (db, "PP", PP_IMAGE);
|
||||
insert_party (db, "VOX", VOX_IMAGE);
|
||||
insert_party (db, "PSOE", psoe_image);
|
||||
insert_party (db, "PP", pp_image);
|
||||
insert_party (db, "VOX", vox_image);
|
||||
set_loaded_initial_data (db);
|
||||
}
|
||||
|
||||
@ -270,7 +283,6 @@ Sqlite.Database get_db () {
|
||||
string home = GLib.Environment.get_home_dir ();
|
||||
GLib.DirUtils.create_with_parents (GLib.Path.get_dirname (@"$home$S$SQLITE_PATH"), 700);
|
||||
string final_sqlite_path = @"$home$S$SQLITE_PATH";
|
||||
print(final_sqlite_path);
|
||||
int rc = Sqlite.Database.open (final_sqlite_path, out db);
|
||||
apply_migrations (db);
|
||||
if (rc != Sqlite.OK) {
|
||||
|
Loading…
Reference in New Issue
Block a user