diff options
author | fiaxh <git@lightrise.org> | 2019-11-25 23:23:06 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2019-11-26 18:37:23 +0100 |
commit | b03da2af60e109921967fd38a2ba16bfb4df9f5d (patch) | |
tree | 60291ef797a7e0e58ee757001c79a8ab77de0fdc /main/src/ui/util/config.vala | |
parent | a10c82191e2d7afa221f752fb318cd6c1f94e6c4 (diff) | |
download | dino-b03da2af60e109921967fd38a2ba16bfb4df9f5d.tar.gz dino-b03da2af60e109921967fd38a2ba16bfb4df9f5d.zip |
Check window width and hight before (re)storing them
Diffstat (limited to 'main/src/ui/util/config.vala')
-rw-r--r-- | main/src/ui/util/config.vala | 61 |
1 files changed, 61 insertions, 0 deletions
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; + } +} + +} |