aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-12-25 15:26:01 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-12-25 15:26:01 +0100
commit5dfb7c41d0619bbe0830e04a2f7a8685c1e00a29 (patch)
tree8986e846cc7f1f979e17b02904f0d0fe4712d357
parentastyle pass (diff)
downloadsmolbote-5dfb7c41d0619bbe0830e04a2f7a8685c1e00a29.tar.xz
--profile no longer causes a crash
-rw-r--r--src/browser.cpp82
-rw-r--r--src/browser.h5
-rw-r--r--src/main.cpp1
3 files changed, 39 insertions, 49 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 6899c00..6305c0e 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -39,42 +39,9 @@ void Browser::setConfiguration(std::shared_ptr<Configuration> &config)
// TODO: change path
m_urlRequestInterceptor = std::make_shared<UrlRequestInterceptor>(QString::fromStdString(m_config->value<std::string>("browser.filterPath").value_or("")));
-}
-
-void Browser::loadProfiles()
-{
- Q_ASSERT(m_config);
-
- const QString &path = QString::fromStdString(m_config->value<std::string>("profile.path").value());
-
-#ifdef QT_DEBUG
- qDebug(">> Looking for profiles... [%s]", qUtf8Printable(path));
-#endif
-
- // Build a profile list from the folders in the profile.path
- QDir profileDir(path);
- const QStringList profileList = profileDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
-
- // set profile parents to nullptr, otherwise both Browser and std::shared_ptr try to free them
- for(const QString &name : profileList) {
- std::shared_ptr<WebEngineProfile> profile = std::make_shared<WebEngineProfile>(name, profileDir.absoluteFilePath(name), nullptr);
- profile->setRequestInterceptor(m_urlRequestInterceptor.get());
- connect(profile.get(), &WebEngineProfile::downloadRequested, m_downloadManager.get(), &DownloadsWidget::addDownload);
- m_profiles.insert(name, profile);
- }
-
- // Also add the Off-the-record profile
- std::shared_ptr<WebEngineProfile> otr = std::make_shared<WebEngineProfile>(nullptr);
- otr->setRequestInterceptor(m_urlRequestInterceptor.get());
- connect(otr.get(), &WebEngineProfile::downloadRequested, m_downloadManager.get(), &DownloadsWidget::addDownload);
- m_profiles.insert("", otr);
-
// set default profile
- m_defaultProfile = m_profiles[QString::fromStdString(m_config->value<std::string>("browser.profile").value())];
+ m_defaultProfile = profile(QString::fromStdString(m_config->value<std::string>("browser.profile").value()));
-#ifdef QT_DEBUG
- qDebug("<< Profiles end...");
-#endif
}
MainWindow *Browser::createWindow()
@@ -133,18 +100,43 @@ MainWindow *Browser::createSession(const QString &profileName, bool newWindow, c
return window;
}
-std::shared_ptr<WebEngineProfile> Browser::profile(const QString name)
+std::shared_ptr<WebEngineProfile> Browser::profile(const QString storageName)
{
- return m_profiles[name];
+ if(m_profiles.contains(storageName)) {
+ return m_profiles[storageName];
+ }
+
+ // profile with name storageName has not been loaded
+ Q_ASSERT(m_config);
+
+ if(storageName.isEmpty()) {
+ // construct off-the-record profile
+ std::shared_ptr<WebEngineProfile> otr = std::make_shared<WebEngineProfile>(nullptr);
+ otr->setRequestInterceptor(m_urlRequestInterceptor.get());
+ connect(otr.get(), &WebEngineProfile::downloadRequested, m_downloadManager.get(), &DownloadsWidget::addDownload);
+ m_profiles.insert("", otr);
+
+ return otr;
+ } else {
+ // regular profile
+ const QString &path = QString::fromStdString(m_config->value<std::string>("profile.path").value());
+
+ // Build a profile list from the folders in the profile.path
+ QDir profileDir(path);
+
+ // set profile parents to nullptr, otherwise both Browser and std::shared_ptr try to free them
+ std::shared_ptr<WebEngineProfile> profile = std::make_shared<WebEngineProfile>(storageName, profileDir.absoluteFilePath(storageName), nullptr);
+ profile->setRequestInterceptor(m_urlRequestInterceptor.get());
+ connect(profile.get(), &WebEngineProfile::downloadRequested, m_downloadManager.get(), &DownloadsWidget::addDownload);
+ m_profiles.insert(storageName, profile);
+
+ return profile;
+ }
+
}
-/*
-QStringList Browser::profiles()
+
+QStringList Browser::profiles() const
{
- QStringList l;
- const QStringList keys = m_profiles.keys();
- for(const QString &key : keys) {
- l.append(key);
- }
- return l;
+ return m_profiles.keys();
}
-*/
+
diff --git a/src/browser.h b/src/browser.h
index bc4a7e4..a193e61 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -29,9 +29,8 @@ public:
void setConfiguration(std::shared_ptr<Configuration> &config);
- void loadProfiles();
- std::shared_ptr<WebEngineProfile> profile(const QString name);
- // QStringList profiles();
+ std::shared_ptr<WebEngineProfile> profile(const QString storageName);
+ QStringList profiles() const;
public slots:
MainWindow *createSession(const QString &profileName, bool newWindow, const QStringList &urls);
diff --git a/src/main.cpp b/src/main.cpp
index 34a9fbf..3483da7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -164,7 +164,6 @@ int main(int argc, char *argv[])
}
instance.setConfiguration(config);
- instance.loadProfiles();
instance.createSession(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments());