aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 8c2b010..512f207 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -79,6 +79,16 @@ void Browser::setup(const QString &defaultProfile)
{
Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set");
+ // load profiles
+ if(defaultProfile == "") {
+ auto *p = new WebProfile(this);
+ p->loadProfile(m_config->section("profile"));
+ WebProfile::setDefaultProfile(p);
+ } else {
+ auto *p = new WebProfile(defaultProfile, this);
+ WebProfile::setDefaultProfile(p);
+ }
+
// plugins
m_plugins.append(loadPlugins(QString::fromStdString(m_config->value<std::string>("plugins.path").value())));
@@ -88,10 +98,18 @@ void Browser::setup(const QString &defaultProfile)
if(plugin) {
m_commands.unite(plugin->commands());
}
+ if(p.instance->inherits("ProfileInterface")) {
+ auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get());
+ Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed");
+ m_commands.insert("profileEditor:editDefaultProfile", [profileEditor]() -> int {
+ return profileEditor->createWidget(WebProfile::defaultProfile(), nullptr)->exec();
+ });
+ }
}
// url request filter
m_urlFilter = std::make_shared<UrlRequestInterceptor>(QString::fromStdString(m_config->value<std::string>("filter.path").value()));
+ WebProfile::defaultProfile()->setRequestInterceptor(m_urlFilter.get());
// cookie request filter
@@ -100,33 +118,20 @@ void Browser::setup(const QString &defaultProfile)
connect(m_bookmarks.get(), &BookmarksWidget::openUrl, this, [this](const QUrl &url) {
m_windows.last()->createTab(url);
});
+ connect(WebProfile::defaultProfile(), &WebProfile::addBookmarkRequested, m_bookmarks.get(), &BookmarksWidget::addBookmark);
// downloads
m_downloads = std::make_shared<DownloadsWidget>(QString::fromStdString(m_config->value<std::string>("downloads.path").value()));
-
- // load profiles
- if(defaultProfile == "") {
- auto *p = new WebProfile(this);
- p->loadProfile(m_config->section("profile"));
- p->setRequestInterceptor(m_urlFilter.get());
- connect(p, &WebProfile::addBookmarkRequested, m_bookmarks.get(), &BookmarksWidget::addBookmark);
- connect(p, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
- WebProfile::setDefaultProfile(p);
- } else {
- auto *p = new WebProfile(defaultProfile, this);
- p->setRequestInterceptor(m_urlFilter.get());
- connect(p, &WebProfile::addBookmarkRequested, m_bookmarks.get(), &BookmarksWidget::addBookmark);
- connect(p, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
- WebProfile::setDefaultProfile(p);
- }
+ connect(WebProfile::defaultProfile(), &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
}
-void Browser::command(const QString &command)
+int Browser::command(const QString &command)
{
if(m_commands.contains(command)) {
- m_commands.value(command)();
+ return m_commands.value(command)();
} else {
qWarning("No such command: %s", qUtf8Printable(command));
+ return -1;
}
}