/[projects]/infoscreen/mainview.cpp
ViewVC logotype

Annotation of /infoscreen/mainview.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 870 - (hide annotations) (download)
Mon Jun 21 13:53:17 2010 UTC (13 years, 11 months ago) by torben
Original Path: infoscreen/MainView.cpp
File size: 7684 byte(s)
dont hack around vboxlayout when stackedlayout does whats needed
1 torben 509 #include "MainView.h"
2 torben 512 #include <QApplication>
3 torben 510 #include <QPushButton>
4 torben 512 #include <QLabel>
5 torben 870 #include <QStackedLayout>
6 torben 867 #include <QSvgWidget>
7 torben 509
8 torben 510 #include <QTimer>
9 torben 533 #include <QKeyEvent>
10 torben 535 #include <QSettings>
11     #include <QMessageBox>
12 torben 510
13 torben 512 #include "MyWebView.h"
14 torben 515 #include "clientsiderender.h"
15 torben 524 #include "pictureview.h"
16 torben 527 #include "videoview.h"
17 torben 511
18 torben 528 #include "httpwrapper.h"
19    
20    
21 torben 870
22 torben 509 MainView::MainView(QWidget* parent)
23 torben 537 : QWidget(parent), timer(0)
24 torben 509 {
25 torben 638 loadSettings();
26 torben 535
27 torben 638 if ( currentMode == ModeXml) {
28     xmlUrl = url + "?screen_id=" + screenid;
29     qDebug() << "Starting XML mode";
30     qDebug() << "xmlUrl" << xmlUrl;
31     }
32 torben 535
33 torben 638 if (currentMode == ModeSimpleWeb){
34     qDebug() << "Starting plain browser mode";
35     web->setVisible(true);
36     web->start(url,screenid);
37 torben 535 }
38    
39 torben 638 if (currentMode == ModeLocal ) {
40     qDebug() << "Starting local mode";
41     qDebug() << "path" << path;
42 torben 535
43 torben 638 readLocalFiles();
44     }
45 torben 535
46 torben 534 this->resize(400,400);
47     this->setWindowState( Qt::WindowFullScreen );
48     this->grabKeyboard();
49 torben 516
50 torben 534 qApp->setOverrideCursor( QCursor( Qt::BlankCursor) );
51 torben 510
52 torben 534 render = new ClientSideRender(this);
53 torben 524
54 torben 534 web = new MyWebView(this);
55 torben 511
56 torben 534 picture = new PictureView(this);
57 torben 517
58 torben 534 video = new VideoView(this);
59 torben 517
60 torben 867 svg = new QSvgWidget(this);
61    
62 torben 870 layout = new QStackedLayout();
63     layout->addWidget(web);
64     layout->addWidget(render);
65     layout->addWidget(picture);
66     layout->addWidget(video);
67     layout->addWidget(svg);
68 torben 534 layout->setContentsMargins(0,0,0,0);
69     setLayout(layout);
70 torben 510
71 torben 528
72 torben 638 if (currentMode == ModeXml || currentMode == ModeLocal) {
73     qDebug() << "Starting timer...";
74 torben 537 timer = new QTimer(this);
75 torben 535 connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() ));
76     timer->start(100);
77     }
78 torben 537 }
79 torben 535
80 torben 638 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    
120 torben 537 void MainView::closeEvent ( QCloseEvent * event )
121     {
122     Q_UNUSED(event);
123     exit(0); //force application shutdown
124 torben 509 }
125    
126 torben 532 void MainView::keyPressEvent ( QKeyEvent* event )
127     {
128 torben 533 int key = event->key();
129     if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) {
130 torben 537 close();
131 torben 533 }
132 torben 532 }
133 torben 509
134     void MainView::onTimer()
135     {
136 torben 512 screenManager.timerTick();
137 torben 524
138 torben 638 if (currentMode == ModeXml) {
139     readXml();
140     }
141 torben 527
142 torben 528 switchScreens();
143     }
144 torben 527
145 torben 524
146 torben 638 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 torben 708 if (ext == "avi" || ext == "mpg" || ext == "mpeg") {
165 torben 638 item.module = ModuleVideo;
166     item.runtime = 1;
167     }
168    
169 torben 708 if (ext == "jpg" || ext == "jpeg" || ext == "png" ) {
170 torben 638 item.module = ModuleImage;
171     item.runtime = 10;
172     }
173    
174 torben 867 if (ext == "svg") {
175     item.module = ModuleSvg;
176     item.runtime = 10;
177     }
178 torben 869
179     if (ext == "htm" || ext == "html") {
180     item.module = ModuleWeb;
181     item.runtime = 10;
182     }
183 torben 867
184 torben 638 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 torben 528 bool MainView::readXml()
195     {
196     const int TIMEOUT = 30*60*1000; // 30 minutter
197     if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) {
198 torben 529
199 torben 527
200 torben 537 bool res = xmlHandler.readXml( xmlUrl );
201 torben 535
202 torben 528 lastXml = QTime::currentTime();
203    
204     screenItems = xmlHandler.getScreenSet();
205    
206     if ( currentItemIdx >= screenItems.size() )
207     currentItemIdx = screenItems.size()-1; //avoid overflow
208    
209    
210     return true;
211     } else {
212     return false;
213 torben 524 }
214 torben 509 }
215 torben 528
216     void MainView::switchScreens()
217     {
218 torben 537 if (video->isVisible() && video->isPlaying() ) {
219     return; //wait until current clip has finished
220     }
221 torben 528
222     if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) {
223    
224 torben 529 QTime now = QTime::currentTime();
225 torben 528 if (lastScreenSwitch.isNull())
226 torben 529 currentItemIdx = -1;
227    
228     bool found = false;
229     int tries = 0;
230    
231 torben 534 if (screenItems.size() > 0) { //only try if we have a any screens
232     while (found == false && tries <= screenItems.size()) { //find next with valid display time
233     tries++;
234     currentItemIdx = (currentItemIdx+1) % screenItems.size();
235     currentItem = screenItems.at(currentItemIdx);
236 torben 529
237 torben 638 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 torben 534 found = true;
242 torben 638 }
243 torben 534 }
244 torben 529 }
245    
246     if (found) {
247 torben 867 switch(currentItem.module) {
248     case ModuleImage:
249 torben 529 ensureVisible(picture);
250     picture->loadFromUrl( currentItem.url );
251 torben 867 break;
252     case ModuleWeb:
253 torben 537 ensureVisible(web);
254     web->load(currentItem.url);
255 torben 867 break;
256     case ModuleVideo:
257 torben 537 ensureVisible(video);
258     video->loadUrl(currentItem.url);
259 torben 867 break;
260     case ModuleSvg:
261     ensureVisible(svg);
262     svg->load(currentItem.url);
263     break;
264     default:
265 torben 638 // ModuleUnknown - what should we do??
266 torben 867 break;
267 torben 537 }
268 torben 529
269     } else {
270     qDebug() << "no screen";
271 torben 542 errorInfoScreen("Der er ingen information at vise");
272 torben 529 }
273 torben 528 lastScreenSwitch = QTime::currentTime();
274 torben 529
275 torben 528 }
276     }
277 torben 529
278 torben 542 void MainView::errorInfoScreen(QString msg)
279 torben 537 {
280     ensureVisible(web);
281     web->setHtml("<html>\
282     <body text='#505050' bgcolor='#000000'>\
283 torben 542 <table width='100%' height='100%'><tr><td align='center' valign='middel'><h1>" + msg+ "</h1></td></tr></table>\
284 torben 537 </body></html>");
285     }
286    
287 torben 529 void MainView::ensureVisible(QWidget* widget)
288     {
289 torben 870 layout->setCurrentWidget(widget);
290 torben 529 }

  ViewVC Help
Powered by ViewVC 1.1.20