20 |
MainView::MainView(QWidget* parent) |
MainView::MainView(QWidget* parent) |
21 |
: QWidget(parent), timer(0) |
: QWidget(parent), timer(0) |
22 |
{ |
{ |
23 |
|
loadSettings(); |
24 |
|
|
25 |
settings = new QSettings("Caddi", "infoscreen"); |
if ( currentMode == ModeXml) { |
26 |
url = settings->value("url").toString(); |
xmlUrl = url + "?screen_id=" + screenid; |
27 |
bool xmlMode = settings->value("xml").toBool(); |
qDebug() << "Starting XML mode"; |
28 |
screenid = settings->value("screenid").toString(); |
qDebug() << "xmlUrl" << xmlUrl; |
29 |
|
} |
|
if (url == "" || screenid == "") { |
|
|
QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); |
|
30 |
|
|
31 |
exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function |
if (currentMode == ModeSimpleWeb){ |
32 |
|
qDebug() << "Starting plain browser mode"; |
33 |
|
web->setVisible(true); |
34 |
|
web->start(url,screenid); |
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 ); |
69 |
setLayout(layout); |
setLayout(layout); |
70 |
|
|
71 |
|
|
72 |
|
if (currentMode == ModeXml || currentMode == ModeLocal) { |
73 |
|
qDebug() << "Starting timer..."; |
|
if (xmlMode == true) { |
|
|
xmlUrl = url + "?screen_id=" + screenid; |
|
|
qDebug() << "Starting XML mode"; |
|
|
qDebug() << "xmlUrl" << xmlUrl; |
|
|
|
|
74 |
timer = new QTimer(this); |
timer = new QTimer(this); |
75 |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
76 |
timer->start(100); |
timer->start(100); |
77 |
} else { |
} |
78 |
qDebug() << "Starting plain browser mode"; |
} |
79 |
web->setVisible(true); |
|
80 |
web->start(url,screenid); |
void MainView::loadSettings() |
81 |
|
{ |
82 |
|
settings = new QSettings("Caddi", "infoscreen"); |
83 |
|
|
84 |
|
qDebug() << "Loading settings" << settings->fileName(); |
85 |
|
|
86 |
|
QString mode = settings->value("mode").toString().toLower(); |
87 |
|
if (mode == "simpleweb") { |
88 |
|
currentMode = ModeSimpleWeb; |
89 |
|
} else if (mode == "xml") { |
90 |
|
currentMode = ModeXml; |
91 |
|
} else if (mode == "local") { |
92 |
|
currentMode = ModeLocal; |
93 |
|
} else { |
94 |
|
currentMode = ModeNone; |
95 |
|
QMessageBox::warning(this, "infoscreen", "no operation mode set or mode given an invalid value"); |
96 |
|
exit(1); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
if (currentMode == ModeSimpleWeb || currentMode == ModeXml) { |
101 |
|
url = settings->value("url").toString(); |
102 |
|
screenid = settings->value("screenid").toString(); |
103 |
|
if (url == "" || screenid == "") { |
104 |
|
QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); |
105 |
|
|
106 |
|
exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
|
if (currentMode == ModeLocal) { |
111 |
|
path = settings->value("path").toString(); |
112 |
|
|
113 |
|
if (path == "") { |
114 |
|
QMessageBox::warning(this,"infoscreen","Could not find path in config file " + settings->fileName()); |
115 |
|
exit(1); |
116 |
|
} |
117 |
} |
} |
118 |
} |
} |
119 |
|
|
135 |
{ |
{ |
136 |
screenManager.timerTick(); |
screenManager.timerTick(); |
137 |
|
|
138 |
readXml(); |
if (currentMode == ModeXml) { |
139 |
|
readXml(); |
140 |
|
} |
141 |
|
|
142 |
switchScreens(); |
switchScreens(); |
143 |
} |
} |
144 |
|
|
145 |
|
|
146 |
|
void MainView::readLocalFiles() |
147 |
|
{ |
148 |
|
QDir dir(path); |
149 |
|
if (! dir.exists()) { |
150 |
|
QMessageBox::warning(this,"infoscreen","Local Source directory not found: " + path); |
151 |
|
exit(1); |
152 |
|
} |
153 |
|
QFileInfoList files = dir.entryInfoList(QDir::Files, QDir::Name); //only files, sort by name |
154 |
|
|
155 |
|
for (int i=0; i<files.size(); ++i) { |
156 |
|
QFileInfo file = files[i]; |
157 |
|
qDebug() << "Found" << file.fileName(); |
158 |
|
|
159 |
|
ScreenItem item; |
160 |
|
item.url = file.filePath(); |
161 |
|
item.module = ModuleUnknown; |
162 |
|
|
163 |
|
QString ext = file.suffix().toLower(); |
164 |
|
if (ext == "avi") { |
165 |
|
item.module = ModuleVideo; |
166 |
|
item.runtime = 1; |
167 |
|
} |
168 |
|
|
169 |
|
if (ext == "jpg" || ext == "jpeg") { |
170 |
|
item.module = ModuleImage; |
171 |
|
item.runtime = 10; |
172 |
|
} |
173 |
|
|
174 |
|
if (item.module != ModuleUnknown) { //no need to enqueue unknown modules |
175 |
|
screenItems.push_back( item ); |
176 |
|
} |
177 |
|
|
178 |
|
} |
179 |
|
|
180 |
|
qDebug() << "Found " << screenItems.size() << " playable items"; |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
bool MainView::readXml() |
bool MainView::readXml() |
185 |
{ |
{ |
186 |
const int TIMEOUT = 30*60*1000; // 30 minutter |
const int TIMEOUT = 30*60*1000; // 30 minutter |
224 |
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
225 |
currentItem = screenItems.at(currentItemIdx); |
currentItem = screenItems.at(currentItemIdx); |
226 |
|
|
227 |
if (currentItem.start <= now && now <= currentItem.stop ) |
if (currentItem.start.isValid() && currentItem.stop.isValid()) { |
228 |
|
if (currentItem.start <= now && now <= currentItem.stop ) |
229 |
|
found = true; |
230 |
|
} else { // if start or stop time was invalid - show them always |
231 |
found = true; |
found = true; |
232 |
|
} |
233 |
} |
} |
234 |
} |
} |
235 |
|
|
236 |
if (found) { |
if (found) { |
237 |
|
|
238 |
if (currentItem.module == "info_image") { |
if (currentItem.module == ModuleImage) { |
239 |
ensureVisible(picture); |
ensureVisible(picture); |
240 |
|
|
241 |
picture->loadFromUrl( currentItem.url ); |
picture->loadFromUrl( currentItem.url ); |
242 |
|
|
243 |
} |
} else if (currentItem.module == ModuleWeb) { |
|
if (currentItem.module == "info_web") { |
|
244 |
ensureVisible(web); |
ensureVisible(web); |
245 |
web->load(currentItem.url); |
web->load(currentItem.url); |
246 |
} |
} else if (currentItem.module == ModuleVideo) { |
|
if (currentItem.module == "info_video") { |
|
247 |
ensureVisible(video); |
ensureVisible(video); |
248 |
video->loadUrl(currentItem.url); |
video->loadUrl(currentItem.url); |
249 |
|
} else { |
250 |
|
// ModuleUnknown - what should we do?? |
251 |
} |
} |
252 |
|
|
|
errorInfoScreen("Unknown module: " + currentItem.module ); |
|
|
|
|
253 |
} else { |
} else { |
254 |
qDebug() << "no screen"; |
qDebug() << "no screen"; |
255 |
errorInfoScreen("Der er ingen information at vise"); |
errorInfoScreen("Der er ingen information at vise"); |