461b437a98bc5eba173e3e0419ed3b3210739e75
[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 #include "WindowManager.h"
8
9 class QTimer;
10 class Clock;
11 class Configuration;
12 class CommunicationManager;
13 class Meeting;
14 class DeviceManager;
15
16 //! BusinessLogic class. Contains all the business logic of the application.
17 /*!
18  * BusinessLogic class. Contains all the business logic of the application. It is responsible
19  * for connecting user interface to lower application layers (IO).
20  */
21 class Engine : public QObject
22 {
23         Q_OBJECT
24
25 public:
26         //! Constructor.
27         /*!
28          * Constructor to initialize an Engine instance.
29          */
30         Engine();
31         //! Destructor.
32         virtual ~Engine();
33         //! Gets default room of the application.
34         /*!
35          * Gets default room of the application.
36          * \return Pointer to the default Room instance.
37          */
38         Room* defaultRoom();
39
40 signals:
41
42         void meetingDetailsFetched( Meeting *aDetailedMeeting );        
43
44 private slots:
45         //! Slot. Closes the application.
46         /*!
47          * Slot. Closes the application.
48          */
49         void closeApplication();
50         //! Slot. Checks actual availability information of the specified room.
51         /*!
52          * Slot. Checks actual availability information of the specified room.
53          * \param aRoom The room which availability information is needed.
54          */
55         void roomStatusInfoNeeded( Room *aRoom );
56         //! Slot. Indicates that some user event has happened.
57         /*!
58          * Slot. Indicates that some user event has happened.
59          */
60         void observedEventDetected();
61         //! Slot. Asks the communication to fetch new meeting data.
62         /*!
63          * Slot. Asks the communication to fetch new meeting data.
64          * \param aCurrentRoom The current room.
65          */
66         void currentRoomChanged( Room *aCurrentRoom );
67         //! Slot. Asks the communication to fetch new meeting data.
68         /*!
69          * Slot. Asks the communication to fetch new meeting data.
70          * \param aCurrentRoom The current room.
71          */
72         void shownWeekChanged( QDate aDate );
73         //! Slot. Handles errors.
74         /*!
75          * Slot. Handles errors and informs the UI by emitting the error() signal with the message in
76          * parameter.
77          * \param aCode The error code.
78          * \param aAddInfo Possible addition info.
79          */
80         void errorHandler( int aCode, const QString &aAddInfo = "" );
81         //! Slot. Fetches meetings from the server.
82         /*!
83          * Slot. Fetches meetings from the server. Parameters are hard coded: the meetings of the default
84          * room from current and +/- 2 weeks are fetched.
85          */
86         void fetchMeetings();
87         //! Slot. Saves fetched meetings to the current instance's local storage.
88         /*!
89          * Slot. Saves fetched meetings to the current instance's local storage. Meetings are soted in a
90          * private QList, it is iterated through and signals are emitted if there is any new, updated or
91          * deleted meeting.
92          * \param aMeetings The list of freshly fetched meetings.
93          */
94         void meetingsFetched( const QList<Meeting*>& );
95         
96         void meetingDetailsFetched( Meeting &aDetailedMeeting );
97         
98         //! Slot. Checks the availability of all the rooms.
99         /*!
100          * Slot. Checks the availability of all the rooms by iterating through the current object's local
101          * room storage and calling the roomStatusInfoNeeded() separately on each of them.
102          */
103         void checkStatusOfAllRooms();
104         //! Slot for popping up the confirmation dialog to change the current operation mode
105         /*!
106          * Slot. Asks Window manager to pop up a confirmation dialog.
107          * \param aMode The operation mode to be changed to
108          */
109         void changeModeOrdered( DeviceManager::OperationMode aMode );
110         //! Slot. Fetches meeting details from the server.
111         /*!
112          * Slot. Fetches meeting details from the server.
113          * \param aMeeting The meeting.
114          */
115         void fetchMeetingDetails( Meeting *aMeeting );
116         //! Slot for receiving the status of the entered password
117         /*!
118          * Slot. Receives the status of the entered password and makes the DeviceManager to change the
119          * operation mode if the password is correct.
120          * \param aPasswordStatus The status of the password.
121          */
122         void passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus );
123         //! Slot for receiving the cancel event of the progress bar.
124         /*!
125          * Slot. Receives the cancel event of the progress bar.
126          */
127         void progressBarCancelled();
128         //! Slot for receiving the cancel event of the progress bar.
129         /*!
130          *  Receives the cancel event of the progress bar when meeting details requested.
131          */
132         void fetchMeetingDetailsCancelled();
133         
134 private:
135         //! Provides the index of the Meeting instance which is at the specified time.
136         /*!
137          * Provides the index of the Meeting instance which is at the specified time. If there are
138          * overlapping meetings then returns one of then undetetministically.
139          * \param aRoom The room which meetings are looked through.
140          * \param aAt Date and time when the meeting is already going.
141          * \return Index of the meeting if found; otherwise, -1.
142          */
143         int indexOfMeetingAt( Room *aRoom, QDateTime aAt );
144         //! Provides the index of the Meeting instance which is starts the closest to the specified time.
145         /*!
146          * Provides the index of the Meeting instance which is starts the closest to the specified time.
147          * If there are overlapping meetings then returns one of then undetetministically.
148          * \param aRoom The room which meetings are looked through.
149          * \param aAt Date and time when the meeting is not yet started.
150          * \return Index of the meeting if found; otherwise, -1.
151          */
152         int indexOfMeetingAfter( Room *aRoom, QDateTime aAfter );
153         //! Indicates if the QList contains the Meeting or not.
154         /*!
155          * Indicates if the QList contains the Meeting or not.
156          * \param aList List of meetings.
157          * \param aMeeting The meeting which is seeked in the list for.
158          * \return True if contains; otherwise, false.
159          */
160         static bool isMeetingInList( const QList<Meeting*> &aList, const Meeting *aMeeting );
161         //! Slot. Fetches meetings from the server.
162         /*!
163          * Slot. Fetches meetings from the server, exact parameters are specified in the parameter list.
164          * \param aFrom Time from when the meetings need to be fetched.
165          * \param aUntil Time until when the meetings need to be fetched.
166          * \param aIn The room which meetings need to be fetched.
167          */
168         void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn );
169
170 private:
171         static QTime endOfTheDay;
172
173         WindowManager *iWindowManager;
174         QTimer *iIdleTimeCounter;
175         Clock *iClock;
176         Configuration *iConfiguration;
177         CommunicationManager *iCommunication;
178         DeviceManager *iDevice;
179
180         QTimer *iAutoRefresh;
181
182         QList<Meeting*> iMeetings;
183 };
184
185 #endif /*ENGINE_H_*/