diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-08 15:00:22 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-08 15:00:22 +0200 |
commit | 99917ab581314f9517569401bc79e150e4ce0881 (patch) | |
tree | bed6fa884a0925e104f9e15c399c1b5e91683a2b /src | |
parent | Improve plugin loading (diff) | |
download | smolbote-99917ab581314f9517569401bc79e150e4ce0881.tar.xz |
Better profile loading
First load all profiles from profile.path, and then the profile.default if
missing, after which set the default profile.
Profile names and whether they're otr can be set by .profile name=string
and otr=bool.
Diffstat (limited to 'src')
-rw-r--r-- | src/browser.cpp | 43 | ||||
-rw-r--r-- | src/mainwindow/widgets/tabwidget.cpp | 3 |
2 files changed, 19 insertions, 27 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index 99ddcc3..8abe10a 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -75,23 +75,6 @@ inline QVector<Plugin> loadPlugins(const QString &path) return list; } -inline QHash<QString, WebProfile *> loadProfiles(const QHash<QString, QString> &defaults, const QString &location) -{ - QDir profilesDir(location); - QHash<QString, WebProfile *> list; - - if(profilesDir.exists()) { - const QFileInfoList entries = profilesDir.entryInfoList({ "*.profile" }, QDir::Files | QDir::Readable); - for(const auto &entry : entries) { - auto *profile = new WebProfile(entry.baseName()); - loadProfile(profile, defaults, entry.absoluteFilePath()); - list.insert(entry.baseName(), profile); - } - } - - return list; -} - Browser::Browser(int &argc, char *argv[]) : SingleApplication(argc, argv) { @@ -125,16 +108,24 @@ void Browser::setup(const QString &defaultProfile) // load profiles { - auto *otr = new WebProfile(this); - loadProfile(otr, m_config->section("profile"), QString::fromStdString(m_config->value<std::string>("profile.path").value()) + "/otr.ini"); - m_profiles.insert(tr("Off-the-record"), otr); - m_profiles.unite(loadProfiles(m_config->section("profile"), QString::fromStdString(m_config->value<std::string>("profile.path").value()))); - - if(defaultProfile == "") { - WebProfile::setDefaultProfile(otr); - } else { - WebProfile::setDefaultProfile(m_profiles.value(defaultProfile)); + const auto defaults = m_config->section("profile"); + const QDir profilesDir(m_config->value<QString>("profile.path").value()); + + if(profilesDir.exists()) { + const auto entries = profilesDir.entryInfoList({"*.profile"}, QDir::Files | QDir::Readable); + + for(const QFileInfo &f : entries) { + auto *profile = loadProfile(f.baseName(), defaults, f.absoluteFilePath()); + m_profiles.insert(f.baseName(), profile); + } + } + + // set default profile + if(!m_profiles.contains(defaultProfile)) { + // if this profile has not been added, it doesn't have a path + m_profiles.insert(defaultProfile, loadProfile(defaultProfile, defaults)); } + WebProfile::setDefaultProfile(m_profiles.value(defaultProfile)); } // url request filter diff --git a/src/mainwindow/widgets/tabwidget.cpp b/src/mainwindow/widgets/tabwidget.cpp index 2858fb0..a3fcbdd 100644 --- a/src/mainwindow/widgets/tabwidget.cpp +++ b/src/mainwindow/widgets/tabwidget.cpp @@ -13,6 +13,7 @@ #include <QMenu> #include <QTabBar> #include "browser.h" +#include <webprofile.h> TabWidget::TabWidget(QWidget *parent) : QTabWidget(parent) @@ -62,10 +63,10 @@ TabWidget::TabWidget(QWidget *parent) Q_CHECK_PTR(browser); for(const QString &name : browser->profiles()) { - auto *profileAction = loadProfile_menu->addAction(name); auto *profile = browser->profile(name); Q_CHECK_PTR(profile); + auto *profileAction = loadProfile_menu->addAction(profile->name()); connect(profileAction, &QAction::triggered, this, [this, profile]() { int index = this->tabBar()->tabAt(mapFromGlobal(tabContextMenu->pos())); auto *view = qobject_cast<WebView *>(this->widget(index)); |