aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp59
-rw-r--r--src/browser.h3
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();