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> |
18 |
#include "httpwrapper.h" |
#include "httpwrapper.h" |
19 |
|
|
20 |
|
|
21 |
|
|
22 |
MainView::MainView(QWidget* parent) |
MainView::MainView(QWidget* parent) |
23 |
: QWidget(parent), timer(0) |
: QWidget(parent), timer(0) |
24 |
{ |
{ |
25 |
|
loadSettings(); |
26 |
|
|
27 |
settings = new QSettings("Caddi", "infoscreen"); |
if ( currentMode == ModeXml) { |
28 |
url = settings->value("url").toString(); |
xmlUrl = url + "?screen_id=" + screenid; |
29 |
bool xmlMode = settings->value("xml").toBool(); |
qDebug() << "Starting XML mode"; |
30 |
screenid = settings->value("screenid").toString(); |
qDebug() << "xmlUrl" << xmlUrl; |
31 |
|
} |
|
if (url == "" || screenid == "") { |
|
|
QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); |
|
32 |
|
|
33 |
exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function |
if (currentMode == ModeSimpleWeb){ |
34 |
|
qDebug() << "Starting plain browser mode"; |
35 |
} |
} |
36 |
|
|
37 |
|
if (currentMode == ModeLocal ) { |
38 |
|
qDebug() << "Starting local mode"; |
39 |
|
qDebug() << "path" << path; |
40 |
|
|
41 |
|
readLocalFiles(); |
42 |
|
} |
43 |
|
|
44 |
this->resize(400,400); |
this->resize(400,400); |
45 |
this->setWindowState( Qt::WindowFullScreen ); |
this->setWindowState( Qt::WindowFullScreen ); |
48 |
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
49 |
|
|
50 |
render = new ClientSideRender(this); |
render = new ClientSideRender(this); |
|
render->setVisible( false ); |
|
51 |
|
|
52 |
web = new MyWebView(this); |
web = new MyWebView(this); |
|
web->setVisible( false); |
|
53 |
|
|
54 |
picture = new PictureView(this); |
picture = new PictureView(this); |
|
picture->setVisible( false ); |
|
55 |
|
|
56 |
video = new VideoView(this); |
video = new VideoView(this); |
|
video->setVisible(false); |
|
57 |
|
|
58 |
QVBoxLayout* layout = new QVBoxLayout(); |
svg = new QSvgWidget(this); |
59 |
layout->addWidget(web,1); |
|
60 |
layout->addWidget(render,1); |
layout = new QStackedLayout(); |
61 |
layout->addWidget(picture,1); |
layout->addWidget(web); |
62 |
layout->addWidget(video,1); |
layout->addWidget(render); |
63 |
layout->addStretch(); |
layout->addWidget(picture); |
64 |
|
layout->addWidget(video); |
65 |
|
layout->addWidget(svg); |
66 |
layout->setContentsMargins(0,0,0,0); |
layout->setContentsMargins(0,0,0,0); |
67 |
setLayout(layout); |
setLayout(layout); |
68 |
|
|
69 |
|
if (currentMode == ModeSimpleWeb) { |
70 |
|
web->setVisible(true); |
71 |
|
web->start(url,screenid); |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
qDebug() << "Starting timer..."; |
76 |
|
timer = new QTimer(this); |
77 |
|
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
78 |
|
timer->start(100); |
79 |
|
} |
80 |
|
|
81 |
if (xmlMode == true) { |
void MainView::loadSettings() |
82 |
xmlUrl = url + "?screen_id=" + screenid; |
{ |
83 |
qDebug() << "Starting XML mode"; |
settings = new QSettings("Caddi", "infoscreen"); |
|
qDebug() << "xmlUrl" << xmlUrl; |
|
84 |
|
|
85 |
timer = new QTimer(this); |
qDebug() << "Loading settings" << settings->fileName(); |
86 |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
|
87 |
timer->start(100); |
QString mode = settings->value("mode").toString().toLower(); |
88 |
} else { |
if (mode == "simpleweb") { |
89 |
qDebug() << "Starting plain browser mode"; |
currentMode = ModeSimpleWeb; |
90 |
web->setVisible(true); |
} else if (mode == "xml") { |
91 |
web->start(url,screenid); |
currentMode = ModeXml; |
92 |
|
} else if (mode == "local") { |
93 |
|
currentMode = ModeLocal; |
94 |
|
} else { |
95 |
|
currentMode = ModeNone; |
96 |
|
QMessageBox::warning(this, "infoscreen", "no operation mode set or mode given an invalid value"); |
97 |
|
exit(1); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
if (currentMode == ModeSimpleWeb || currentMode == ModeXml) { |
102 |
|
url = settings->value("url").toString(); |
103 |
|
screenid = settings->value("screenid").toString(); |
104 |
|
if (url == "" || screenid == "") { |
105 |
|
QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); |
106 |
|
|
107 |
|
exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function |
108 |
|
} |
109 |
|
} |
110 |
|
|
111 |
|
if (currentMode == ModeLocal) { |
112 |
|
path = settings->value("path").toString(); |
113 |
|
|
114 |
|
if (path == "") { |
115 |
|
QMessageBox::warning(this,"infoscreen","Could not find path in config file " + settings->fileName()); |
116 |
|
exit(1); |
117 |
|
} |
118 |
} |
} |
119 |
} |
} |
120 |
|
|
134 |
|
|
135 |
void MainView::onTimer() |
void MainView::onTimer() |
136 |
{ |
{ |
137 |
|
qDebug() << "onTimer()"; |
138 |
screenManager.timerTick(); |
screenManager.timerTick(); |
139 |
|
|
140 |
readXml(); |
if (currentMode == ModeXml) { |
141 |
|
readXml(); |
142 |
|
} |
143 |
|
|
144 |
|
if (currentMode == ModeXml || currentMode == ModeLocal) { |
145 |
|
switchScreens(); |
146 |
|
} |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
void MainView::readLocalFiles() |
151 |
|
{ |
152 |
|
QDir dir(path); |
153 |
|
if (! dir.exists()) { |
154 |
|
QMessageBox::warning(this,"infoscreen","Local Source directory not found: " + path); |
155 |
|
exit(1); |
156 |
|
} |
157 |
|
QFileInfoList files = dir.entryInfoList(QDir::Files, QDir::Name); //only files, sort by name |
158 |
|
|
159 |
|
for (int i=0; i<files.size(); ++i) { |
160 |
|
QFileInfo file = files[i]; |
161 |
|
qDebug() << "Found" << file.fileName(); |
162 |
|
|
163 |
|
ScreenItem item; |
164 |
|
item.url = file.filePath(); |
165 |
|
item.module = ModuleUnknown; |
166 |
|
|
167 |
|
QString ext = file.suffix().toLower(); |
168 |
|
if (ext == "avi" || ext == "mpg" || ext == "mpeg") { |
169 |
|
item.module = ModuleVideo; |
170 |
|
item.runtime = 1; |
171 |
|
} |
172 |
|
|
173 |
|
if (ext == "jpg" || ext == "jpeg" || ext == "png" ) { |
174 |
|
item.module = ModuleImage; |
175 |
|
item.runtime = 10; |
176 |
|
} |
177 |
|
|
178 |
|
if (ext == "svg") { |
179 |
|
item.module = ModuleSvg; |
180 |
|
item.runtime = 10; |
181 |
|
} |
182 |
|
|
183 |
|
if (ext == "htm" || ext == "html") { |
184 |
|
item.module = ModuleWeb; |
185 |
|
item.runtime = 10; |
186 |
|
} |
187 |
|
|
188 |
|
if (item.module != ModuleUnknown) { //no need to enqueue unknown modules |
189 |
|
screenItems.push_back( item ); |
190 |
|
} |
191 |
|
|
192 |
switchScreens(); |
} |
193 |
|
|
194 |
|
qDebug() << "Found " << screenItems.size() << " playable items"; |
195 |
} |
} |
196 |
|
|
197 |
|
|
238 |
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
239 |
currentItem = screenItems.at(currentItemIdx); |
currentItem = screenItems.at(currentItemIdx); |
240 |
|
|
241 |
if (currentItem.start <= now && now <= currentItem.stop ) |
if (currentItem.start.isValid() && currentItem.stop.isValid()) { |
242 |
|
if (currentItem.start <= now && now <= currentItem.stop ) |
243 |
|
found = true; |
244 |
|
} else { // if start or stop time was invalid - show them always |
245 |
found = true; |
found = true; |
246 |
|
} |
247 |
} |
} |
248 |
} |
} |
249 |
|
|
250 |
if (found) { |
if (found) { |
251 |
|
switch(currentItem.module) { |
252 |
if (currentItem.module == "info_image") { |
case ModuleImage: |
253 |
ensureVisible(picture); |
ensureVisible(picture); |
|
|
|
254 |
picture->loadFromUrl( currentItem.url ); |
picture->loadFromUrl( currentItem.url ); |
255 |
|
break; |
256 |
} |
case ModuleWeb: |
|
if (currentItem.module == "info_web") { |
|
257 |
ensureVisible(web); |
ensureVisible(web); |
258 |
web->load(currentItem.url); |
web->load(currentItem.url); |
259 |
} |
break; |
260 |
if (currentItem.module == "info_video") { |
case ModuleVideo: |
261 |
ensureVisible(video); |
ensureVisible(video); |
262 |
video->loadUrl(currentItem.url); |
video->loadUrl(currentItem.url); |
263 |
|
break; |
264 |
|
case ModuleSvg: |
265 |
|
ensureVisible(svg); |
266 |
|
svg->load(currentItem.url); |
267 |
|
break; |
268 |
|
default: |
269 |
|
// ModuleUnknown - what should we do?? |
270 |
|
break; |
271 |
} |
} |
272 |
|
|
|
|
|
273 |
} else { |
} else { |
274 |
qDebug() << "no screen"; |
qDebug() << "no screen"; |
275 |
noInfoScreen(); |
errorInfoScreen("Der er ingen information at vise"); |
276 |
} |
} |
277 |
lastScreenSwitch = QTime::currentTime(); |
lastScreenSwitch = QTime::currentTime(); |
278 |
|
|
279 |
} |
} |
280 |
} |
} |
281 |
|
|
282 |
void MainView::noInfoScreen() |
void MainView::errorInfoScreen(QString msg) |
283 |
{ |
{ |
284 |
ensureVisible(web); |
ensureVisible(web); |
285 |
web->setHtml("<html>\ |
web->setHtml("<html>\ |
286 |
<body text='#505050' bgcolor='#000000'>\ |
<body text='#505050' bgcolor='#000000'>\ |
287 |
<table width='100%' height='100%'><tr><td align='center' valign='middel'><h1>Der er ingen information at vise</h1></td></tr></table>\ |
<table width='100%' height='100%'><tr><td align='center' valign='middel'><h1>" + msg+ "</h1></td></tr></table>\ |
288 |
</body></html>"); |
</body></html>"); |
289 |
} |
} |
290 |
|
|
291 |
void MainView::ensureVisible(QWidget* widget) |
void MainView::ensureVisible(QWidget* widget) |
292 |
{ |
{ |
293 |
if (! widget->isVisible()) { |
layout->setCurrentWidget(widget); |
|
hideAll(); |
|
|
widget->setVisible(true); |
|
|
} |
|
294 |
} |
} |
295 |
|
|
|
void MainView::hideAll() |
|
|
{ |
|
|
render->setVisible( false ); |
|
|
web->setVisible( false); |
|
|
picture->setVisible( false ); |
|
|
video->setVisible(false); |
|
|
} |
|