From 87b464b53cfd6b9feca826b5caed7b45b373f348 Mon Sep 17 00:00:00 2001 From: oupson Date: Mon, 27 Feb 2023 11:58:55 +0100 Subject: [PATCH] Init sqlite database on config creation --- src/meson.build | 2 +- src/newpane.vala | 13 +------------ src/services/Config.vala | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/meson.build b/src/meson.build index 9df2929..cb7cbb7 100644 --- a/src/meson.build +++ b/src/meson.build @@ -12,8 +12,8 @@ footerm_deps = [ dependency('gtk4'), dependency('libadwaita-1'), dependency('vte-2.91-gtk4', version: '>= 0.70.0'), - dependency('json-glib-1.0', version: '>= 1.2.0'), dependency('libssh2'), + dependency('sqlite3') ] subdir('model') diff --git a/src/newpane.vala b/src/newpane.vala index d451928..14719a6 100644 --- a/src/newpane.vala +++ b/src/newpane.vala @@ -51,18 +51,7 @@ namespace Footerm { }); try { - var config_dir = GLib.File.new_for_path(GLib.Environment.get_user_config_dir()); - var server_files = config_dir.get_child("servers.json"); - - if (server_files.query_exists()) { - var parser = new Json.Parser(); - - parser.load_from_file(server_files.get_path()); - - // TODO - } else { - GLib.debug("Server file does not exist"); - } + var config = Footerm.Services.Config.get_instance(); } catch (Error e) { GLib.warning("Failed to read server list : %s", e.message); } diff --git a/src/services/Config.vala b/src/services/Config.vala index 06b363b..1cfe0de 100644 --- a/src/services/Config.vala +++ b/src/services/Config.vala @@ -19,14 +19,33 @@ */ namespace Footerm.Services { + public errordomain ConfigError { + DATABASE + } + public class Config { private static Config instance = null; - public static Config get_instance() { + public static Config get_instance() throws Footerm.Services.ConfigError { if (Config.instance == null) { Config.instance = new Config(); } return Config.instance; } + + private Sqlite.Database db; + + public Config() throws Footerm.Services.ConfigError { + var config_dir = GLib.File.new_for_path(GLib.Environment.get_user_config_dir()); + var config_db_file = config_dir.get_child("config.db"); + + debug("Database path is %s", config_db_file.get_path()); + int ec = Sqlite.Database.open (config_db_file.get_path(), out this.db); + if (ec != Sqlite.OK) { + throw new ConfigError.DATABASE(@"Can't open database: $(db.errcode ()): $(db.errmsg ())"); + } + + debug("Opened database"); + } } }