From a225fa42924ae71031a20bd4d0a47129f5471de1 Mon Sep 17 00:00:00 2001 From: Han Young Date: Wed, 19 May 2021 17:21:51 +0800 Subject: [PATCH] add version and help commandline options --- src/about.cpp | 5 +---- src/kiwixapp.h | 4 +++- src/main.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/about.cpp b/src/about.cpp index ffc38371..e2e60014 100644 --- a/src/about.cpp +++ b/src/about.cpp @@ -2,9 +2,6 @@ #include "ui_about.h" #include "kiwixapp.h" -#define _STR(...) # __VA_ARGS__ -#define STR(X) _STR(X) - About::About(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDialog) @@ -23,7 +20,7 @@ About::About(QWidget *parent) : htmlText = htmlText.replace("{{LIBRARIES}}", gt("about-libraries-title")); htmlText = htmlText.replace("{{GITHUB_URL}}", "https://github.com/kiwix/kiwix-desktop"); - htmlText = htmlText.replace("{{VERSION}}", STR(VERSION)); + htmlText = htmlText.replace("{{VERSION}}", version); htmlText = htmlText.replace("{{TRACKER_URL}}", "https://github.com/kiwix/kiwix-desktop/issues"); ui->aboutText->setHtml(htmlText); } diff --git a/src/kiwixapp.h b/src/kiwixapp.h index 2c63505d..3834627e 100644 --- a/src/kiwixapp.h +++ b/src/kiwixapp.h @@ -122,5 +122,7 @@ public slots: }; QString gt(const QString &key); - +#define _STR(...) # __VA_ARGS__ +#define STR(X) _STR(X) +static QString version = STR(VERSION); #endif // KIWIXAPP_H diff --git a/src/main.cpp b/src/main.cpp index 304a2bcf..163ff259 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,6 @@ #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) #include #endif - int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -16,9 +15,12 @@ int main(int argc, char *argv[]) QWebEngineUrlScheme::registerScheme(scheme); #endif KiwixApp a(argc, argv); + a.setApplicationVersion(version); QCommandLineParser parser; QString zimfile; - + parser.setApplicationDescription(QStringLiteral("The Kiwix Desktop is a viewer/manager of ZIM files for GNU/Linux and Microsoft Windows OSes.")); + parser.addHelpOption(); + parser.addVersionOption(); parser.addPositionalArgument("zimfile", "The zim file"); parser.process(a); auto positionalArguments = parser.positionalArguments();