/[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 537 by torben, Fri Jan 8 21:53:23 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    
24        settings = new QSettings("Caddi", "infoscreen");
25        url = settings->value("url").toString();
26        bool xmlMode = settings->value("xml").toBool();
27        screenid = settings->value("screenid").toString();
28    
29        if (url == "" || screenid == "") {
30            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
33        }
34    
35    
36    
37      this->resize(400,400);      this->resize(400,400);
38      this->setWindowState( Qt::WindowFullScreen );      this->setWindowState( Qt::WindowFullScreen );
39      this->grabKeyboard();      this->grabKeyboard();
# Line 47  MainView::MainView(QWidget* parent) Line 63  MainView::MainView(QWidget* parent)
63    
64    
65    
     QTimer* timer = new QTimer(this);  
     connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() ));  
     timer->start(100);  
66    
67        if (xmlMode == true) {
68            xmlUrl = url + "?screen_id=" + screenid;
69            qDebug() << "Starting XML mode";
70            qDebug() << "xmlUrl" << xmlUrl;
71    
72            timer = new QTimer(this);
73            connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() ));
74            timer->start(100);
75        } else {
76            qDebug() << "Starting plain browser mode";
77            web->setVisible(true);
78            web->start(url,screenid);
79        }
80    }
81    
82    void MainView::closeEvent ( QCloseEvent * event )
83    {
84        Q_UNUSED(event);
85        exit(0); //force application shutdown
86  }  }
87    
88  void MainView::keyPressEvent ( QKeyEvent* event )  void MainView::keyPressEvent ( QKeyEvent* event )
89  {  {
90      int key = event->key();      int key = event->key();
91      if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) {      if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) {
92          qApp->quit();          close();
93      }      }
94  }    }  
95    
# Line 76  bool MainView::readXml() Line 108  bool MainView::readXml()
108      const int TIMEOUT = 30*60*1000; // 30 minutter      const int TIMEOUT = 30*60*1000; // 30 minutter
109      if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) {      if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) {
110    
111          xmlHandler.readXml( "http://infoscreen.sundhedhorsens.dk/infoscreen/screen_xml.php?screen_id=1" );  
112            bool res = xmlHandler.readXml( xmlUrl );
113                    if (res == false)
114    
115          lastXml = QTime::currentTime();          lastXml = QTime::currentTime();
116    
# Line 94  bool MainView::readXml() Line 128  bool MainView::readXml()
128    
129  void MainView::switchScreens()  void MainView::switchScreens()
130  {  {
131        if (video->isVisible() && video->isPlaying() ) {
132            return; //wait until current clip has finished
133        }
134    
135      if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) {      if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) {
136    
# Line 123  void MainView::switchScreens() Line 160  void MainView::switchScreens()
160                  picture->loadFromUrl( currentItem.url );                  picture->loadFromUrl( currentItem.url );
161    
162              }              }
163                if (currentItem.module == "info_web") {
164                    ensureVisible(web);
165                    web->load(currentItem.url);
166                }
167                if (currentItem.module == "info_video") {
168                    ensureVisible(video);
169                    video->loadUrl(currentItem.url);
170                }
171    
172    
173          } else {          } else {
174              qDebug() << "no screen";              qDebug() << "no screen";
175              hideAll();                          noInfoScreen();
176          }          }
177          lastScreenSwitch = QTime::currentTime();          lastScreenSwitch = QTime::currentTime();
178    
179      }      }
180  }  }
181    
182    void MainView::noInfoScreen()
183    {
184            ensureVisible(web);
185            web->setHtml("<html>\
186                    <body text='#505050' bgcolor='#000000'>\
187                    <table width='100%' height='100%'><tr><td align='center' valign='middel'><h1>Der er ingen information at vise</h1></td></tr></table>\
188                    </body></html>");
189    }
190    
191  void MainView::ensureVisible(QWidget* widget)  void MainView::ensureVisible(QWidget* widget)
192  {  {
193      if (! widget->isVisible()) {      if (! widget->isVisible()) {

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

  ViewVC Help
Powered by ViewVC 1.1.20