User interface update
[qtmeetings] / src / BusinessLogic / Engine.cpp
index af3e342..e46ddc9 100644 (file)
@@ -5,10 +5,10 @@
 #include "Configuration.h"
 #include "DisplaySettings.h"
 #include "CommunicationManager.h"
-#include "DeviceManager.h"
+// #include "DeviceManager.h"
 #include "Clock.h"
 #include "ErrorMapper.h"
-#include "WeeklyViewWidget.h"
+#include "UIManager.h"
 
 #include <QApplication>
 #include <QTimer>
 QTime Engine::endOfTheDay = QTime( 23, 59, 0, 0); // end of the day is 11:59pm
 const int IDLE_TIME_MULTIPLIER = 60000; // Multiplies milliseconds to minutes
 
+// Macro to help deleting objects. This could be global.
+#define QT_DELETE(X) \
+       if ( X != 0 ) \
+       { \
+               delete X; \
+               X = 0; \
+       }
+
+
 Engine::Engine() :
-       iClock( 0), iConfiguration(Configuration::instance() ), iCommunication( 0)
+               iClock( 0 ), iConfiguration( 0 ), iCommunication( 0 ),
+               iWindowManager( 0 ), iUIManager( 0 )
 {
        qDebug() << "Engine::Engine()";
        iCommunicationFailed = false;
-       // if reading of configuration fails, signal that initialization failed
-       if (iConfiguration == 0)
-       {
-               QTimer::singleShot( 0, this, SLOT( closeApplication() ));
-               return;
-       }
-
-       //initialize window manager
-       iWindowManager = new WindowManager( iConfiguration );
-       connect(iWindowManager, SIGNAL( roomStatusInfoNeeded( Room * ) ), this, SLOT( roomStatusInfoNeeded( Room * ) ));
-       connect(iWindowManager, SIGNAL( observedEventDetected() ), this, SLOT( observedEventDetected() ));
-       connect(iWindowManager, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( fetchMeetingDetails( Meeting * ) ));
-       connect(iWindowManager, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) ));
-       connect(iWindowManager, SIGNAL( shownWeekChanged( QDate ) ), this, SLOT( shownWeekChanged( QDate ) ));
-       connect(iWindowManager, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ));
-
-       // initialize communication
-       iCommunication = new CommunicationManager( *(iConfiguration->connectionSettings()) );
-       connect(iCommunication, SIGNAL( error( int, CommunicationManager::CommunicationType ) ), this, SLOT( errorHandler( int ) ));
-       connect(iCommunication, SIGNAL( meetingsFetched( const QList<Meeting*>& ) ), this, SLOT( meetingsFetched( const QList<Meeting*>& ) ));
-       connect(iCommunication, SIGNAL( meetingDetailsFetched( Meeting& ) ), this, SLOT( meetingDetailsFetched( Meeting& ) ));
-
+       iCurrentWeekFetched = false;
+       
+       initConfiguration();
+       initDevice();
+       initCommunication();
+       initUserInterface();
+       
        //initialize idle time counter
        iIdleTimeCounter = new QTimer();
        iIdleTimeCounter->setSingleShot( true);
-       iIdleTimeCounter->setInterval(IDLE_TIME_MULTIPLIER
-                       * iConfiguration->displaySettings()->screensaver() );
+       iIdleTimeCounter->setInterval(IDLE_TIME_MULTIPLIER * iConfiguration->displaySettings()->screensaver() );
        iIdleTimeCounter->start();
-       connect(iIdleTimeCounter, SIGNAL( timeout() ), iWindowManager, SLOT( showRoomStatus() ));
 
        // create application clock
        iClock = new Clock;
