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