X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2FBusinessLogic%2FEngine.cpp;fp=src%2FBusinessLogic%2FEngine.cpp;h=6cf5ee40f65760be2f553a590d596f1c36ac8467;hb=6a31f3484996e9b7e719954c3a64a56d3fa586aa;hp=c7aad8b12f81d2c5b750c30661312922f3007f04;hpb=59b4a9d85f3cd02e90c8efcecc66f9150f8a61f8;p=qtmeetings diff --git a/src/BusinessLogic/Engine.cpp b/src/BusinessLogic/Engine.cpp index c7aad8b..6cf5ee4 100644 --- a/src/BusinessLogic/Engine.cpp +++ b/src/BusinessLogic/Engine.cpp @@ -32,8 +32,7 @@ Engine::Engine() : iWindowManager( 0 ), iUIManager( 0 ) { qDebug() << "Engine::Engine()"; - iCommunicationFailed = false; - iCurrentWeekFetched = false; + iCommunicationFailed = true; initConfiguration(); initDevice(); @@ -53,9 +52,15 @@ Engine::Engine() : // Create auto refresh timer iAutoRefresh = new QTimer; - iAutoRefresh->setInterval(iConfiguration->connectionSettings()->refreshInterval() * 1000); + + iAutoRefresh->setInterval(Configuration::instance()->getRefreshinterval() * 1000); + iAutoRefresh->start(); connect( iAutoRefresh, SIGNAL( timeout() ), iAutoRefresh, SLOT( start() ) ); + connect( iAutoRefresh, SIGNAL( timeout() ), this, SLOT( updateRoomInfo() ) ); + + connect(iWindowManager, SIGNAL(closeClicked()), this, SLOT(closeApplication())); + // connect( iAutoRefresh, SIGNAL( timeout() ), this, SLOT( fetchMeetings() ) ); if( iDevice->currentOperationMode() == DeviceManager::KioskMode ) @@ -64,7 +69,7 @@ Engine::Engine() : } connectSignals(); - + connect( Configuration::instance(), SIGNAL( configurationChanged() ), this, SLOT( configurationChanged() ) ); // QTimer::singleShot( 0, this, SLOT( fetchMeetings() ) ); // TODO: continue implementation @@ -105,7 +110,6 @@ Room* Engine::defaultRoom() void Engine::checkStatusOfAllRooms() { // TODO: Check if date has changed - // qDebug() << "Engine::checkStatusOfAllRooms()"; // iterate trough on the rooms for (int i = 0; i < iConfiguration->rooms().count(); i++) { @@ -182,10 +186,14 @@ void Engine::fetchMeetingDetails( Meeting *aMeeting ) void Engine::meetingsFetched( const QList &aMeetings ) { qDebug() << "Engine::meetingsFetched( const QList & )"; - // TODO: should check if this week's meetings were fetched - if( iCommunicationFailed || !iCurrentWeekFetched ) + QTime c = QTime::currentTime(); + iLastCommunication.setHMS( c.hour(), c.minute(), c.second() ); + + qDebug() << "Error length: "<< iCommunicationError.length(); + qDebug() << "Error: "<< iCommunicationError; + + if( iCommunicationError.length() == 0 ) { - iCurrentWeekFetched = true; iCommunicationFailed = false; iUIManager->connectionEstablished(); } @@ -208,21 +216,42 @@ void Engine::meetingsFetched( const QList &aMeetings ) void Engine::errorHandler( int aCode, const QString &aAddInfo ) { + iCommunicationFailed = true; + if( aCode >= 100 && aCode < 150 ) { - iCommunicationFailed = true; - if ( iUIManager != 0 ) iUIManager->connectionLost(); + if ( iUIManager != 0 ) + { + iUIManager->connectionLost(); + } } if ( iWindowManager != 0 ) { - iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) ); + iCommunicationError = ErrorMapper::codeToString( aCode, aAddInfo ); + //iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) ); } } +bool Engine::connected() +{ + return !iCommunicationFailed; +} + +QTime Engine::lastUpdated() +{ + return iLastCommunication; +} + +QString Engine::errorMessage() +{ + return iCommunicationError; +} + void Engine::fetchMeetings( const int aWeek, const int aYear, const Room *aIn ) { qDebug() << "Engine::fetchMeetings( const int aWeek, const int aYear, const Room * )"; + iCommunicationError = ""; iCommunication->fetchMeetings(aWeek, aYear, *aIn); } @@ -234,6 +263,7 @@ void Engine::cancelFetchMeetingDetails() void Engine::shownWeekChanged( QDate aFrom ) { qDebug() << "[Engine::shownWeekChanged] "; + iCommunicationError = ""; iCommunication->fetchMeetings( aFrom.weekNumber(), aFrom.year(), *iCurrentRoom/*defaultRoom()*/ ); } @@ -308,7 +338,7 @@ void Engine::connectSignals() void Engine::initCommunication() { // initialize communication - iCommunication = new CommunicationManager( *(iConfiguration->connectionSettings()) ); + iCommunication = new CommunicationManager(/* *(iConfiguration->connectionSettings()) */); connect( iCommunication, SIGNAL( error( int, CommunicationManager::CommunicationType ) ), this, SLOT( errorHandler( int ) ) ); connect( iCommunication, SIGNAL( meetingsFetched( const QList& ) ), @@ -385,4 +415,16 @@ void Engine::tick( QDateTime aCurrentDateTime ) } } iCurrentDate = aCurrentDateTime.date(); -} \ No newline at end of file +} + + +void Engine::updateRoomInfo() +{ + qDebug() << "ENGINE::: updateMeetings"; + iUIManager->currentRoomChanged( iCurrentRoom ); +} + +void Engine::configurationChanged() +{ + iAutoRefresh->setInterval(Configuration::instance()->getRefreshinterval() * 1000); +}