From b51ae9a65c5ca8c242fcb7ec7c8cd11f073c524e Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Fri, 3 Oct 2014 10:58:11 +0000 Subject: [PATCH] Use message boxes for command line parser The error and information output from command line parsing needs to be graphical on Windows since the application is not a console application. Made the output graphical on all platforms. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@4462 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- main.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 5cf7b3407..278e88f99 100644 --- a/main.cpp +++ b/main.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #if QT_VERSION >= 0x050200 #include @@ -60,8 +61,8 @@ int main(int argc, char *argv[]) #if QT_VERSION >= 0x050200 QCommandLineParser parser; parser.setApplicationDescription ("\nJT65A & JT9 Weak Signal Communications Program."); - parser.addHelpOption (); - parser.addVersionOption (); + auto help_option = parser.addHelpOption (); + auto version_option = parser.addVersionOption (); #if WSJT_STANDARD_FILE_LOCATIONS // support for multiple instances running from a single installation @@ -75,7 +76,24 @@ int main(int argc, char *argv[]) , a.translate ("main", "Writable files in test location. Use with caution, for testing only.")); parser.addOption (test_option); - parser.process (a); + if (!parser.parse (a.arguments ())) + { + QMessageBox::critical (nullptr, a.applicationName (), parser.errorText ()); + return -1; + } + else + { + if (parser.isSet (help_option)) + { + QMessageBox::information (nullptr, a.applicationName (), parser.helpText ()); + return 0; + } + else if (parser.isSet (version_option)) + { + QMessageBox::information (nullptr, a.applicationName (), a.applicationVersion ()); + return 0; + } + } QStandardPaths::setTestModeEnabled (parser.isSet (test_option)); @@ -157,12 +175,12 @@ int main(int argc, char *argv[]) } catch (std::exception const& e) { - QMessageBox::critical (nullptr, QObject::tr ("Error"), e.what ()); + QMessageBox::critical (nullptr, a.applicationName (), e.what ()); std::cerr << "Error: " << e.what () << '\n'; } catch (...) { - QMessageBox::critical (nullptr, QObject::tr ("Unexpected"), QObject::tr ("Error")); + QMessageBox::critical (nullptr, a.applicationName (), QObject::tr ("Unexpected error")); std::cerr << "Unexpected error\n"; throw; // hoping the runtime might tell us more about the exception }