diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-16 13:55:35 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-06-16 13:55:35 +0200 |
commit | b27e55b0bbba9a1678159abe44280e173374f971 (patch) | |
tree | a7a5bb75ad9b4dc3fc31b39b5ab2fe860b55a27e /src | |
parent | Add extra-cmake-modules to make depends (diff) | |
download | smolbote-b27e55b0bbba9a1678159abe44280e173374f971.tar.xz |
Sort .profile by time
Remove ProfileInterface::setProfiles
ProfileView: Add General tab
ProfileView: some cleanup
ProfileView: Add Cookies tab
Diffstat (limited to 'src')
-rw-r--r-- | src/browser.cpp | 59 | ||||
-rw-r--r-- | src/browser.h | 3 |
2 files changed, 40 insertions, 22 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index 4c6549c..e3857dc 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -43,6 +43,7 @@ inline Plugin loadPluginFromPath(const QString &path) #ifdef QT_DEBUG } else { qDebug("Loading pluing: %s [failed]", qUtf8Printable(path)); + qDebug("%s", qUtf8Printable(loader.errorString())); #endif } @@ -99,7 +100,7 @@ Browser::~Browser() //qDeleteAll(m_plugins); m_plugins.clear(); - qDeleteAll(m_profiles); + } void Browser::setConfiguration(std::shared_ptr<Configuration> &config) @@ -112,24 +113,55 @@ void Browser::setup(const QString &defaultProfile) { Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set"); + // load plugins first + m_plugins.append(loadPlugins(QString::fromStdString(m_config->value<std::string>("plugins.path").value()))); + + // register commands + for(const Plugin &p : qAsConst(m_plugins)) { + + if(p.instance->inherits("ProfileInterface")) { + auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get()); + Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed"); + + connect(this, &Browser::registerProfile, [=](WebProfile *profile) { + profileEditor->registerProfile(profile); + }); + } + + auto *plugin = qobject_cast<PluginInterface *>(p.instance.get()); + if(plugin) { + m_commands.unite(plugin->commands()); + } + } + // load profiles { 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); + const auto entries = profilesDir.entryInfoList({"*.profile"}, QDir::Files | QDir::Readable, QDir::Time); for(const QFileInfo &f : entries) { - auto *profile = loadProfile(f.baseName(), defaults, f.absoluteFilePath()); - m_profiles.insert(f.baseName(), profile); + auto name = f.baseName(); + auto *profile = loadProfile(name, defaults, f.absoluteFilePath(), this); + m_profiles.insert(name, profile); + connect(profile, &WebProfile::destroyed, this, [=]() { + m_profiles.remove(name); + }); + emit registerProfile(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)); + auto *profile = loadProfile(defaultProfile, defaults, QString(), this); + m_profiles.insert(defaultProfile, profile); + connect(profile, &WebProfile::destroyed, this, [=]() { + m_profiles.remove(defaultProfile); + }); + emit registerProfile(profile); } WebProfile::setDefaultProfile(m_profiles.value(defaultProfile)); } @@ -150,24 +182,7 @@ void Browser::setup(const QString &defaultProfile) m_downloads = std::make_shared<DownloadsWidget>(QString::fromStdString(m_config->value<std::string>("downloads.path").value())); connect(WebProfile::defaultProfile(), &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); - // load plugins last - m_plugins.append(loadPlugins(QString::fromStdString(m_config->value<std::string>("plugins.path").value()))); - // register commands - for(const Plugin &p : qAsConst(m_plugins)) { - - if(p.instance->inherits("ProfileInterface")) { - auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get()); - Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed"); - - profileEditor->setProfiles(&m_profiles); - } - - auto *plugin = qobject_cast<PluginInterface *>(p.instance.get()); - if(plugin) { - m_commands.unite(plugin->commands()); - } - } } diff --git a/src/browser.h b/src/browser.h index 8148e99..9e606dd 100644 --- a/src/browser.h +++ b/src/browser.h @@ -58,6 +58,9 @@ public: return m_plugins; } +signals: + void registerProfile(WebProfile *profile); + public slots: void createSession(const QString &profileName, bool newWindow, const QStringList &urls); MainWindow *createWindow(); |