1 |
torben |
899 |
#include "mainview.h" |
2 |
torben |
512 |
#include <QApplication> |
3 |
torben |
510 |
#include <QPushButton> |
4 |
torben |
512 |
#include <QLabel> |
5 |
torben |
870 |
#include <QStackedLayout> |
6 |
torben |
867 |
#include <QSvgWidget> |
7 |
torben |
509 |
|
8 |
torben |
2103 |
#include <QDir> |
9 |
torben |
510 |
#include <QTimer> |
10 |
torben |
533 |
#include <QKeyEvent> |
11 |
torben |
535 |
#include <QSettings> |
12 |
|
|
#include <QMessageBox> |
13 |
torben |
510 |
|
14 |
torben |
884 |
#include "webview.h" |
15 |
torben |
515 |
#include "clientsiderender.h" |
16 |
torben |
524 |
#include "pictureview.h" |
17 |
torben |
527 |
#include "videoview.h" |
18 |
torben |
883 |
#include "clockoverlay.h" |
19 |
torben |
528 |
#include "httpwrapper.h" |
20 |
torben |
875 |
#include "screenmanager.h" |
21 |
torben |
528 |
|
22 |
|
|
|
23 |
torben |
870 |
|
24 |
torben |
509 |
MainView::MainView(QWidget* parent) |
25 |
torben |
537 |
: QWidget(parent), timer(0) |
26 |
torben |
509 |
{ |
27 |
torben |
638 |
loadSettings(); |
28 |
torben |
535 |
|
29 |
torben |
638 |
if ( currentMode == ModeXml) { |
30 |
|
|
xmlUrl = url + "?screen_id=" + screenid; |
31 |
|
|
qDebug() << "Starting XML mode"; |
32 |
|
|
qDebug() << "xmlUrl" << xmlUrl; |
33 |
torben |
882 |
qDebug() << "xmlInterval" << xmlInterval/(60*1000); |
34 |
torben |
638 |
} |
35 |
torben |
535 |
|
36 |
torben |
638 |
if (currentMode == ModeSimpleWeb){ |
37 |
|
|
qDebug() << "Starting plain browser mode"; |
38 |
torben |
535 |
} |
39 |
|
|
|
40 |
torben |
638 |
if (currentMode == ModeLocal ) { |
41 |
|
|
qDebug() << "Starting local mode"; |
42 |
|
|
qDebug() << "path" << path; |
43 |
torben |
535 |
|
44 |
torben |
638 |
readLocalFiles(); |
45 |
|
|
} |
46 |
torben |
535 |
|
47 |
torben |
1210 |
this->resize(640,480); |
48 |
torben |
534 |
this->setWindowState( Qt::WindowFullScreen ); |
49 |
|
|
this->grabKeyboard(); |
50 |
torben |
516 |
|
51 |
torben |
534 |
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
52 |
torben |
510 |
|
53 |
torben |
534 |
render = new ClientSideRender(this); |
54 |
torben |
524 |
|
55 |
torben |
884 |
web = new WebView(this); |
56 |
torben |
511 |
|
57 |
torben |
534 |
picture = new PictureView(this); |
58 |
torben |
517 |
|
59 |
torben |
534 |
video = new VideoView(this); |
60 |
torben |
517 |
|
61 |
torben |
867 |
svg = new QSvgWidget(this); |
62 |
|
|
|
63 |
torben |
870 |
layout = new QStackedLayout(); |
64 |
|
|
layout->addWidget(web); |
65 |
|
|
layout->addWidget(render); |
66 |
|
|
layout->addWidget(picture); |
67 |
|
|
layout->addWidget(video); |
68 |
|
|
layout->addWidget(svg); |
69 |
torben |
534 |
layout->setContentsMargins(0,0,0,0); |
70 |
|
|
setLayout(layout); |
71 |
torben |
510 |
|
72 |
torben |
902 |
if (showClock == true) { |
73 |
|
|
clockOverlay = new ClockOverlay(this); |
74 |
|
|
clockOverlay->move(10,10); |
75 |
|
|
clockOverlay->resize(150,75); |
76 |
|
|
} |
77 |
torben |
883 |
|
78 |
|
|
|
79 |
|
|
|
80 |
torben |
872 |
if (currentMode == ModeSimpleWeb) { |
81 |
|
|
web->setVisible(true); |
82 |
|
|
web->start(url,screenid); |
83 |
|
|
} |
84 |
torben |
528 |
|
85 |
torben |
875 |
if (enableScreenManager) { |
86 |
torben |
876 |
screenManager = new ScreenManager(screenManagerOn, screenManagerOff); |
87 |
torben |
875 |
} else { |
88 |
|
|
qDebug() << "ScreenManager is disabled"; |
89 |
|
|
} |
90 |
torben |
873 |
|
91 |
torben |
875 |
|
92 |
torben |
873 |
qDebug() << "Starting timer..."; |
93 |
|
|
timer = new QTimer(this); |
94 |
|
|
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
95 |
|
|
timer->start(100); |
96 |
torben |
537 |
} |
97 |
torben |
535 |
|
98 |
torben |
638 |
void MainView::loadSettings() |
99 |
|
|
{ |
100 |
|
|
settings = new QSettings("Caddi", "infoscreen"); |
101 |
|
|
|
102 |
|
|
qDebug() << "Loading settings" << settings->fileName(); |
103 |
|
|
|
104 |
|
|
QString mode = settings->value("mode").toString().toLower(); |
105 |
|
|
if (mode == "simpleweb") { |
106 |
|
|
currentMode = ModeSimpleWeb; |
107 |
|
|
} else if (mode == "xml") { |
108 |
|
|
currentMode = ModeXml; |
109 |
|
|
} else if (mode == "local") { |
110 |
|
|
currentMode = ModeLocal; |
111 |
|
|
} else { |
112 |
|
|
currentMode = ModeNone; |
113 |
|
|
QMessageBox::warning(this, "infoscreen", "no operation mode set or mode given an invalid value"); |
114 |
|
|
exit(1); |
115 |
|
|
} |
116 |
|
|
|
117 |
torben |
876 |
enableScreenManager = settings->value("enablescreenmanager").toBool(); |
118 |
|
|
if (enableScreenManager) { |
119 |
|
|
screenManagerOn = settings->value("screenmanager_on").toTime(); |
120 |
|
|
screenManagerOff = settings->value("screenmanager_off").toTime(); |
121 |
|
|
} |
122 |
torben |
638 |
|
123 |
torben |
902 |
showClock = settings->value("showclock").toBool(); |
124 |
|
|
|
125 |
torben |
881 |
xmlInterval = settings->value("xmlinterval", 30).toInt(); |
126 |
|
|
xmlInterval = (xmlInterval * 60 * 1000); //convert to milliseconds |
127 |
torben |
875 |
|
128 |
torben |
881 |
|
129 |
torben |
638 |
if (currentMode == ModeSimpleWeb || currentMode == ModeXml) { |
130 |
|
|
url = settings->value("url").toString(); |
131 |
|
|
screenid = settings->value("screenid").toString(); |
132 |
|
|
if (url == "" || screenid == "") { |
133 |
|
|
QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); |
134 |
|
|
|
135 |
|
|
exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function |
136 |
|
|
} |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
if (currentMode == ModeLocal) { |
140 |
|
|
path = settings->value("path").toString(); |
141 |
|
|
|
142 |
|
|
if (path == "") { |
143 |
|
|
QMessageBox::warning(this,"infoscreen","Could not find path in config file " + settings->fileName()); |
144 |
|
|
exit(1); |
145 |
|
|
} |
146 |
|
|
} |
147 |
|
|
} |
148 |
|
|
|
149 |
torben |
537 |
void MainView::closeEvent ( QCloseEvent * event ) |
150 |
|
|
{ |
151 |
|
|
Q_UNUSED(event); |
152 |
|
|
exit(0); //force application shutdown |
153 |
torben |
509 |
} |
154 |
|
|
|
155 |
torben |
532 |
void MainView::keyPressEvent ( QKeyEvent* event ) |
156 |
|
|
{ |
157 |
torben |
533 |
int key = event->key(); |
158 |
|
|
if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) { |
159 |
torben |
537 |
close(); |
160 |
torben |
533 |
} |
161 |
torben |
1210 |
|
162 |
|
|
if (key == 'f' || key == 'F') { |
163 |
|
|
Qt::WindowStates current = this->windowState(); |
164 |
|
|
if (current == Qt::WindowFullScreen) { |
165 |
|
|
this->setWindowState(Qt::WindowActive); |
166 |
|
|
} else { |
167 |
|
|
this->setWindowState(Qt::WindowFullScreen); |
168 |
|
|
} |
169 |
|
|
} |
170 |
|
|
|
171 |
torben |
532 |
} |
172 |
torben |
509 |
|
173 |
|
|
void MainView::onTimer() |
174 |
|
|
{ |
175 |
torben |
875 |
if (enableScreenManager == true) { |
176 |
|
|
screenManager->timerTick(); |
177 |
|
|
} |
178 |
torben |
524 |
|
179 |
torben |
638 |
if (currentMode == ModeXml) { |
180 |
|
|
readXml(); |
181 |
|
|
} |
182 |
torben |
527 |
|
183 |
torben |
873 |
if (currentMode == ModeXml || currentMode == ModeLocal) { |
184 |
|
|
switchScreens(); |
185 |
|
|
} |
186 |
torben |
902 |
if (showClock == true) { |
187 |
|
|
clockOverlay->timerTick(); |
188 |
|
|
} |
189 |
torben |
528 |
} |
190 |
torben |
527 |
|
191 |
torben |
524 |
|
192 |
torben |
638 |
void MainView::readLocalFiles() |
193 |
|
|
{ |
194 |
|
|
QDir dir(path); |
195 |
|
|
if (! dir.exists()) { |
196 |
|
|
QMessageBox::warning(this,"infoscreen","Local Source directory not found: " + path); |
197 |
|
|
exit(1); |
198 |
|
|
} |
199 |
|
|
QFileInfoList files = dir.entryInfoList(QDir::Files, QDir::Name); //only files, sort by name |
200 |
|
|
|
201 |
|
|
for (int i=0; i<files.size(); ++i) { |
202 |
|
|
QFileInfo file = files[i]; |
203 |
|
|
qDebug() << "Found" << file.fileName(); |
204 |
|
|
|
205 |
|
|
ScreenItem item; |
206 |
|
|
item.url = file.filePath(); |
207 |
|
|
item.module = ModuleUnknown; |
208 |
|
|
|
209 |
|
|
QString ext = file.suffix().toLower(); |
210 |
torben |
708 |
if (ext == "avi" || ext == "mpg" || ext == "mpeg") { |
211 |
torben |
638 |
item.module = ModuleVideo; |
212 |
|
|
item.runtime = 1; |
213 |
|
|
} |
214 |
|
|
|
215 |
torben |
708 |
if (ext == "jpg" || ext == "jpeg" || ext == "png" ) { |
216 |
torben |
638 |
item.module = ModuleImage; |
217 |
|
|
item.runtime = 10; |
218 |
|
|
} |
219 |
|
|
|
220 |
torben |
867 |
if (ext == "svg") { |
221 |
|
|
item.module = ModuleSvg; |
222 |
|
|
item.runtime = 10; |
223 |
|
|
} |
224 |
torben |
869 |
|
225 |
|
|
if (ext == "htm" || ext == "html") { |
226 |
|
|
item.module = ModuleWeb; |
227 |
|
|
item.runtime = 10; |
228 |
|
|
} |
229 |
torben |
867 |
|
230 |
torben |
638 |
if (item.module != ModuleUnknown) { //no need to enqueue unknown modules |
231 |
|
|
screenItems.push_back( item ); |
232 |
|
|
} |
233 |
|
|
|
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
qDebug() << "Found " << screenItems.size() << " playable items"; |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
|
240 |
torben |
528 |
bool MainView::readXml() |
241 |
|
|
{ |
242 |
torben |
881 |
if ( lastXml.isNull() || lastXml.elapsed() > xmlInterval) { |
243 |
|
|
qDebug() << "Reading XML"; |
244 |
torben |
529 |
|
245 |
torben |
527 |
|
246 |
torben |
537 |
bool res = xmlHandler.readXml( xmlUrl ); |
247 |
torben |
535 |
|
248 |
torben |
528 |
lastXml = QTime::currentTime(); |
249 |
|
|
|
250 |
|
|
screenItems = xmlHandler.getScreenSet(); |
251 |
|
|
|
252 |
|
|
if ( currentItemIdx >= screenItems.size() ) |
253 |
|
|
currentItemIdx = screenItems.size()-1; //avoid overflow |
254 |
|
|
|
255 |
|
|
|
256 |
|
|
return true; |
257 |
|
|
} else { |
258 |
|
|
return false; |
259 |
torben |
524 |
} |
260 |
torben |
509 |
} |
261 |
torben |
528 |
|
262 |
|
|
void MainView::switchScreens() |
263 |
|
|
{ |
264 |
torben |
537 |
if (video->isVisible() && video->isPlaying() ) { |
265 |
|
|
return; //wait until current clip has finished |
266 |
|
|
} |
267 |
torben |
528 |
|
268 |
|
|
if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) { |
269 |
torben |
529 |
QTime now = QTime::currentTime(); |
270 |
torben |
528 |
if (lastScreenSwitch.isNull()) |
271 |
torben |
529 |
currentItemIdx = -1; |
272 |
|
|
|
273 |
|
|
bool found = false; |
274 |
|
|
int tries = 0; |
275 |
|
|
|
276 |
torben |
534 |
if (screenItems.size() > 0) { //only try if we have a any screens |
277 |
|
|
while (found == false && tries <= screenItems.size()) { //find next with valid display time |
278 |
|
|
tries++; |
279 |
|
|
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
280 |
|
|
currentItem = screenItems.at(currentItemIdx); |
281 |
torben |
529 |
|
282 |
torben |
638 |
if (currentItem.start.isValid() && currentItem.stop.isValid()) { |
283 |
|
|
if (currentItem.start <= now && now <= currentItem.stop ) |
284 |
|
|
found = true; |
285 |
|
|
} else { // if start or stop time was invalid - show them always |
286 |
torben |
534 |
found = true; |
287 |
torben |
638 |
} |
288 |
torben |
534 |
} |
289 |
torben |
529 |
} |
290 |
|
|
|
291 |
|
|
if (found) { |
292 |
torben |
867 |
switch(currentItem.module) { |
293 |
|
|
case ModuleImage: |
294 |
torben |
529 |
ensureVisible(picture); |
295 |
|
|
picture->loadFromUrl( currentItem.url ); |
296 |
torben |
867 |
break; |
297 |
|
|
case ModuleWeb: |
298 |
torben |
537 |
ensureVisible(web); |
299 |
|
|
web->load(currentItem.url); |
300 |
torben |
867 |
break; |
301 |
|
|
case ModuleVideo: |
302 |
torben |
537 |
ensureVisible(video); |
303 |
|
|
video->loadUrl(currentItem.url); |
304 |
torben |
867 |
break; |
305 |
|
|
case ModuleSvg: |
306 |
|
|
ensureVisible(svg); |
307 |
|
|
svg->load(currentItem.url); |
308 |
|
|
break; |
309 |
|
|
default: |
310 |
torben |
638 |
// ModuleUnknown - what should we do?? |
311 |
torben |
867 |
break; |
312 |
torben |
537 |
} |
313 |
torben |
529 |
|
314 |
|
|
} else { |
315 |
torben |
542 |
errorInfoScreen("Der er ingen information at vise"); |
316 |
torben |
885 |
currentItem = ScreenItem(); |
317 |
|
|
currentItem.runtime = 60; //switch screens again in 1 minute |
318 |
torben |
529 |
} |
319 |
torben |
528 |
lastScreenSwitch = QTime::currentTime(); |
320 |
torben |
529 |
|
321 |
torben |
528 |
} |
322 |
|
|
} |
323 |
torben |
529 |
|
324 |
torben |
542 |
void MainView::errorInfoScreen(QString msg) |
325 |
torben |
537 |
{ |
326 |
torben |
891 |
ensureVisible(web); |
327 |
|
|
QString html("<html><body text='#505050' bgcolor='#000000'>"); |
328 |
|
|
html.append("<table width='100%' height='100%'><tr><td align='center' valign='middel'><h1>") |
329 |
|
|
.append(msg) |
330 |
|
|
.append("</h1></td></tr></table></body></html>"); |
331 |
|
|
web->setHtml(html); |
332 |
torben |
537 |
} |
333 |
|
|
|
334 |
torben |
529 |
void MainView::ensureVisible(QWidget* widget) |
335 |
|
|
{ |
336 |
torben |
870 |
layout->setCurrentWidget(widget); |
337 |
torben |
529 |
} |