const int IDLE_TIME_MULTIPLIER = 60000; // Multiplies milliseconds to minutes
Engine::Engine() :
- iClock( 0 ), iConfiguration( Configuration::instance() ), iCommunication( 0 )
+ iClock( 0), iConfiguration(Configuration::instance() ), iCommunication( 0)
{
qDebug() << "Engine::Engine()";
+ iCommunicationFailed = false;
// if reading of configuration fails, signal that initialization failed
- if ( iConfiguration == 0 )
+ if (iConfiguration == 0)
{
- QTimer::singleShot( 0, this, SLOT( closeApplication() ) );
+ 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 ) ) );
-
-
+ 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& ) ) );
+ 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& ) ));
//initialize idle time counter
iIdleTimeCounter = new QTimer();
return false;
}
- void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
+ void Engine::meetingsFetched(const QList<Meeting*> &aMeetings)
{
qDebug() << "Engine::meetingsFetched( const QList<Meeting*> & )";
+ if( iCommunicationFailed )
+ {
+ iCommunicationFailed = false;
+ //iWindowManager->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 < aMeetings.count(); i++)
{
// if the (i)th meeting is not in the local meeting list
- if ( !isMeetingInList( iMeetings, aMeetings.at( i ) ) )
+ if ( !isMeetingInList(iMeetings, aMeetings.at(i) ) )
{
// add to the local database =)
Meeting* m = new Meeting( *(aMeetings.at( i )) );
{
qDebug() << "Engine::meetingDetailsFetched( Meeting & )";
iWindowManager->closeProgressBar();
+ if( iCommunicationFailed )
+ {
+ iCommunicationFailed = false;
+ iWindowManager->connectionEstablished();
+ }
- iWindowManager->showMeetingInfo( &aDetailedMeeting );
+ iWindowManager->showMeetingInfo( &aDetailedMeeting);
}
- void Engine::errorHandler( int aCode, const QString &aAddInfo )
+ 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;
+ if( !iCommunicationFailed )
+ {
+ // Only inform window manager when first error appears
+ iCommunicationFailed = true;
+ //iWindowManager->connectionLost();
+ }
+ }
iWindowManager->closeProgressBar();
}
- iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) );
+ iWindowManager->error(ErrorMapper::codeToString(aCode, aAddInfo) );
}
- void Engine::currentRoomChanged( Room *aCurrentRoom )
+ void Engine::currentRoomChanged(Room *aCurrentRoom)
{
qDebug() << "Engine::currentRoomChanged to " << aCurrentRoom->name();
- QDateTime from( iWindowManager->weeklyView()->beginnigOfShownWeek() );
- QDateTime to( from.addDays( 8 ) );
- fetchMeetings( from, to, aCurrentRoom );
+ QDateTime from(iWindowManager->weeklyView()->beginnigOfShownWeek() );
+ QDateTime to(from.addDays( 8) );
+ fetchMeetings(from, to, aCurrentRoom);
}
- void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn )
+ void Engine::fetchMeetings(const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn)
{
- qDebug() << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )";
- iCommunication->fetchMeetings( aFrom, aUntil, *aIn );
+ qDebug()
+ << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )";
+ iCommunication->fetchMeetings(aFrom, aUntil, *aIn);
}
- void Engine::shownWeekChanged( QDate aFrom )
+ 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" );
- fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() );
+ 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() );
}
- void Engine::changeModeOrdered( DeviceManager::OperationMode aMode )
- {
+ 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 );
+ .arg(iDevice->operationModeToString(aMode) );
+
+ iWindowManager->showPasswordDialog(iConfiguration->adminPassword(), message);
}
- void Engine::passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus )
+ void Engine::passwordEntered(PasswordDialog::PasswordStatus aPasswordStatus)
{
qDebug() << "Engine::passwordEntered( PasswordDialog::PasswordStatus )";
iWindowManager->closePasswordDialog();