aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp66
1 files changed, 45 insertions, 21 deletions
diff --git a/src/main.cpp b/src/main.cpp
index c9b6007..c1060aa 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -12,24 +12,53 @@
#include <configuration/configuration.h>
#include <memory>
#include <iostream>
+#include "plugin.h"
int main(int argc, char **argv)
{
// create and load configuration
std::shared_ptr<Configuration> config = std::make_shared<Configuration>();
if(!config->parse(argc, argv)) {
- qWarning("Check --help for usage.");
+ qWarning("Error parsing command line, check --help for usage.");
return -1;
}
if(!config->parse(config->value<std::string>("config").value())) {
qWarning("Error parsing config file.");
}
+ // --version
+ if(config->exists("version")) {
+ std::cout << "smolbote " << SMOLBOTE_VERSION << std::endl;
+ return 0;
+ }
+
+ // --build
+ if(config->exists("build")) {
+ std::cout << SMOLBOTE_BRANCH << ":" << SMOLBOTE_COMMIT;
+ return 0;
+ }
+
+ QVector<Plugin> plugins = loadPlugins(config->value<QString>("plugins.path").value());
+ QHash<QString, std::function<int()>> pluginCommands;
+ for(const auto &plugin : plugins) {
+ auto *pluginInterface = qobject_cast<PluginInterface*>(plugin.instance);
+ Q_CHECK_PTR(pluginInterface);
+
+ pluginCommands.unite(pluginInterface->commands());
+ }
+
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::endl;
+ std::cout << "Usage: " << argv[0] << " [options] [command/URL(s)]" << std::endl << std::endl;
std::cout << "Command-line Options: " << std::endl << config->commandlineOptions() << std::endl;
+
+ std::cout << "Commands: " << std::endl;
+ for(auto it = pluginCommands.constBegin(); it != pluginCommands.constEnd(); ++it) {
+ std::cout << it.key().toStdString() << std::endl;
+ }
+ std::cout << std::endl;
+
std::cout << "Configuration Options: " << std::endl << config->configurationOptions() << std::endl;
#ifdef Q_OS_LINUX
@@ -38,32 +67,27 @@ int main(int argc, char **argv)
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);
app.setup(QString::fromStdString(config->value<std::string>("profile.default").value()));
-
- if(config->exists("commands")) {
- for(const QString &cmd : app.commands()) {
- std::cout << cmd.toStdString() << std::endl;
- }
- exit(0);
+ for(const Plugin &plugin : plugins) {
+ app.registerPlugin(plugin);
}
- if(config->exists("command")) {
- exit(app.command(QString::fromStdString(config->value<std::string>("command").value())));
+ auto arguments = config->value<std::vector<std::string>>("args");
+ QStringList urls;
+
+ if(arguments) {
+ for(const auto &u : arguments.value()) {
+ if(pluginCommands.contains(QString::fromStdString(u))) {
+ return pluginCommands.value(QString::fromStdString(u))();
+ } else {
+ urls.append(QString::fromStdString(u));
+ }
+ }
}
// set up socket
@@ -86,7 +110,7 @@ int main(int argc, char **argv)
QObject::connect(&app, &Browser::messageAvailable, &app, &Browser::createSession);
}
- app.sendMessage("", false, config->positionalArguments());
+ app.sendMessage("", false, urls);
if(isSingleInstance)
return app.exec();
else