User interface update
[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 roomStatusChanged( Room::Status aStatus, QTime aUntil );
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. Saves fetched meetings to the current instance's local storage.
73         /*!
74          * Slot. Saves fetched meetings to the current instance's local storage. Meetings are soted in a
75          * private QList, it is iterated through and signals are emitted if there is any new, updated or
76          * deleted meeting.
77          * \param aMeetings The list of freshly fetched meetings.
78          */
79         void meetingsFetched( const QList<Meeting*>& );
80         //! Slot. Checks the availability of all the rooms.
81         /*!
82          * Slot. Checks the availability of all the rooms by iterating through the current object's local
83          * room storage and calling the roomStatusInfoNeeded() separately on each of them.
84          */
85         void checkStatusOfAllRooms();
86         //! Slot for receiving the failure event of operation mode changing.
87         /*!
88          * Slot. Receives the failure event of operation mode changing.
89          */
90         void changeModeFailed();
91         //! Slot for receiving the cancel event of the progress bar.
92         /*!
93          *  Receives the cancel event of the progress bar when meeting details requested.
94          */
95         void fetchMeetingDetails( Meeting *aMeeting );
96         void cancelFetchMeetingDetails();
97         
98         void handleViewEvent();
99         void previousViewRestored();
100         
101         //! Slot for dialog activation signal.
102         /*!
103          * This slot is used to inform that dialog is activated. It stops
104          * the idle time counter so screensaver is not activated while the
105          * dialog is displayed.
106          */
107         void dialogActivated();
108         //! Slot for dialog deactivation signal.
109         /*!
110          * This slot is used to inform that dialog is deactivated. It restarts
111          * the idle time counter so that the screensaver is being activated again
112          * as needed.
113          */
114         void dialogDeactivated();
115         
116         void stopIdleTimeCounter();
117         void startIdleTimeCounter();
118
119         void changeDeviceMode();
120         
121         void currentRoomChanged( Room *aRoom );
122         
123         void tick( QDateTime aCurrentDateTime );
124         
125         /**
126          * Updates the current rooms info.
127          */
128         void updateRoomInfo();
129         /**
130          *
131          */
132         void configurationChanged();
133
134 private:
135         // Make the UIManager as friendly class so it can connect to private slots.
136         friend class UIManager;
137         
138         //! Provides the index of the Meeting instance which is at the specified time.
139         /*!
140          * Provides the index of the Meeting instance which is at the specified time. If there are
141          * overlapping meetings then returns one of then undetetministically.
142          * \param aRoom The room which meetings are looked through.
143          * \param aAt Date and time when the meeting is already going.
144          * \return Index of the meeting if found; otherwise, -1.
145          */
146         int indexOfMeetingAt( Room *aRoom, QDateTime aAt );
147         //! Provides the index of the Meeting instance which is starts the closest to the specified time.
148         /*!
149          * Provides the index of the Meeting instance which is starts the closest to the specified time.
150          * If there are overlapping meetings then returns one of then undetetministically.
151          * \param aRoom The room which meetings are looked through.
152          * \param aAt Date and time when the meeting is not yet started.
153          * \return Index of the meeting if found; otherwise, -1.
154          */
155         int indexOfMeetingAfter( Room *aRoom, QDateTime aAfter );
156         //! Slot. Fetches meetings from the server.
157         /*!
158          * Slot. Fetches meetings from the server, exact parameters are specified in the parameter list.
159          * \param aWeek Week for which the meetings need to be fetched.
160          * \param aYear Year for which the meetings need to be fetched.
161          * \param aIn The room which meetings need to be fetched.
162          */
163         void fetchMeetings( const int aWeek, const int aYear, const Room *aIn );
164         //! Initialize configuration package.
165         /*!
166          * This method initializes configuration classes and
167          * connects signals from and to the engine.
168          */
169         void initConfiguration();
170         //! Initialize device package.
171         /*!
172          * This method initializes device manager and
173          * connects signals from and to the engine.
174          */
175         void initDevice();
176         //! Initialize communication package.
177         /*!
178          * This method initializes the communication manager and
179          * connects signals from and to the engine.
180          */
181         void initCommunication();
182         //! Initialize user interface package.
183         /*!
184          * This method initializes the user interface and
185          * connects signals from and to the engine. This method
186          * makes the window manager visible and shows weekly
187          * view as the first view.
188          */
189         void initUserInterface();
190         //! Connects signal between objects.
191         /*!
192          * Signals that could not be connected while initializing different
193          * packages are connected here.
194          */
195         void connectSignals();
196         
197         bool isMeetingInList(const QList<Meeting*> &aList, const Meeting *aMeeting);
198
199 private:
200         static QTime endOfTheDay;
201
202         WindowManager *iWindowManager;
203         
204         QTimer *iIdleTimeCounter;
205         Clock *iClock;
206         QDate iCurrentDate;
207         Configuration *iConfiguration;
208         CommunicationManager *iCommunication;
209         DeviceManager *iDevice;
210         UIManager *iUIManager;
211
212         QTimer *iAutoRefresh;
213
214         QList<Meeting*> iMeetings;
215         
216         Room *iCurrentRoom;
217         bool iCommunicationFailed;
218         bool iCurrentWeekFetched;
219 };
220
221 #endif /*ENGINE_H_*/