-       connect(iClock, SIGNAL( tick( QDateTime ) ), this, SLOT( checkStatusOfAllRooms() ));
-       connect(iClock, SIGNAL( tick( QDateTime ) ), iWindowManager, SLOT( distributeDateTimeInfo( QDateTime ) ));
+       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->start();
-       connect(iAutoRefresh, SIGNAL( timeout() ), iAutoRefresh, SLOT( start() ));
-       connect(iAutoRefresh, SIGNAL( timeout() ), this, SLOT( fetchMeetings() ));
 
-       // create device manager
-       iDevice = new DeviceManager( iConfiguration->startupSettings() );
-       connect(iDevice, SIGNAL( error( int, const QString& ) ), this, SLOT( errorHandler( int, const QString& ) ));
-       connect(iDevice, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ), this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ));
-       iDevice->initDeviceManager();
+       iAutoRefresh->setInterval(Configuration::instance()->getRefreshinterval() * 1000);
 
-       if (iDevice->currentOperationMode() == DeviceManager::KioskMode)
-               iWindowManager->fullScreen();
+       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 )
+       {
+               iWindowManager->setFullscreen();
+       }
 
-       QTimer::singleShot( 0, this, SLOT( fetchMeetings() ));
+       connectSignals();
+       connect( Configuration::instance(), SIGNAL( configurationChanged() ), this, SLOT( configurationChanged() ) );
+       // QTimer::singleShot( 0, this, SLOT( fetchMeetings() ) );
 
        // TODO: continue implementation
 }
@@ -83,15 +78,18 @@ Engine::~Engine()
        qDebug() << "Engine::~Engine()";
        while ( !iMeetings.isEmpty() )
                delete iMeetings.takeFirst();
-       iIdleTimeCounter->stop();
-       delete iIdleTimeCounter;
-       iIdleTimeCounter = 0;
-       delete iWindowManager;
-       iWindowManager = 0;
-       delete iClock;
-       iClock = 0;
-       delete iDevice;
-       iDevice = 0;
+       
+       if ( iIdleTimeCounter != 0 )
+       {
+               iIdleTimeCounter->stop();
+               delete iIdleTimeCounter;
+               iIdleTimeCounter = 0;
+       }
+       QT_DELETE( iClock );
+       QT_DELETE( iDevice );
+
+       QT_DELETE( iUIManager );
+       QT_DELETE( iWindowManager );
 }
 
 void Engine::closeApplication()
@@ -101,23 +99,6 @@ void Engine::closeApplication()
        QTimer::singleShot( 1000, QApplication::instance(), SLOT( quit() ));
 }
 
