forked from Libki/libki-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
220 lines (180 loc) · 5.8 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* Copyright 2010 Kyle M Hall <kyle.m.hall@gmail.com>
*
* This file is part of Libki.
*
* Libki 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.
*
* Libki 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 Libki. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QApplication>
#include <QProcess>
#include <QWebView>
#include "loginwindow.h"
#include "timerwindow.h"
#include "networkclient.h"
#include <stdlib.h>
void myMessageHandler(QtMsgType type,
const QMessageLogContext&,
const QString& msg)
{
QString txt;
switch (type) {
case QtDebugMsg:
txt = QString("Debug: %1\n").arg(msg);
break;
case QtWarningMsg:
txt = QString("Warning: %1\n").arg(msg);
break;
case QtCriticalMsg:
txt = QString("Critical: %1\n").arg(msg);
break;
case QtFatalMsg:
txt = QString("Fatal: %1\n").arg(msg);
break;
default:
break;
}
QFile outFile("libki_client.log");
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << endl;
}
int main(int argc, char *argv[]) {
// qInstallMessageHandler(myMessageHandler);
QApplication app(argc, argv);
QString os_username;
#ifdef Q_OS_WIN
os_username = getenv("USERNAME");
#endif // ifdef Q_OS_WIN
#ifdef Q_OS_UNIX
os_username = getenv("USER");
#endif // ifdef Q_OS_UNIX
qDebug() << "OS Username: " << os_username;
// Translate the application if the locale is available
QString locale = QLocale::system().name();
QString filename = QString("languages/libkiclient_") + locale;
QTranslator translator;
if (translator.load(filename, ":/")) {
app.installTranslator(&translator);
qDebug() << "Translation file loaded" << filename;
} else qDebug() << "Translation file not found:" << filename;
/* Apply the stylesheet */
QFile qss("libki.qss");
qss.open(QFile::ReadOnly);
app.setStyleSheet(qss.readAll());
qss.close();
QCoreApplication::setOrganizationName("Libki");
QCoreApplication::setOrganizationDomain("libki.org");
QCoreApplication::setApplicationName("Libki Kiosk Management System");
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings settings;
settings.setIniCodec("UTF-8");
QString onlyRunFor;
onlyRunFor = settings.value("node/onlyRunFor").toString();
qDebug() << "onlyRunFor: " << onlyRunFor;
if (!onlyRunFor.isEmpty()) {
if (onlyRunFor != os_username) {
qDebug() << "onlyRunFor does not match OS username, exiting.";
exit(1);
}
}
QString onlyStopFor;
onlyStopFor = settings.value("node/onlyStopFor").toString();
qDebug() << "onlyStopFor: " << onlyStopFor;
if (!onlyStopFor.isEmpty()) {
if (onlyStopFor == os_username) {
qDebug() << "onlyStopFor matches OS username, exiting.";
exit(1);
}
}
#ifdef Q_OS_WIN
// If this is an MS Windows platform, use the keylocker programs to limit
// mischief.
QProcess::startDetached("windows/on_startup.exe");
#endif // ifdef Q_OS_WIN
settings.setValue("session/ClientBehavior", "");
settings.setValue("session/ReservationShowUsername", "");
settings.setValue("session/LoggedInUser", "");
settings.sync();
LoginWindow *loginWindow = new LoginWindow();
TimerWindow *timerWindow = new TimerWindow();
NetworkClient *networkClient = new NetworkClient();
QObject::connect(
loginWindow,
SIGNAL(loginSucceeded(const QString&,const QString&,int,int)),
timerWindow,
SLOT(startTimer(const QString&,const QString&,int,int))
);
QObject::connect(timerWindow, SIGNAL(requestLogout()), networkClient,
SLOT(attemptLogout()));
QObject::connect(networkClient, SIGNAL(logoutSucceeded()), timerWindow,
SLOT(stopTimer()));
QObject::connect(timerWindow, SIGNAL(timerStopped()), loginWindow,
SLOT(displayLoginWindow()));
QObject::connect(
loginWindow,
SIGNAL(attemptLogin(const QString&,const QString&)),
networkClient,
SLOT(attemptLogin(const QString&,const QString&))
);
QObject::connect(
networkClient,
SIGNAL(loginSucceeded(QString,QString,int,int)),
loginWindow,
SLOT(attemptLoginSuccess(QString,QString,int,int))
);
QObject::connect(
networkClient,
SIGNAL(loginFailed(QString)),
loginWindow,
SLOT(attemptLoginFailure(QString))
);
QObject::connect(
networkClient,
SIGNAL(setReservationStatus(QString)),
loginWindow,
SLOT(handleReservationStatus(QString))
);
QObject::connect(
loginWindow,
SIGNAL(displayingReservationMessage(QString)),
networkClient,
SLOT(acknowledgeReservation(QString))
);
QObject::connect(
networkClient,
SIGNAL(handleBanners()),
loginWindow,
SLOT(handleBanners())
);
QObject::connect(
networkClient,
SIGNAL(timeUpdatedFromServer(int)),
timerWindow,
SLOT(updateTimeLeft(int))
);
QObject::connect(networkClient,
SIGNAL(messageRecieved(QString)),
timerWindow,
SLOT(showMessage(QString)));
QObject::connect(networkClient,
SIGNAL(allowClose(bool)),
loginWindow,
SLOT(setAllowClose(bool)));
QObject::connect(networkClient,
SIGNAL(allowClose(bool)),
timerWindow,
SLOT(setAllowClose(bool)));
loginWindow->show();
return app.exec();
}