utility: loading project via commanlineargument

loading a project via commanline with --project or -p argument
This commit is contained in:
Andreas Stallinger
2016-01-12 13:24:04 +01:00
parent b8faa5506d
commit 46a629358c
7 changed files with 110 additions and 2 deletions
@@ -0,0 +1,69 @@
#include "qt/commandline/QtCommandLineParser.h"
#include "utility/ConfigManager.h"
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/text/TextAccess.h"
QtCommandLineParser::QtCommandLineParser()
{
}
QtCommandLineParser::~QtCommandLineParser()
{
}
void QtCommandLineParser::setup()
{
setApplicationDescription("Coati helper");
addVersionOption();
addHelpOption();
QCommandLineOption projectOption(QStringList() << "p" << "project",
QCoreApplication::translate("main", "Load Coati with the a Coatiprojectfile <CoatiProject>."),
QCoreApplication::translate("main", "CoatiProject"));
addOption(projectOption);
}
void QtCommandLineParser::parseCommandline()
{
if(isSet("project"))
{
QString projectfilename = value("project") ;
FilePath projectfile(projectfilename.toStdString());
bool isValidProjectfile = true;
std::stringstream errorstring("Provided Projectfile is not valid: ");
errorstring << "Provided Projectfile('" << projectfile.fileName() << ") ";
if(!projectfile.exists())
{
errorstring << "does not exist";
isValidProjectfile = false;
}
if(projectfile.extension() != ".coatiproject")
{
errorstring << "has a wrong fileending";
isValidProjectfile = false;
}
std::shared_ptr<ConfigManager> configManager = ConfigManager::createEmpty();
if(!configManager->load(TextAccess::createFromFile(projectfile.str())))
{
errorstring << "could not be loaded";
isValidProjectfile = false;
}
if(isValidProjectfile)
{
MessageLoadProject(projectfile.str()).dispatch();
}
else
{
MessageStatus(errorstring.str(), true).dispatch();
LOG_ERROR(errorstring.str());
}
}
}
@@ -0,0 +1,19 @@
#ifndef QTCOMMANDLINEPARSER_H
#define QTCOMMANDLINEPARSER_H
#include <QCommandLineParser>
#include "Application.h"
class QtCommandLineParser : public QCommandLineParser
{
public:
QtCommandLineParser();
~QtCommandLineParser();
void setup();
void parseCommandline();
private:
};
#endif //QTCOMMANDLINEPARSER_H