/[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 542 by torben, Sun Jan 10 09:12:55 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    
114          lastXml = QTime::currentTime();          lastXml = QTime::currentTime();
115    
# Line 94  bool MainView::readXml() Line 127  bool MainView::readXml()
127    
128  void MainView::switchScreens()  void MainView::switchScreens()
129  {  {
130        if (video->isVisible() && video->isPlaying() ) {
131            return; //wait until current clip has finished
132        }
133    
134      if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) {      if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) {
135    
# Line 123  void MainView::switchScreens() Line 159  void MainView::switchScreens()
159                  picture->loadFromUrl( currentItem.url );                  picture->loadFromUrl( currentItem.url );
160    
161              }              }
162                if (currentItem.module == "info_web") {
163                    ensureVisible(web);
164                    web->load(currentItem.url);
165                }
166                if (currentItem.module == "info_video") {
167                    ensureVisible(video);
168                    video->loadUrl(currentItem.url);
169                }
170    
171                errorInfoScreen("Unknown module: " + currentItem.module );
172    
173          } else {          } else {
174              qDebug() << "no screen";              qDebug() << "no screen";
175              hideAll();              errorInfoScreen("Der er ingen information at vise");
176          }          }
177          lastScreenSwitch = QTime::currentTime();          lastScreenSwitch = QTime::currentTime();
178    
179      }      }
180  }  }
181    
182    void MainView::errorInfoScreen(QString msg)
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>" + msg+ "</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.542

  ViewVC Help
Powered by ViewVC 1.1.20