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