Changed communication to take a week and year as parameters instead of dates as it...
authorOlli Kasari <olli.kasari@ixonos.com>
Mon, 1 Jun 2009 13:02:43 +0000 (16:02 +0300)
committerOlli Kasari <olli.kasari@ixonos.com>
Mon, 1 Jun 2009 13:02:43 +0000 (16:02 +0300)
src/BusinessLogic/Engine.cpp
src/BusinessLogic/Engine.h
src/BusinessLogic/UIManager.cpp
src/IO/Communication/CommunicationManager.cpp
src/IO/Communication/CommunicationManager.h

index aac84d4..c7aad8b 100644 (file)
@@ -48,7 +48,7 @@ Engine::Engine() :
 
        // create application clock
        iClock = new Clock;
-       connect( iClock, SIGNAL( tick( QDateTime ) ), this, SLOT( checkStatusOfAllRooms() ) );
+       connect( iClock, SIGNAL( tick( QDateTime ) ), this, SLOT( tick( QDateTime )/*checkStatusOfAllRooms()*/ ) );
        // connect( iClock, SIGNAL( tick( QDateTime ) ), iWindowManager, SLOT( distributeDateTimeInfo( QDateTime ) ) );
 
        // Create auto refresh timer
@@ -104,7 +104,8 @@ Room* Engine::defaultRoom()
 
 void Engine::checkStatusOfAllRooms()
 {
-//     qDebug() << "Engine::checkStatusOfAllRooms()";
+       // TODO: Check if date has changed
+       //      qDebug() << "Engine::checkStatusOfAllRooms()";
        // iterate trough on the rooms
        for (int i = 0; i < iConfiguration->rooms().count(); i++)
        {
@@ -165,7 +166,7 @@ void Engine::roomStatusInfoNeeded(Room *aRoom)
        // ...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
+       //currently works only for default room
        if ( aRoom->equals( *(iCurrentRoom) ) )
        {
                emit roomStatusChanged( status, until );
@@ -191,6 +192,7 @@ void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
 
        for ( int i = 0; i < iMeetings.count(); ++i ) 
        {
+               // TODO: Check if these are current week's meetings and do not overwrite those
                Meeting* m = iMeetings.takeAt( i );
                delete m;
        }
@@ -217,11 +219,11 @@ void Engine::errorHandler( int aCode, const QString &aAddInfo )
        }
 }
 
-void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn )
+void Engine::fetchMeetings( const int aWeek, const int aYear, const Room *aIn )
 {
        qDebug()
-                       << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )";
-       iCommunication->fetchMeetings(aFrom, aUntil, *aIn);
+                       << "Engine::fetchMeetings( const int aWeek, const int aYear, const Room * )";
+       iCommunication->fetchMeetings(aWeek, aYear, *aIn);
 }
 
 void Engine::cancelFetchMeetingDetails()
@@ -232,10 +234,7 @@ void Engine::cancelFetchMeetingDetails()
 void Engine::shownWeekChanged( QDate aFrom )
 {
        qDebug() << "[Engine::shownWeekChanged] <Invoked>";
-       QDateTime from( aFrom );
-       QDateTime to( aFrom.addDays( 7 ), QTime( 23, 59 ) );
-       qDebug() << "[Engine::shownWeekChanged] <From " << aFrom.toString( "d.m. h:mm" ) << " to " << to.toString( "d.m. h:mm" ) << ">";
-       iCommunication->fetchMeetings( from, to, *iCurrentRoom/*defaultRoom()*/ );
+       iCommunication->fetchMeetings( aFrom.weekNumber(), aFrom.year(), *iCurrentRoom/*defaultRoom()*/ );
 }
 
 void Engine::changeDeviceMode()
@@ -370,3 +369,20 @@ void Engine::currentRoomChanged(Room *aRoom)
        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() )
+               {
+                       qDebug() << "[Engine::tick] detected week change, fetching meetings";
+                       fetchMeetings( aCurrentDateTime.date().weekNumber(), aCurrentDateTime.date().year(), iCurrentRoom );
+               }
+       }
+       iCurrentDate = aCurrentDateTime.date();
+}
\ No newline at end of file
index 6bacdd8..c58e423 100644 (file)
@@ -120,6 +120,8 @@ private slots:
        
        void currentRoomChanged( Room *aRoom );
        
