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) |
24 |
: QWidget(parent), timer(0) |
: 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 |
|
} |
|
if (url == "" || screenid == "") { |
|
|
QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); |
|
33 |
|
|
34 |
exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function |
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 ); |
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 |
if (xmlMode == true) { |
qDebug() << "Starting timer..."; |
83 |
xmlUrl = url + "?screen_id=" + screenid; |
timer = new QTimer(this); |
84 |
qDebug() << "Starting XML mode"; |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
85 |
qDebug() << "xmlUrl" << xmlUrl; |
timer->start(100); |
86 |
|
} |
87 |
|
|
88 |
timer = new QTimer(this); |
void MainView::loadSettings() |
89 |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
{ |
90 |
timer->start(100); |
settings = new QSettings("Caddi", "infoscreen"); |
91 |
} else { |
|
92 |
qDebug() << "Starting plain browser mode"; |
qDebug() << "Loading settings" << settings->fileName(); |
93 |
web->setVisible(true); |
|
94 |
web->start(url,screenid); |
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 |
|
|
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 |
readXml(); |
if (ext == "jpg" || ext == "jpeg" || ext == "png" ) { |
191 |
|
item.module = ModuleImage; |
192 |
|
item.runtime = 10; |
193 |
|
} |
194 |
|
|
195 |
switchScreens(); |
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 |
|
} |
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 |
|
|
221 |
bool res = xmlHandler.readXml( xmlUrl ); |
bool res = xmlHandler.readXml( xmlUrl ); |
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: |
|
if (currentItem.module == "info_web") { |
|
274 |
ensureVisible(web); |
ensureVisible(web); |
275 |
web->load(currentItem.url); |
web->load(currentItem.url); |
276 |
} |
break; |
277 |
if (currentItem.module == "info_video") { |
case ModuleVideo: |
278 |
ensureVisible(video); |
ensureVisible(video); |
279 |
video->loadUrl(currentItem.url); |
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 |
|
|
|
errorInfoScreen("Unknown module: " + currentItem.module ); |
|
|
|
|
290 |
} else { |
} else { |
|
qDebug() << "no screen"; |
|
291 |
errorInfoScreen("Der er ingen information at vise"); |
errorInfoScreen("Der er ingen information at vise"); |
292 |
} |
} |
293 |
lastScreenSwitch = QTime::currentTime(); |
lastScreenSwitch = QTime::currentTime(); |
306 |
|
|
307 |
void MainView::ensureVisible(QWidget* widget) |
void MainView::ensureVisible(QWidget* widget) |
308 |
{ |
{ |
309 |
if (! widget->isVisible()) { |
layout->setCurrentWidget(widget); |
|
hideAll(); |
|
|
widget->setVisible(true); |
|
|
} |
|
310 |
} |
} |
311 |
|
|
|
void MainView::hideAll() |
|
|
{ |
|
|
render->setVisible( false ); |
|
|
web->setVisible( false); |
|
|
picture->setVisible( false ); |
|
|
video->setVisible(false); |
|
|
} |
|