aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp89
1 files changed, 57 insertions, 32 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index bb29ff7..99ddcc3 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -22,30 +22,54 @@
#include <QFileInfoList>
#include <QPluginLoader>
-inline QVector<Plugin> loadPlugins(const QString &location)
+inline Plugin loadPluginFromPath(const QString &path)
{
- QDir pluginsDir(location);
- QVector<Plugin> list;
+ Plugin p;
+ QPluginLoader loader(path);
- if(pluginsDir.exists()) {
- const QStringList entries = pluginsDir.entryList(QDir::Files | QDir::Readable);
+ if(loader.load()) {
+#ifdef QT_DEBUG
+ qDebug("Loading plugin: %s [ok]", qUtf8Printable(path));
+#endif
- for(const QString &name : entries) {
- QPluginLoader loader(pluginsDir.absoluteFilePath(name));
+ p.instance = std::shared_ptr<QObject>(loader.instance());
- if(loader.load()) {
#ifdef QT_DEBUG
- qDebug("Loading plugin: %s [ok]", qUtf8Printable(pluginsDir.absoluteFilePath(name)));
+ } else {
+ qDebug("Loading pluing: %s [failed]", qUtf8Printable(path));
#endif
- Plugin p;
- p.instance = std::shared_ptr<QObject>(loader.instance());
+ }
+
+ return p;
+}
+
+inline QVector<Plugin> loadPlugins(const QString &path)
+{
+ QVector<Plugin> list;
+ QFileInfo location(path);
+ if(!location.exists()) {
+ return list;
+ }
+
+ if(location.isFile()) {
+ // only load this one plugin
+ auto p = loadPluginFromPath(location.absoluteFilePath());
+ if(p.instance)
+ list.append(p);
+
+ } else if(location.isDir()) {
+ // load all profiles from this directory
+ const auto entries = QDir(location.absoluteFilePath()).entryInfoList(QDir::Files | QDir::Readable);
+ for(const auto &f : entries) {
+ auto p = loadPluginFromPath(f.absoluteFilePath());
+ if(p.instance)
list.append(p);
- } else {
+ }
+
+ } else {
#ifdef QT_DEBUG
- qDebug("Loading plugin: %s [failed]", qUtf8Printable(name));
+ qDebug("Path is neither file nor folder: %s", qUtf8Printable(path));
#endif
- }
- }
}
return list;
@@ -113,7 +137,24 @@ void Browser::setup(const QString &defaultProfile)
}
}
- // plugins
+ // 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
+
+ // bookmarks
+ m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value()));
+ 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()));
+ 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
@@ -132,22 +173,6 @@ void Browser::setup(const QString &defaultProfile)
}
}
- // 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
-
- // bookmarks
- m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value()));
- 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()));
- connect(WebProfile::defaultProfile(), &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
}
WebProfile *Browser::profile(const QString &name) const