4dfd00b3677d16ee1efcd4e44b4a772f7ca26d99
[qtmeetings] / src / IO / Communication / CommunicationManager.h
1 #ifndef COMMUNICATIONMANAGER_H_
2 #define COMMUNICATIONMANAGER_H_
3
4 #include <QObject>
5 #include <QList>
6 #include <QDateTime>
7 #include "Communication.h"
8 #include "Room.h"
9 #include "MessagingUtils.h"
10
11 class ConnectionSettings;
12 class Meeting;
13
14 //! Responsible for Exchange server communication and request encoding and response parsing.
15 /*!
16  *  CommunicationManager holds two connections to the Exchange server:
17  *  Fetching and modifying connection. Fetching connetion is read only connection
18  *  which has static authentication information defined in the application configuration.
19  *  The modifying connection's authentication information varies, according to the user interface.
20  * 
21  *  NOTE! Currently Modifying connection is NOT implemented.
22  */
23 class CommunicationManager : public QObject
24 {
25         Q_OBJECT
26
27 public:
28         enum CommunicationType
29         {
30                 FetchingCommunication,
31                 ModifyingCommunication
32         };
33
34 public:
35         //! Constructor.
36         /*! 
37          *  \param aConnection Reference to the fetching ConnectionSettings.
38         */
39         CommunicationManager( const ConnectionSettings &aConnection );
40         virtual ~CommunicationManager();
41         //! Starts fetching meetings. Meetings are returned by the meetingsFetched signal.
42         /*! 
43          *  Calls the MS Exchange GetUserAvailability WebService method. 
44          *  \param aFrom QDateTime to start searching from.
45          *  \param aUntil QDateTime to search meetings until.
46          *  \param aIn Meeting room meetings are searched.
47         */
48         void fetchMeetings( /*const QDateTime &aFrom, const QDateTime &aUntil*/const int aWeek, const int aYear, const Room &aIn );
49         //! Starts fetching a meeting details. Details are returned by the meetingDetailsFetched signal.
50         /*! 
51          *  \param aMeeting A meeting the detailed information is wanted.
52         */
53         void fetchMeetingDetails( Meeting &aMeeting );
54         //! Cancels all meeting detail requests.
55         void cancelFetchMeetingDetails();
56 /* Not supported member functions which are using the modifying communication
57         void setModifyCredentials( const QString &aUsername, const QString &aPassword ) {};
58         void createMeeting( const Meeting &aMeeting ) {};
59         void updateMeeting( const Meeting &aMeeting ) {};
60         void deleteMeeting( const Meeting &aMeeting ) {};
61 */
62
63 signals:
64         //! Emitted when an error happens. Error could be QHttp or SOAP related.
65         /*! 
66         *   \param aCode An error code defined by CommunicationManager.
67         *   \param aType FetchingCommunication or ModifyingCommunication.
68         */
69         void error( int aCode, CommunicationManager::CommunicationType aType );
70         //! Emitted when a http request is ongoing. Reports the bytes read from the server.
71         /*! 
72         *   \param aDone Bytes read from the server.
73         *   \param aTotal Bytes total of the response.
74         *   \param aType FetchingCommunication or ModifyingCommunication.
75         */
76         void readProgress( int aDone, int aTotal, CommunicationManager::CommunicationType aType );
77         //! Emitted when meetings are fetched.
78         /*! 
79         *   \param aMeetings Meetings found according to the search criteria.
80         */
81         void meetingsFetched( const QList<Meeting*> &aMeetings );
82         //! Emitted when meeting details are fetched.
83         /*! 
84         *   \param aDetailedMeeting Meeting which contains detailed information.
85         */
86         void meetingDetailsFetched( Meeting &aDetailedMeeting );
87
88 protected slots:
89         //! Connected to Communication::requestFinished.
90         void requestFinished( int aRequestId, int aError );
91         //! Connected to Communication::readProgress.
92         void readProgress( int aRequestId, int aDone, int aTotal );
93         
94 protected:
95         //! Gets the secondary id number of a meeting.
96         /*! 
97          *  Calls the MS Exchange ConvertId WebService method. Converts primary id
98          *  number to secondary id number.
99          *  \param aMeeting A meeting which contains primaryId number.
100         */
101         void getSecondaryIdForMeeting( Meeting &aMeeting );
102         //! Gets the details of a meeting.
103         /*! 
104          *  Calls the MS Exchange GetCalendarItem WebService method.
105          *  \param aMeeting A meeting the detailed information is wanted.
106         */
107         void getMeetingDetails( Meeting &aMeeting );
108         
109         /*! 
110          *  Lists the WebService methods known by the CommunicationManager.
111         */
112         enum RequestType
113         {
114                 GetUserAvailability = 1,
115                 ConvertId,
116                 GetCalendarItem
117         };
118         //! Internal data structure which contains data about requests made to Exchange server.
119         class RequestData
120         {
121         public:
122                 RequestData( RequestType aType, int aRequestId ) : 
123                         type( aType ), requestId( aRequestId ), room( NULL ), meeting( NULL ) {};
124                 ~RequestData()
125                 {
126                         if( type == GetUserAvailability )
127                                 delete room;
128                 };
129                 //! Holds one of the enum RequestType value
130                 RequestType type;
131                 //! Request ID number returned by the Communication::request
132                 int requestId;
133                 //! Pointer to a Room related to this request. NULL by default. Owned.
134                 Room* room;
135                 //! Pointer to a Meeting related to this request. Not owned.
136                 Meeting* meeting;
137         };
138         //! Adds a request to the iRequestInfos list.
139         /*! 
140          *  \param aType One of the enum RequestType value.
141          *  \param aRequestId Request ID number returned by the Communication::request
142         */
143         void addRequest( RequestType aType, int aRequestId );
144         //! Takes RequestData off from the iRequestInfos list.
145         /*! 
146          *  Returns a pointer to RequestData data structure. Removes RequestData from
147          *  the iRequestInfos list.
148          *  \param aRequestId Request ID number returned by the Communication::request
149         */
150         RequestData* takeRequest( int aRequestId );
151         //! Finds a RequestData from the iRequestInfos list.
152         /*! 
153          *  Returns a pointer to RequestData, NULL if not found.
154          *  \param aRequestType Request type
155         */
156         const RequestData* findRequest( RequestType aRequestType ) const;
157         
158 private:
159         //! Instance of Connection settings of the fetching communication
160         ConnectionSettings *iConnectionSettings;
161         //! Instance of the fetching communication
162         Communication* iFetchingCommunication;
163         //! Instance of the modifying communication
164         Communication* iModifyingCommunication;
165         //! Temporary list which holds the lastest meetings fetched
166         QList<Meeting*> iMeetings;
167         //! Additional information about requests made to the Exchange server
168         QList<RequestData*> iRequestInfos;
169         //! A flag that all meeting detail requests has been cancelled
170         QList<int> iCancelledRequests;
171 };
172
173 #endif /*COMMUNICATIONMANAGER_H_*/