qtmeetings sources to Maemo garage
[qtmeetings] / src / BusinessLogic / Engine.h
1 #ifndef ENGINE_H_
2 #define ENGINE_H_
3
4 #include <QObject>
5 #include <QDateTime>
6 #include "Room.h"
7
8 class QTimer;
9 class Clock;
10 class Configuration;
11 class CommunicationManager;
12 class Meeting;
13 class DeviceManager;
14
15 //! BusinessLogic class. Contains all the business logic of the application.
16 /*!
17  * BusinessLogic class. Contains all the business logic of the application. It is responsible
18  * for connecting user interface to lower application layers (IO).
19  */
20 class Engine : public QObject
21 {
22         Q_OBJECT
23
24 public:
25         //! Constructor.
26         /*!
27          * Constructor to initialize an Engine instance.
28          */
29         Engine();
30         //! Destructor.
31         virtual ~Engine();
32
33         //! Gets the clock instance used by the object to get up-to-date date and time info.
34         /*!
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.
37          */
38         Clock* clock();
39         //! Gets the application's configuration.
40         /*!
41          * Gets the application's configuration.
42          * \return Pointer to the Configuration instance.
43          */
44         Configuration* configuration();
45         //! Gets default room of the application.
46         /*!
47          * Gets default room of the application.
48          * \return Pointer to the default Room instance.
49          */
50         Room* defaultRoom();
51         //! Gets the deviceManager instance
52         /*!
53          * Gets the deviceManager instance.
54          * \return Pointer to the deviceManager instance.
55          */
56         DeviceManager* deviceManager();
57
58 signals:
59         //! Signal. Emitted if initialization of the current instance failed.
60         /*!
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.
64          */
65         void initializationFailed();
66         //! Signal. Emitted if the availability information of the specified room changed.
67         /*!
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.
72          */
73         void roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aUntil );
74         //! Signal. Emitted if new meeting was found on the server.
75         /*!
76          * Signal. Emitted if new meeting was found on the server.
77          * \param aMeeting The new meeting which was added.
78          */
79         void meetingAdded( Meeting *aMeeting );
80         //! Signal. Emitted if meeting was deleted on the server.
81         /*!
82          * Signal. Emitted if meeting was deleted on the server.
83          * \param aMeeting The meeting which was deleted.
84          */
85         void meetingDeleted( Meeting *aMeeting );
86         //! Signal. Emitted error occured and error message must be shown on UI.
87         /*!
88          * Signal. Emitted error occured and error message must be shown on UI.
89          * \param aErrorMessage The message.
90          */
91         void error( const QString &aErrorMessage );
92
93         void meetingDetailsFetched( Meeting *aDetailedMeeting );
94
95 public slots:
96         //! Slot. Checks actual availability information of the specified room.
97         /*!
98          * Slot. Checks actual availability information of the specified room.
99          * \param aRoom The room which availability information is needed.
100          */
101         void roomStatusInfoNeeded( Room *aRoom );
102         //! Slot. Fetches meetings from the server.
103         /*!
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.
108          */
109         void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, Room *aIn );
110         
111         void fetchMeetingDetails( Meeting * );
112         
113         /*!
114          * Slot. Sets the current meeting room iCurrentRoom.
115          * \param aCurrentRoom
116          */
117         void currentRoomChanged( Room *aCurrentRoom );
118
119 private slots:
120         //! Slot. Handles errors.
121         /*!
122          * Slot. Handles errors and informs the UI by emitting the error() signal with the message in
123          * parameter.
124          * \param aCode The error code.
125          * \param aAddInfo Possible addition info.
126          */
127         void errorHandler( int aCode, const QString &aAddInfo = "" );
128         //! Slot. Fetches meetings from the server.
129         /*!
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.
132          */
133         void fetchMeetings();
134         //! Slot. Saves fetched meetings to the current instance's local storage.
135         /*!
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
138          * deleted meeting.
139          * \param aMeetings The list of freshly fetched meetings.
140          */
141         void meetingsFetched( const QList<Meeting*>& );
142         
143         void meetingDetailsFetched( Meeting &aDetailedMeeting );
144         
145         //! Slot. Checks the availability of all the rooms.
146         /*!
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.
149          */
150         void checkStatusOfAllRooms();
151
152 private:
153         //! Provides the index of the Meeting instance which is at the specified time.
154         /*!
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.
160          */
161         int indexOfMeetingAt( Room *aRoom, QDateTime aAt );
162         //! Provides the index of the Meeting instance which is starts the closest to the specified time.
163         /*!
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.
169          */
170         int indexOfMeetingAfter( Room *aRoom, QDateTime aAfter );
171         //! Indicates if the QList contains the Meeting or not.
172         /*!
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.
177          */
178         static bool isMeetingInList( const QList<Meeting*> &aList, const Meeting *aMeeting );
179
180 private:
181         static QTime endOfTheDay;
182
183         Clock *iClock;
184         Configuration *iConfiguration;
185         CommunicationManager *iCommunication;
186         DeviceManager *iDevice;
187
188         QTimer *iAutoRefresh;
189
190         QList<Meeting*> iMeetings;
191
192         Room *iCurrentRoom;     /*! Not owned */
193 };
194
195 #endif /*ENGINE_H_*/