2018-02-21 18:46:54 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
|
|
|
|
* Copyright (C) 2018 Tom Zander <tomz@freedommail.ch>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "PaymentDataProvider.h"
|
|
|
|
|
#include "Calculator.h"
|
|
|
|
|
#include "QRCreator.h"
|
|
|
|
|
#include <Logger.h>
|
2019-05-08 08:42:09 +02:00
|
|
|
#include <clientversion.h>
|
|
|
|
|
#include <NetworkManager.h>
|
2019-11-12 15:35:54 +01:00
|
|
|
#include <utilstrencodings.h>
|
2019-05-08 08:42:09 +02:00
|
|
|
|
2018-02-21 18:46:54 +01:00
|
|
|
#include <qguiapplication.h>
|
|
|
|
|
#include <QCommandLineParser>
|
|
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QStandardPaths>
|
2019-05-08 08:42:09 +02:00
|
|
|
#include <qtextstream.h>
|
2018-02-21 18:46:54 +01:00
|
|
|
|
2019-05-08 08:42:09 +02:00
|
|
|
#include <signal.h>
|
2018-02-21 18:46:54 +01:00
|
|
|
#include <boost/asio/ip/address_v4.hpp>
|
|
|
|
|
|
2019-05-08 08:42:09 +02:00
|
|
|
void HandleSIGTERM(int) {
|
|
|
|
|
QCoreApplication::quit();
|
|
|
|
|
}
|
2018-02-21 18:46:54 +01:00
|
|
|
|
|
|
|
|
int main(int x, char **y)
|
|
|
|
|
{
|
|
|
|
|
QGuiApplication app(x, y);
|
|
|
|
|
app.setOrganizationName("flowee");
|
|
|
|
|
app.setOrganizationDomain("flowee.org");
|
|
|
|
|
app.setApplicationName("cashier");
|
|
|
|
|
|
|
|
|
|
QString logsconf = QStandardPaths::locate(QStandardPaths::AppConfigLocation, "logs.conf");
|
|
|
|
|
QString logFile = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/cashier.log";
|
|
|
|
|
Log::Manager::instance()->parseConfig(logsconf.toLocal8Bit().toStdString(), logFile.toLocal8Bit().toStdString());
|
|
|
|
|
|
|
|
|
|
QCommandLineParser parser;
|
2019-05-08 08:42:09 +02:00
|
|
|
QCommandLineOption connect("connect", "server location and port", "<ADDERSS>");
|
|
|
|
|
QCommandLineOption debug(QStringList() << "debug", "Use debug level logging");
|
|
|
|
|
QCommandLineOption version(QStringList() << "version", "Display version");
|
2018-02-21 18:46:54 +01:00
|
|
|
parser.addOption(connect);
|
2019-05-08 08:42:09 +02:00
|
|
|
parser.addOption(debug);
|
|
|
|
|
parser.addOption(version);
|
2018-02-21 18:46:54 +01:00
|
|
|
parser.addHelpOption();
|
|
|
|
|
parser.process(app);
|
|
|
|
|
|
|
|
|
|
if (parser.positionalArguments().size() > 1)
|
|
|
|
|
parser.showHelp(1);
|
|
|
|
|
|
2019-05-08 08:42:09 +02:00
|
|
|
if (parser.isSet(debug)) {
|
|
|
|
|
auto *logger = Log::Manager::instance();
|
|
|
|
|
logger->clearChannels();
|
|
|
|
|
logger->clearLogLevels(Log::DebugLevel);
|
|
|
|
|
logger->addConsoleChannel();
|
2018-02-21 18:46:54 +01:00
|
|
|
}
|
2019-05-08 08:42:09 +02:00
|
|
|
if (parser.isSet(version)) {
|
|
|
|
|
QTextStream out(stdout);
|
|
|
|
|
out << app.applicationName() << " " << FormatFullVersion().c_str() << endl;
|
|
|
|
|
out << "License GPLv3+: GNU GPL version 3 or later" << endl;
|
|
|
|
|
out << "This is free software: you are free to change and redistribute it." << endl << endl;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct sigaction sa;
|
|
|
|
|
sa.sa_handler = HandleSIGTERM;
|
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
|
sigaction(SIGTERM, &sa, NULL);
|
|
|
|
|
sigaction(SIGINT, &sa, NULL);
|
|
|
|
|
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
|
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
|
2018-02-21 18:46:54 +01:00
|
|
|
if (parser.isSet(connect)) {
|
2019-05-08 08:42:09 +02:00
|
|
|
std::string hostname;
|
2019-06-02 20:16:49 +02:00
|
|
|
uint16_t port = -1;
|
2019-05-08 08:42:09 +02:00
|
|
|
SplitHostPort(parser.value(connect).toStdString(), port, hostname);
|
2018-02-21 18:46:54 +01:00
|
|
|
QSettings settings;
|
|
|
|
|
settings.beginGroup(HubConfig::GROUP_ID);
|
2019-05-08 08:42:09 +02:00
|
|
|
settings.setValue(HubConfig::KEY_SERVER_PORT, port);
|
|
|
|
|
settings.setValue(HubConfig::KEY_SERVER_HOSTNAME, QString::fromStdString(hostname));
|
2018-02-21 18:46:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qmlRegisterType<Calculator>("org.flowee", 1, 0, "Calculator");
|
|
|
|
|
qmlRegisterSingletonType<PaymentDataProvider>("org.flowee", 1, 0, "Payments", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
|
|
|
|
|
Q_UNUSED(scriptEngine)
|
|
|
|
|
PaymentDataProvider *dp = new PaymentDataProvider(engine);
|
|
|
|
|
QRCreator *qr = new QRCreator(dp);
|
|
|
|
|
engine->addImageProvider("qr", qr);
|
|
|
|
|
return dp;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QQmlApplicationEngine engine;
|
|
|
|
|
engine.load(QUrl(QLatin1String("qrc:/qml/mainwindow.qml")));
|
|
|
|
|
if (engine.rootObjects().isEmpty())
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
|
}
|