aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-05-15 19:17:51 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-05-15 19:17:51 +0200
commite43cf73d33d731b5d817d98c3dcb3d66eba1f718 (patch)
tree20a2d826c95761d8317104c92e66be085a977a5e /src
parentProfile editor plugin (diff)
downloadsmolbote-e43cf73d33d731b5d817d98c3dcb3d66eba1f718.tar.xz
Move help and version functions to main (out of Configuration)
Make loading profiles a free function in Browser
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp45
-rw-r--r--src/browser.h2
-rw-r--r--src/main.cpp36
3 files changed, 58 insertions, 25 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 790abcb..09db2d1 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -20,6 +20,35 @@
#include <QDir>
#include <QPluginLoader>
+QVector<Plugin> loadPlugins(const QString &location)
+{
+ QDir pluginsDir(location);
+ QVector<Plugin> list;
+
+ if(pluginsDir.exists()) {
+ const QStringList entries = pluginsDir.entryList(QDir::Files | QDir::Readable);
+
+ for(const QString &name : entries) {
+ QPluginLoader loader(pluginsDir.absoluteFilePath(name));
+
+ if(loader.load()) {
+#ifdef QT_DEBUG
+ qDebug("Loading plugin: %s [ok]", qUtf8Printable(name));
+#endif
+ Plugin p;
+ p.instance = std::shared_ptr<QObject>(loader.instance());
+ list.append(p);
+ } else {
+#ifdef QT_DEBUG
+ qDebug("Loading plugin: %s [failed]", qUtf8Printable(name));
+#endif
+ }
+ }
+ }
+
+ return list;
+}
+
Browser::Browser(int &argc, char *argv[])
: SingleApplication(argc, argv)
{
@@ -51,21 +80,7 @@ void Browser::setup(const QString &defaultProfile)
Q_ASSERT_X(m_config, "Browser::setup", "Configuration not set");
// plugins
- QDir pluginsDir(QString::fromStdString(m_config->value<std::string>("plugins.path").value()));
- if(pluginsDir.exists()) {
- const QStringList entries = pluginsDir.entryList(QDir::Files | QDir::Readable);
- for(const QString &name : entries) {
- QPluginLoader loader(pluginsDir.absoluteFilePath(name));
- qDebug("Loading plugin %s: %s", qUtf8Printable(name), loader.load() ? "ok" : "failed");
- if(!loader.isLoaded()) {
- qDebug("Error: %s", qUtf8Printable(loader.errorString()));
- } else {
- Plugin p;
- p.instance = std::shared_ptr<QObject>(loader.instance());
- m_plugins.append(p);
- }
- }
- }
+ m_plugins.append(loadPlugins(QString::fromStdString(m_config->value<std::string>("plugins.path").value())));
// url request filter
m_urlFilter = std::make_shared<UrlRequestInterceptor>(QString::fromStdString(m_config->value<std::string>("filter.path").value()));
diff --git a/src/browser.h b/src/browser.h
index 3052279..01de9bb 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -15,6 +15,8 @@
#include <memory>
#include <interfaces.h>
+QVector<Plugin> loadPlugins(const QString &location);
+
class Configuration;
class BookmarksWidget;
class DownloadsWidget;
diff --git a/src/main.cpp b/src/main.cpp
index 548aec8..f1ac1ae 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,30 +7,46 @@
*/
#include "browser.h"
-#include "mainwindow/mainwindow.h"
#include "version.h"
-#include "webengine/webprofile.h"
+#include <QFile>
#include <configuration/configuration.h>
#include <memory>
-#include <QFile>
+#include <iostream>
int main(int argc, char **argv)
{
- Browser app(argc, argv);
-
- // set this, otherwise the webview becomes black when using a stylesheet
- app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
-
// create and load configuration
std::shared_ptr<Configuration> config = std::make_shared<Configuration>();
- if(!config->parseCommandLine(argc, argv)) {
+ if(!config->parse(argc, argv)) {
qWarning("Check --help for usage.");
return -1;
}
- if(!config->parseConfigFile(config->value<std::string>("config").value())) {
+ if(!config->parse(config->value<std::string>("config").value())) {
qWarning("Error parsing config file.");
}
+ if(config->exists("help")) {
+ std::cout << "smolbote " << SMOLBOTE_VERSION << ": yet another no-frills browser" << std::endl;
+ std::cout << "Usage: " << argv[0] << " [options] URL(s)" << std::endl;
+
+ std::cout << std::endl << "Command-line Options: " << std::endl << config->commandlineOptions() << std::endl;
+ std::cout << std::endl << "Configuration Options: " << std::endl << config->configurationOptions() << std::endl;
+ return 0;
+ }
+
+ if(config->exists("version")) {
+ std::cout << "smolbote " << SMOLBOTE_VERSION << std::endl;
+ return 0;
+ }
+
+ if(config->exists("build")) {
+ std::cout << SMOLBOTE_BRANCH << ":" << SMOLBOTE_COMMIT;
+ return 0;
+ }
+
+ Browser app(argc, argv);
+ // set this, otherwise the webview becomes black when using a stylesheet
+ app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
app.setConfiguration(config);
// set up socket