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