diff options
| author | Joel Klinghed <the_jk@yahoo.com> | 2017-07-22 23:18:26 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@yahoo.com> | 2017-07-22 23:19:37 +0200 |
| commit | a3da855cddff3c3c71311af6ce3e7629a459024d (patch) | |
| tree | 7ed8cad6256f74fb83632f608891ceeb32e1f59a /src/gui_gtk.cc | |
| parent | d9e1e04c09a99b2a507e071f434fd394f4781051 (diff) | |
Add application config for GUI
QT5 stored in .config/org.the_jk/tp.Monitor.conf on Linux
GTK stored in dconf
Diffstat (limited to 'src/gui_gtk.cc')
| -rw-r--r-- | src/gui_gtk.cc | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/gui_gtk.cc b/src/gui_gtk.cc index 99172e3..4c1cc13 100644 --- a/src/gui_gtk.cc +++ b/src/gui_gtk.cc @@ -10,6 +10,7 @@ #include <vector> #include "gui_about.hh" +#include "gui_config.hh" #include "gui_form.hh" #include "gui_formapply.hh" #include "gui_listmodel.hh" @@ -510,11 +511,53 @@ private: std::unordered_map<Attribute, GtkTextTag*> tags_; }; +class GtkConfig : public GuiConfig { +public: + GtkConfig() + : settings_(g_settings_new("org.the_jk.tp.Monitor")) { + } + + ~GtkConfig() override { + g_settings_sync(); + } + + using Config::get; + std::string const& get(std::string const& key, + std::string const& fallback) override { + auto variant = g_settings_get_user_value(settings_.get(), key.c_str()); + if (!variant) return fallback; + memory_[key] = g_variant_get_string(variant, nullptr); + g_variant_unref(variant); + return memory_[key]; + } + char const* get(std::string const& key, + char const* fallback) override { + auto variant = g_settings_get_user_value(settings_.get(), key.c_str()); + if (!variant) return fallback; + memory_[key] = g_variant_get_string(variant, nullptr); + g_variant_unref(variant); + return memory_[key].c_str(); + } + bool is_set(std::string const& key) override { + auto variant = g_settings_get_user_value(settings_.get(), key.c_str()); + if (!variant) return false; + g_variant_unref(variant); + return true; + } + void set(std::string const& key, std::string const& value) override { + g_settings_set_string(settings_.get(), key.c_str(), value.c_str()); + } + +private: + shared_gobject<GSettings> settings_; + std::unordered_map<std::string, std::string> memory_; +}; + class GtkGuiMain : public virtual GuiMain, public GtkGuiWindow { public: GtkGuiMain(std::string const& title, uint32_t width, uint32_t height) : title_(title), width_(width), height_(height), split_(0.5), - menu_(nullptr), statusbar_(nullptr) { + config_(new GtkConfig()), menu_(nullptr), statusbar_(nullptr) { } void set_menu(GuiMenu* menu) override { @@ -643,6 +686,10 @@ private: return true; } + Config* config() override { + return config_.get(); + } + std::string title_; uint32_t width_; uint32_t height_; @@ -651,6 +698,7 @@ private: shared_gobject<MainApp> app_; shared_gobject<ListModel> listmodel_; std::unique_ptr<AttributedText> package_; + std::unique_ptr<GtkConfig> config_; Observers<GuiMain::Listener*> observers_; GuiMenu* menu_; GuiStatusBar* statusbar_; |