-void Engine::observedEventDetected()
-{
-       qDebug() << "Engine::observedEventDetected()";
-       if ( !iIdleTimeCounter->isActive() )
-       {
-               iWindowManager->weeklyView()->showCurrentWeek();
-       }
-       iWindowManager->showWeeklyView();
-       // prepare to restart idle counter
-       if (iIdleTimeCounter->isActive() )
-       {
-               iIdleTimeCounter->stop();
-       }
-       // (re)start idle counter
-       iIdleTimeCounter->start();
-}
-
 Room* Engine::defaultRoom()
 {
        qDebug() << "Engine::defaultRoom()";
@@ -126,19 +107,19 @@ 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) );
        }
 }
 
 int Engine::indexOfMeetingAt(Room *aRoom, QDateTime aAt)
 {
-       qDebug() << "Engine::indexOfMeetingAt( Room *, QDateTime )";
-       for (int i = 0; i < iMeetings.count(); i++)
+//     qDebug() << "Engine::indexOfMeetingAt( Room *, QDateTime )";
+       for ( int i = 0; i < iMeetings.count(); i++ )
        {
                // exchange server ensures that there is only one meeting in a room at a specified time
                if (aRoom->equals(iMeetings.at( i )->room() ) && iMeetings.at( i )->startsAt() <= aAt && iMeetings.at( i )->endsAt() >= aAt)
@@ -151,7 +132,7 @@ int Engine::indexOfMeetingAt(Room *aRoom, QDateTime aAt)
 
 int Engine::indexOfMeetingAfter(Room *aRoom, QDateTime aAfter)
 {
-       qDebug() << "Engine::indexOfMeetingAfter( Room *, QDateTime )";
+//     qDebug() << "Engine::indexOfMeetingAfter( Room *, QDateTime )";
        // seeks for the next meeting on the SAME DAY
        int min = -1;
        for (int i = 0; i < iMeetings.count(); i++)
@@ -171,8 +152,8 @@ int Engine::indexOfMeetingAfter(Room *aRoom, QDateTime aAfter)
 
 void Engine::roomStatusInfoNeeded(Room *aRoom)
 {
-       qDebug() << "Engine::roomStatusInfoNeeded( Room * )";
-       if (aRoom == 0)
+//     qDebug() << "Engine::roomStatusInfoNeeded( Room * )";
+       if ( aRoom == 0 )
        {
                return;
        }
@@ -181,198 +162,245 @@ void Engine::roomStatusInfoNeeded(Room *aRoom)
        int indexOfNextMeeting = indexOfMeetingAfter(aRoom, iClock->datetime() );
 
        // if there is no meeting, then status is Free; otherwise Busy
-       Room::Status
-                       status =
-                                       (indexOfCurrentMeeting == -1 ) ? Room::FreeStatus : Room::BusyStatus;
+       Room::Status status = (indexOfCurrentMeeting == -1 ) ? Room::FreeStatus : Room::BusyStatus;
        // if room is Busy, then check end time, otherwise...
        QTime until = (status == Room::BusyStatus ) ? iMeetings.at( indexOfCurrentMeeting )->endsAt().time() :
        // ...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 );
+       ( ( 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()
-{
-       Room *room = defaultRoom();
-       qDebug() << "Engine::fetchMeetings for " << room->name();
-       fetchMeetings(iClock->datetime(), iClock->datetime().addDays( 7), room);
+       //currently works only for default room
+       if ( aRoom->equals( *(iCurrentRoom) ) )
+       {
+               emit roomStatusChanged( status, until );
+       }
 }
 
-void Engine::fetchMeetingDetails(Meeting *aMeeting)
+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);
-}
-
-bool Engine::isMeetingInList(const QList<Meeting*> &aList, const Meeting *aMeeting)
-{
-       qDebug()
-                       << "Engine::isMeetingInList( const QList<Meeting*> &, const Meeting * )";
-       for (int i = 0; i < aList.count(); i++)
-       {
-               if (aMeeting->equals( *(aList.at(i))) )
-               {
-                       return true;
-               }
-       }
-       return false;
+       iCommunication->fetchMeetingDetails( *aMeeting );
 }
 
-void Engine::meetingsFetched(const QList<Meeting*> &aMeetings)
+void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
 {
        qDebug() << "Engine::meetingsFetched( const QList<Meeting*> & )";
-       if( iCommunicationFailed )
+       // TODO: should check if this week's meetings were fetched
+       if( iCommunicationFailed || !iCurrentWeekFetched )
        {
+               iCurrentWeekFetched = true;
                iCommunicationFailed = false;
-               //iWindowManager->connectionEstablished();
+               iUIManager->connectionEstablished();
        }
 
-       // check if there is any new meeting in the list came from the server -> added
-       for (int i = 0; i < aMeetings.count(); i++)
+       for ( int i = 0; i < iMeetings.count(); ++i ) 
        {
-               // if the (i)th meeting is not in the local meeting list
-               if ( !isMeetingInList(iMeetings, aMeetings.at(i) ) )
-               {
-                       // add to the local database =)
-                       Meeting* m = new Meeting( *(aMeetings.at( i )) );
-                       iMeetings.append(m);
-                       // and signal the changes
-                       iWindowManager->insertMeeting(m);
-               }
+               // TODO: Check if these are current week's meetings and do not overwrite those
+               Meeting* m = iMeetings.takeAt( i );
+               delete m;
+       }
+       iMeetings.clear();
+       for ( int i = 0; i < aMeetings.count(); ++i ) {
+               Meeting* m = new Meeting( *( aMeetings.at( i ) ) );
+               iMeetings.append( m );
        }
 
-       // check if there is any meeting NOT in the list came from the server -> deleted
-       for (int i = 0; i < iMeetings.count(); i++)
+       // refresh room status info
+       roomStatusInfoNeeded( iCurrentRoom /*defaultRoom()*/ );
+}
+
+void Engine::errorHandler( int aCode, const QString &aAddInfo )
+{      
+       if( aCode >= 100 && aCode < 150 )
        {
-               // if the (i)th meeting is in the local but NOT in the server's meeting list
-               if ( !isMeetingInList(aMeetings, iMeetings.at(i) ) )
-               {
-                       Meeting* m = iMeetings.takeAt(i);
-                       // signal the changes
-                       iWindowManager->deleteMeeting(m);
-                       // delete the meeting from the local list
-                       delete m;
-               }
+               iCommunicationFailed = true;
+
+               if ( iUIManager != 0 )
+                       {
+                               iUIManager->connectionLost();
+                       }
+       }
+       if ( iWindowManager != 0 )
+       {
+               iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) );
        }
+}
 
-       // refresh room status info
-       roomStatusInfoNeeded(defaultRoom() );
+void Engine::fetchMeetings( const int aWeek, const int aYear, const Room *aIn )
+{
+       qDebug()
+                       << "Engine::fetchMeetings( const int aWeek, const int aYear, const Room * )";
+       iCommunication->fetchMeetings(aWeek, aYear, *aIn);
 }
 
-void Engine::meetingDetailsFetched(Meeting &aDetailedMeeting)
+void Engine::cancelFetchMeetingDetails()
 {
-       qDebug() << "Engine::meetingDetailsFetched( Meeting & )";
-       iWindowManager->closeProgressBar();
-       if( iCommunicationFailed )
+       iCommunication->cancelFetchMeetingDetails();
+}
+
+void Engine::shownWeekChanged( QDate aFrom )
+{
+       qDebug() << "[Engine::shownWeekChanged] <Invoked>";
+       iCommunication->fetchMeetings( aFrom.weekNumber(), aFrom.year(), *iCurrentRoom/*defaultRoom()*/ );
+}
+
+void Engine::changeDeviceMode()
+{
+       connect( iDevice, SIGNAL( changeModeFailed() ), this, SLOT( changeModeFailed() ) );
+       iAutoRefresh->stop(); // Stop the meeting update
+       iDevice->changeMode();
+}
+
+void Engine::changeModeFailed()
+{
+       qDebug() << "Engine::progressBarCancelled()";
+       iAutoRefresh->start(); //we start the metting updating
+}
+
+void Engine::initUserInterface()
+{
+       qDebug() << "[Engine::initUserInterface] <Invoked>";
+       
+       // Initialize the window manager and connect what ever signals can be connected
+       iWindowManager = new WindowManager;
+       // Create the UIManager which internally handles most of the UI actions
+       iUIManager = new UIManager( this, iWindowManager );
+       
+       connect( iWindowManager, SIGNAL( eventDetected() ), this, SLOT( handleViewEvent() ) );
+       connect( iWindowManager, SIGNAL( previousViewRestored() ), iUIManager, SLOT( previousViewRestored() ) );
+       connect( iWindowManager, SIGNAL( dialogActivated() ), this, SLOT( dialogActivated() ) );
+       connect( iWindowManager, SIGNAL( dialogDeactivated() ), this, SLOT( dialogDeactivated() ) );
+       
+       // Show the UI
+       iWindowManager->setWindowState( Qt::WindowMaximized );
+       iWindowManager->show();
+       iUIManager->showMainView();
+       
+       // This triggers the meeting fetching
+       iUIManager->currentRoomChanged( this->iCurrentRoom );
+       
+       qDebug() << "[Engine::initUserInterface] <Finished>";
+}
+
+void Engine::handleViewEvent()
+{
+       if ( iIdleTimeCounter != 0 && iIdleTimeCounter->isActive())
        {
-               iCommunicationFailed = false;
-               iWindowManager->connectionEstablished();
+               // Restart the idle time counter when view event is received
+               iIdleTimeCounter->stop();
+               iIdleTimeCounter->start();
        }
-       iWindowManager->showMeetingInfo( &aDetailedMeeting);
 }
 
-void Engine::errorHandler(int aCode, const QString &aAddInfo)
+void Engine::initConfiguration()
 {
-       qDebug() << "Engine::ErrorHandler, aCode: " << aCode;
-       // inform UI about the problem
-       if( aCode >= 100 && aCode <= 150 ) { //communication errors
+       iConfiguration = Configuration::instance();
+       if ( iConfiguration == 0 )
        {
-               //we don't want these to close operation changing
-               qDebug() << "CommunicationManager signaled an error:" << aCode;
-               if( !iCommunicationFailed )
-               {
-                       // Only inform window manager when first error appears
-                       iCommunicationFailed = true;
-                       //iWindowManager->connectionLost();
-               }
+               QTimer::singleShot( 0, this, SLOT( closeApplication() ) );
        }
-               iWindowManager->closeProgressBar();
-       }
-       iWindowManager->error(ErrorMapper::codeToString(aCode, aAddInfo) );
+       iCurrentRoom = iConfiguration->defaultRoom();
 }
 
-void Engine::currentRoomChanged(Room *aCurrentRoom)
+void Engine::connectSignals()
 {
-       qDebug() << "Engine::currentRoomChanged to " << aCurrentRoom->name();
-       QDateTime from(iWindowManager->weeklyView()->beginnigOfShownWeek() );
-       QDateTime to(from.addDays( 8) );
-       fetchMeetings(from, to, aCurrentRoom);
+       // Connect engine objects signals to UIManager
+       connect( iClock, SIGNAL( tick( QDateTime ) ), iUIManager, SLOT( updateTime( QDateTime ) ) );
+       connect( iIdleTimeCounter, SIGNAL( timeout() ) , iUIManager, SLOT( roomStatusIndicatorRequested() ) );
+       
+       iUIManager->connectDeviceManager( iDevice );
+       iUIManager->connectCommunicationManager( iCommunication );
 }
 
-void Engine::fetchMeetings(const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn)
+void Engine::initCommunication()
 {
-       qDebug()
-                       << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )";
-       iCommunication->fetchMeetings(aFrom, aUntil, *aIn);
+       // initialize communication
+       iCommunication = new CommunicationManager(/* *(iConfiguration->connectionSettings()) */);
+       connect( iCommunication, SIGNAL( error( int, CommunicationManager::CommunicationType  ) ),
+                       this, SLOT( errorHandler( int ) ) );
+       connect( iCommunication, SIGNAL( meetingsFetched( const QList<Meeting*>& ) ),
+                       this, SLOT( meetingsFetched( const QList<Meeting*>& ) ) );
 }
 
-void Engine::shownWeekChanged(QDate aFrom)
+void Engine::initDevice()
 {
-       qDebug() << "Engine::shownWeekChanged( QDate )";
-       QDateTime from(aFrom);
-       QDateTime to(aFrom.addDays( 7), QTime( 23, 59) );
-       qDebug() << "Engine::shownWeekChanged " << aFrom.toString("d.m. h:mm")
-                       << " to " << to.toString("d.m. h:mm");
-       fetchMeetings(from, to, iWindowManager->weeklyView()->currentRoom() );
+       // create device manager
+       iDevice = new DeviceManager( iConfiguration->startupSettings() );
+       connect( iDevice, SIGNAL( error( int, const QString& ) ), this, SLOT( errorHandler( int, const QString& ) ) );  
+       iDevice->initDeviceManager();
 }
 
-void Engine::changeModeOrdered(DeviceManager::OperationMode aMode)
+void Engine::dialogActivated()
 {
-       qDebug() << "Engine::changeModeOrdered( DeviceManager::OperationMode )";
-       QString message = tr( "You are about to change operation mode to %1." )
-       .arg(iDevice->operationModeToString(aMode) );
+       if ( iIdleTimeCounter != 0 )
+       {
+               iIdleTimeCounter->stop();
+       }
+}
 
-       iWindowManager->showPasswordDialog(iConfiguration->adminPassword(), message);
+void Engine::dialogDeactivated()
+{
+       if ( iIdleTimeCounter != 0 )
+       {
+               iIdleTimeCounter->start();
+       }
 }
 
-void Engine::passwordEntered(PasswordDialog::PasswordStatus aPasswordStatus)
+void Engine::previousViewRestored()
 {
-       qDebug() << "Engine::passwordEntered( PasswordDialog::PasswordStatus )";
-       iWindowManager->closePasswordDialog();
+       if ( iIdleTimeCounter != 0 )
+       {
+               iIdleTimeCounter->start();
+       }
+}
 
-       switch (aPasswordStatus)
+void Engine::stopIdleTimeCounter()
+{
+       if ( iIdleTimeCounter != 0 )
        {
-               case PasswordDialog::Correct:
-               {
-                       iAutoRefresh->stop(); //we stop the metting updating
-                       iWindowManager->showProgressBar( "Changing current operation mode." );
-                       connect(iDevice, SIGNAL( changingMode( const QString & ) ), iWindowManager, SLOT( updateProgressBar( const QString & ) ));
-                       connect( iDevice, SIGNAL( changingMode( const QString & ) ),
-                                       iWindowManager, SLOT( updateProgressBar( const QString & ) ) );
-                       connect( iDevice, SIGNAL( changeModeFailed() ), this, SLOT( changeModeFailed() ) );
-                       iDevice->changeMode( true);
-                       break;
-               }
-               case PasswordDialog::Incorrect:
-               {
-                       iWindowManager->error(tr("Incorrect password.") );
-                       iDevice->changeMode( false);
-                       break;
-               }
-               default: //case PasswordDialog::Canceled
+               iIdleTimeCounter->stop();
+       }
+}
+
+void Engine::startIdleTimeCounter()
+{
+       if ( iIdleTimeCounter != 0 )
+       {
+               iIdleTimeCounter->start();
+       }
+}
+
+void Engine::currentRoomChanged(Room *aRoom)
+{
+       qDebug() << "[Engine::currentRoomChanged] <invoked>";
+       iCurrentRoom = aRoom;
+       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() )
                {
-                       iDevice->changeMode( false);
+                       qDebug() << "[Engine::tick] detected week change, fetching meetings";
+                       fetchMeetings( aCurrentDateTime.date().weekNumber(), aCurrentDateTime.date().year(), iCurrentRoom );
                }
        }
+       iCurrentDate = aCurrentDateTime.date();
 }
 
-void Engine::changeModeFailed()
+
+void Engine::updateRoomInfo()
 {
-       qDebug() << "Engine::changeModeFailed()";
-       iWindowManager->closeProgressBar();
-       iAutoRefresh->start(); //we start the metting updating
+       qDebug() << "ENGINE::: updateMeetings";
+       roomStatusInfoNeeded(iCurrentRoom);
 }
 
-void Engine::fetchMeetingDetailsCancelled()
+void Engine::configurationChanged()
 {
-       iCommunication->cancelFetchMeetingDetails();
-       iWindowManager->closeProgressBar();
+       iAutoRefresh->setInterval(Configuration::instance()->getRefreshinterval() * 1000);
 }