aboutsummaryrefslogtreecommitdiff
path: root/lib/web
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-09-08 13:13:24 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-09-08 13:13:24 +0200
commitccae7d1520548aaec95f6bd7302dd72c6fbdd6b9 (patch)
treeda6706a388a4318bc309f840ca302b3a998b7572 /lib/web
parentMove ProfileManager to libweb (diff)
downloadsmolbote-ccae7d1520548aaec95f6bd7302dd72c6fbdd6b9.tar.xz
Replace ProfileManager::profileList() with ProfileManager::idList()
Diffstat (limited to 'lib/web')
-rw-r--r--lib/web/profilemanager.cpp43
-rw-r--r--lib/web/profilemanager.h8
2 files changed, 33 insertions, 18 deletions
diff --git a/lib/web/profilemanager.cpp b/lib/web/profilemanager.cpp
index f3de3b5..b747bf6 100644
--- a/lib/web/profilemanager.cpp
+++ b/lib/web/profilemanager.cpp
@@ -43,18 +43,18 @@ WebProfile *ProfileManager::loadProfile(const QString &path)
Q_CHECK_PTR(ptr->profile);
ptr->profile->setSearch(ptr->settings.value("search", defaults.value("profile.search")).toString());
- connect(ptr->profile, &WebProfile::searchChanged, &ptr->settings, [&](const QString &url) {
- ptr->settings.setValue("search", url);
+ connect(ptr->profile, &WebProfile::searchChanged, &ptr->settings, [this, id](const QString &url) {
+ this->m_profiles.at(id)->settings.setValue("search", url);
});
ptr->profile->setHomepage(ptr->settings.value("homepage", defaults.value("profile.homepage")).toUrl());
- connect(ptr->profile, &WebProfile::homepageChanged, &ptr->settings, [&](const QUrl &url) {
- ptr->settings.setValue("homepage", url);
+ connect(ptr->profile, &WebProfile::homepageChanged, &ptr->settings, [this, id](const QUrl &url) {
+ this->m_profiles.at(id)->settings.setValue("homepage", url);
});
ptr->profile->setNewtab(ptr->settings.value("newtab", defaults.value("profile.newtab")).toUrl());
- connect(ptr->profile, &WebProfile::newtabChanged, &ptr->settings, [&](const QUrl &url) {
- ptr->settings.setValue("newtab", url);
+ connect(ptr->profile, &WebProfile::newtabChanged, &ptr->settings, [this, id](const QUrl &url) {
+ this->m_profiles.at(id)->settings.setValue("newtab", url);
});
ptr->settings.beginGroup("properties");
@@ -81,6 +81,28 @@ WebProfile *ProfileManager::loadProfile(const QString &path)
return m_profiles.at(id)->profile;
}
+QMenu *ProfileManager::createProfileMenu(std::function<void(WebProfile *)> callback, QWidget *parent) const
+{
+ QMenu *menu = new QMenu(parent);
+ for(auto it = m_profiles.cbegin(); it != m_profiles.cend(); ++it) {
+ WebProfile *profile = it->second->profile;
+ QAction *action = menu->addAction(profile->name());
+ connect(action, &QAction::triggered, [profile, callback]() {
+ callback(profile);
+ });
+ }
+ return menu;
+}
+
+const QStringList ProfileManager::idList() const
+{
+ QStringList ids;
+ for(auto it = m_profiles.cbegin(); it != m_profiles.cend(); ++it) {
+ ids.append(it->first);
+ }
+ return ids;
+}
+
const QString ProfileManager::id(WebProfile *profile) const
{
for(auto it = m_profiles.cbegin(); it != m_profiles.cend(); ++it) {
@@ -105,12 +127,3 @@ const QString ProfileManager::configurationPath(const QString &id) const
}
return QString();
}
-
-const QMap<QString, WebProfile *> ProfileManager::profileList() const
-{
- QMap<QString, WebProfile *> profiles;
- for(auto it = m_profiles.cbegin(); it != m_profiles.cend(); ++it) {
- profiles.insert(it->first, it->second->profile);
- }
- return profiles;
-}
diff --git a/lib/web/profilemanager.h b/lib/web/profilemanager.h
index f58fdb5..72af472 100644
--- a/lib/web/profilemanager.h
+++ b/lib/web/profilemanager.h
@@ -15,8 +15,8 @@
#include <QSettings>
#include <map>
#include <memory>
-
-typedef QMapIterator<QString, WebProfile *> ProfileIterator;
+#include <functional>
+#include <QMenu>
#define profileManager ProfileManager::instance()
@@ -32,10 +32,12 @@ public:
WebProfile *loadProfile(const QString &path);
+ QMenu *createProfileMenu(std::function<void(WebProfile *)> callback, QWidget *parent = nullptr) const;
+
+ const QStringList idList() const;
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