From e297dbd8052ef4e66f069e2dd1865ae7fa8af28e Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Thu, 21 Mar 2013 11:01:59 +0100 Subject: Imported Upstream version 0.3.1.0 --- CliParser.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 5 deletions(-) (limited to 'CliParser.cpp') diff --git a/CliParser.cpp b/CliParser.cpp index ffd511d..13aeac1 100644 --- a/CliParser.cpp +++ b/CliParser.cpp @@ -7,12 +7,18 @@ #include "CliParser.h" +#include + CliParser::CliParser(QObject *parent) : QObject(parent) { } -void CliParser::cli(const QStringList &ultracopierArguments,const bool &external) +/** \brief method to parse the ultracopier arguments + \param ultracopierArguments the argument list + \param external true if the arguments come from other instance of ultracopier +*/ +void CliParser::cli(const QStringList &ultracopierArguments,const bool &external,const bool &onlyCheck) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"ultracopierArguments: "+ultracopierArguments.join(";")); if(ultracopierArguments.size()==1) @@ -22,15 +28,73 @@ void CliParser::cli(const QStringList &ultracopierArguments,const bool &external // else do nothing, is normal starting without arguements return; } - if(ultracopierArguments.size()==2 && ultracopierArguments.last()=="quit" && external) + if(ultracopierArguments.size()==2) { - QCoreApplication::exit(); + if(ultracopierArguments.last()=="quit" && external) + { + if(onlyCheck) + return; + QCoreApplication::exit(); + return; + } + if(ultracopierArguments.last()=="--help") + { + showHelp(false); + return; + } + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Command line not understand"); + showHelp(); + return; + } + if(ultracopierArguments.size()==3) + { + if(ultracopierArguments[1]=="Transfer-list") + { + if(onlyCheck) + return; + QFile transferFile(ultracopierArguments.last()); + if(transferFile.open(QIODevice::ReadOnly)) + { + QString content; + QByteArray data=transferFile.readLine(64); + if(data.size()<=0) + { + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("Problem at the reading, or file size is null")); + QMessageBox::warning(NULL,tr("Warning"),tr("Problem at the reading, or file size is null")); + transferFile.close(); + return; + } + content=QString::fromUtf8(data); + content.remove('\n'); + QStringList transferListArguments=content.split(';'); + if(transferListArguments.size()!=4 || transferListArguments[0]!="Ultracopier-0.3" || transferListArguments[1]!="Transfer-list") + { + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("This file is not supported transfer list")); + QMessageBox::warning(NULL,tr("Warning"),tr("This file is not supported transfer list")); + transferFile.close(); + return; + } + transferFile.close(); + emit newTransferList(transferListArguments[3],transferListArguments[2],ultracopierArguments.last()); + } + else + { + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("Unable to open the transfer list file: %1").arg(transferFile.errorString())); + QMessageBox::warning(NULL,tr("Warning"),tr("Unable to open the transfer list file")); + return; + } + return; + } + ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Command line not understand"); + showHelp(); return; } if(ultracopierArguments.size()>3) { if(ultracopierArguments[1]=="Copy" || ultracopierArguments[1]=="cp") { + if(onlyCheck) + return; QStringList transferList=ultracopierArguments; transferList.removeFirst(); transferList.removeFirst(); @@ -49,6 +113,8 @@ void CliParser::cli(const QStringList &ultracopierArguments,const bool &external } if(ultracopierArguments[1]=="Move" || ultracopierArguments[1]=="mv") { + if(onlyCheck) + return; QStringList transferList=ultracopierArguments; transferList.removeFirst(); transferList.removeFirst(); @@ -66,8 +132,38 @@ void CliParser::cli(const QStringList &ultracopierArguments,const bool &external return; } ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Command line not understand"); - QMessageBox::warning(NULL,tr("Warning"),tr("Command line not understand")); + showHelp(); + return; } ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Command line not understand"); - QMessageBox::warning(NULL,tr("Warning"),tr("Command line not understand")); + showHelp(); +} + +/** \brief show the help + *\param incorrectArguments if the help is call because the arguments are wrong */ +void CliParser::showHelp(const bool &incorrectArguments) +{ + if(incorrectArguments) + qDebug() << "Incorrect arguments detected"; + qDebug() << tr("The arguments possibles are:"); + qDebug() << "--help : "+tr("To have this help"); + qDebug() << "quit : "+tr("To quit the other instance running (if have)"); + qDebug() << "Transfer-list [transfer list file] : "+tr("To pass transfer list to do"); + qDebug() << "cp [source [source2]] [destination] : "+tr("To copy sources separated by space to destination. If destination is \"?\", ultracopier will ask it to the user"); + qDebug() << "mv [source [source2]] [destination] : "+tr("Same as above, but with move"); + + QString message; + if(incorrectArguments) + message+=""+tr("Command line not understand")+"
\n"; + message+=+""+tr("The arguments possibles are:")+"\n"; + if(incorrectArguments) + QMessageBox::warning(NULL,tr("Warning"),message); + else + QMessageBox::information(NULL,tr("Help"),message); } -- cgit v1.2.3