--- infoscreen/MainView.cpp 2010/01/07 19:42:12 534 +++ infoscreen/MainView.cpp 2010/06/21 12:23:07 867 @@ -3,9 +3,12 @@ #include #include #include +#include #include #include +#include +#include #include "MyWebView.h" #include "clientsiderender.h" @@ -16,8 +19,29 @@ MainView::MainView(QWidget* parent) - : QWidget(parent) + : QWidget(parent), timer(0) { + loadSettings(); + + if ( currentMode == ModeXml) { + xmlUrl = url + "?screen_id=" + screenid; + qDebug() << "Starting XML mode"; + qDebug() << "xmlUrl" << xmlUrl; + } + + if (currentMode == ModeSimpleWeb){ + qDebug() << "Starting plain browser mode"; + web->setVisible(true); + web->start(url,screenid); + } + + if (currentMode == ModeLocal ) { + qDebug() << "Starting local mode"; + qDebug() << "path" << path; + + readLocalFiles(); + } + this->resize(400,400); this->setWindowState( Qt::WindowFullScreen ); this->grabKeyboard(); @@ -36,28 +60,79 @@ video = new VideoView(this); video->setVisible(false); + svg = new QSvgWidget(this); + svg->setVisible(false); + QVBoxLayout* layout = new QVBoxLayout(); layout->addWidget(web,1); layout->addWidget(render,1); layout->addWidget(picture,1); layout->addWidget(video,1); + layout->addWidget(svg,1); layout->addStretch(); layout->setContentsMargins(0,0,0,0); setLayout(layout); + if (currentMode == ModeXml || currentMode == ModeLocal) { + qDebug() << "Starting timer..."; + timer = new QTimer(this); + connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); + timer->start(100); + } +} + +void MainView::loadSettings() +{ + settings = new QSettings("Caddi", "infoscreen"); + + qDebug() << "Loading settings" << settings->fileName(); + + QString mode = settings->value("mode").toString().toLower(); + if (mode == "simpleweb") { + currentMode = ModeSimpleWeb; + } else if (mode == "xml") { + currentMode = ModeXml; + } else if (mode == "local") { + currentMode = ModeLocal; + } else { + currentMode = ModeNone; + QMessageBox::warning(this, "infoscreen", "no operation mode set or mode given an invalid value"); + exit(1); + } + - QTimer* timer = new QTimer(this); - connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); - timer->start(100); + if (currentMode == ModeSimpleWeb || currentMode == ModeXml) { + url = settings->value("url").toString(); + screenid = settings->value("screenid").toString(); + if (url == "" || screenid == "") { + QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); + + exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function + } + } + if (currentMode == ModeLocal) { + path = settings->value("path").toString(); + + if (path == "") { + QMessageBox::warning(this,"infoscreen","Could not find path in config file " + settings->fileName()); + exit(1); + } + } +} + +void MainView::closeEvent ( QCloseEvent * event ) +{ + Q_UNUSED(event); + exit(0); //force application shutdown } void MainView::keyPressEvent ( QKeyEvent* event ) { int key = event->key(); if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) { - qApp->quit(); + close(); } } @@ -65,18 +140,64 @@ { screenManager.timerTick(); - readXml(); + if (currentMode == ModeXml) { + readXml(); + } switchScreens(); } +void MainView::readLocalFiles() +{ + QDir dir(path); + if (! dir.exists()) { + QMessageBox::warning(this,"infoscreen","Local Source directory not found: " + path); + exit(1); + } + QFileInfoList files = dir.entryInfoList(QDir::Files, QDir::Name); //only files, sort by name + + for (int i=0; i TIMEOUT) { - xmlHandler.readXml( "http://infoscreen.sundhedhorsens.dk/infoscreen/screen_xml.php?screen_id=1" ); + + bool res = xmlHandler.readXml( xmlUrl ); lastXml = QTime::currentTime(); @@ -94,6 +215,9 @@ void MainView::switchScreens() { + if (video->isVisible() && video->isPlaying() ) { + return; //wait until current clip has finished + } if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) { @@ -110,30 +234,56 @@ currentItemIdx = (currentItemIdx+1) % screenItems.size(); currentItem = screenItems.at(currentItemIdx); - if (currentItem.start <= now && now <= currentItem.stop ) + if (currentItem.start.isValid() && currentItem.stop.isValid()) { + if (currentItem.start <= now && now <= currentItem.stop ) + found = true; + } else { // if start or stop time was invalid - show them always found = true; + } } } if (found) { - - if (currentItem.module == "info_image") { + switch(currentItem.module) { + case ModuleImage: ensureVisible(picture); - picture->loadFromUrl( currentItem.url ); - + break; + case ModuleWeb: + ensureVisible(web); + web->load(currentItem.url); + break; + case ModuleVideo: + ensureVisible(video); + video->loadUrl(currentItem.url); + break; + case ModuleSvg: + ensureVisible(svg); + svg->load(currentItem.url); + break; + default: + // ModuleUnknown - what should we do?? + break; } - } else { qDebug() << "no screen"; - hideAll(); + errorInfoScreen("Der er ingen information at vise"); } lastScreenSwitch = QTime::currentTime(); } } +void MainView::errorInfoScreen(QString msg) +{ + ensureVisible(web); + web->setHtml("\ + \ +

" + msg+ "

\ + "); +} + void MainView::ensureVisible(QWidget* widget) { if (! widget->isVisible()) { @@ -148,4 +298,5 @@ web->setVisible( false); picture->setVisible( false ); video->setVisible(false); + svg->setVisible(false); }