aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-05-26 09:39:56 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-05-26 09:39:56 +0200
commitd8bb83aac827f8ccc959a716834e6e4ffb2927ed (patch)
tree93c37d473ba37b0582a4fd029e6d3ed8f421cb31 /src
parentDock widget shortcut toggle widget visibility (diff)
downloadsmolbote-d8bb83aac827f8ccc959a716834e6e4ffb2927ed.tar.xz
Profile command
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp41
-rw-r--r--src/browser.h4
-rw-r--r--src/main.cpp5
3 files changed, 27 insertions, 23 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;
}
}
diff --git a/src/browser.h b/src/browser.h
index e5df9de..0a0d956 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -35,7 +35,7 @@ public:
void setConfiguration(std::shared_ptr<Configuration> &config);
void setup(const QString &defaultProfile);
- void command(const QString &command);
+ int command(const QString &command);
QStringList commands() const
{
return m_commands.keys();
@@ -53,7 +53,7 @@ private:
QVector<MainWindow *> m_windows;
QVector<Plugin> m_plugins;
- QHash<QString, std::function<void()>> m_commands;
+ QHash<QString, std::function<int()>> m_commands;
};
#endif // SMOLBOTE_BROWSER_H
diff --git a/src/main.cpp b/src/main.cpp
index 89f3005..c9b6007 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -59,12 +59,11 @@ int main(int argc, char **argv)
for(const QString &cmd : app.commands()) {
std::cout << cmd.toStdString() << std::endl;
}
- return 0;
+ exit(0);
}
if(config->exists("command")) {
- app.command(QString::fromStdString(config->value<std::string>("command").value()));
- return 0;
+ exit(app.command(QString::fromStdString(config->value<std::string>("command").value())));
}
// set up socket