From b03da2af60e109921967fd38a2ba16bfb4df9f5d Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 25 Nov 2019 23:23:06 +0100 Subject: Check window width and hight before (re)storing them --- main/src/ui/util/config.vala | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 main/src/ui/util/config.vala (limited to 'main/src/ui/util') diff --git a/main/src/ui/util/config.vala b/main/src/ui/util/config.vala new file mode 100644 index 00000000..4ca0d8a0 --- /dev/null +++ b/main/src/ui/util/config.vala @@ -0,0 +1,61 @@ +using Gee; +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui { + +public class Config : Object { + + public Database db { get; private set; } + + public Config(Database db) { + this.db = db; + + window_maximize = col_to_bool_or_default("window_maximized", false); + window_width = col_to_int_or_default("window_width", 1200); + window_height = col_to_int_or_default("window_height", 700); + } + + private bool window_maximize_; + public bool window_maximize { + get { return window_maximize_; } + set { + if (value == window_maximize_) return; + db.settings.insert().or("REPLACE").value(db.settings.key, "window_maximized").value(db.settings.value, value.to_string()).perform(); + window_maximize_ = value; + } + } + + public int window_height_; + public int window_height { + get { return window_height_; } + set { + if (value == window_height_) return; + db.settings.insert().or("REPLACE").value(db.settings.key, "window_height").value(db.settings.value, value.to_string()).perform(); + window_height_ = value; + } + } + + public int window_width_; + public int window_width { + get { return window_width_; } + set { + if (value == window_width_) return; + db.settings.insert().or("REPLACE").value(db.settings.key, "window_width").value(db.settings.value, value.to_string()).perform(); + window_width_ = value; + } + } + + private bool col_to_bool_or_default(string key, bool def) { + string? val = db.settings.select({db.settings.value}).with(db.settings.key, "=", key)[db.settings.value]; + return val != null ? bool.parse(val) : def; + } + + private int col_to_int_or_default(string key, int def) { + string? val = db.settings.select({db.settings.value}).with(db.settings.key, "=", key)[db.settings.value]; + return val != null ? int.parse(val) : def; + } +} + +} -- cgit v1.2.3-54-g00ecf