+       void tick( QDateTime aCurrentDateTime );
+       
 private:
        // Make the UIManager as friendly class so it can connect to private slots.
        friend class UIManager;
@@ -145,11 +147,11 @@ private:
        //! Slot. Fetches meetings from the server.
        /*!
         * Slot. Fetches meetings from the server, exact parameters are specified in the parameter list.
-        * \param aFrom Time from when the meetings need to be fetched.
-        * \param aUntil Time until when the meetings need to be fetched.
+        * \param aWeek Week for which the meetings need to be fetched.
+        * \param aYear Year for which the meetings need to be fetched.
         * \param aIn The room which meetings need to be fetched.
         */
-       void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn );
+       void fetchMeetings( const int aWeek, const int aYear, const Room *aIn );
        //! Initialize configuration package.
        /*!
         * This method initializes configuration classes and
@@ -192,6 +194,7 @@ private:
        
        QTimer *iIdleTimeCounter;
        Clock *iClock;
+       QDate iCurrentDate;
        Configuration *iConfiguration;
        CommunicationManager *iCommunication;
        DeviceManager *iDevice;
index 0b94628..505597b 100644 (file)
@@ -243,9 +243,8 @@ void UIManager::currentRoomChanged(Room *aRoom)
        qDebug() << "[UIManager::currentRoomChanged] <Invoked>";
        if ( iWeeklyView != 0 )
        {
-               QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
-               QDateTime to = QDateTime( from.addDays( 8 ) );
-               iEngine->fetchMeetings( from, to, aRoom );
+               QDateTime shown = QDateTime( iWeeklyView->beginnigOfShownWeek() );
+               iEngine->fetchMeetings( shown.date().weekNumber(), shown.date().year(), aRoom );
        }
 }
 
index c941c7d..2f340a0 100644 (file)
@@ -39,15 +39,31 @@ CommunicationManager::~CommunicationManager()
                delete iMeetings.takeFirst();
 }
 
-void CommunicationManager::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room &aIn )
+void CommunicationManager::fetchMeetings( const int aWeek, const int aYear, const Room &aIn )
 {
        //prevent making multiple simultaneous user availibility requests
+       //TODO: Would be nice to queue these requests instead of just aborting 
        const RequestData* rd = findRequest( GetUserAvailability );
        if( rd )
                return;
+       
+       // Set from to beginning, 00:00 of the requested week
+       QDateTime from = QDateTime::currentDateTime();
+       from = from.addYears( aYear - from.date().year() );
+       from = from.addDays( -1*(from.date().dayOfWeek()-1) );
+       from = from.addDays( (aWeek - from.date().weekNumber())*7 );
+       QTime midnight = from.time();
+       midnight.setHMS( 0,0,0 );
+       from.setTime( midnight );
+       qDebug() << "CommunicationManager::fetchMeetings from: " << from.toString();
+       
+       QDateTime until = from.addDays(7);
+       qDebug() << "CommunicationManager::fetchMeetings until: " << until.toString();
+       
+       
        ReqMsgGetUserAvailability msg;
        msg.setTimeZone();
-       msg.setTimeWindow( aFrom, aUntil );
+       msg.setTimeWindow( from, until );
        msg.addUser( aIn.address() );
                
        int id = iFetchingCommunication->request( msg.getContentTypeForHeader(), msg.getMessage() );
index 6307c28..4dfd00b 100644 (file)
@@ -45,7 +45,7 @@ public:
         *  \param aUntil QDateTime to search meetings until.
         *  \param aIn Meeting room meetings are searched.
        */
-       void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room &aIn );
+       void fetchMeetings( /*const QDateTime &aFrom, const QDateTime &aUntil*/const int aWeek, const int aYear, const Room &aIn );
        //! Starts fetching a meeting details. Details are returned by the meetingDetailsFetched signal.
        /*! 
         *  \param aMeeting A meeting the detailed information is wanted.