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