diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-11-04 21:55:20 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-11-04 21:55:20 +0200 |
commit | d631875b20244cb8eb0523c88cc838808e9ff4b0 (patch) | |
tree | 254afb4e16ac0a7db059eb4f568eb5f9c3e92c1d /src/webengine/webprofilemanager.h | |
parent | Fix gcc compile errors and warnings (diff) | |
download | smolbote-d631875b20244cb8eb0523c88cc838808e9ff4b0.tar.xz |
Move lib/webprofile into src/webengine
Diffstat (limited to 'src/webengine/webprofilemanager.h')
-rw-r--r-- | src/webengine/webprofilemanager.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/webengine/webprofilemanager.h b/src/webengine/webprofilemanager.h new file mode 100644 index 0000000..3e82936 --- /dev/null +++ b/src/webengine/webprofilemanager.h @@ -0,0 +1,84 @@ +/* + * 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 <QDir> +#include <QFile> +#include <QMap> +#include <QMenu> +#include <QObject> +#include <QSettings> +#include <functional> + +struct ProfileDefault_t +{ + QString search; + QString homepage; + QString newtab; +}; + +class WebProfileManager : public QObject +{ + Q_OBJECT +public: + explicit WebProfileManager(QObject *parent); + ~WebProfileManager(); + + /** Create a profile with specified id + * param id The profile ID + * param path The path to the profile settings + * param isOffTheRecord Off-the-record toggle + * return WebProfile* The profile, or nullptr if one could not be created + */ + WebProfile *profile(const QString &id, const QString &path = QString(), bool isOffTheRecord = true); + + /** Set a profile for deletion + * param id The profile ID + * return void + */ + void deleteProfile(const QString &id); + + void profileMenu(QMenu *menu, const std::function<void(WebProfile *)> &callback, WebProfile *current = nullptr, bool checkable = false) const; + + const QStringList idList() const + { + return profiles.keys(); + } + QString id(WebProfile *profile) const + { + QMapIterator<QString, Profile> i(profiles); + while(i.hasNext()) { + i.next(); + if(i.value().ptr == profile) + return i.key(); + } + return QString(); + } + +private: + struct Profile { + WebProfile *ptr = nullptr; + QSettings *settings = nullptr; + bool selfDestruct = false; + + QVariant value(const QString &key, const QVariant &defaultValue) const + { + if(settings == nullptr) + return defaultValue; + else + return settings->value(key, defaultValue); + } + }; + + QMap<QString, Profile> profiles; +}; + +#endif // SMOLBOTE_PROFILEMANAGER_H |