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

Diff of /infoscreen/mainview.cpp

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

revision 534 by torben, Thu Jan 7 19:42:12 2010 UTC revision 708 by torben, Wed May 5 08:43:40 2010 UTC
# Line 6  Line 6 
6    
7  #include <QTimer>  #include <QTimer>
8  #include <QKeyEvent>  #include <QKeyEvent>
9    #include <QSettings>
10    #include <QMessageBox>
11    
12  #include "MyWebView.h"  #include "MyWebView.h"
13  #include "clientsiderender.h"  #include "clientsiderender.h"
# Line 16  Line 18 
18    
19    
20  MainView::MainView(QWidget* parent)  MainView::MainView(QWidget* parent)
21      : QWidget(parent)      : QWidget(parent), timer(0)
22  {  {
23        loadSettings();
24    
25        if ( currentMode == ModeXml) {
26            xmlUrl = url + "?screen_id=" + screenid;
27            qDebug() << "Starting XML mode";
28            qDebug() << "xmlUrl" << xmlUrl;
29        }
30    
31        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 );
46      this->grabKeyboard();      this->grabKeyboard();
# Line 46  MainView::MainView(QWidget* parent) Line 69  MainView::MainView(QWidget* parent)
69      setLayout(layout);      setLayout(layout);
70    
71    
72        if (currentMode == ModeXml || currentMode == ModeLocal) {
73            qDebug() << "Starting timer...";
74            timer = new QTimer(this);
75            connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() ));
76            timer->start(100);
77        }
78    }
79    
80    void MainView::loadSettings()
81    {
82        settings = new QSettings("Caddi", "infoscreen");
83    
84      QTimer* timer = new QTimer(this);      qDebug() << "Loading settings" << settings->fileName();
85      connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() ));  
86      timer->start(100);      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    void MainView::closeEvent ( QCloseEvent * event )
121    {
122        Q_UNUSED(event);
123        exit(0); //force application shutdown
124  }  }
125    
126  void MainView::keyPressEvent ( QKeyEvent* event )  void MainView::keyPressEvent ( QKeyEvent* event )
127  {  {
128      int key = event->key();      int key = event->key();
129      if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) {      if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) {
130          qApp->quit();          close();
131      }      }
132  }    }  
133    
# Line 65  void MainView::onTimer() Line 135  void MainView::onTimer()
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" || ext == "mpg" || ext == "mpeg") {
165                item.module = ModuleVideo;
166                item.runtime = 1;
167            }
168    
169            if (ext == "jpg" || ext == "jpeg" || ext == "png" ) {
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
187      if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) {      if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) {
188    
189          xmlHandler.readXml( "http://infoscreen.sundhedhorsens.dk/infoscreen/screen_xml.php?screen_id=1" );  
190            bool res = xmlHandler.readXml( xmlUrl );
191    
192          lastXml = QTime::currentTime();          lastXml = QTime::currentTime();
193    
# Line 94  bool MainView::readXml() Line 205  bool MainView::readXml()
205    
206  void MainView::switchScreens()  void MainView::switchScreens()
207  {  {
208        if (video->isVisible() && video->isPlaying() ) {
209            return; //wait until current clip has finished
210        }
211    
212      if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) {      if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) {
213    
# Line 110  void MainView::switchScreens() Line 224  void MainView::switchScreens()
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) {
244                    ensureVisible(web);
245                    web->load(currentItem.url);
246                } else if (currentItem.module == ModuleVideo) {
247                    ensureVisible(video);
248                    video->loadUrl(currentItem.url);
249                } else {
250                    // ModuleUnknown - what should we do??
251              }              }
252    
   
253          } else {          } else {
254              qDebug() << "no screen";              qDebug() << "no screen";
255              hideAll();              errorInfoScreen("Der er ingen information at vise");
256          }          }
257          lastScreenSwitch = QTime::currentTime();          lastScreenSwitch = QTime::currentTime();
258    
259      }      }
260  }  }
261    
262    void MainView::errorInfoScreen(QString msg)
263    {
264            ensureVisible(web);
265            web->setHtml("<html>\
266                    <body text='#505050' bgcolor='#000000'>\
267            <table width='100%' height='100%'><tr><td align='center' valign='middel'><h1>" + msg+ "</h1></td></tr></table>\
268                    </body></html>");
269    }
270    
271  void MainView::ensureVisible(QWidget* widget)  void MainView::ensureVisible(QWidget* widget)
272  {  {
273      if (! widget->isVisible()) {      if (! widget->isVisible()) {

Legend:
Removed from v.534  
changed lines
  Added in v.708

  ViewVC Help
Powered by ViewVC 1.1.20