--- infoscreen/MainView.cpp 2010/01/05 20:14:22 527 +++ infoscreen/MainView.cpp 2010/01/07 19:31:07 533 @@ -5,17 +5,22 @@ #include #include +#include #include "MyWebView.h" #include "clientsiderender.h" #include "pictureview.h" #include "videoview.h" +#include "httpwrapper.h" + + MainView::MainView(QWidget* parent) : QWidget(parent) { this->resize(400,400); this->setWindowState( Qt::WindowFullScreen ); + this->grabKeyboard(); qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); @@ -26,7 +31,7 @@ web->setVisible( false); picture = new PictureView(this); - picture->setVisible( true ); + picture->setVisible( false ); video = new VideoView(this); video->setVisible(false); @@ -40,32 +45,107 @@ layout->setContentsMargins(0,0,0,0); setLayout(layout); + + QTimer* timer = new QTimer(this); connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); - timer->start(1000); + timer->start(100); - web->start(); } +void MainView::keyPressEvent ( QKeyEvent* event ) +{ + int key = event->key(); + if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) { + qApp->quit(); + } +} void MainView::onTimer() { - static int count = 0; screenManager.timerTick(); - //if (count == 0) - // video->loadUrl(""); + readXml(); + + switchScreens(); +} + + +bool MainView::readXml() +{ + const int TIMEOUT = 30*60*1000; // 30 minutter + if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) { + + xmlHandler.readXml( "http://infoscreen.sundhedhorsens.dk/infoscreen/screen_xml.php?screen_id=1" ); + + lastXml = QTime::currentTime(); + + screenItems = xmlHandler.getScreenSet(); + + if ( currentItemIdx >= screenItems.size() ) + currentItemIdx = screenItems.size()-1; //avoid overflow + + + return true; + } else { + return false; + } +} + +void MainView::switchScreens() +{ + + if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) { + + QTime now = QTime::currentTime(); + if (lastScreenSwitch.isNull()) + currentItemIdx = -1; + + bool found = false; + int tries = 0; + + if (screenItems.size() > 0) { //only try if we have a any screens + while (found == false && tries <= screenItems.size()) { //find next with valid display time + tries++; + currentItemIdx = (currentItemIdx+1) % screenItems.size(); + currentItem = screenItems.at(currentItemIdx); + + if (currentItem.start <= now && now <= currentItem.stop ) + found = true; + } + } + + if (found) { + + if (currentItem.module == "info_image") { + ensureVisible(picture); + picture->loadFromUrl( currentItem.url ); - if ( (count%10) == 0) { + } - int t = count / 10; - if ( (t%2) == 0) { - picture->loadFromUrl("http://87.104.25.138/infoscreens/data/images/image1.jpg"); } else { - picture->loadFromUrl("http://87.104.25.138/infoscreens/data/images/image2.jpg"); + qDebug() << "no screen"; + hideAll(); } + lastScreenSwitch = QTime::currentTime(); + + } +} + +void MainView::ensureVisible(QWidget* widget) +{ + if (! widget->isVisible()) { + hideAll(); + widget->setVisible(true); } - count++; +} + +void MainView::hideAll() +{ + render->setVisible( false ); + web->setVisible( false); + picture->setVisible( false ); + video->setVisible(false); }