Merge
authorMikko Siren <mikko.siren@ixonos.com>
Wed, 27 May 2009 14:14:44 +0000 (17:14 +0300)
committerMikko Siren <mikko.siren@ixonos.com>
Wed, 27 May 2009 14:14:44 +0000 (17:14 +0300)
1  2 
src/BusinessLogic/Engine.cpp
src/BusinessLogic/Engine.h
src/BusinessLogic/UIManager.cpp

  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
  
 -Engine::Engine() :
 -      iClock( 0), iConfiguration(Configuration::instance() ), iCommunication( 0)
 -{
 -      qDebug() << "Engine::Engine()";
 -      // if reading of configuration fails, signal that initialization failed
 -      if (iConfiguration == 0)
 -      {
 -              QTimer::singleShot( 0, this, SLOT( closeApplication() ));
 -              return;
 +// Macro to help deleting objects. This could be global.
 +#define QT_DELETE(X) \
 +      if ( X != 0 ) \
 +      { \
 +              delete X; \
 +              X = 0; \
        }
  
 -      //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& ) ));
  
 +Engine::Engine() :
 +              iClock( 0 ), iConfiguration( 0 ), iCommunication( 0 ),
 +              iWindowManager( 0 ), iUIManager( 0 )
 +{
 +      qDebug() << "Engine::Engine()";
 +      
 +      initConfiguration();
 +      initDevice();
 +      initCommunication();
 +      initUserInterface();
 +      
        //initialize idle time counter
        iIdleTimeCounter = new QTimer();
-       iIdleTimeCounter->setSingleShot( true );
-       // iIdleTimeCounter->setInterval( IDLE_TIME_MULTIPLIER * iConfiguration->displaySettings()->screensaver() );
-       iIdleTimeCounter->setInterval( 10000 );
+       iIdleTimeCounter->setSingleShot( true);
+       iIdleTimeCounter->setInterval(IDLE_TIME_MULTIPLIER * iConfiguration->displaySettings()->screensaver() );
        iIdleTimeCounter->start();
 -      connect(iIdleTimeCounter, SIGNAL( timeout() ), iWindowManager, SLOT( showRoomStatus() ));
  
        // create application clock
        iClock = new Clock;
        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();
 -
 -      if (iDevice->currentOperationMode() == DeviceManager::KioskMode)
 -              iWindowManager->fullScreen();
 +      connect( iAutoRefresh, SIGNAL( timeout() ), iAutoRefresh, SLOT( start() ) );
-       connect( iAutoRefresh, SIGNAL( timeout() ), this, SLOT( fetchMeetings() ) );
++      // connect( iAutoRefresh, SIGNAL( timeout() ), this, SLOT( fetchMeetings() ) );
 +      
 +      if( iDevice->currentOperationMode() == DeviceManager::KioskMode )
 +      {
 +              iWindowManager->setFullscreen();
 +      }
  
 -      QTimer::singleShot( 0, this, SLOT( fetchMeetings() ));
 +      connectSignals();
 +      
-       QTimer::singleShot( 0, this, SLOT( fetchMeetings() ) );
++      // QTimer::singleShot( 0, this, SLOT( fetchMeetings() ) );
  
        // TODO: continue implementation
  }
@@@ -164,30 -183,27 +161,34 @@@ void Engine::roomStatusInfoNeeded(Room 
        // 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);
 +//    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);
 -      qDebug() << "Engine::fetchMeetings for " << iWindowManager->weeklyView()->currentRoom();
++      qDebug() << "Engine::fetchMeetings for " << iCurrentRoom;
+       QDateTime from( iWindowManager->weeklyView()->beginnigOfShownWeek() );
+       QDateTime to( from.addDays( 7 ) );
 -      fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() );
++      // fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() );
++      // Signal is connected to the currentRoomChanged slot which keeps the iCurrentRoom up to date
++      fetchMeetings( from, to, iCurrentRoom );
  }
++*/
  
- 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() ));
 +/*    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 );
  }
  
@@@ -205,163 -221,95 +206,168 @@@ void Engine::meetingsFetched( const QLi
                iMeetings.append( m );
        }
  
 -      iWindowManager->refreshMeetings( iMeetings );
        // refresh room status info
-       roomStatusInfoNeeded(defaultRoom() );
+       roomStatusInfoNeeded( defaultRoom() );
  }
  
 -void Engine::meetingDetailsFetched( Meeting &aDetailedMeeting )
 -{
 -      qDebug() << "Engine::meetingDetailsFetched( Meeting & )";
 -      iWindowManager->closeProgressBar();
 -      iWindowManager->showMeetingInfo( &aDetailedMeeting );
 -}
 -
  void Engine::errorHandler( int aCode, const QString &aAddInfo )
 -{
 -      qDebug() << "Engine::ErrorHandler, aCode: " << aCode;
 -      // inform UI about the problem
 -      if( aCode >= 100 && aCode <= 150 ) { //communication errors
 -              //we don't want these to close operation changing
 -              qDebug() << "CommunicationManager signaled an error:" << aCode;
 -              iWindowManager->closeProgressBar();
 +{     
 +      if ( iWindowManager != 0 )
 +      {
 +              iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) );
        }
 -      iWindowManager->error( ErrorMapper::codeToString(aCode, aAddInfo ) );
  }
  
 -void Engine::currentRoomChanged( Room *aCurrentRoom )
 +void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn )
  {
 -      qDebug() << "Engine::currentRoomChanged to " << aCurrentRoom->name();
 -      QDateTime from(iWindowManager->weeklyView()->beginnigOfShownWeek() );
 -      QDateTime to( from.addDays( 7 ) );
 -      fetchMeetings( from, to, aCurrentRoom );
 +      qDebug()
 +                      << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )";
 +      iCommunication->fetchMeetings(aFrom, aUntil, *aIn);
  }
  
 -void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn )
 +void Engine::cancelFetchMeetingDetails()
  {
 -      qDebug() << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )";
 -      iCommunication->fetchMeetings( aFrom, aUntil, *aIn );
 +      iCommunication->cancelFetchMeetingDetails();
  }
  
  void Engine::shownWeekChanged( QDate aFrom )
  {
 -      qDebug() << "Engine::shownWeekChanged( QDate )";
 +      qDebug() << "[Engine::shownWeekChanged] <Invoked>";
        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() );
 +      qDebug() << "[Engine::shownWeekChanged] <From " << aFrom.toString( "d.m. h:mm" ) << " to " << to.toString( "d.m. h:mm" ) << ">";
 +      iCommunication->fetchMeetings( from, to, *defaultRoom() );
 +//    fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() );
 +}
 +
 +void Engine::changeDeviceMode( bool aChange )
 +{
 +      if ( aChange )
 +      {
 +              connect( iDevice, SIGNAL( changingModeFailed() ), this, SLOT( changeModeFailed() ) );
 +              iAutoRefresh->stop(); // Stop the meeting update
 +      }
 +      iDevice->changeMode( aChange );
 +}
 +
 +void Engine::changeModeFailed()
 +{
 +      qDebug() << "Engine::progressBarCancelled()";
 +      iDevice->changeMode( false );
 +      iAutoRefresh->start(); //we start the metting updating
  }
  
 -void Engine::changeModeOrdered( DeviceManager::OperationMode aMode )
 +void Engine::initUserInterface()
  {
 -      qDebug() << "Engine::changeModeOrdered( DeviceManager::OperationMode )";
 -      QString message = tr( "You are about to change operation mode to %1." ).arg( iDevice->operationModeToString(aMode ) );
 +      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();
 +      
 +      qDebug() << "[Engine::initUserInterface] <Finished>";
 +}
  
 -      iWindowManager->showPasswordDialog( iConfiguration->adminPassword(), message );
 +void Engine::handleViewEvent()
 +{
 +      if ( iIdleTimeCounter != 0 )
 +      {
 +              // Restart the idle time counter when view event is received
 +              iIdleTimeCounter->stop();
 +              iIdleTimeCounter->start();
 +      }
  }
  
 -void Engine::passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus )
 +void Engine::initConfiguration()
  {
 -      qDebug() << "Engine::passwordEntered( PasswordDialog::PasswordStatus )";
 -      iWindowManager->closePasswordDialog();
 -
 -      switch ( aPasswordStatus ) {
 -              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
 -                      iDevice->changeMode( false );
 +      iConfiguration = Configuration::instance();
 +      if ( iConfiguration == 0 )
 +      {
 +              QTimer::singleShot( 0, this, SLOT( closeApplication() ) );
        }
++      iCurrentRoom = iConfiguration->defaultRoom();
  }
  
 -void Engine::changeModeFailed()
 +void Engine::connectSignals()
  {
 -      qDebug() << "Engine::changeModeFailed()";
 -      iWindowManager->closeProgressBar();
 -      iAutoRefresh->start(); //we start the metting updating
 +      // 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::fetchMeetingDetailsCancelled()
 +void Engine::initCommunication()
  {
 -      iCommunication->cancelFetchMeetingDetails();
 -      iWindowManager->closeProgressBar();
 +      // 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::initDevice()
 +{
 +      // 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::dialogActivated()
 +{
 +      if ( iIdleTimeCounter != 0 )
 +      {
 +              iIdleTimeCounter->stop();
 +      }
 +}
 +
 +void Engine::dialogDeactivated()
 +{
 +      if ( iIdleTimeCounter != 0 )
 +      {
 +              iIdleTimeCounter->start();
 +      }
 +}
 +
 +void Engine::previousViewRestored()
 +{
 +      if ( iIdleTimeCounter != 0 )
 +      {
 +              iIdleTimeCounter->start();
 +      }
 +}
 +
 +void Engine::stopIdleTimeCounter()
 +{
 +      if ( iIdleTimeCounter != 0 )
 +      {
 +              iIdleTimeCounter->stop();
 +      }
 +}
 +
 +void Engine::startIdleTimeCounter()
 +{
 +      if ( iIdleTimeCounter != 0 )
 +      {
 +              iIdleTimeCounter->start();
 +      }
 +}
 +
++void Engine::currentRoomChanged(Room *aRoom)
++{
++      iCurrentRoom = aRoom;
++}
@@@ -72,7 -83,7 +72,7 @@@ private slots
         * Slot. Fetches meetings from the server. Parameters are hard coded: the meetings of the default
         * room from current and +/- 2 weeks are fetched.
         */
