Ajout des options --help, -v,--version et --license

Le fichier gnugpl.txt s'appelle desormais LICENSE et est integre au binaire QET


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@196 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavierqet
2007-10-28 01:32:57 +00:00
parent 4780f87cb9
commit 5c1260fe0c
9 changed files with 266 additions and 182 deletions

View File

@@ -1,6 +1,7 @@
#include "qetapp.h"
#include "qetdiagrameditor.h"
#include "qetelementeditor.h"
#include <iostream>
#define QUOTE(x) STRINGIFY(x)
#define STRINGIFY(x) #x
@@ -16,6 +17,31 @@ QETApp::QETApp(int &argc, char **argv) : QApplication(argc, argv) {
QString system_language = QLocale::system().name().left(2);
setLanguage(system_language);
// parse les arguments
foreach(QString argument, arguments()) {
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
QString ced_arg("--common-elements-dir=");
if (argument.startsWith(ced_arg)) {
QString ced_value = argument.right(argument.length() - ced_arg.length());
overrideCommonElementsDir(ced_value);
}
#endif
bool must_exit = false;
if (argument == QString("--help")) {
printHelp();
must_exit = true;
} else if (argument == QString("--version") || argument == QString("-v")) {
printVersion();
must_exit = true;
} else if (argument == QString("--license")) {
printLicense();
must_exit = true;
}
if (must_exit) {
std::exit(EXIT_SUCCESS);
}
}
// nettoyage avant de quitter l'application
connect(this, SIGNAL(aboutToQuit()), this, SLOT(cleanup()));
@@ -62,17 +88,6 @@ QETApp::QETApp(int &argc, char **argv) : QApplication(argc, argv) {
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(checkRemainingWindows()));
}
// parse les arguments
foreach(QString argument, arguments()) {
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
QString ced_arg("--common-elements-dir=");
if (argument.startsWith(ced_arg)) {
QString ced_value = argument.right(argument.length() - ced_arg.length());
overrideCommonElementsDir(ced_value);
}
#endif
}
// Creation et affichage d'un editeur de schema
QStringList files;
foreach(QString argument, arguments()) {
@@ -505,3 +520,26 @@ bool QETApp::event(QEvent *e) {
return(QApplication::event(e));
}
}
void QETApp::printHelp() {
QString help(
tr("Usage : ") + QFileInfo(applicationFilePath()).fileName() + tr(" [options] [fichier]...\n\n") +
tr("QElectroTech, une application de r\351alisation de sch\351mas \351lectriques.\n\n"
"Options disponibles : \n"
" --help Afficher l'aide sur les options\n"
" -v, --version Afficher la version\n"
" --license Afficher la licence\n")
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
+ tr(" --common-elements-dir=DIR Definir le dossier de la collection d'elements\n")
#endif
);
std::cout << qPrintable(help) << std::endl;
}
void QETApp::printVersion() {
std::cout << qPrintable(QET::version) << std::endl;
}
void QETApp::printLicense() {
std::cout << qPrintable(QET::license()) << std::endl;
}