--- infoscreen/MainView.cpp 2010/03/29 09:34:16 637 +++ infoscreen/MainView.cpp 2010/04/07 17:00:07 638 @@ -20,19 +20,26 @@ MainView::MainView(QWidget* parent) : QWidget(parent), timer(0) { + loadSettings(); - settings = new QSettings("Caddi", "infoscreen"); - url = settings->value("url").toString(); - bool xmlMode = settings->value("xml").toBool(); - screenid = settings->value("screenid").toString(); - - if (url == "" || screenid == "") { - QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); + if ( currentMode == ModeXml) { + xmlUrl = url + "?screen_id=" + screenid; + qDebug() << "Starting XML mode"; + qDebug() << "xmlUrl" << xmlUrl; + } - exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function + 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 ); @@ -62,20 +69,51 @@ setLayout(layout); - - - if (xmlMode == true) { - xmlUrl = url + "?screen_id=" + screenid; - qDebug() << "Starting XML mode"; - qDebug() << "xmlUrl" << xmlUrl; - + if (currentMode == ModeXml || currentMode == ModeLocal) { + qDebug() << "Starting timer..."; timer = new QTimer(this); connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); timer->start(100); - } else { - qDebug() << "Starting plain browser mode"; - web->setVisible(true); - web->start(url,screenid); + } +} + +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); + } + + + 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); + } } } @@ -97,12 +135,52 @@ { 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; iloadFromUrl( currentItem.url ); - } else if (currentItem.module == "info_web") { + } else if (currentItem.module == ModuleWeb) { ensureVisible(web); web->load(currentItem.url); - } else if (currentItem.module == "info_video") { + } else if (currentItem.module == ModuleVideo) { ensureVisible(video); video->loadUrl(currentItem.url); } else { - errorInfoScreen("Unknown module: " + currentItem.module ); + // ModuleUnknown - what should we do?? } } else {