From ccae7d1520548aaec95f6bd7302dd72c6fbdd6b9 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 8 Sep 2018 13:13:24 +0200 Subject: Replace ProfileManager::profileList() with ProfileManager::idList() --- lib/web/profilemanager.cpp | 43 ++++++++++++++++++++++++++++--------------- lib/web/profilemanager.h | 8 +++++--- 2 files changed, 33 insertions(+), 18 deletions(-) (limited to 'lib/web') 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 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 ProfileManager::profileList() const -{ - QMap 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 #include #include - -typedef QMapIterator ProfileIterator; +#include +#include #define profileManager ProfileManager::instance() @@ -32,10 +32,12 @@ public: WebProfile *loadProfile(const QString &path); + QMenu *createProfileMenu(std::function 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 profileList() const; private: struct ProfileData -- cgit v1.2.1