@@ -463,8 +463,7 @@ void MainWindow::switchLanguage()
463463 qDebug () << " selected language" << langCode;
464464 if (langCode!=DoxygenWizard::langCode)
465465 {
466- m_settings.setValue (QString::fromLatin1 (" language/code" ), langCode);
467- m_settings.sync ();
466+ setLanguage (langCode);
468467 quit ();
469468 }
470469 }
@@ -891,6 +890,18 @@ void MainWindow::outputLogFinish()
891890 m_saveLog->setEnabled (true );
892891}
893892
893+ #define TXT_ARGS QString::fromLatin1 (argc > 2 ?" Too many arguments specified\n\n " :" " )
894+ static void usage(const char *exeName, const QString txt)
895+ {
896+ QMessageBox msgBox;
897+ QString fullText = txt;
898+ fullText += QString::fromLatin1 (" Usage: %1 [--debug] [--language [lang]] [config file]\n " ).arg (QString::fromLatin1 (exeName));
899+ fullText += QString::fromLatin1 (" Usage: %1 --help\n " ).arg (QString::fromLatin1 (exeName));
900+ fullText += QString::fromLatin1 (" Usage: %1 --version\n " ).arg (QString::fromLatin1 (exeName));
901+ msgBox.setText (fullText);
902+ msgBox.exec ();
903+ }
904+
894905// -----------------------------------------------------------------------
895906int main (int argc,char **argv)
896907{
@@ -905,21 +916,27 @@ int main(int argc,char **argv)
905916#endif
906917
907918 QApplication a (argc,argv);
908- int locArgc = argc;
909919
910- if (locArgc == 2 )
920+ int optInd=1 ;
921+ bool langSet = false ;
922+ QString langSel;
923+ while (optInd<argc && argv[optInd][0 ]==' -' && argv[optInd][1 ]==' -' )
911924 {
912- if (!qstrcmp (argv[1 ]," --help" ))
925+ if (!qstrcmp (argv[optInd ]," --help" ))
913926 {
914- QMessageBox msgBox;
915- msgBox.setText (QString::fromLatin1 (" Usage: %1 [config file]" ).arg (QString::fromLatin1 (argv[0 ])));
916- msgBox.exec ();
927+ usage (argv[0 ],TXT_ARGS);
928+ if (argc > 2 ) exit (1 );
917929 exit (0 );
918930 }
919- else if (!qstrcmp (argv[1 ]," --version" ))
931+ else if (!qstrcmp (argv[optInd ]," --version" ))
920932 {
921933 QMessageBox msgBox;
922- if (!qstrcmp (qVersion (),QT_VERSION_STR))
934+ if (argc > 2 )
935+ {
936+ usage (argv[0 ],TXT_ARGS);
937+ exit (1 );
938+ }
939+ else if (!qstrcmp (qVersion (),QT_VERSION_STR))
923940 {
924941 msgBox.setText (QString::fromLatin1 (" Doxywizard version: %1, Qt version: %2" ).arg (QString::fromLatin1 (getFullVersion ().c_str ())).arg (QString::fromLatin1 (QT_VERSION_STR)));
925942 }
@@ -930,25 +947,48 @@ int main(int argc,char **argv)
930947 msgBox.exec ();
931948 exit (0 );
932949 }
933- }
934- if (!qstrcmp (argv[1 ]," --debug" ) && ((locArgc == 2 ) || (locArgc == 3 )))
935- {
936- DoxygenWizard::debugFlag = true ;
937- locArgc--;
950+ else if (!qstrcmp (argv[optInd]," --debug" ))
951+ {
952+ DoxygenWizard::debugFlag = true ;
953+ }
954+ else if (!qstrcmp (argv[optInd]," --language" ))
955+ {
956+ langSet = true ;
957+ if (optInd+1 >=argc || (argv[optInd+1 ][0 ]==' -' && argv[optInd+1 ][1 ]==' -' ))
958+ {
959+ langSel = QString::fromLatin1 (" en" );
960+ }
961+ else
962+ {
963+ langSel = QString::fromLatin1 (argv[optInd+1 ]);
964+ optInd++;
965+ }
966+ if (!isLanguageCodeSupported (langSel))
967+ {
968+ usage (argv[0 ],QString::fromLatin1 (" Unknown language selected\n\n " ));
969+ exit (1 );
970+ }
971+ }
972+ optInd++;
938973 }
939974
940- if (locArgc > 2 )
975+ if (optInd+ 2 <=argc )
941976 {
942- QMessageBox msgBox;
943- msgBox.setText (QString::fromLatin1 (" Too many arguments specified\n\n Usage: %1 [config file]" ).arg (QString::fromLatin1 (argv[0 ])));
944- msgBox.exec ();
977+ usage (argv[0 ],TXT_ARGS);
945978 exit (1 );
946979 }
947- else
980+
948981 {
949982 qDebug () << " Starting doxywizard..." ;
950983
951- DoxygenWizard::langCode = getStartupLanguageCode ();
984+ if (langSet)
985+ {
986+ DoxygenWizard::langCode = langSel;
987+ }
988+ else
989+ {
990+ DoxygenWizard::langCode = getStartupLanguageCode ();
991+ }
952992 QTranslator qtTranslator;
953993 if (!DoxygenWizard::langCode.isEmpty () &&
954994 qtTranslator.load (QString::fromLatin1 (" :/i18n/qtbase_%1.qm" ).arg (DoxygenWizard::langCode))
@@ -967,7 +1007,11 @@ int main(int argc,char **argv)
9671007 }
9681008
9691009 MainWindow &main = MainWindow::instance ();
970- if (locArgc==2 && argv[argc-1 ][0 ]!=' -' ) // name of config file as an argument
1010+ if (langSet)
1011+ {
1012+ main.setLanguage (langSel);
1013+ }
1014+ if (optInd+1 ==argc && argv[argc-1 ][0 ]!=' -' ) // name of config file as an argument
9711015 {
9721016 main.loadConfigFromFile (QString::fromLocal8Bit (argv[argc-1 ]));
9731017 }
0 commit comments