aboutsummaryrefslogtreecommitdiff
path: root/lib/web/profilemanager.h
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-09-07 13:11:58 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-09-07 13:11:58 +0200
commit4739f509d9d5ebaef71a51cece8f75b6a7e4b3dc (patch)
treee3f89c1db2aaaa605f0cbd4d752479a611fb5aac /lib/web/profilemanager.h
parentSome cppcheck fixes (diff)
downloadsmolbote-4739f509d9d5ebaef71a51cece8f75b6a7e4b3dc.tar.xz
Move ProfileManager to libweb
Diffstat (limited to 'lib/web/profilemanager.h')
-rw-r--r--lib/web/profilemanager.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/web/profilemanager.h b/lib/web/profilemanager.h
new file mode 100644
index 0000000..f58fdb5
--- /dev/null
+++ b/lib/web/profilemanager.h
@@ -0,0 +1,62 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_PROFILEMANAGER_H
+#define SMOLBOTE_PROFILEMANAGER_H
+
+#include <QObject>
+#include <QMap>
+#include <webprofile.h>
+#include <QSettings>
+#include <map>
+#include <memory>
+
+typedef QMapIterator<QString, WebProfile *> ProfileIterator;
+
+#define profileManager ProfileManager::instance()
+
+class WebProfile;
+class ProfileManager : public QObject
+{
+ Q_OBJECT
+public:
+ explicit ProfileManager(const QHash<QString, QString> &profileSection, QObject *parent = nullptr);
+
+ static void setInstance(ProfileManager *instance);
+ static ProfileManager *instance();
+
+ WebProfile *loadProfile(const QString &path);
+
+ const QString id(WebProfile *profile) const;
+ WebProfile *profile(const QString &id) const;
+ const QString configurationPath(const QString &id) const;
+ const QMap<QString, WebProfile *> profileList() const;
+
+private:
+ struct ProfileData
+ {
+ ProfileData(const QString &path = QString()) : settings(path, QSettings::IniFormat) {
+ this->path = path;
+ }
+
+ ~ProfileData() {
+ this->settings.sync();
+ }
+
+ WebProfile *profile = nullptr;
+ QSettings settings;
+ QString path;
+ };
+
+ std::map<QString, std::unique_ptr<ProfileData>> m_profiles;
+
+ static ProfileManager *s_instance;
+ const QHash<QString, QString> defaults;
+};
+
+#endif // SMOLBOTE_PROFILEMANAGER_H