// 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
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++)
{
// ...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 );
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;
}
}
}
-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()
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()
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
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;
//! 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
QTimer *iIdleTimeCounter;
Clock *iClock;
+ QDate iCurrentDate;
Configuration *iConfiguration;
CommunicationManager *iCommunication;
DeviceManager *iDevice;
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() );