aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/web/profilemanager.cpp15
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/browser.cpp19
-rw-r--r--src/main.cpp6
-rw-r--r--src/plugin.h51
-rw-r--r--src/util.cpp45
-rw-r--r--src/util.h20
7 files changed, 85 insertions, 73 deletions
diff --git a/lib/web/profilemanager.cpp b/lib/web/profilemanager.cpp
index 75fd413..d6c61a9 100644
--- a/lib/web/profilemanager.cpp
+++ b/lib/web/profilemanager.cpp
@@ -15,21 +15,6 @@ ProfileManager::ProfileManager(const QHash<QString, QString> &profileSection, co
: QObject(parent)
, defaults(profileSection)
{
- // load profiles from path
- const QDir profilesDir(defaults.value("profile.path"));
-
- if(profilesDir.exists()) {
- const auto entries = profilesDir.entryInfoList({ "*.profile" }, QDir::Files | QDir::Readable, QDir::Time);
-
- for(const QFileInfo &f : entries) {
- loadProfile(f.absoluteFilePath());
- }
- }
-
- const QString defaultProfile = defaults.value("profile.default", defaultId);
- if(m_profiles.count(defaultProfile) == 0) {
- loadProfile(defaultProfile);
- }
}
WebProfile *ProfileManager::loadProfile(const QString &path)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6162cd4..8d43df5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,6 +13,8 @@ set(srclist
browser.h
session.cpp
session.h
+ util.cpp
+ util.h
# resources (icons, etc)
${PROJECT_SOURCE_DIR}/data/resources.qrc
diff --git a/src/browser.cpp b/src/browser.cpp
index e93123c..1542370 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -10,6 +10,7 @@
#include "addressbar/addressbar.h"
#include "mainwindow/mainwindow.h"
#include "subwindow/subwindow.h"
+#include "util.h"
#include "webengine/urlinterceptor.h"
#include <QAction>
#include <QDir>
@@ -111,14 +112,20 @@ void Browser::setup(const QString &defaultProfile)
// load profiles
m_profileManager = new ProfileManager(m_config->section("profile"), defaultProfile, this);
- // connect profiles
- for(const QString &id : m_profileManager->idList()) {
- auto *profile = m_profileManager->profile(id);
- connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload);
- profile->setRequestInterceptor(m_urlFilter.get());
+ for(const QString &profilePath : Util::files(m_config->value<QString>("profile.path").value(), { "*.profile" })) {
+ this->loadProfile(profilePath);
}
+
// set default profile
- WebProfile::setDefaultProfile(m_profileManager->profile(defaultProfile));
+ {
+ const QString id = m_config->value<QString>("profile.default").value();
+ auto *profile = m_profileManager->profile(id);
+ if(profile == nullptr) {
+ profile = this->loadProfile(id).second;
+ }
+
+ WebProfile::setDefaultProfile(profile);
+ }
// bookmarks
m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value()));
diff --git a/src/main.cpp b/src/main.cpp
index 98f2965..69389d0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -9,6 +9,7 @@
#include "browser.h"
#include "plugin.h"
#include "session.h"
+#include "util.h"
#include "version.h"
#include <QFile>
#include <QLibraryInfo>
@@ -86,7 +87,10 @@ int main(int argc, char **argv)
return 0;
}
- QVector<Plugin> plugins = loadPlugins(config->value<QString>("plugins.path").value());
+ QVector<Plugin> plugins;
+ for(const QString &path : Util::files(config->value<QString>("plugins.path").value())) {
+ plugins.append(loadPluginFromPath(path));
+ }
QMap<QString, std::function<int()>> pluginCommands;
for(const auto &plugin : plugins) {
auto *pluginInterface = qobject_cast<PluginInterface *>(plugin.instance);
diff --git a/src/plugin.h b/src/plugin.h
index 4de3407..e43215b 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -39,55 +39,4 @@ inline Plugin loadPluginFromPath(const QString &path)
return p;
}
-inline QVector<Plugin> loadPlugins(const QString &path)
-{
- QVector<Plugin> list;
-
- // quit if there's nothing to load
- if(path.isEmpty())
- return list;
-
- // plugins can be a semicolon-separated list
- if(path.contains(';')) {
- auto pluginList = path.split(';');
- for(const auto &pluginPath : pluginList) {
- auto plugin = loadPluginFromPath(pluginPath);
- if(plugin.instance)
- list.append(plugin);
- }
-
- return list;
- }
-
- // check if path is path to a file or a folder
- QFileInfo location(path);
-
- if(!location.exists()) {
- qDebug("Plugin path doesn't exist.");
- 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);
- }
-#ifdef QT_DEBUG
- } else {
- qDebug("Path is neither file nor folder: %s", qUtf8Printable(path));
-#endif
- }
-
- return list;
-}
-
#endif // SMOLBOTE_PLUGIN_H
diff --git a/src/util.cpp b/src/util.cpp
new file mode 100644
index 0000000..5b1478b
--- /dev/null
+++ b/src/util.cpp
@@ -0,0 +1,45 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "util.h"
+#include <QDir>
+#include <QFileInfo>
+
+#define ListSeparator QLatin1Literal(";")
+
+QStringList Util::files(const QString &location, const QStringList &nameFilters)
+{
+ if(location.isEmpty())
+ return QStringList();
+
+ QStringList filelist;
+
+ // check if location is a list of locations (contains a ';')
+ if(location.contains(ListSeparator)) {
+ const QStringList locations = location.split(ListSeparator);
+
+ for(const QString &l : locations) {
+ filelist.append(Util::files(l, nameFilters));
+ }
+
+ return filelist;
+ }
+
+ const QFileInfo info(location);
+
+ // check if location is a folder
+ if(info.isDir()) {
+ for(const QFileInfo &entryInfo : QDir(info.absoluteFilePath()).entryInfoList(nameFilters, QDir::Files | QDir::Readable, QDir::Time)) {
+ filelist.append(entryInfo.absoluteFilePath());
+ }
+ } else if(info.isFile()) {
+ filelist.append(info.absoluteFilePath());
+ }
+
+ return filelist;
+} \ No newline at end of file
diff --git a/src/util.h b/src/util.h
new file mode 100644
index 0000000..4ea6639
--- /dev/null
+++ b/src/util.h
@@ -0,0 +1,20 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_UTIL_H
+#define SMOLBOTE_UTIL_H
+
+#include <QStringList>
+
+namespace Util {
+
+QStringList files(const QString &location, const QStringList &nameFilters = QStringList());
+
+}
+
+#endif // SMOLBOTE_UTIL_H