aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/browser.cpp3
-rw-r--r--src/commandline.cpp135
-rw-r--r--src/commandline.h38
-rw-r--r--src/main.cpp26
5 files changed, 12 insertions, 192 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1321604..dd325ec 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,8 +13,6 @@ add_executable(poi
singleapplication.h
browser.cpp
browser.h
- commandline.cpp
- commandline.h
../data/resources.qrc
# main window
diff --git a/src/browser.cpp b/src/browser.cpp
index 9b691e4..3f4805a 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -28,7 +28,8 @@ Browser::Browser(int &argc, char *argv[])
Browser::~Browser()
{
- m_bookmarks->save();
+ if(m_bookmarks)
+ m_bookmarks->save();
qDeleteAll(m_windows);
m_windows.clear();
}
diff --git a/src/commandline.cpp b/src/commandline.cpp
deleted file mode 100644
index 6082686..0000000
--- a/src/commandline.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "commandline.h"
-#include "version.h"
-#include <configuration.h>
-#include <iomanip>
-#include <iostream>
-
-inline std::string optionText(const QStringList &opts)
-{
- std::string r;
- for(auto i = opts.constBegin(); i != opts.constEnd(); ) {
- if(i->length() == 1) {
- r.append("-" + i->toStdString());
- } else {
- r.append("--" + i->toStdString());
- }
-
- ++i;
- if(i != opts.constEnd()) {
- r.append(", ");
- }
- }
- return r;
-}
-
-inline void printOption(const QCommandLineOption &option)
-{
- std::cout << " "
- << std::setw(18) << std::left << optionText(option.names())
- << std::setw(32) << std::left << option.description().toStdString()
- << std::setw(18) << std::left << option.defaultValues().join(", ").toStdString()
- << std::endl;
-}
-
-constexpr const char *socketPath()
-{
-#if defined(Q_OS_UNIX)
- // could be a path such as "/tmp/foo"
- return "/tmp/smolbote.socket";
-#elif defined(Q_OS_WIN32)
- // could be a pipe path such as "\\.\pipe\foo"
- return "\\\\.\\pipe\\smolbote_socket";
-#endif
-}
-
-CommandLine::CommandLine()
- : QCommandLineParser()
- , helpOption(addHelpOption())
- , versionOption(addVersionOption())
- , buildOption("build", "Displays build information.")
- , configOption({ "c", "config" }, "Sets configuration file.", "path", Configuration::defaultUserConfigLocation())
- , profileOption({ "p", "profile" }, "Sets default profile.", "profile", "")
- , socketOption("socket", "Sets local socket.", "name", socketPath())
- , newWindowOption("in-new-window", "Open URL in new window")
-{
- setApplicationDescription("yet another no-frills browser");
-
- addOption(buildOption);
- addOption(configOption);
- addOption(profileOption);
- addOption(socketOption);
- addOption(newWindowOption);
-
- addPositionalArgument("URL", "URL(s) to open");
-}
-
-void CommandLine::parseCommandLine(const QCoreApplication &app)
-{
- QCommandLineParser::parse(app.arguments());
-
- application = const_cast<QCoreApplication *>(&app);
-
- if(isSet(helpOption)) {
- printHelp();
- }
-
- if(isSet(versionOption)) {
- printVersion();
- }
-
- if(isSet(buildOption)) {
- printBuild();
- }
-}
-
-void CommandLine::printHelp(int exitCode)
-{
- std::cout << "Usage: " << application->arguments().at(0).toStdString() << " [options] URL" << std::endl;
- std::cout << application->applicationName().toStdString() << " " << SMOLBOTE_DESCRIBE << ": "
- << applicationDescription().toStdString() << std::endl
- << std::endl;
-
- std::cout << "Options: " << std::endl;
- printOption(helpOption);
- printOption(versionOption);
- printOption(buildOption);
- printOption(configOption);
- printOption(profileOption);
- printOption(socketOption);
- printOption(newWindowOption);
- std::cout << std::endl;
-
- std::cout << "You can also overwrite configuration options using the syntax: " << std::endl
- << "--browser.setting.path=value" << std::endl
- << "More information on available keys can be found on the manual page." << std::endl
- << std::endl;
-
- std::cout << "Arguments: " << std::endl;
- std::cout << "- "
- << std::setw(20) << std::left << "URL"
- << std::setw(40) << std::left << "URL(s) to open"
- << std::endl
- << std::endl;
-
- exit(exitCode);
-}
-
-void CommandLine::printVersion(int exitCode)
-{
- std::cout << application->applicationName().toStdString() << " " << SMOLBOTE_DESCRIBE << std::endl;
- exit(exitCode);
-}
-
-void CommandLine::printBuild(int exitCode)
-{
- std::cout << SMOLBOTE_BRANCH << ":" << SMOLBOTE_COMMIT << std::endl;
- exit(exitCode);
-}
diff --git a/src/commandline.h b/src/commandline.h
deleted file mode 100644
index cb2f334..0000000
--- a/src/commandline.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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/smolbote.hg
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#ifndef SMOLBOTE_COMMANDLINE_H
-#define SMOLBOTE_COMMANDLINE_H
-
-#include <QCommandLineParser>
-
-class CommandLine : public QCommandLineParser
-{
-public:
- CommandLine();
-
- void parseCommandLine(const QCoreApplication &app);
-
- void printHelp(int exitCode = 0);
- void printVersion(int exitCode = 0);
- void printBuild(int exitCode = 0);
-
- const QCommandLineOption helpOption;
- const QCommandLineOption versionOption;
- const QCommandLineOption buildOption;
-
- const QCommandLineOption configOption;
- const QCommandLineOption profileOption;
- const QCommandLineOption socketOption;
- const QCommandLineOption newWindowOption;
-
-private:
- QCoreApplication *application;
-};
-
-#endif // SMOLBOTE_COMMANDLINE_H
diff --git a/src/main.cpp b/src/main.cpp
index 52df7ac..bfe4ecd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,7 +7,6 @@
*/
#include "browser.h"
-#include "commandline.h"
#include "mainwindow/mainwindow.h"
#include "version.h"
#include "webengine/webprofile.h"
@@ -18,36 +17,31 @@ int main(int argc, char **argv)
{
Browser app(argc, argv);
- CommandLine parser;
- parser.parseCommandLine(app);
-
// create and load configuration
std::shared_ptr<Configuration> config = std::make_shared<Configuration>();
- config->read(parser.value(parser.configOption));
-
- if(!parser.unknownOptionNames().isEmpty()) {
- qDebug("config->parse: %s", config->parse(argc, argv) ? "true" : "false");
+ if(!config->parseCommandLine(argc, argv)) {
+ qWarning("Check --help for usage.");
+ return -1;
+ }
+ if(!config->parseConfigFile(config->value<std::string>("config").value())) {
+ qWarning("Error parsing config file.");
}
app.setConfiguration(config);
// set up socket
- bool isSingleInstance = app.bindLocalSocket(parser.value(parser.socketOption));
+ bool isSingleInstance = app.bindLocalSocket(QString::fromStdString(config->value<std::string>("socket").value()));
#ifdef QT_DEBUG
- qDebug("bindLocalSocket(%s) = %s", qUtf8Printable(parser.value(parser.socketOption)), isSingleInstance ? "true" : "false");
+ qDebug("bindLocalSocket(%s) = %s", qUtf8Printable(QString::fromStdString(config->value<std::string>("socket").value())), isSingleInstance ? "true" : "false");
#endif
// if we are the only instance, set up the browser
if(isSingleInstance) {
- if(parser.isSet(parser.profileOption))
- app.setup(parser.value(parser.profileOption));
- else
- app.setup(QString::fromStdString(config->value<std::string>("profile.default").value()));
-
+ app.setup(QString::fromStdString(config->value<std::string>("profile.default").value()));
QObject::connect(&app, &Browser::messageAvailable, &app, &Browser::createSession);
}
- app.sendMessage(parser.value(parser.profileOption), parser.isSet(parser.newWindowOption), parser.positionalArguments());
+ app.sendMessage("", false, config->positionalArguments());
if(isSingleInstance)
return app.exec();