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> |
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) |
29 |
xmlUrl = url + "?screen_id=" + screenid; |
xmlUrl = url + "?screen_id=" + screenid; |
30 |
qDebug() << "Starting XML mode"; |
qDebug() << "Starting XML mode"; |
31 |
qDebug() << "xmlUrl" << xmlUrl; |
qDebug() << "xmlUrl" << xmlUrl; |
32 |
|
qDebug() << "xmlInterval" << xmlInterval/(60*1000); |
33 |
} |
} |
34 |
|
|
35 |
if (currentMode == ModeSimpleWeb){ |
if (currentMode == ModeSimpleWeb){ |
36 |
qDebug() << "Starting plain browser mode"; |
qDebug() << "Starting plain browser mode"; |
|
web->setVisible(true); |
|
|
web->start(url,screenid); |
|
37 |
} |
} |
38 |
|
|
39 |
if (currentMode == ModeLocal ) { |
if (currentMode == ModeLocal ) { |
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 MyWebView(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 |
|
if (currentMode == ModeSimpleWeb) { |
72 |
|
web->setVisible(true); |
73 |
|
web->start(url,screenid); |
74 |
|
} |
75 |
|
|
76 |
if (currentMode == ModeXml || currentMode == ModeLocal) { |
if (enableScreenManager) { |
77 |
qDebug() << "Starting timer..."; |
screenManager = new ScreenManager(screenManagerOn, screenManagerOff); |
78 |
timer = new QTimer(this); |
} else { |
79 |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
qDebug() << "ScreenManager is disabled"; |
|
timer->start(100); |
|
80 |
} |
} |
81 |
|
|
82 |
|
|
83 |
|
qDebug() << "Starting timer..."; |
84 |
|
timer = new QTimer(this); |
85 |
|
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
86 |
|
timer->start(100); |
87 |
} |
} |
88 |
|
|
89 |
void MainView::loadSettings() |
void MainView::loadSettings() |
105 |
exit(1); |
exit(1); |
106 |
} |
} |
107 |
|
|
108 |
|
enableScreenManager = settings->value("enablescreenmanager").toBool(); |
109 |
|
if (enableScreenManager) { |
110 |
|
screenManagerOn = settings->value("screenmanager_on").toTime(); |
111 |
|
screenManagerOff = settings->value("screenmanager_off").toTime(); |
112 |
|
} |
113 |
|
|
114 |
|
xmlInterval = settings->value("xmlinterval", 30).toInt(); |
115 |
|
xmlInterval = (xmlInterval * 60 * 1000); //convert to milliseconds |
116 |
|
|
117 |
|
|
118 |
if (currentMode == ModeSimpleWeb || currentMode == ModeXml) { |
if (currentMode == ModeSimpleWeb || currentMode == ModeXml) { |
119 |
url = settings->value("url").toString(); |
url = settings->value("url").toString(); |
151 |
|
|
152 |
void MainView::onTimer() |
void MainView::onTimer() |
153 |
{ |
{ |
154 |
screenManager.timerTick(); |
if (enableScreenManager == true) { |
155 |
|
screenManager->timerTick(); |
156 |
|
} |
157 |
|
|
158 |
if (currentMode == ModeXml) { |
if (currentMode == ModeXml) { |
159 |
readXml(); |
readXml(); |
160 |
} |
} |
161 |
|
|
162 |
switchScreens(); |
if (currentMode == ModeXml || currentMode == ModeLocal) { |
163 |
|
switchScreens(); |
164 |
|
} |
165 |
} |
} |
166 |
|
|
167 |
|
|
183 |
item.module = ModuleUnknown; |
item.module = ModuleUnknown; |
184 |
|
|
185 |
QString ext = file.suffix().toLower(); |
QString ext = file.suffix().toLower(); |
186 |
if (ext == "avi") { |
if (ext == "avi" || ext == "mpg" || ext == "mpeg") { |
187 |
item.module = ModuleVideo; |
item.module = ModuleVideo; |
188 |
item.runtime = 1; |
item.runtime = 1; |
189 |
} |
} |
190 |
|
|
191 |
if (ext == "jpg" || ext == "jpeg") { |
if (ext == "jpg" || ext == "jpeg" || ext == "png" ) { |
192 |
item.module = ModuleImage; |
item.module = ModuleImage; |
193 |
item.runtime = 10; |
item.runtime = 10; |
194 |
} |
} |
195 |
|
|
196 |
|
if (ext == "svg") { |
197 |
|
item.module = ModuleSvg; |
198 |
|
item.runtime = 10; |
199 |
|
} |
200 |
|
|
201 |
|
if (ext == "htm" || ext == "html") { |
202 |
|
item.module = ModuleWeb; |
203 |
|
item.runtime = 10; |
204 |
|
} |
205 |
|
|
206 |
if (item.module != ModuleUnknown) { //no need to enqueue unknown modules |
if (item.module != ModuleUnknown) { //no need to enqueue unknown modules |
207 |
screenItems.push_back( item ); |
screenItems.push_back( item ); |
208 |
} |
} |
215 |
|
|
216 |
bool MainView::readXml() |
bool MainView::readXml() |
217 |
{ |
{ |
218 |
const int TIMEOUT = 30*60*1000; // 30 minutter |
if ( lastXml.isNull() || lastXml.elapsed() > xmlInterval) { |
219 |
if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) { |
qDebug() << "Reading XML"; |
220 |
|
|
221 |
|
|
222 |
bool res = xmlHandler.readXml( xmlUrl ); |
bool res = xmlHandler.readXml( xmlUrl ); |
266 |
} |
} |
267 |
|
|
268 |
if (found) { |
if (found) { |
269 |
|
switch(currentItem.module) { |
270 |
if (currentItem.module == ModuleImage) { |
case ModuleImage: |
271 |
ensureVisible(picture); |
ensureVisible(picture); |
|
|
|
272 |
picture->loadFromUrl( currentItem.url ); |
picture->loadFromUrl( currentItem.url ); |
273 |
|
break; |
274 |
} else if (currentItem.module == ModuleWeb) { |
case ModuleWeb: |
275 |
ensureVisible(web); |
ensureVisible(web); |
276 |
web->load(currentItem.url); |
web->load(currentItem.url); |
277 |
} else if (currentItem.module == ModuleVideo) { |
break; |
278 |
|
case ModuleVideo: |
279 |
ensureVisible(video); |
ensureVisible(video); |
280 |
video->loadUrl(currentItem.url); |
video->loadUrl(currentItem.url); |
281 |
} else { |
break; |
282 |
|
case ModuleSvg: |
283 |
|
ensureVisible(svg); |
284 |
|
svg->load(currentItem.url); |
285 |
|
break; |
286 |
|
default: |
287 |
// ModuleUnknown - what should we do?? |
// ModuleUnknown - what should we do?? |
288 |
|
break; |
289 |
} |
} |
290 |
|
|
291 |
} else { |
} else { |
|
qDebug() << "no screen"; |
|
292 |
errorInfoScreen("Der er ingen information at vise"); |
errorInfoScreen("Der er ingen information at vise"); |
293 |
} |
} |
294 |
lastScreenSwitch = QTime::currentTime(); |
lastScreenSwitch = QTime::currentTime(); |
307 |
|
|
308 |
void MainView::ensureVisible(QWidget* widget) |
void MainView::ensureVisible(QWidget* widget) |
309 |
{ |
{ |
310 |
if (! widget->isVisible()) { |
layout->setCurrentWidget(widget); |
|
hideAll(); |
|
|
widget->setVisible(true); |
|
|
} |
|
311 |
} |
} |
312 |
|
|
|
void MainView::hideAll() |
|
|
{ |
|
|
render->setVisible( false ); |
|
|
web->setVisible( false); |
|
|
picture->setVisible( false ); |
|
|
video->setVisible(false); |
|
|
} |
|