aboutsummaryrefslogtreecommitdiff
path: root/lib/webprofile/webprofilemanager.h
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2019-01-16 16:52:07 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2019-01-16 16:52:07 +0100
commit2a696a57abafb25978aef1af5758fe75b706d1f0 (patch)
tree9c9b3468398b16711a573e0c8b87ae2ad03100b4 /lib/webprofile/webprofilemanager.h
parentRewrite lib/urlfilter (diff)
downloadsmolbote-2a696a57abafb25978aef1af5758fe75b706d1f0.tar.xz
Rewrite lib/web to lib/webprofile
- libweb was supposed to be a general QtWebEngine wrapper, but only turned out to do profiles and profile management. The new name should make this more obvious. - Renamed ProfileManager to WebProfileManager, and cut out duplicate code. - Temporary profiles: temporary profiles are not kept after closing the browser.
Diffstat (limited to 'lib/webprofile/webprofilemanager.h')
-rw-r--r--lib/webprofile/webprofilemanager.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/webprofile/webprofilemanager.h b/lib/webprofile/webprofilemanager.h
new file mode 100644
index 0000000..822dc7d
--- /dev/null
+++ b/lib/webprofile/webprofilemanager.h
@@ -0,0 +1,78 @@
+/*
+ * 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>
+
+class WebProfileManager : public QObject
+{
+ Q_OBJECT
+public:
+ explicit WebProfileManager(const QHash<QString, QString> &profileSection, 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, 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;
+ const QHash<QString, QString> defaults;
+};
+
+#endif // SMOLBOTE_PROFILEMANAGER_H