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

Diff of /infoscreen/mainview.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 533 by torben, Thu Jan 7 19:31:07 2010 UTC revision 874 by torben, Tue Jun 22 20:30:17 2010 UTC
# Line 2  Line 2 
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>
10    #include <QSettings>
11    #include <QMessageBox>
12    
13  #include "MyWebView.h"  #include "MyWebView.h"
14  #include "clientsiderender.h"  #include "clientsiderender.h"
# Line 15  Line 18 
18  #include "httpwrapper.h"  #include "httpwrapper.h"
19    
20    
21    
22  MainView::MainView(QWidget* parent)  MainView::MainView(QWidget* parent)
23   : QWidget(parent)      : QWidget(parent), timer(0)
24  {  {
25          this->resize(400,400);      loadSettings();
26          this->setWindowState( Qt::WindowFullScreen );  
27                  this->grabKeyboard();      if ( currentMode == ModeXml) {
28            xmlUrl = url + "?screen_id=" + screenid;
29            qDebug() << "Starting XML mode";
30            qDebug() << "xmlUrl" << xmlUrl;
31        }
32    
33        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          qApp->setOverrideCursor( QCursor( Qt::BlankCursor) );          readLocalFiles();
42        }
43    
44          render = new ClientSideRender(this);      this->resize(400,400);
45          render->setVisible( false );      this->setWindowState( Qt::WindowFullScreen );
46        this->grabKeyboard();
47    
48          web = new MyWebView(this);      qApp->setOverrideCursor( QCursor( Qt::BlankCursor) );
         web->setVisible( false);  
49    
50          picture = new PictureView(this);      render = new ClientSideRender(this);
         picture->setVisible( false );  
51    
52          video = new VideoView(this);      web = new MyWebView(this);
         video->setVisible(false);  
53    
54          QVBoxLayout* layout = new QVBoxLayout();      picture = new PictureView(this);
         layout->addWidget(web,1);  
         layout->addWidget(render,1);  
         layout->addWidget(picture,1);  
         layout->addWidget(video,1);  
         layout->addStretch();  
         layout->setContentsMargins(0,0,0,0);  
         setLayout(layout);  
55    
56        video = new VideoView(this);
57    
58        svg = new QSvgWidget(this);
59    
60          QTimer* timer = new QTimer(this);      layout = new QStackedLayout();
61          connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() ));      layout->addWidget(web);
62          timer->start(100);      layout->addWidget(render);
63        layout->addWidget(picture);
64        layout->addWidget(video);
65        layout->addWidget(svg);
66        layout->setContentsMargins(0,0,0,0);
67        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    void MainView::loadSettings()
82    {
83        settings = new QSettings("Caddi", "infoscreen");
84    
85        qDebug() << "Loading settings" << settings->fileName();
86    
87        QString mode = settings->value("mode").toString().toLower();
88        if (mode == "simpleweb") {
89            currentMode = ModeSimpleWeb;
90        } else if (mode == "xml") {
91            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    
121    void MainView::closeEvent ( QCloseEvent * event )
122    {
123        Q_UNUSED(event);
124        exit(0); //force application shutdown
125  }  }
126    
127  void MainView::keyPressEvent ( QKeyEvent* event )  void MainView::keyPressEvent ( QKeyEvent* event )
128  {  {
129      int key = event->key();      int key = event->key();
130      if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) {      if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) {
131          qApp->quit();          close();
132      }      }
133  }    }  
134    
# Line 65  void MainView::onTimer() Line 136  void MainView::onTimer()
136  {  {
137      screenManager.timerTick();      screenManager.timerTick();
138    
139      readXml();      if (currentMode == ModeXml) {
140            readXml();
141        }
142    
143        if (currentMode == ModeXml || currentMode == ModeLocal) {
144            switchScreens();
145        }
146    }
147    
148    
149      switchScreens();  void MainView::readLocalFiles()
150    {
151        QDir dir(path);
152        if (! dir.exists()) {
153            QMessageBox::warning(this,"infoscreen","Local Source directory not found: " + path);
154            exit(1);
155        }
156        QFileInfoList files = dir.entryInfoList(QDir::Files, QDir::Name); //only files, sort by name
157    
158        for (int i=0; i<files.size(); ++i) {
159            QFileInfo file = files[i];
160            qDebug() << "Found" << file.fileName();
161    
162            ScreenItem item;
163            item.url = file.filePath();
164            item.module = ModuleUnknown;
165    
166            QString ext = file.suffix().toLower();
167            if (ext == "avi" || ext == "mpg" || ext == "mpeg") {
168                item.module = ModuleVideo;
169                item.runtime = 1;
170            }
171    
172            if (ext == "jpg" || ext == "jpeg" || ext == "png" ) {
173                item.module = ModuleImage;
174                item.runtime = 10;
175            }
176    
177            if (ext == "svg") {
178                item.module = ModuleSvg;
179                item.runtime = 10;
180            }
181            
182            if (ext == "htm" || ext == "html") {
183                item.module = ModuleWeb;
184                item.runtime = 10;
185            }
186    
187            if (item.module != ModuleUnknown) { //no need to enqueue unknown modules
188                screenItems.push_back( item );
189            }
190    
191        }
192    
193        qDebug() << "Found " << screenItems.size() << " playable items";
194  }  }
195    
196    
# Line 76  bool MainView::readXml() Line 199  bool MainView::readXml()
199      const int TIMEOUT = 30*60*1000; // 30 minutter      const int TIMEOUT = 30*60*1000; // 30 minutter
200      if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) {      if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) {
201    
202          xmlHandler.readXml( "http://infoscreen.sundhedhorsens.dk/infoscreen/screen_xml.php?screen_id=1" );  
203            bool res = xmlHandler.readXml( xmlUrl );
204    
205          lastXml = QTime::currentTime();          lastXml = QTime::currentTime();
206    
# Line 94  bool MainView::readXml() Line 218  bool MainView::readXml()
218    
219  void MainView::switchScreens()  void MainView::switchScreens()
220  {  {
221        if (video->isVisible() && video->isPlaying() ) {
222            return; //wait until current clip has finished
223        }
224    
225      if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) {      if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) {
226    
# Line 104  void MainView::switchScreens() Line 231  void MainView::switchScreens()
231          bool found = false;          bool found = false;
232          int tries = 0;          int tries = 0;
233    
234                  if (screenItems.size() > 0) { //only try if we have a any screens          if (screenItems.size() > 0) { //only try if we have a any screens
235                  while (found == false && tries <= screenItems.size()) { //find next with valid display time              while (found == false && tries <= screenItems.size()) { //find next with valid display time
236                  tries++;                  tries++;
237                  currentItemIdx = (currentItemIdx+1) % screenItems.size();                  currentItemIdx = (currentItemIdx+1) % screenItems.size();
238                  currentItem = screenItems.at(currentItemIdx);                  currentItem = screenItems.at(currentItemIdx);
239    
240                  if (currentItem.start <= now && now <= currentItem.stop )                  if (currentItem.start.isValid() && currentItem.stop.isValid()) {
241                          found = true;                      if (currentItem.start <= now && now <= currentItem.stop )
242                          }                          found = true;
243                    } else { // if start or stop time was invalid - show them always
244                        found = true;
245                    }
246                }
247          }          }
248    
249          if (found) {          if (found) {
250                switch(currentItem.module) {
251              if (currentItem.module == "info_image") {              case ModuleImage:
252                  ensureVisible(picture);                  ensureVisible(picture);
   
253                  picture->loadFromUrl( currentItem.url );                  picture->loadFromUrl( currentItem.url );
254                    break;
255                case ModuleWeb:
256                    ensureVisible(web);
257                    web->load(currentItem.url);
258                    break;
259                case ModuleVideo:
260                    ensureVisible(video);
261                    video->loadUrl(currentItem.url);
262                    break;
263                case ModuleSvg:
264                    ensureVisible(svg);
265                    svg->load(currentItem.url);
266                    break;
267                default:
268                    // ModuleUnknown - what should we do??
269                    break;
270              }              }
271    
   
272          } else {          } else {
273              qDebug() << "no screen";              qDebug() << "no screen";
274              hideAll();              errorInfoScreen("Der er ingen information at vise");
275          }          }
276          lastScreenSwitch = QTime::currentTime();          lastScreenSwitch = QTime::currentTime();
277    
278      }      }
279  }  }
280    
281  void MainView::ensureVisible(QWidget* widget)  void MainView::errorInfoScreen(QString msg)
282  {  {
283      if (! widget->isVisible()) {          ensureVisible(web);
284          hideAll();          web->setHtml("<html>\
285          widget->setVisible(true);                  <body text='#505050' bgcolor='#000000'>\
286      }          <table width='100%' height='100%'><tr><td align='center' valign='middel'><h1>" + msg+ "</h1></td></tr></table>\
287                    </body></html>");
288  }  }
289    
290  void MainView::hideAll()  void MainView::ensureVisible(QWidget* widget)
291  {  {
292      render->setVisible( false );      layout->setCurrentWidget(widget);    
     web->setVisible( false);  
     picture->setVisible( false );  
     video->setVisible(false);  
293  }  }
294    

Legend:
Removed from v.533  
changed lines
  Added in v.874

  ViewVC Help
Powered by ViewVC 1.1.20