From c299a5e9c1ce2cd7af2eb02645993b21b9448f34 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 28 May 2018 11:42:09 +0200 Subject: Changing Window profile --- src/browser.cpp | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'src/browser.cpp') diff --git a/src/browser.cpp b/src/browser.cpp index 512f207..05d9a0b 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -18,9 +18,11 @@ #include #include #include +#include +#include #include -QVector loadPlugins(const QString &location) +inline QVector loadPlugins(const QString &location) { QDir pluginsDir(location); QVector list; @@ -49,6 +51,21 @@ QVector loadPlugins(const QString &location) return list; } +inline QHash loadProfiles(const QString &location) +{ + QDir profilesDir(location); + QHash list; + + if(profilesDir.exists()) { + const QFileInfoList entries = profilesDir.entryInfoList({ "*.profile" }, QDir::Files | QDir::Readable); + for(const auto &entry : entries) { + list.insert(entry.baseName(), new WebProfile(entry.baseName())); + } + } + + return list; +} + Browser::Browser(int &argc, char *argv[]) : SingleApplication(argc, argv) { @@ -67,6 +84,7 @@ Browser::~Browser() //qDeleteAll(m_plugins); m_plugins.clear(); + qDeleteAll(m_profiles); } void Browser::setConfiguration(std::shared_ptr &config) @@ -80,13 +98,16 @@ void Browser::setup(const QString &defaultProfile) Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set"); // load profiles - if(defaultProfile == "") { - auto *p = new WebProfile(this); - p->loadProfile(m_config->section("profile")); - WebProfile::setDefaultProfile(p); - } else { - auto *p = new WebProfile(defaultProfile, this); - WebProfile::setDefaultProfile(p); + { + auto *otr = new WebProfile(this); + m_profiles.insert(tr("Off-the-record"), otr); + m_profiles.unite(loadProfiles(QString::fromStdString(m_config->value("profile.path").value()))); + + if(defaultProfile == "") { + WebProfile::setDefaultProfile(otr); + } else { + WebProfile::setDefaultProfile(m_profiles.value(defaultProfile)); + } } // plugins @@ -125,6 +146,14 @@ void Browser::setup(const QString &defaultProfile) connect(WebProfile::defaultProfile(), &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); } +WebProfile *Browser::profile(const QString &name) const +{ + if(m_profiles.contains(name)) + return m_profiles.value(name); + else + return nullptr; +} + int Browser::command(const QString &command) { if(m_commands.contains(command)) { -- cgit v1.2.1