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