/* * 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/gitea/aqua/smolbote * * SPDX-License-Identifier: GPL-3.0 */ #ifndef SMOLBOTE_WEBPROFILEMANAGER_H #define SMOLBOTE_WEBPROFILEMANAGER_H #include "webprofile.h" #include #include #include #include #include #include #include void profileMenu(QMenu *menu, const std::function &callback, WebProfile *current = nullptr, bool checkable = false); class Browser; class WebProfileManager : public QObject { Q_OBJECT friend class Browser; friend void profileMenu(QMenu *, const std::function &, WebProfile *current, bool); public: explicit WebProfileManager(QObject *parent); ~WebProfileManager() override; static auto instance() -> const WebProfileManager *; static void setInstance(WebProfileManager *ptr); /** Create a profile with specified id * param id The profile ID * return WebProfile* The profile, or nullptr if one could not be created */ WebProfile *profile(const QString &id) const; /** Set a profile for deletion * param id The profile ID * return void */ [[deprecated]] void deleteProfile(const QString &id); const QStringList idList() const { return profiles.keys(); } QString id(WebProfile *profile) const { QMapIterator i(profiles); while(i.hasNext()) { i.next(); if(i.value().ptr == profile) return i.key(); } return QString(); } protected: WebProfile *add(const QString &id, const QString &path = QString(), bool isOffTheRecord = true); private: struct Profile { WebProfile *ptr = nullptr; QSettings *settings = nullptr; bool selfDestruct = false; }; QMap profiles; }; #endif // SMOLBOTE_PROFILEMANAGER_H