11 class CommunicationManager;
15 //! BusinessLogic class. Contains all the business logic of the application.
17 * BusinessLogic class. Contains all the business logic of the application. It is responsible
18 * for connecting user interface to lower application layers (IO).
20 class Engine : public QObject
27 * Constructor to initialize an Engine instance.
33 //! Gets the clock instance used by the object to get up-to-date date and time info.
35 * Gets the clock instance used by the object to get up-to-date date and time info.
36 * \return Pointer to the Clock instance.
39 //! Gets the application's configuration.
41 * Gets the application's configuration.
42 * \return Pointer to the Configuration instance.
44 Configuration* configuration();
45 //! Gets default room of the application.
47 * Gets default room of the application.
48 * \return Pointer to the default Room instance.
51 //! Gets the deviceManager instance
53 * Gets the deviceManager instance.
54 * \return Pointer to the deviceManager instance.
56 DeviceManager* deviceManager();
59 //! Signal. Emitted if initialization of the current instance failed.
61 * Signal. Emitted if initialization of the current instance failed, if reading of the configuration
62 * was not successful. It's purpose to inform the userinterface that the Engine is not ready for
63 * controlling the application, application must be shut down.
65 void initializationFailed();
66 //! Signal. Emitted if the availability information of the specified room changed.
68 * Signal. Emitted if the availability information of the specified room changed.
69 * \param aRoom The Room instance which availability changed.
70 * \param aStatus The status of the room.
71 * \param aUntil Time until the spacified status is valid.
73 void roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aUntil );
74 //! Signal. Emitted if new meeting was found on the server.
76 * Signal. Emitted if new meeting was found on the server.
77 * \param aMeeting The new meeting which was added.
79 void meetingAdded( Meeting *aMeeting );
80 //! Signal. Emitted if meeting was deleted on the server.
82 * Signal. Emitted if meeting was deleted on the server.
83 * \param aMeeting The meeting which was deleted.
85 void meetingDeleted( Meeting *aMeeting );
86 //! Signal. Emitted error occured and error message must be shown on UI.
88 * Signal. Emitted error occured and error message must be shown on UI.
89 * \param aErrorMessage The message.
91 void error( const QString &aErrorMessage );
93 void meetingDetailsFetched( Meeting *aDetailedMeeting );
96 //! Slot. Checks actual availability information of the specified room.
98 * Slot. Checks actual availability information of the specified room.
99 * \param aRoom The room which availability information is needed.
101 void roomStatusInfoNeeded( Room *aRoom );
102 //! Slot. Fetches meetings from the server.
104 * Slot. Fetches meetings from the server, exact parameters are specified in the parameter list.
105 * \param aFrom Time from when the meetings need to be fetched.
106 * \param aUntil Time until when the meetings need to be fetched.
107 * \param aIn The room which meetings need to be fetched.
109 void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, Room *aIn );
111 void fetchMeetingDetails( Meeting * );
114 * Slot. Sets the current meeting room iCurrentRoom.
115 * \param aCurrentRoom
117 void currentRoomChanged( Room *aCurrentRoom );
120 //! Slot. Handles errors.
122 * Slot. Handles errors and informs the UI by emitting the error() signal with the message in
124 * \param aCode The error code.
125 * \param aAddInfo Possible addition info.
127 void errorHandler( int aCode, const QString &aAddInfo = "" );
128 //! Slot. Fetches meetings from the server.
130 * Slot. Fetches meetings from the server. Parameters are hard coded: the meetings of the default
131 * room from current and +/- 2 weeks are fetched.
133 void fetchMeetings();
134 //! Slot. Saves fetched meetings to the current instance's local storage.
136 * Slot. Saves fetched meetings to the current instance's local storage. Meetings are soted in a
137 * private QList, it is iterated through and signals are emitted if there is any new, updated or
139 * \param aMeetings The list of freshly fetched meetings.
141 void meetingsFetched( const QList<Meeting*>& );
143 void meetingDetailsFetched( Meeting &aDetailedMeeting );
145 //! Slot. Checks the availability of all the rooms.
147 * Slot. Checks the availability of all the rooms by iterating through the current object's local
148 * room storage and calling the roomStatusInfoNeeded() separately on each of them.
150 void checkStatusOfAllRooms();
153 //! Provides the index of the Meeting instance which is at the specified time.
155 * Provides the index of the Meeting instance which is at the specified time. If there are
156 * overlapping meetings then returns one of then undetetministically.
157 * \param aRoom The room which meetings are looked through.
158 * \param aAt Date and time when the meeting is already going.
159 * \return Index of the meeting if found; otherwise, -1.
161 int indexOfMeetingAt( Room *aRoom, QDateTime aAt );
162 //! Provides the index of the Meeting instance which is starts the closest to the specified time.
164 * Provides the index of the Meeting instance which is starts the closest to the specified time.
165 * If there are overlapping meetings then returns one of then undetetministically.
166 * \param aRoom The room which meetings are looked through.
167 * \param aAt Date and time when the meeting is not yet started.
168 * \return Index of the meeting if found; otherwise, -1.
170 int indexOfMeetingAfter( Room *aRoom, QDateTime aAfter );
171 //! Indicates if the QList contains the Meeting or not.
173 * Indicates if the QList contains the Meeting or not.
174 * \param aList List of meetings.
175 * \param aMeeting The meeting which is seeked in the list for.
176 * \return True if contains; otherwise, false.
178 static bool isMeetingInList( const QList<Meeting*> &aList, const Meeting *aMeeting );
181 static QTime endOfTheDay;
184 Configuration *iConfiguration;
185 CommunicationManager *iCommunication;
186 DeviceManager *iDevice;
188 QTimer *iAutoRefresh;
190 QList<Meeting*> iMeetings;
192 Room *iCurrentRoom; /*! Not owned */