--      void fetchMeetings();
++//    void fetchMeetings();
        //! Slot. Saves fetched meetings to the current instance's local storage.
        /*!
         * Slot. Saves fetched meetings to the current instance's local storage. Meetings are soted in a
        /*!
         *  Receives the cancel event of the progress bar when meeting details requested.
         */
 -      void fetchMeetingDetailsCancelled();
 +      void fetchMeetingDetails( Meeting *aMeeting );
 +      void cancelFetchMeetingDetails();
 +      
 +      void handleViewEvent();
 +      void previousViewRestored();
 +      
 +      //! Slot for dialog activation signal.
 +      /*!
 +       * This slot is used to inform that dialog is activated. It stops
 +       * the idle time counter so screensaver is not activated while the
 +       * dialog is displayed.
 +       */
 +      void dialogActivated();
 +      //! Slot for dialog deactivation signal.
 +      /*!
 +       * This slot is used to inform that dialog is deactivated. It restarts
 +       * the idle time counter so that the screensaver is being activated again
 +       * as needed.
 +       */
 +      void dialogDeactivated();
 +      
 +      void stopIdleTimeCounter();
 +      void startIdleTimeCounter();
  
 +      void changeDeviceMode( bool aChange );
 +      
++      void currentRoomChanged( Room *aRoom );
++      
  private:
 +      // Make the UIManager as friendly class so it can connect to private slots.
 +      friend class UIManager;
 +      
        //! Provides the index of the Meeting instance which is at the specified time.
        /*!
         * Provides the index of the Meeting instance which is at the specified time. If there are
@@@ -202,6 -172,6 +204,8 @@@ private
        QTimer *iAutoRefresh;
  
        QList<Meeting*> iMeetings;
++      
++      Room *iCurrentRoom;
  };
  
  #endif /*ENGINE_H_*/
