From c8352009ceb6b9240ef7c1ad5be93f42312b59a2 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 12 Apr 2025 19:05:24 +0530 Subject: Switch to using map for configuration --- src/Configuration.hpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/Configuration.hpp') diff --git a/src/Configuration.hpp b/src/Configuration.hpp index 06335dc..a1eca51 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -1,14 +1,33 @@ #pragma once #include +#include class Configuration : public QObject { Q_OBJECT +private: + std::unordered_map config_map{ + {"new_view_url", "https://duckduckgo.com"}, + {"close_window_when_no_views", true}, + }; + public: using QObject::QObject; - QString new_view_url = "https://duckduckgo.com"; + void set_config(const QString &name, const QVariant &value) { + qDebug() << "config update" << name << value; + config_map[name] = value; + emit config_updated(name, value); + } + + QVariant get_config(const QString &name) const { return config_map.at(name); } + + QString new_view_url() const { return get_config("new_view_url").toString(); } + bool close_window_when_no_views() const { + return get_config("close_window_when_no_views").toBool(); + } - bool close_window_when_no_views = true; +signals: + void config_updated(const QString &name, const QVariant &value); }; -- cgit v1.3.1