Merged
[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 #include "DeviceManager.h"
9 #include "PasswordDialog.h"
10
11 class QTimer;
12 class Clock;
13 class Configuration;
14 class CommunicationManager;
15 class Meeting;
16 class WeeklyViewWidget;
17 class SettingsView;
18 class RoomStatusIndicatorWidget;
19 class PasswordDialog;
20 class MeetingInfoDialog;
21
22 //! BusinessLogic class. Contains all the business logic of the application.
23 /*!
24  * BusinessLogic class. Contains all the business logic of the application. It is responsible
25  * for connecting user interface to lower application layers (IO).
26  */
27 class Engine : public QObject
28 {
29         Q_OBJECT
30
31 public:
32         //! Constructor.
33         /*!
34          * Constructor to initialize an Engine instance.
35          */
36         Engine();
37         //! Destructor.
38         virtual ~Engine();
39         //! Gets default room of the application.
40         /*!
41          * Gets default room of the application.
42          * \return Pointer to the default Room instance.
43          */
44         Room* defaultRoom();
45
46 signals:
47
48         void meetingDetailsFetched( Meeting *aDetailedMeeting );        
49
50 private slots:
51         //! Slot. Closes the application.
52         /*!
53          * Slot. Closes the application.
54          */
55         void closeApplication();
56         //! Slot. Checks actual availability information of the specified room.
57         /*!
58          * Slot. Checks actual availability information of the specified room.
59          * \param aRoom The room which availability information is needed.
60          */
61         void roomStatusInfoNeeded( Room *aRoom );
62         //! Slot. Asks the communication to fetch new meeting data.
63         /*!
64          * Slot. Asks the communication to fetch new meeting data.
65          * \param aCurrentRoom The current room.
66          */
67         void currentRoomChanged( Room *aCurrentRoom );
68         //! Slot. Asks the communication to fetch new meeting data.
69         /*!
70          * Slot. Asks the communication to fetch new meeting data.
71          * \param aCurrentRoom The current room.
72          */
73         void shownWeekChanged( QDate aDate );
74         //! Slot. Handles errors.
75         /*!
76          * Slot. Handles errors and informs the UI by emitting the error() signal with the message in
77          * parameter.
78          * \param aCode The error code.
79          * \param aAddInfo Possible addition info.
80          */
81         void errorHandler( int aCode, const QString &aAddInfo = "" );
82         //! Slot. Fetches meetings from the server.
83         /*!
84          * Slot. Fetches meetings from the server. Parameters are hard coded: the meetings of the default
85          * room from current and +/- 2 weeks are fetched.
86          */
87         void fetchMeetings();
88         //! Slot. Saves fetched meetings to the current instance's local storage.
89         /*!
90          * Slot. Saves fetched meetings to the current instance's local storage. Meetings are soted in a
91          * private QList, it is iterated through and signals are emitted if there is any new, updated or
92          * deleted meeting.
93          * \param aMeetings The list of freshly fetched meetings.
94          */
95         void meetingsFetched( const QList<Meeting*>& );
96         
97         void meetingDetailsFetched( Meeting &aDetailedMeeting );
98         
99         //! Slot. Checks the availability of all the rooms.
100         /*!
101          * Slot. Checks the availability of all the rooms by iterating through the current object's local
102          * room storage and calling the roomStatusInfoNeeded() separately on each of them.
103          */
104         void checkStatusOfAllRooms();
105         //! Slot for popping up the confirmation dialog to change the current operation mode
106         /*!
107          * Slot. Asks Window manager to pop up a confirmation dialog.
108          * \param aMode The operation mode to be changed to
109          */
110         void changeModeOrdered( DeviceManager::OperationMode aMode );
111         //! Slot. Fetches meeting details from the server.
112         /*!
113          * Slot. Fetches meeting details from the server.
114          * \param aMeeting The meeting.
115          */
116         void fetchMeetingDetails( Meeting *aMeeting );
117         //! Slot for receiving the status of the entered password
118         /*!
119          * Slot. Receives the status of the entered password and makes the DeviceManager to change the
120          * operation mode if the password is correct.
121          * \param aPasswordStatus The status of the password.
122          */
123         void passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus );
124         //! Slot for receiving the cancel event of the progress bar.
125         /*!
126          * Slot. Receives the cancel event of the progress bar.
127          */
128         void progressBarCancelled();
129         //! Slot for receiving the cancel event of the progress bar.
130         /*!
131          *  Receives the cancel event of the progress bar when meeting details requested.
132          */
133         void fetchMeetingDetailsCancelled();
134         
135         void handleViewEvent();
136         void previousViewRestored();
137         void settingsViewRequested();
138         
139         void idleTimerTimeout();
140         
141         void settingsOkClicked();
142         
143         //! Slot for dialog activation signal.
144         /*!
145          * This slot is used to inform that dialog is activated. It stops
146          * the idle time counter so screensaver is not activated while the
147          * dialog is displayed.
148          */
149         void dialogActivated();
150         //! Slot for dialog deactivation signal.
151         /*!
152          * This slot is used to inform that dialog is deactivated. It restarts
153          * the idle time counter so that the screensaver is being activated again
154          * as needed.
155          */
156         void dialogDeactivated();
157         
158 private:
159         //! Provides the index of the Meeting instance which is at the specified time.
160         /*!
161          * Provides the index of the Meeting instance which is at the specified time. If there are
162          * overlapping meetings then returns one of then undetetministically.
163          * \param aRoom The room which meetings are looked through.
164          * \param aAt Date and time when the meeting is already going.
165          * \return Index of the meeting if found; otherwise, -1.
166          */
167         int indexOfMeetingAt( Room *aRoom, QDateTime aAt );
168         //! Provides the index of the Meeting instance which is starts the closest to the specified time.
169         /*!
170          * Provides the index of the Meeting instance which is starts the closest to the specified time.
171          * If there are overlapping meetings then returns one of then undetetministically.
172          * \param aRoom The room which meetings are looked through.
173          * \param aAt Date and time when the meeting is not yet started.
174          * \return Index of the meeting if found; otherwise, -1.
175          */
176         int indexOfMeetingAfter( Room *aRoom, QDateTime aAfter );
177         //! Indicates if the QList contains the Meeting or not.
178         /*!
179          * Indicates if the QList contains the Meeting or not.
180          * \param aList List of meetings.
181          * \param aMeeting The meeting which is seeked in the list for.
182          * \return True if contains; otherwise, false.
183          */
184         static bool isMeetingInList( const QList<Meeting*> &aList, const Meeting *aMeeting );
185         //! Slot. Fetches meetings from the server.
186         /*!
187          * Slot. Fetches meetings from the server, exact parameters are specified in the parameter list.
188          * \param aFrom Time from when the meetings need to be fetched.
189          * \param aUntil Time until when the meetings need to be fetched.
190          * \param aIn The room which meetings need to be fetched.
191          */
192         void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn );
193         //! Initialize configuration package.
194         /*!
195          * This method initializes configuration classes and
196          * connects signals from and to the engine.
197          */
198         void initConfiguration();
199         //! Initialize device package.
200         /*!
201          * This method initializes device manager and
202          * connects signals from and to the engine.
203          */
204         void initDevice();
205         //! Initialize communication package.
206         /*!
207          * This method initializes the communication manager and
208          * connects signals from and to the engine.
209          */
210         void initCommunication();
211         //! Initialize user interface package.
212         /*!
213          * This method initializes the user interface and
214          * connects signals from and to the engine. This method
215          * makes the window manager visible and shows weekly
216          * view as the first view.
217          */
218         void initUserInterface();
219         //! Connects signal between objects.
220         /*!
221          * Signals that could not be connected while initializing different
222          * packages are connected here.
223          */
224         void connectSignals();
225
226 private:
227         static QTime endOfTheDay;
228
229         WindowManager *iWindowManager;
230         WeeklyViewWidget *iWeeklyView;
231         SettingsView *iSettingsView;
232         RoomStatusIndicatorWidget *iRoomStatusIndicator;
233         
234         PasswordDialog *iPasswordDialog;
235         MeetingInfoDialog *iMeetingInfoDialog;
236         
237         QTimer *iIdleTimeCounter;
238         Clock *iClock;
239         Configuration *iConfiguration;
240         CommunicationManager *iCommunication;
241         DeviceManager *iDevice;
242
243         QTimer *iAutoRefresh;
244
245         QList<Meeting*> iMeetings;
246 };
247
248 #endif /*ENGINE_H_*/