2424#include " certandpininfo.hpp"
2525#include " logging.hpp"
2626#include " retriableerror.hpp"
27+ #include " utils/qt_comp.hpp"
2728
2829#include < QCommandLineParser>
2930#include < QDir>
3637#include < QStyleHints>
3738#include < QTranslator>
3839
40+ #include < algorithm>
41+ #include < array>
42+
43+ using namespace Qt ::Literals::StringLiterals;
44+
3945inline CommandWithArguments::second_type parseArgumentJson (const QString& argumentStr)
4046{
4147 const auto argumentJson = QJsonDocument::fromJson (argumentStr.toUtf8 ());
@@ -51,26 +57,26 @@ Application::Application(int& argc, char** argv, const QString& name) :
5157 QApplication(argc, argv), translator(new QTranslator(this ))
5258{
5359 setApplicationName (name);
54- setApplicationDisplayName (QStringLiteral ( " Web eID" ) );
60+ setApplicationDisplayName (u " Web eID" _s );
5561 setApplicationVersion (QStringLiteral (PROJECT_VERSION));
56- setOrganizationDomain (QStringLiteral ( " web-eid.eu" ) );
57- setOrganizationName (QStringLiteral ( " RIA" ) );
62+ setOrganizationDomain (u " web-eid.eu" _s );
63+ setOrganizationName (u " RIA" _s );
5864 setQuitOnLastWindowClosed (false );
5965
6066 installTranslator (translator);
6167 loadTranslations ();
6268
6369 auto list = QUrl::idnWhitelist ();
6470 list.append ({
65- QStringLiteral ( " fi" ) ,
66- QStringLiteral ( " ee" ) ,
67- QStringLiteral ( " lt" ) ,
68- QStringLiteral ( " lv" ) ,
71+ u " fi" _s ,
72+ u " ee" _s ,
73+ u " lt" _s ,
74+ u " lv" _s ,
6975 });
7076 QUrl::setIdnWhitelist (list);
7177
72- for (const QString& font : QDir (QStringLiteral ( " :/fonts" ) ).entryList ()) {
73- QFontDatabase::addApplicationFont (QStringLiteral ( " :/fonts/%1" ) .arg (font));
78+ for (const QString& font : QDir (u " :/fonts" _s ).entryList ()) {
79+ QFontDatabase::addApplicationFont (u " :/fonts/%1" _s .arg (font));
7480 }
7581
7682 registerMetatypes ();
@@ -93,8 +99,7 @@ bool Application::isDarkTheme()
9399 // supported OS-s.
94100 static const bool isDarkTheme = [] {
95101 QProcess p;
96- p.start (QStringLiteral (" gsettings" ),
97- {" get" , " org.gnome.desktop.interface" , " color-scheme" });
102+ p.start (u" gsettings" _s, {u" get" _s, u" org.gnome.desktop.interface" _s, u" color-scheme" _s});
98103 if (p.waitForFinished ()) {
99104 return p.readAllStandardOutput ().contains (" dark" );
100105 }
@@ -108,56 +113,52 @@ bool Application::isDarkTheme()
108113
109114void Application::loadTranslations (const QString& lang)
110115{
111- static const QStringList SUPPORTED_LANGS {
112- QStringLiteral (" en" ), QStringLiteral (" et" ), QStringLiteral (" fi" ), QStringLiteral (" hr" ),
113- QStringLiteral (" ru" ), QStringLiteral (" de" ), QStringLiteral (" fr" ), QStringLiteral (" nl" ),
114- QStringLiteral (" cs" ), QStringLiteral (" sk" )};
116+ static constexpr std::array SUPPORTED_LANGS {u" en" _sv, u" et" _sv, u" fi" _sv, u" hr" _sv, u" ru" _sv,
117+ u" de" _sv, u" fr" _sv, u" nl" _sv, u" cs" _sv, u" sk" _sv};
115118 QLocale locale;
116- QString langSetting = QSettings ().value (QStringLiteral ( " lang" ) , lang).toString ();
117- if (SUPPORTED_LANGS. contains (langSetting )) {
119+ QString langSetting = QSettings ().value (u " lang" _s , lang).toString ();
120+ if (std::ranges::find ( SUPPORTED_LANGS, langSetting) != SUPPORTED_LANGS. cend ( )) {
118121 locale = QLocale (langSetting);
119122 }
120- void (translator->load (locale, QStringLiteral ( " :/translations/" ) ));
123+ void (translator->load (locale, u " :/translations/" _s ));
121124}
122125
123126CommandWithArgumentsPtr Application::parseArgs ()
124127{
125128 // On Windows Chrome, the native messaging host is also passed a command line argument with a
126129 // handle to the calling Chrome native window: --parent-window=<decimal handle value>.
127130 // We don't use it, but need to support it to avoid unknown option errors.
128- QCommandLineOption parentWindow (QStringLiteral (" parent-window" ),
129- QStringLiteral (" Parent window handle (unused)" ),
130- QStringLiteral (" parent-window" ));
131+ QCommandLineOption parentWindow (u" parent-window" _s, u" Parent window handle (unused)" _s,
132+ u" parent-window" _s);
131133
132- QCommandLineOption aboutArgument (QStringLiteral (" about" ),
133- QStringLiteral (" Show Web-eID about window" ));
134+ QCommandLineOption aboutArgument (u" about" _s, u" Show Web-eID about window" _s);
135+ QCommandLineOption commandLineMode (
136+ {u" c" _s, u" command-line-mode" _s},
137+ u" Command-line mode, read commands from command line arguments instead of "
138+ " standard input." _s);
134139
135140 QCommandLineParser parser;
136- parser.setApplicationDescription (QStringLiteral (
137- " Application that communicates with the Web eID browser extension via standard input and "
141+ parser.setApplicationDescription (
142+ u " Application that communicates with the Web eID browser extension via standard input and "
138143 " output, but also works standalone in command-line mode. Performs PKI cryptographic "
139- " operations with eID smart cards for signing and authentication purposes." ) );
144+ " operations with eID smart cards for signing and authentication purposes." _s );
140145
141146 parser.addHelpOption ();
142- parser.addOptions ({{{" c" , " command-line-mode" },
143- " Command-line mode, read commands from command line arguments instead of "
144- " standard input." },
145- aboutArgument,
146- parentWindow});
147+ parser.addVersionOption ();
148+ parser.addOptions ({commandLineMode, aboutArgument, parentWindow});
147149
148- static const auto COMMANDS = " ' " + CMDLINE_GET_SIGNING_CERTIFICATE + " ' , '"
149- + CMDLINE_AUTHENTICATE + " ', ' " + CMDLINE_SIGN + " '. " ;
150+ static const auto COMMANDS = u" '%1', '%2' , '%3'. " _s. arg (CMDLINE_GET_SIGNING_CERTIFICATE,
151+ CMDLINE_AUTHENTICATE, CMDLINE_SIGN) ;
150152
151153 parser.addPositionalArgument (
152- QStringLiteral (" command" ),
153- QStringLiteral (" The command to execute in command-line mode, any of " ) + COMMANDS);
154- parser.addPositionalArgument (
155- QStringLiteral (" arguments" ),
156- QStringLiteral (" Arguments to the given command as a JSON-encoded string." ));
154+ u" command" _s, u" The command to execute in command-line mode, any of " _s + COMMANDS,
155+ u" (%1|%2|%3)" _s.arg (CMDLINE_GET_SIGNING_CERTIFICATE, CMDLINE_AUTHENTICATE, CMDLINE_SIGN));
156+ parser.addPositionalArgument (u" arguments" _s,
157+ u" Arguments to the given command as a JSON-encoded string." _s);
157158
158159 parser.process (arguments ());
159160
160- if (parser.isSet (QStringLiteral ( " command-line-mode " ) )) {
161+ if (parser.isSet (commandLineMode )) {
161162 const auto args = parser.positionalArguments ();
162163 if (args.size () != 2 ) {
163164 throw ArgumentError (" Provide two positional arguments in command-line mode." );
0 commit comments