Re-factored the basic idea of the application: Engine is the main class that ownsWind...
[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
9 class QTimer;
10 class Clock;
11 class Configuration;
12 class CommunicationManager;
13 class Meeting;
14 class DeviceManager;
15
16 //! BusinessLogic class. Contains all the business logic of the application.
17 /*!
18  * BusinessLogic class. Contains all the business logic of the application. It is responsible
19  * for connecting user interface to lower application layers (IO).
20  */
21 class Engine : public QObject
22 {
23         Q_OBJECT
24
25 public:
26         //! Constructor.
27         /*!
28          * Constructor to initialize an Engine instance.
29          */
30         Engine();
31         //! Destructor.
32         virtual ~Engine();
33         //! Gets default room of the application.
34         /*!
35          * Gets default room of the application.
36          * \return Pointer to the default Room instance.
37          */
38         Room* defaultRoom();
39
40 signals:
41
42         void meetingDetailsFetched( Meeting *aDetailedMeeting );        
43
44 private slots:
45         //! Slot. Closes the application.
46         /*!
47          * Slot. Closes the application.
48          */
49         void closeApplication();
50         //! Slot. Checks actual availability information of the specified room.
51         /*!
52          * Slot. Checks actual availability information of the specified room.
53          * \param aRoom The room which availability information is needed.
54          */
55         void roomStatusInfoNeeded( Room *aRoom );
56         //! Slot. Indicates that some user event has happened.
57         /*!
58          * Slot. Indicates that some user event has happened.
59          */
60         void observedEventDetected();
61         //! Slot. Asks the communication to fetch new meeting data.
62         /*!
63          * Slot. Asks the communication to fetch new meeting data.
64          * \param aCurrentRoom The current room.
65          */
66         void currentRoomChanged( Room *aCurrentRoom );
67         //! Slot. Asks the communication to fetch new meeting data.
68         /*!
69          * Slot. Asks the communication to fetch new meeting data.
70          * \param aCurrentRoom The current room.
71          */
72         void shownWeekChanged( QDate aDate );
73         //! Slot. Handles errors.
74         /*!
75          * Slot. Handles errors and informs the UI by emitting the error() signal with the message in
76          * parameter.
77          * \param aCode The error code.
78          * \param aAddInfo Possible addition info.
79          */
80         void errorHandler( int aCode, const QString &aAddInfo = "" );
81         //! Slot. Fetches meetings from the server.
82         /*!
83          * Slot. Fetches meetings from the server. Parameters are hard coded: the meetings of the default
84          * room from current and +/- 2 weeks are fetched.
85          */
86         void fetchMeetings();
87         //! Slot. Saves fetched meetings to the current instance's local storage.
88         /*!
89          * Slot. Saves fetched meetings to the current instance's local storage. Meetings are soted in a
90          * private QList, it is iterated through and signals are emitted if there is any new, updated or
91          * deleted meeting.
92          * \param aMeetings The list of freshly fetched meetings.
93          */
94         void meetingsFetched( const QList<Meeting*>& );
95         
96         void meetingDetailsFetched( Meeting &aDetailedMeeting );
97         
98         //! Slot. Checks the availability of all the rooms.
99         /*!
100          * Slot. Checks the availability of all the rooms by iterating through the current object's local
101          * room storage and calling the roomStatusInfoNeeded() separately on each of them.
102          */
103         void checkStatusOfAllRooms();
104         //! Slot for popping up the confirmation dialog to change the current operation mode
105         /*!
106          * Slot. Asks Window manager to pop up a confirmation dialog.
107          * \param aMode The operation mode to be changed to
108          */
109         void changeModeOrdered( DeviceManager::OperationMode aMode );
110         //! Slot. Fetches meeting details from the server.
111         /*!
112          * Slot. Fetches meeting details from the server.
113          * \param aMeeting The meeting.
114          */
115         void fetchMeetingDetails( Meeting *aMeeting );
116 private:
117         //! Provides the index of the Meeting instance which is at the specified time.
118         /*!
119          * Provides the index of the Meeting instance which is at the specified time. If there are
120          * overlapping meetings then returns one of then undetetministically.
121          * \param aRoom The room which meetings are looked through.
122          * \param aAt Date and time when the meeting is already going.
123          * \return Index of the meeting if found; otherwise, -1.
124          */
125         int indexOfMeetingAt( Room *aRoom, QDateTime aAt );
126         //! Provides the index of the Meeting instance which is starts the closest to the specified time.
127         /*!
128          * Provides the index of the Meeting instance which is starts the closest to the specified time.
129          * If there are overlapping meetings then returns one of then undetetministically.
130          * \param aRoom The room which meetings are looked through.
131          * \param aAt Date and time when the meeting is not yet started.
132          * \return Index of the meeting if found; otherwise, -1.
133          */
134         int indexOfMeetingAfter( Room *aRoom, QDateTime aAfter );
135         //! Indicates if the QList contains the Meeting or not.
136         /*!
137          * Indicates if the QList contains the Meeting or not.
138          * \param aList List of meetings.
139          * \param aMeeting The meeting which is seeked in the list for.
140          * \return True if contains; otherwise, false.
141          */
142         static bool isMeetingInList( const QList<Meeting*> &aList, const Meeting *aMeeting );
143         //! Slot. Fetches meetings from the server.
144         /*!
145          * Slot. Fetches meetings from the server, exact parameters are specified in the parameter list.
146          * \param aFrom Time from when the meetings need to be fetched.
147          * \param aUntil Time until when the meetings need to be fetched.
148          * \param aIn The room which meetings need to be fetched.
149          */
150         void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn );
151
152 private:
153         static QTime endOfTheDay;
154
155         WindowManager *iWindowManager;
156         QTimer *iIdleTimeCounter;
157         Clock *iClock;
158         Configuration *iConfiguration;
159         CommunicationManager *iCommunication;
160         DeviceManager *iDevice;
161
162         QTimer *iAutoRefresh;
163
164         QList<Meeting*> iMeetings;
165 };
166
167 #endif /*ENGINE_H_*/