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