aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt6
-rw-r--r--src/configuration.cpp25
-rw-r--r--src/configuration.h3
-rw-r--r--src/forms/aboutdialog.cpp9
-rw-r--r--src/forms/aboutdialog.h2
-rw-r--r--src/main.cpp38
6 files changed, 60 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6167424..e5e5f22 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -107,9 +107,9 @@ set(SourceCode
"src/forms/aboutdialog.h"
"src/forms/aboutdialog.ui"
# todo: move to src/webengine
- "src/forms/cookiesform.cpp"
- "src/forms/cookiesform.h"
- "src/forms/cookiesform.ui"
+ #"src/forms/cookiesform.cpp"
+ #"src/forms/cookiesform.h"
+ #"src/forms/cookiesform.ui"
# plugin interfaces
plugins/interfaces.h)
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 4e72d18..c114155 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -12,7 +12,7 @@
namespace po = boost::program_options;
-Configuration::Configuration(const QStringList &options)
+Configuration::Configuration()
{
m_homePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString();
@@ -81,20 +81,13 @@ Configuration::Configuration(const QStringList &options)
// store the defaults into the vm
{
- int argc = options.length();
- const char* argv[argc];
- for(int i = 0; i < argc; ++i) {
- argv[i] = qUtf8Printable(options.at(i));
- }
-
- po::store(po::parse_command_line(argc, argv, desc), vm);
+ const char* argv[0];
+ po::store(po::parse_command_line(0, argv, desc), vm);
}
}
-Configuration::~Configuration()
-{
-}
+Configuration::~Configuration() = default;
bool Configuration::read(const QString &path)
{
@@ -103,3 +96,13 @@ bool Configuration::read(const QString &path)
return true;
}
+bool Configuration::parse(int argc, const char **argv)
+{
+ try {
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ } catch (const po::error &e) {
+ return false;
+ }
+
+ return true;
+}
diff --git a/src/configuration.h b/src/configuration.h
index 27988b9..c9223eb 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -19,10 +19,11 @@
class Configuration
{
public:
- explicit Configuration(const QStringList &options = QStringList());
+ explicit Configuration();
~Configuration();
bool read(const QString &path);
+ bool parse(int argc, const char **argv);
template <typename T>
std::optional<T> value(const char *path) const
diff --git a/src/forms/aboutdialog.cpp b/src/forms/aboutdialog.cpp
index 89cb23e..5b788bd 100644
--- a/src/forms/aboutdialog.cpp
+++ b/src/forms/aboutdialog.cpp
@@ -11,10 +11,6 @@
#include "version.h"
#include <boost/version.hpp>
-// The extra level of indirection will allow the preprocessor to expand the macros before they are converted to strings.
-#define STRINGIFY(x) #x
-#define STR(x) STRINGIFY(x)
-
// compiler
// clang also defines __GNUC__, so we need to check for clang first
#if defined(__clang__)
@@ -32,7 +28,10 @@ AboutDialog::AboutDialog(QWidget *parent)
setAttribute(Qt::WA_DeleteOnClose, true);
ui->setupUi(this);
- ui->icon->setPixmap(qApp->windowIcon().pixmap(72, 72));
+ // clang-tidy: don't use static_cast to downcast from a base to a derived class,
+ // use dynamic_cast instead
+ //ui->icon->setPixmap(qApp->windowIcon().pixmap(72, 72));
+ ui->icon->setPixmap(dynamic_cast<QApplication *>(QApplication::instance())->windowIcon().pixmap(72, 72));
auto *aboutLabel = new QLabel(this);
aboutLabel->setWordWrap(true);
diff --git a/src/forms/aboutdialog.h b/src/forms/aboutdialog.h
index 1a1b4eb..3175939 100644
--- a/src/forms/aboutdialog.h
+++ b/src/forms/aboutdialog.h
@@ -22,7 +22,7 @@ class AboutDialog : public QDialog
public:
explicit AboutDialog(QWidget *parent = nullptr);
- ~AboutDialog();
+ ~AboutDialog() override;
private:
Ui::AboutDialog *ui;
diff --git a/src/main.cpp b/src/main.cpp
index 70f22be..973ac58 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -10,7 +10,6 @@
#include "src/mainwindow/mainwindow.h"
#include "version.h"
#include <QCommandLineParser>
-#include <QDir>
#include <QStandardPaths>
#include <iostream>
@@ -66,7 +65,9 @@ int main(int argc, char **argv)
parser.addPositionalArgument("URL", "URL(s) to open");
- parser.process(instance);
+ // use parse instead of process
+ // process calls exit() on unknown options
+ parser.parse(instance.arguments());
#ifdef QT_DEBUG
qDebug("config=%s", qUtf8Printable(parser.value(configOption)));
@@ -83,6 +84,7 @@ int main(int argc, char **argv)
qUtf8Printable(parser.value(defaultConfigOption)),
config->read(parser.value(defaultConfigOption)) ? "ok" : "failed");
}
+
// then load in the user configuration, which will overwrite it
if(parser.isSet(configOption)) {
qDebug("Reading configuration [%s]: %s",
@@ -90,6 +92,38 @@ int main(int argc, char **argv)
config->read(parser.value(configOption)) ? "ok" : "failed");
}
+ // parse command-line overrides
+ // we assume the users knows what they're doing, so we only pass the unknown options to program_options
+ // passing any unknown options though will cause it to fail, so we need to filter out the regular options
+ // unfortunately, QCommandLineParser will only give us the unknown option
+ // names, so we need to build a list, add them as options, reparse, and then
+ // we get their values
+ if(!parser.unknownOptionNames().isEmpty()) {
+ int _argc = parser.unknownOptionNames().length() + 1;
+ const char* _argv[_argc];
+
+ // program_options requires 0 to be the program name, otherwise it seems to fail
+ _argv[0] = qUtf8Printable(instance.arguments().at(0));
+
+ // create a list of unknown QCommandLineOption's
+ // parser.addOptions() takes a list, so this is a QList
+ QList<QCommandLineOption> opts;
+ for (const QString &opt : parser.unknownOptionNames()) {
+ QCommandLineOption o(opt, "dummy desc", "dummy value");
+ opts.append(o);
+ }
+
+ // add list and reparse to set the new options
+ parser.addOptions(opts);
+ parser.parse(instance.arguments());
+
+ for(int i = 1; i < _argc; ++i) {
+ _argv[i] = qUtf8Printable(QString("--%1=%2").arg(opts[i-1].names().at(0), parser.value(opts[i-1])));
+ }
+
+ qDebug("Parsing command-line overrides: %s", config->parse(_argc, _argv) ? "ok" : "failed");
+ }
+
// check for other instances
// if we socket hasn't been disabled (socket is not none)
if(parser.value(socketOption) != "none") {