index 3de5117,0000000..d6d16b3
mode 100644,000000..100644
--- /dev/null
@@@ -1,299 -1,0 +1,300 @@@
 +#include "UIManager.h"
 +
 +#include <QDateTime>
 +#include <QTime>
 +
 +#include "Engine.h"
 +#include "WindowManager.h"
 +#include "ViewBase.h"
 +#include "WeeklyViewWidget.h"
 +#include "SettingsView.h"
 +#include "RoomStatusIndicatorWidget.h"
 +#include "MeetingInfoDialog.h"
 +#include "ProgressBar.h"
 +#include "CommunicationManager.h"
 +#include "Configuration.h"
 +#include "DisplaySettings.h"
 +
 +#include <QtDebug>
 +
 +#define QT_DELETE(X) \
 +      if ( X != 0 ) \
 +      { \
 +              delete X; \
 +              X = 0; \
 +      }
 +
 +UIManager::UIManager( Engine *aEngine, WindowManager *aWindowManager ) :
 +      iEngine( aEngine ),
 +      iWindowManager( aWindowManager ),
 +      iWeeklyView( 0 ),
 +      iSettingsView( 0 ),
 +      iRoomStatusIndicator( 0 ),
 +      iPasswordDialog( 0 ),
 +      iProgressBar( 0 ),
 +      iMeetingInfo( 0 )
 +{
 +      if ( iEngine == 0 ) return;
 +      if ( iWindowManager == 0 ) return;
 +      
 +      qDebug() << "[UIManager::ctor] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
 +      
 +      createWeeklyView();
 +      createSettingsView();
 +      createRoomStatusIndicator();
 +      createPasswordDialog();
 +      createProgressBar();
 +      createMeetingInfoDialog();
 +      
 +      qDebug() << "[UIManager::ctor] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
 +}
 +
 +UIManager::~UIManager()
 +{
 +      iEngine = 0;
 +      iWindowManager = 0;
 +      
 +      QT_DELETE( iMeetingInfo );
 +      QT_DELETE( iProgressBar );
 +      QT_DELETE( iPasswordDialog );
 +      QT_DELETE( iRoomStatusIndicator );
 +      QT_DELETE( iSettingsView );
 +      QT_DELETE( iWeeklyView );
 +}
 +
 +void UIManager::showMainView()
 +{
 +      iWindowManager->showView( iWeeklyView );
 +}
 +
 +void UIManager::showProgressBar( QString aText )
 +{
 +      if ( iProgressBar != 0 )
 +      {
 +              iProgressBar->update( aText );
 +              iWindowManager->showDialog( iProgressBar );
 +      }
 +}
 +
 +// ===============================================
 +//            INITIALIZE THE UIMANAGER
 +void UIManager::createWeeklyView()
 +{
 +      iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), iEngine->iConfiguration );
 +      
 +      // Connect signals to UIManager
 +      connect( iWeeklyView, SIGNAL( settingsButtonClicked() ), this, SLOT( settingsViewRequest() ) );
 +      connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) ) );
 +      connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( showMeetingProgressBar( Meeting * ) ) );
 +      // Connect signals to engine
 +      connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), iEngine, SLOT( fetchMeetingDetails( Meeting * ) ) );
 +      connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), iEngine, SLOT( shownWeekChanged( QDate ) ) );
