3 |
#include <QPushButton> |
#include <QPushButton> |
4 |
#include <QLabel> |
#include <QLabel> |
5 |
#include <QVBoxLayout> |
#include <QVBoxLayout> |
6 |
|
#include <QSvgWidget> |
7 |
|
|
8 |
#include <QTimer> |
#include <QTimer> |
9 |
#include <QKeyEvent> |
#include <QKeyEvent> |
21 |
MainView::MainView(QWidget* parent) |
MainView::MainView(QWidget* parent) |
22 |
: QWidget(parent), timer(0) |
: QWidget(parent), timer(0) |
23 |
{ |
{ |
24 |
|
loadSettings(); |
25 |
|
|
26 |
settings = new QSettings("Caddi", "infoscreen"); |
if ( currentMode == ModeXml) { |
27 |
url = settings->value("url").toString(); |
xmlUrl = url + "?screen_id=" + screenid; |
28 |
bool xmlMode = settings->value("xml").toBool(); |
qDebug() << "Starting XML mode"; |
29 |
screenid = settings->value("screenid").toString(); |
qDebug() << "xmlUrl" << xmlUrl; |
30 |
|
} |
|
if (url == "" || screenid == "") { |
|
|
QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); |
|
31 |
|
|
32 |
exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function |
if (currentMode == ModeSimpleWeb){ |
33 |
|
qDebug() << "Starting plain browser mode"; |
34 |
|
web->setVisible(true); |
35 |
|
web->start(url,screenid); |
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 ); |
60 |
video = new VideoView(this); |
video = new VideoView(this); |
61 |
video->setVisible(false); |
video->setVisible(false); |
62 |
|
|
63 |
|
svg = new QSvgWidget(this); |
64 |
|
svg->setVisible(false); |
65 |
|
|
66 |
QVBoxLayout* layout = new QVBoxLayout(); |
QVBoxLayout* layout = new QVBoxLayout(); |
67 |
layout->addWidget(web,1); |
layout->addWidget(web,1); |
68 |
layout->addWidget(render,1); |
layout->addWidget(render,1); |
69 |
layout->addWidget(picture,1); |
layout->addWidget(picture,1); |
70 |
layout->addWidget(video,1); |
layout->addWidget(video,1); |
71 |
|
layout->addWidget(svg,1); |
72 |
layout->addStretch(); |
layout->addStretch(); |
73 |
layout->setContentsMargins(0,0,0,0); |
layout->setContentsMargins(0,0,0,0); |
74 |
setLayout(layout); |
setLayout(layout); |
75 |
|
|
76 |
|
|
77 |
|
if (currentMode == ModeXml || currentMode == ModeLocal) { |
78 |
|
qDebug() << "Starting timer..."; |
|
if (xmlMode == true) { |
|
|
xmlUrl = url + "?screen_id=" + screenid; |
|
|
qDebug() << "Starting XML mode"; |
|
|
qDebug() << "xmlUrl" << xmlUrl; |
|
|
|
|
79 |
timer = new QTimer(this); |
timer = new QTimer(this); |
80 |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
81 |
timer->start(100); |
timer->start(100); |
82 |
} else { |
} |
83 |
qDebug() << "Starting plain browser mode"; |
} |
84 |
web->setVisible(true); |
|
85 |
web->start(url,screenid); |
void MainView::loadSettings() |
86 |
|
{ |
87 |
|
settings = new QSettings("Caddi", "infoscreen"); |
88 |
|
|
89 |
|
qDebug() << "Loading settings" << settings->fileName(); |
90 |
|
|
91 |
|
QString mode = settings->value("mode").toString().toLower(); |
92 |
|
if (mode == "simpleweb") { |
93 |
|
currentMode = ModeSimpleWeb; |
94 |
|
} else if (mode == "xml") { |
95 |
|
currentMode = ModeXml; |
96 |
|
} else if (mode == "local") { |
97 |
|
currentMode = ModeLocal; |
98 |
|
} else { |
99 |
|
currentMode = ModeNone; |
100 |
|
QMessageBox::warning(this, "infoscreen", "no operation mode set or mode given an invalid value"); |
101 |
|
exit(1); |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
|
if (currentMode == ModeSimpleWeb || currentMode == ModeXml) { |
106 |
|
url = settings->value("url").toString(); |
107 |
|
screenid = settings->value("screenid").toString(); |
108 |
|
if (url == "" || screenid == "") { |
109 |
|
QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); |
110 |
|
|
111 |
|
exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function |
112 |
|
} |
113 |
|
} |
114 |
|
|
115 |
|
if (currentMode == ModeLocal) { |
116 |
|
path = settings->value("path").toString(); |
117 |
|
|
118 |
|
if (path == "") { |
119 |
|
QMessageBox::warning(this,"infoscreen","Could not find path in config file " + settings->fileName()); |
120 |
|
exit(1); |
121 |
|
} |
122 |
} |
} |
123 |
} |
} |
124 |
|
|
140 |
{ |
{ |
141 |
screenManager.timerTick(); |
screenManager.timerTick(); |
142 |
|
|
143 |
readXml(); |
if (currentMode == ModeXml) { |
144 |
|
readXml(); |
145 |
|
} |
146 |
|
|
147 |
switchScreens(); |
switchScreens(); |
148 |
} |
} |
149 |
|
|
150 |
|
|
151 |
|
void MainView::readLocalFiles() |
152 |
|
{ |
153 |
|
QDir dir(path); |
154 |
|
if (! dir.exists()) { |
155 |
|
QMessageBox::warning(this,"infoscreen","Local Source directory not found: " + path); |
156 |
|
exit(1); |
157 |
|
} |
158 |
|
QFileInfoList files = dir.entryInfoList(QDir::Files, QDir::Name); //only files, sort by name |
159 |
|
|
160 |
|
for (int i=0; i<files.size(); ++i) { |
161 |
|
QFileInfo file = files[i]; |
162 |
|
qDebug() << "Found" << file.fileName(); |
163 |
|
|
164 |
|
ScreenItem item; |
165 |
|
item.url = file.filePath(); |
166 |
|
item.module = ModuleUnknown; |
167 |
|
|
168 |
|
QString ext = file.suffix().toLower(); |
169 |
|
if (ext == "avi" || ext == "mpg" || ext == "mpeg") { |
170 |
|
item.module = ModuleVideo; |
171 |
|
item.runtime = 1; |
172 |
|
} |
173 |
|
|
174 |
|
if (ext == "jpg" || ext == "jpeg" || ext == "png" ) { |
175 |
|
item.module = ModuleImage; |
176 |
|
item.runtime = 10; |
177 |
|
} |
178 |
|
|
179 |
|
if (ext == "svg") { |
180 |
|
item.module = ModuleSvg; |
181 |
|
item.runtime = 10; |
182 |
|
} |
183 |
|
|
184 |
|
if (item.module != ModuleUnknown) { //no need to enqueue unknown modules |
185 |
|
screenItems.push_back( item ); |
186 |
|
} |
187 |
|
|
188 |
|
} |
189 |
|
|
190 |
|
qDebug() << "Found " << screenItems.size() << " playable items"; |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
bool MainView::readXml() |
bool MainView::readXml() |
195 |
{ |
{ |
196 |
const int TIMEOUT = 30*60*1000; // 30 minutter |
const int TIMEOUT = 30*60*1000; // 30 minutter |
234 |
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
235 |
currentItem = screenItems.at(currentItemIdx); |
currentItem = screenItems.at(currentItemIdx); |
236 |
|
|
237 |
if (currentItem.start <= now && now <= currentItem.stop ) |
if (currentItem.start.isValid() && currentItem.stop.isValid()) { |
238 |
|
if (currentItem.start <= now && now <= currentItem.stop ) |
239 |
|
found = true; |
240 |
|
} else { // if start or stop time was invalid - show them always |
241 |
found = true; |
found = true; |
242 |
|
} |
243 |
} |
} |
244 |
} |
} |
245 |
|
|
246 |
if (found) { |
if (found) { |
247 |
|
switch(currentItem.module) { |
248 |
if (currentItem.module == "info_image") { |
case ModuleImage: |
249 |
ensureVisible(picture); |
ensureVisible(picture); |
|
|
|
250 |
picture->loadFromUrl( currentItem.url ); |
picture->loadFromUrl( currentItem.url ); |
251 |
|
break; |
252 |
} |
case ModuleWeb: |
|
if (currentItem.module == "info_web") { |
|
253 |
ensureVisible(web); |
ensureVisible(web); |
254 |
web->load(currentItem.url); |
web->load(currentItem.url); |
255 |
} |
break; |
256 |
if (currentItem.module == "info_video") { |
case ModuleVideo: |
257 |
ensureVisible(video); |
ensureVisible(video); |
258 |
video->loadUrl(currentItem.url); |
video->loadUrl(currentItem.url); |
259 |
|
break; |
260 |
|
case ModuleSvg: |
261 |
|
ensureVisible(svg); |
262 |
|
svg->load(currentItem.url); |
263 |
|
break; |
264 |
|
default: |
265 |
|
// ModuleUnknown - what should we do?? |
266 |
|
break; |
267 |
} |
} |
268 |
|
|
|
errorInfoScreen("Unknown module: " + currentItem.module ); |
|
|
|
|
269 |
} else { |
} else { |
270 |
qDebug() << "no screen"; |
qDebug() << "no screen"; |
271 |
errorInfoScreen("Der er ingen information at vise"); |
errorInfoScreen("Der er ingen information at vise"); |
298 |
web->setVisible( false); |
web->setVisible( false); |
299 |
picture->setVisible( false ); |
picture->setVisible( false ); |
300 |
video->setVisible(false); |
video->setVisible(false); |
301 |
|
svg->setVisible(false); |
302 |
} |
} |