-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
106 lines (85 loc) · 3.66 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlContext>
#include <QQmlComponent>
#include <QQmlApplicationEngine>
#include "qtquick2applicationviewer.h"
#include "kassomatcontroller.h"
#include "databasecontroller.h"
#include "QDjango/db/QDjango.h"
#include "QDjango/db/QDjangoQuerySet.h"
#include "model/product.h"
#include "model/genericmodel.h"
#include "QsLog/QsLog.h"
#include "qslogdestsql.h"
#include <QtQml>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QCoreApplication::setApplicationName("Kassomat");
QCoreApplication::setApplicationVersion("0.0.1");
QString deviceName = "ttyACM0";
bool headless = false;
{
QCommandLineParser parser;
parser.setApplicationDescription("Kassomat");
parser.addHelpOption();
parser.addVersionOption();
// Add option to select the device name
QCommandLineOption deviceNameOption(QStringList() << "n" << "name",
QCoreApplication::translate("main", "the <name> of the device to connect to."),
QCoreApplication::translate("main", "device name"));
parser.addOption(deviceNameOption);
// Add option to run headless
QCommandLineOption headlessOption("headless", QCoreApplication::translate("main", "run headless"));
parser.addOption(headlessOption);
// Process the actual command line arguments given by the user
parser.process(app);
// Evaluate the arguments and set the variables
if(parser.isSet(deviceNameOption)) {
deviceName = parser.value(deviceNameOption);
}
headless = parser.isSet(headlessOption);
}
try {
// setup the KassomatController
KassomatController kassomatController;
kassomatController.setSmartPayoutDevice(deviceName);
kassomatController.test();
while (true) {
qDebug() << "polling the device now";
kassomatController.poll();
sleep(2);
}
// setup the DatabaseController
DatabaseController databaseController;
// initialize the logging
QsLogging::Logger& logger = QsLogging::Logger::instance();
//logger.setLoggingLevel(QsLogging::TraceLevel);
QsLogging::DestinationPtr destSQL( QsLogging::DestinationPtr(new QsLogDestSQL) );
logger.addDestination(destSQL);
//QList<Product *> p;
GenericModel<Project> projectlist(databaseController.listProjects(false));
//p = databaseController.listProducts();
//productlist.addItems(p);
qmlRegisterType<Product>("db.product",1,0,"productlist");
// QtQuick2ApplicationViewer viewer;
// //in .qml files eine variable namens "controller" global verfuegbar machen
// viewer.rootContext()->setContextProperty("controller", &kassomatController);
// viewer.rootContext()->setContextProperty("projectlist", &projectlist );
// viewer.rootContext()->setContextProperty("database", &databaseController );
// viewer.setMainQmlFile(QStringLiteral("qml/kassomat/main.qml"));
// viewer.showExpanded();
QQmlEngine engine;
engine.rootContext()->setContextProperty("controller", &kassomatController);
engine.rootContext()->setContextProperty("projectlist", &projectlist);
engine.rootContext()->setContextProperty("database", &databaseController);
if(! headless) {
QQmlComponent component(&engine, QUrl::fromLocalFile("./qml/kassomat/main.qml"));
component.create();
}
return app.exec();
} catch(char const *msg) {
qFatal("FATAL Error: %s", msg);
return 1;
}
}