++      connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iEngine, SLOT( currentRoomChanged( Room * ) ) );
 +}
 +
 +void UIManager::createSettingsView()
 +{
 +      iSettingsView = new SettingsView;
 +      
 +      // Connect signals
 +      connect( iSettingsView, SIGNAL( okClicked() ), this, SLOT( settingsOkClicked() ) );
 +}
 +
 +void UIManager::createRoomStatusIndicator()
 +{
 +      iRoomStatusIndicator = new RoomStatusIndicatorWidget( iEngine->defaultRoom(), Room::FreeStatus, QTime::currentTime(), iEngine->iConfiguration->displaySettings()->dateFormat() );
 +}
 +
 +void UIManager::createPasswordDialog()
 +{
 +      iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), tr("UIManager::createPasswordDialog"), tr("UIManager::createPasswordDialog") );
 +      
 +      connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
 +}
 +
 +void UIManager::createProgressBar()
 +{
 +      iProgressBar = new ProgressBar( tr("CHANGE THIS"), true );
 +      
 +      // Connect to UIManager
 +      connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBarCancelled() ) );
 +      // Connect to Engine
 +      connect( iProgressBar, SIGNAL( cancel() ), iEngine, SLOT( cancelFetchMeetingDetails() ) );
 +}
 +
 +void UIManager::createMeetingInfoDialog()
 +{
 +      iMeetingInfo = new MeetingInfoDialog();
 +}
 +
 +void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
 +{
 +      connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
 +                      this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
 +      
 +      connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), this, SLOT( updateProgressBarText( const QString & ) ) );
 +      connect( aDeviceManager, SIGNAL( changeModeFailed() ), this, SLOT( hideProgressBar() ) );
 +}
 +
 +void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
 +{
 +      connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
 +      connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> & ) ), this, SLOT( meetingsFetched( const QList<Meeting *> & ) ) );
 +}
 +
 +// ============================================
 +//            UIMANAGER SLOTS
 +void UIManager::settingsViewRequest()
 +{
 +      // Show the settings view and stop the idle timer
 +      if ( iSettingsView != 0 )
 +      {
 +              iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
 +              iEngine->stopIdleTimeCounter();
 +      }
 +}
 +
 +void UIManager::settingsOkClicked()
 +{
 +      // Show the weekly view and restart the idle timer
 +      if ( iWeeklyView != 0 )
 +      {
 +              iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
 +              iEngine->startIdleTimeCounter();
 +      }
 +}
 +
 +void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
 +{
 +      qDebug() << "[UIManager::meetingsFetched] <Change the weekly views method to slot so we don't need this>";
 +      if ( iWeeklyView != 0 )
 +      {
 +              iWeeklyView->refreshMeetings( aMeetings );
 +      }
 +}
 +
 +void UIManager::showMeetingProgressBar( Meeting *aMeeting )
 +{
 +      if ( iProgressBar != 0 )
 +      {
 +              iProgressBar->update( tr("Fetching meeting info...") );
 +              iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
 +              iEngine->stopIdleTimeCounter();
 +      }
 +}
 +
 +void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
 +{
 +      qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
 +      if ( iMeetingInfo != 0 )
 +      {
 +              if ( iProgressBar != 0 && iProgressBar->isVisible() )
 +              {
 +                      iProgressBar->close(); // Close it in case it's visible
 +              }
 +              MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
 +              iWindowManager->showDialog( static_cast<QDialog *>( tmp ) );
 +// TODO : We should use the member variable and implement correctly the setMeeting() method !!!
 +//            iMeetingInfo->setMeeting( &aDetailedMeeting );
 +//            iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
 +      }
 +}
 +
 +void UIManager::roomStatusIndicatorRequested()
 +{
 +      if ( iRoomStatusIndicator != 0 )
 +      {
 +              iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
 +              iEngine->stopIdleTimeCounter();
 +      }
 +}
 +
 +void UIManager::previousViewRestored()
 +{
 +      iEngine->startIdleTimeCounter();
 +}
 +
 +void UIManager::progressBarCancelled()
 +{
 +      if ( iProgressBar != 0 )
 +      {
 +              iProgressBar->close();
 +              iEngine->startIdleTimeCounter();
 +      }
 +}
 +
 +void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
 +{
 +      qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
 +      
 +      QString message = tr( "You are about to change operation mode to %1." )
 +                              .arg( iEngine->iDevice->operationModeToString( aMode ) );
 +
 +      if ( iPasswordDialog != 0 )
 +      {
 +              // TODO : Set the new text for password dialog
 +              iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
 +      }
 +}
 +
 +void UIManager::currentRoomChanged(Room *aRoom)
 +{
 +      if ( iWeeklyView != 0 )
 +      {
 +              QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
 +              QDateTime to = QDateTime( from.addDays( 8 ) );
 +              iEngine->fetchMeetings( from, to, aRoom );
 +      }
 +}
 +
 +void UIManager::updateTime(QDateTime aDateTime)
 +{
 +      if ( iWeeklyView != 0 )
 +      {
 +              iWeeklyView->setCurrentDateTime( aDateTime );
 +      }
 +}
 +
 +void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
 +{
 +      switch( aStatus )
 +      {
 +              case PasswordDialog::Correct:
 +                      // Show the progress bar..
 +                      if ( iProgressBar != 0 )
 +                      {
 +                              iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false );
 +                      }
 +                      // ... and initiate the mode changing
 +                      iEngine->changeDeviceMode( true );
 +                      break;
 +              case PasswordDialog::Incorrect:
 +                      iWindowManager->error( tr("Incorrect Password") );
 +              case PasswordDialog::Canceled:
 +                      iEngine->changeDeviceMode( false );
 +                      break;
 +      }
 +      
 +      // Close the dialog after we have handled the status
 +      if ( iPasswordDialog != 0 )
 +      {
 +              iPasswordDialog->close();
 +      }
 +}
 +
 +void UIManager::updateProgressBarText(const QString &aText)
 +{
 +      if ( iProgressBar != 0 )
 +      {
 +              iProgressBar->update( aText );
 +      }
 +}
 +
 +void UIManager::hideProgressBar()
 +{
 +      qDebug() << "[UIManager::hideProgressBar] <Invoked>";
 +      if ( iProgressBar != 0 && iProgressBar->isVisible() )
 +      {
 +              iProgressBar->close();
 +      }
 +}