Progress bar related updating
[qtmeetings] / src / BusinessLogic / Engine.cpp
index 6e677c4..a61006c 100644 (file)
@@ -21,6 +21,7 @@ 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 )
        {
@@ -35,6 +36,9 @@ Engine::Engine() :
        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()) );
@@ -80,6 +84,7 @@ Engine::Engine() :
 
 Engine::~Engine()
 {
+       qDebug() << "Engine::~Engine()";
        while ( !iMeetings.isEmpty() )
                delete iMeetings.takeFirst();
        iIdleTimeCounter->stop();
@@ -102,6 +107,7 @@ void Engine::closeApplication()
 
 void Engine::observedEventDetected()
 {
+       qDebug() << "Engine::observedEventDetected()";
        iWindowManager->showWeeklyView();
        // prepare to restart idle counter
        if ( iIdleTimeCounter->isActive() )
@@ -114,11 +120,13 @@ void Engine::observedEventDetected()
 
 Room* Engine::defaultRoom()
 {
+       qDebug() << "Engine::defaultRoom()";
        return iConfiguration->defaultRoom();
 }
 
 void Engine::checkStatusOfAllRooms()
 {
+       qDebug() << "Engine::checkStatusOfAllRooms()";
        // iterate trough on the rooms
        for ( int i = 0; i < iConfiguration->rooms().count(); i++ )
        {
@@ -129,6 +137,7 @@ void Engine::checkStatusOfAllRooms()
 
 int Engine::indexOfMeetingAt( Room *aRoom, QDateTime aAt )
 {
+       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
@@ -144,6 +153,7 @@ int Engine::indexOfMeetingAt( Room *aRoom, QDateTime aAt )
 
 int Engine::indexOfMeetingAfter( Room *aRoom, QDateTime aAfter )
 {
+       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++ )
@@ -166,6 +176,7 @@ int Engine::indexOfMeetingAfter( Room *aRoom, QDateTime aAfter )
 
 void Engine::roomStatusInfoNeeded( Room *aRoom )
 {
+       qDebug() << "Engine::roomStatusInfoNeeded( Room * )";
        if ( aRoom == 0 )
        {
                return;
@@ -195,11 +206,20 @@ void Engine::fetchMeetings()
 
 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 )) ) )
@@ -212,6 +232,7 @@ bool Engine::isMeetingInList( const QList<Meeting*> &aList, const Meeting *aMeet
 
 void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
 {
+       qDebug() << "Engine::meetingsFetched( const QList<Meeting*> & )";
        // check if there is any new meeting in the list came from the server -> added
        for ( int i = 0; i < aMeetings.count(); i++ )
        {
@@ -246,6 +267,8 @@ void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
 
 void Engine::meetingDetailsFetched( Meeting &aDetailedMeeting )
 {
+       qDebug() << "Engine::meetingDetailsFetched( Meeting & )";
+       iWindowManager->closeProgressBar();
        iWindowManager->showMeetingInfo( &aDetailedMeeting );
 }
 
@@ -253,8 +276,9 @@ void Engine::errorHandler( int aCode, const QString &aAddInfo )
 {
        qDebug() << "Engine::ErrorHandler, aCode: " << aCode;
        // inform UI about the problem
-       if( aCode >= 100 && aCode <= 110 )
+       if( aCode >= 100 && aCode <= 150 )
                qDebug() << "CommunicationManager signaled an error:" << aCode;
+       iWindowManager->closeProgressBar();
        iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) );
 }
 
@@ -268,12 +292,13 @@ void Engine::currentRoomChanged( Room *aCurrentRoom )
 
 void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn )
 {
-       qDebug() << "Engine::fetchMeetings";
+       qDebug() << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )";
        iCommunication->fetchMeetings( aFrom, aUntil, *aIn );
 }
 
 void Engine::shownWeekChanged( QDate aFrom )
 {
+       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" );
@@ -281,9 +306,54 @@ void Engine::shownWeekChanged( QDate aFrom )
 }
 
 void Engine::changeModeOrdered( DeviceManager::OperationMode aMode )
-{
+{      
+       qDebug() << "Engine::changeModeOrdered( DeviceManager::OperationMode )";
        QString message = tr( "You are about to change operation mode to %1." )
                                .arg( iDevice->operationModeToString( aMode ) );
        
        iWindowManager->showPasswordDialog( iConfiguration->adminPassword(), message );
 }
+
+void Engine::passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus )
+{
+       qDebug() << "Engine::passwordEntered( PasswordDialog::PasswordStatus )";
+       iWindowManager->closePasswordDialog();
+       
+       switch ( aPasswordStatus )
+       {
+               case PasswordDialog::Correct :
+               {
+                       iWindowManager->showProgressBar( "Changing current operation mode.", true );
+                       connect( iWindowManager, SIGNAL( progressBarCancelled() ), this, SLOT( progressBarCancelled() ) );
+                       connect( iDevice, SIGNAL( changingMode( const QString & ) ),
+                                       iWindowManager, SLOT( updateProgressBar( const QString & ) ) );
+                       connect( iDevice, SIGNAL( changingModeFailed() ), this, SLOT( progressBarCancelled() ) );
+                       iDevice->changeMode( true );
+                       break;
+               }
+               case PasswordDialog::Incorrect :
+               {
+                       iWindowManager->error( tr( "Incorrect password." ) );
+                       iDevice->changeMode( false );
+                       break;
+               }
+               default : //case PasswordDialog::Canceled
+               {
+                       iDevice->changeMode( false );
+               }
+       }
+}
+
+void Engine::progressBarCancelled()
+{
+       qDebug() << "Engine::progressBarCancelled()";
+       //TODO: cancel the on-going event
+       iWindowManager->closeProgressBar();
+       iDevice->changeMode( false );
+}
+
+void Engine::fetchMeetingDetailsCancelled()
+{
+       iCommunication->cancelFetchMeetingDetails();
+       iWindowManager->closeProgressBar();
+}