Merged
[qtmeetings] / src / BusinessLogic / Engine.cpp
index e4a527a..fb0fe9f 100644 (file)
@@ -15,7 +15,7 @@
 #include <QList>
 #include <QtDebug>
 
-QTime Engine::endOfTheDay = QTime( 23, 59, 0, 0 ); // end of the day is 11:59pm
+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.
@@ -51,7 +51,7 @@ Engine::Engine() :
 
        // Create auto refresh timer
        iAutoRefresh = new QTimer;
-       iAutoRefresh->setInterval( iConfiguration->connectionSettings()->refreshInterval() * 1000 );
+       iAutoRefresh->setInterval(iConfiguration->connectionSettings()->refreshInterval() * 1000);
        iAutoRefresh->start();
        connect( iAutoRefresh, SIGNAL( timeout() ), iAutoRefresh, SLOT( start() ) );
        connect( iAutoRefresh, SIGNAL( timeout() ), this, SLOT( fetchMeetings() ) );
@@ -91,7 +91,7 @@ void Engine::closeApplication()
 {
        qDebug() << "Engine::closeApplication()";
        // closes application after 1 second
-       QTimer::singleShot( 1000, QApplication::instance(), SLOT( quit() ) );
+       QTimer::singleShot( 1000, QApplication::instance(), SLOT( quit() ));
 }
 
 Room* Engine::defaultRoom()
@@ -104,22 +104,20 @@ void Engine::checkStatusOfAllRooms()
 {
 //     qDebug() << "Engine::checkStatusOfAllRooms()";
        // iterate trough on the rooms
-       for ( int i = 0; i < iConfiguration->rooms().count(); i++ )
+       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 )
+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
-               if ( aRoom->equals( iMeetings.at( i )->room() )
-                         && iMeetings.at( i )->startsAt() <= aAt
-                         && iMeetings.at( i )->endsAt() >= aAt )
+               if (aRoom->equals(iMeetings.at( i )->room() ) && iMeetings.at( i )->startsAt() <= aAt && iMeetings.at( i )->endsAt() >= aAt)
                {
                        return i;
                }
@@ -127,21 +125,18 @@ int Engine::indexOfMeetingAt( Room *aRoom, QDateTime aAt )
        return -1;
 }
 
-int Engine::indexOfMeetingAfter( Room *aRoom, QDateTime aAfter )
+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++ )
+       for (int i = 0; i < iMeetings.count(); i++)
        {
                // if the meeting is in the same room, on the same day but after the specified time
-               if ( aRoom->equals( iMeetings.at( i )->room() )
-                         && iMeetings.at( i )->startsAt().date() == aAfter.date()
-                         && iMeetings.at( i )->startsAt() > aAfter )
+               if (aRoom->equals(iMeetings.at( i )->room() ) && iMeetings.at( i )->startsAt().date() == aAfter.date() && iMeetings.at( i )->startsAt() > aAfter)
                {
                        // if there was not any meeting find yet or the previously found is a later one then the (i)th
-                       if ( min == -1
-                                 || iMeetings.at( min )->startsAt() > iMeetings.at( i )->startsAt() )
+                       if (min == -1 || iMeetings.at( min )->startsAt() > iMeetings.at( i )->startsAt() )
                        {
                                min = i;
                        }
@@ -150,7 +145,7 @@ int Engine::indexOfMeetingAfter( Room *aRoom, QDateTime aAfter )
        return min;
 }
 
-void Engine::roomStatusInfoNeeded( Room *aRoom )
+void Engine::roomStatusInfoNeeded(Room *aRoom)
 {
 //     qDebug() << "Engine::roomStatusInfoNeeded( Room * )";
        if ( aRoom == 0 )
@@ -158,15 +153,17 @@ void Engine::roomStatusInfoNeeded( Room *aRoom )
                return;
        }
 
-       int indexOfCurrentMeeting = indexOfMeetingAt( aRoom, iClock->datetime() );
-       int indexOfNextMeeting = indexOfMeetingAfter( aRoom, iClock->datetime() );
+       int indexOfCurrentMeeting = indexOfMeetingAt(aRoom, iClock->datetime() );
+       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 );
+       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 );
 
        //currently works only for deafult room
 //     if( aRoom->equals( *(defaultRoom() ) ) )
@@ -177,15 +174,16 @@ void Engine::fetchMeetings()
 {
        Room *room = defaultRoom();
        qDebug() << "Engine::fetchMeetings for " << room->name();
-       fetchMeetings( iClock->datetime(), iClock->datetime().addDays( 7 ), room );
+       fetchMeetings(iClock->datetime(), iClock->datetime().addDays( 7), room);
 }
 
 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++ )
+       qDebug()
+                       << "Engine::isMeetingInList( const QList<Meeting*> &, const Meeting * )";
+       for (int i = 0; i < aList.count(); i++)
        {
-               if ( aMeeting->equals( *(aList.at( i )) ) )
+               if (aMeeting->equals( *(aList.at(i))) )
                {
                        return true;
                }
@@ -193,30 +191,30 @@ bool Engine::isMeetingInList( const QList<Meeting*> &aList, const Meeting *aMeet
        return false;
 }
 
-void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
+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++ )
+       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 )) );
-                       iMeetings.append( m );
+                       iMeetings.append(m);
                        // and signal the changes
 //                     iWeeklyView->insertMeeting( m );
                }
        }
 
        // check if there is any meeting NOT in the list came from the server -> deleted
-       for ( int i = 0; i < iMeetings.count(); i++ )
+       for (int i = 0; i < iMeetings.count(); i++)
        {
                // if the (i)th meeting is in the local but NOT in the server's meeting list
-               if ( !isMeetingInList( aMeetings, iMeetings.at( i ) ) )
+               if ( !isMeetingInList(aMeetings, iMeetings.at(i) ) )
                {
-                       Meeting* m = iMeetings.takeAt( i );
+                       Meeting* m = iMeetings.takeAt(i);
                        // signal the changes
 //                     iWeeklyView->deleteMeeting( m );
                        // delete the meeting from the local list
@@ -225,25 +223,19 @@ void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
        }
 
        // refresh room status info
-       roomStatusInfoNeeded( defaultRoom() );
+       roomStatusInfoNeeded(defaultRoom() );
 }
 
 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->error( ErrorMapper::codeToString( aCode, aAddInfo ) );
 }
 
 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::fetchMeetingDetails(Meeting *aMeeting)