X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2FBusinessLogic%2FEngine.cpp;h=e46ddc94cb671d4163e076662ff3b7c8d154a42a;hb=663a2fc8ce3a0b8b987655fe709a831a3db9b315;hp=195b0aaab2c4cbf8fc01cf47336aee4f764ef513;hpb=fca5bd9a27f0bbb3c60ae13218a503c5df26c897;p=qtmeetings diff --git a/src/BusinessLogic/Engine.cpp b/src/BusinessLogic/Engine.cpp index 195b0aa..e46ddc9 100644 --- a/src/BusinessLogic/Engine.cpp +++ b/src/BusinessLogic/Engine.cpp @@ -33,6 +33,7 @@ Engine::Engine() : { qDebug() << "Engine::Engine()"; iCommunicationFailed = false; + iCurrentWeekFetched = false; initConfiguration(); initDevice(); @@ -47,14 +48,17 @@ Engine::Engine() : // create application clock iClock = new Clock; - connect( iClock, SIGNAL( tick( QDateTime ) ), this, SLOT( checkStatusOfAllRooms() ) ); + connect( iClock, SIGNAL( tick( QDateTime ) ), this, SLOT( tick( QDateTime )/*checkStatusOfAllRooms()*/ ) ); // connect( iClock, SIGNAL( tick( QDateTime ) ), iWindowManager, SLOT( distributeDateTimeInfo( QDateTime ) ) ); // 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( iAutoRefresh, SIGNAL( timeout() ), this, SLOT( fetchMeetings() ) ); if( iDevice->currentOperationMode() == DeviceManager::KioskMode ) @@ -63,7 +67,7 @@ Engine::Engine() : } connectSignals(); - + connect( Configuration::instance(), SIGNAL( configurationChanged() ), this, SLOT( configurationChanged() ) ); // QTimer::singleShot( 0, this, SLOT( fetchMeetings() ) ); // TODO: continue implementation @@ -103,12 +107,12 @@ Room* Engine::defaultRoom() void Engine::checkStatusOfAllRooms() { -// qDebug() << "Engine::checkStatusOfAllRooms()"; + // TODO: Check if date has changed // iterate trough on the rooms for (int i = 0; i < iConfiguration->rooms().count(); i++) { // and check the status - roomStatusInfoNeeded(iConfiguration->rooms().at(i) ); + roomStatusInfoNeeded( iConfiguration->rooms().at(i) ); } } @@ -164,46 +168,33 @@ void Engine::roomStatusInfoNeeded(Room *aRoom) // ...if there is meeting following on the same day then check end time, otherwise end is the of the working day ( ( indexOfNextMeeting != -1 ) ? iMeetings.at( indexOfNextMeeting )->startsAt().time() : Engine::endOfTheDay ); - //currently works only for deafult room -// if( aRoom->equals( *(defaultRoom() ) ) ) -// iWindowManager->roomStatusChanged( aRoom, status, until ); -} - -/* -void Engine::fetchMeetings() -{ - qDebug() << "Engine::fetchMeetings for " << iCurrentRoom; - QDateTime from( iWindowManager->weeklyView()->beginnigOfShownWeek() ); - QDateTime to( from.addDays( 7 ) ); - // fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() ); - // Signal is connected to the currentRoomChanged slot which keeps the iCurrentRoom up to date - fetchMeetings( from, to, iCurrentRoom ); + //currently works only for default room + if ( aRoom->equals( *(iCurrentRoom) ) ) + { + emit roomStatusChanged( status, until ); + } } -*/ void Engine::fetchMeetingDetails( Meeting *aMeeting ) { qDebug() << "Engine::fetchMeetingDetails( Meeting* )"; -/* iWindowManager->showProgressBar(tr("Please Wait"), true); - iWindowManager->updateProgressBar(tr("Fetching Meeting Details...") ); - connect(iWindowManager, - SIGNAL( progressBarCancelled() ), this, - SLOT( fetchMeetingDetailsCancelled() )); - iCommunication->fetchMeetingDetails( *aMeeting); */ iCommunication->fetchMeetingDetails( *aMeeting ); } void Engine::meetingsFetched( const QList &aMeetings ) { qDebug() << "Engine::meetingsFetched( const QList & )"; - if( iCommunicationFailed ) + // TODO: should check if this week's meetings were fetched + if( iCommunicationFailed || !iCurrentWeekFetched ) { + iCurrentWeekFetched = true; iCommunicationFailed = false; - iWindowManager->connectionEstablished(); + iUIManager->connectionEstablished(); } for ( int i = 0; i < iMeetings.count(); ++i ) { + // TODO: Check if these are current week's meetings and do not overwrite those Meeting* m = iMeetings.takeAt( i ); delete m; } @@ -214,7 +205,7 @@ void Engine::meetingsFetched( const QList &aMeetings ) } // refresh room status info - roomStatusInfoNeeded( defaultRoom() ); + roomStatusInfoNeeded( iCurrentRoom /*defaultRoom()*/ ); } void Engine::errorHandler( int aCode, const QString &aAddInfo ) @@ -222,8 +213,11 @@ void Engine::errorHandler( int aCode, const QString &aAddInfo ) if( aCode >= 100 && aCode < 150 ) { iCommunicationFailed = true; - //TODO: Call window manager - //if ( iWindowManager != 0 ) iWindowManager->connectionLost(); + + if ( iUIManager != 0 ) + { + iUIManager->connectionLost(); + } } if ( iWindowManager != 0 ) { @@ -231,11 +225,11 @@ void Engine::errorHandler( int aCode, const QString &aAddInfo ) } } -void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn ) +void Engine::fetchMeetings( const int aWeek, const int aYear, const Room *aIn ) { qDebug() - << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )"; - iCommunication->fetchMeetings(aFrom, aUntil, *aIn); + << "Engine::fetchMeetings( const int aWeek, const int aYear, const Room * )"; + iCommunication->fetchMeetings(aWeek, aYear, *aIn); } void Engine::cancelFetchMeetingDetails() @@ -246,28 +240,19 @@ void Engine::cancelFetchMeetingDetails() void Engine::shownWeekChanged( QDate aFrom ) { qDebug() << "[Engine::shownWeekChanged] "; - QDateTime from( aFrom ); - QDateTime to( aFrom.addDays( 7 ), QTime( 23, 59 ) ); - qDebug() << "[Engine::shownWeekChanged] "; - iCommunication->fetchMeetings( from, to, *defaultRoom() ); -// fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() ); + iCommunication->fetchMeetings( aFrom.weekNumber(), aFrom.year(), *iCurrentRoom/*defaultRoom()*/ ); } -void Engine::changeDeviceMode( bool aChange ) +void Engine::changeDeviceMode() { - if ( aChange ) - } - { - connect( iDevice, SIGNAL( changingModeFailed() ), this, SLOT( changeModeFailed() ) ); - iAutoRefresh->stop(); // Stop the meeting update - } - iDevice->changeMode( aChange ); + connect( iDevice, SIGNAL( changeModeFailed() ), this, SLOT( changeModeFailed() ) ); + iAutoRefresh->stop(); // Stop the meeting update + iDevice->changeMode(); } void Engine::changeModeFailed() { qDebug() << "Engine::progressBarCancelled()"; - iDevice->changeMode( false ); iAutoRefresh->start(); //we start the metting updating } @@ -290,12 +275,15 @@ void Engine::initUserInterface() iWindowManager->show(); iUIManager->showMainView(); + // This triggers the meeting fetching + iUIManager->currentRoomChanged( this->iCurrentRoom ); + qDebug() << "[Engine::initUserInterface] "; } void Engine::handleViewEvent() { - if ( iIdleTimeCounter != 0 ) + if ( iIdleTimeCounter != 0 && iIdleTimeCounter->isActive()) { // Restart the idle time counter when view event is received iIdleTimeCounter->stop(); @@ -326,7 +314,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& ) ), @@ -383,5 +371,36 @@ void Engine::startIdleTimeCounter() void Engine::currentRoomChanged(Room *aRoom) { + qDebug() << "[Engine::currentRoomChanged] "; iCurrentRoom = aRoom; -} \ No newline at end of file + roomStatusInfoNeeded( iCurrentRoom ); +} + +void Engine::tick( QDateTime aCurrentDateTime ) +{ + // Called once every second + checkStatusOfAllRooms(); + if( aCurrentDateTime.date() != iCurrentDate) + { + // Check if week has changed and fetch meetings for this week + if( aCurrentDateTime.date().weekNumber() != iCurrentDate.weekNumber() + || aCurrentDateTime.date().year() != iCurrentDate.year() ) + { + qDebug() << "[Engine::tick] detected week change, fetching meetings"; + fetchMeetings( aCurrentDateTime.date().weekNumber(), aCurrentDateTime.date().year(), iCurrentRoom ); + } + } + iCurrentDate = aCurrentDateTime.date(); +} + + +void Engine::updateRoomInfo() +{ + qDebug() << "ENGINE::: updateMeetings"; + roomStatusInfoNeeded(iCurrentRoom); +} + +void Engine::configurationChanged() +{ + iAutoRefresh->setInterval(Configuration::instance()->getRefreshinterval() * 1000); +}