From e43cf73d33d731b5d817d98c3dcb3d66eba1f718 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 15 May 2018 19:17:51 +0200 Subject: Move help and version functions to main (out of Configuration) Make loading profiles a free function in Browser --- src/browser.cpp | 45 ++++++++++++++++++++++++++++++--------------- src/browser.h | 2 ++ src/main.cpp | 36 ++++++++++++++++++++++++++---------- 3 files changed, 58 insertions(+), 25 deletions(-) (limited to 'src') 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 #include +QVector loadPlugins(const QString &location) +{ + QDir pluginsDir(location); + QVector 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(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("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(loader.instance()); - m_plugins.append(p); - } - } - } + m_plugins.append(loadPlugins(QString::fromStdString(m_config->value("plugins.path").value()))); // url request filter m_urlFilter = std::make_shared(QString::fromStdString(m_config->value("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 #include +QVector 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 #include #include -#include +#include 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 config = std::make_shared(); - if(!config->parseCommandLine(argc, argv)) { + if(!config->parse(argc, argv)) { qWarning("Check --help for usage."); return -1; } - if(!config->parseConfigFile(config->value("config").value())) { + if(!config->parse(config->value("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 -- cgit v1.2.1