From b27e55b0bbba9a1678159abe44280e173374f971 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 16 Jun 2018 13:55:35 +0200 Subject: Sort .profile by time Remove ProfileInterface::setProfiles ProfileView: Add General tab ProfileView: some cleanup ProfileView: Add Cookies tab --- src/browser.cpp | 59 ++++++++++++++++++++++++++++++++++++--------------------- src/browser.h | 3 +++ 2 files changed, 40 insertions(+), 22 deletions(-) (limited to 'src') 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 &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("plugins.path").value()))); + + // register commands + for(const Plugin &p : qAsConst(m_plugins)) { + + if(p.instance->inherits("ProfileInterface")) { + auto *profileEditor = qobject_cast(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(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("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(QString::fromStdString(m_config->value("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("plugins.path").value()))); - // register commands - for(const Plugin &p : qAsConst(m_plugins)) { - - if(p.instance->inherits("ProfileInterface")) { - auto *profileEditor = qobject_cast(p.instance.get()); - Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed"); - - profileEditor->setProfiles(&m_profiles); - } - - auto *plugin = qobject_cast(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(); -- cgit v1.2.1