2019-04-06 17:16:42 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QProcessEnvironment>
|
|
|
|
#include <QSqlDatabase>
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include <QSqlError>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QDebug>
|
2020-05-23 22:52:42 +02:00
|
|
|
#include <QSettings>
|
2019-04-06 17:16:42 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <exception>
|
|
|
|
#include "encodingdetector.h"
|
|
|
|
#include "pdfprocessor.h"
|
|
|
|
#include "defaulttextprocessor.h"
|
2019-04-10 18:57:27 +02:00
|
|
|
#include "utils.h"
|
2019-04-06 17:16:42 +02:00
|
|
|
#include "command.h"
|
|
|
|
#include "commandadd.h"
|
2019-04-07 20:22:20 +02:00
|
|
|
#include "commanddelete.h"
|
2019-04-16 08:54:49 +02:00
|
|
|
#include "commandupdate.h"
|
2019-04-20 23:31:14 +02:00
|
|
|
#include "commandsearch.h"
|
2019-04-16 08:54:49 +02:00
|
|
|
#include "databasefactory.h"
|
|
|
|
#include "logger.h"
|
2020-05-23 22:52:42 +02:00
|
|
|
#include "../shared/common.h"
|
|
|
|
|
2019-04-06 17:16:42 +02:00
|
|
|
void printUsage(QString argv0)
|
|
|
|
{
|
2020-05-24 15:36:27 +02:00
|
|
|
qInfo() << "Usage:" << argv0 << "command";
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
|
|
|
|
2019-04-16 08:54:49 +02:00
|
|
|
Command *commandFromName(QString name, SqliteDbService &dbService)
|
2019-04-06 17:16:42 +02:00
|
|
|
{
|
2020-05-23 22:52:42 +02:00
|
|
|
if(name == "add")
|
|
|
|
{
|
|
|
|
return new CommandAdd(dbService);
|
|
|
|
}
|
|
|
|
if(name == "delete")
|
|
|
|
{
|
|
|
|
return new CommandDelete(dbService);
|
|
|
|
}
|
|
|
|
if(name == "update")
|
|
|
|
{
|
|
|
|
return new CommandUpdate(dbService);
|
|
|
|
}
|
|
|
|
if(name == "search")
|
|
|
|
{
|
|
|
|
return new CommandSearch(dbService);
|
|
|
|
}
|
2019-04-20 23:31:14 +02:00
|
|
|
|
2020-05-23 22:52:42 +02:00
|
|
|
return nullptr;
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2020-05-23 22:52:42 +02:00
|
|
|
Common::setupAppInfo();
|
2019-04-06 17:16:42 +02:00
|
|
|
|
2020-05-23 22:52:42 +02:00
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
QStringList args = app.arguments();
|
|
|
|
QString argv0 = args.takeFirst();
|
|
|
|
if(args.length() < 1)
|
|
|
|
{
|
|
|
|
printUsage(argv0);
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-04-06 17:16:42 +02:00
|
|
|
|
2020-05-24 15:36:27 +02:00
|
|
|
QString connectionString = Common::databasePath();
|
2020-05-23 22:52:42 +02:00
|
|
|
DatabaseFactory dbFactory(connectionString);
|
|
|
|
SqliteDbService dbService(dbFactory);
|
2020-05-24 15:36:27 +02:00
|
|
|
QString commandName = args.first();
|
2020-05-23 22:52:42 +02:00
|
|
|
Command *cmd = commandFromName(commandName, dbService);
|
|
|
|
if(cmd != nullptr)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return cmd->handle(args);
|
|
|
|
}
|
|
|
|
catch(const QSSGeneralException &e)
|
|
|
|
{
|
|
|
|
Logger::error() << "Exception caught, message: " << e.message << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Logger::error() << "Unknown command " << commandName << endl;
|
|
|
|
}
|
|
|
|
return 1;
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|