From 4739f509d9d5ebaef71a51cece8f75b6a7e4b3dc Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 7 Sep 2018 13:11:58 +0200 Subject: Move ProfileManager to libweb --- lib/web/profilemanager.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 lib/web/profilemanager.h (limited to 'lib/web/profilemanager.h') 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 +#include +#include +#include +#include +#include + +typedef QMapIterator ProfileIterator; + +#define profileManager ProfileManager::instance() + +class WebProfile; +class ProfileManager : public QObject +{ + Q_OBJECT +public: + explicit ProfileManager(const QHash &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 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> m_profiles; + + static ProfileManager *s_instance; + const QHash defaults; +}; + +#endif // SMOLBOTE_PROFILEMANAGER_H -- cgit v1.2.1