aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp59
1 files changed, 37 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());
- }
- }
}