User interface update
[qtmeetings] / src / IO / Communication / Communication.h
1 #ifndef COMMUNICATION_H_
2 #define COMMUNICATION_H_
3
4 #include <QObject>
5 #include <QHttp>
6 #include <QHash>
7
8 class QByteArray;
9 class ConnectionSettings;
10
11 //! Class for handling HTTP requests and responses.
12 /*!
13  *  This class uses the QHttp class to make HTTP requests. HTTP responses are
14  *  returned as QByteArray.
15  */
16 class Communication : public QObject
17 {
18         Q_OBJECT
19
20 public:
21         //! Constructor.
22         /*! 
23          *  \param aConnection Reference to ConnectionSettings which holds
24          *  the server to connect to and authentication information.
25         */
26         Communication(/* const ConnectionSettings &aConnection*/ );
27         
28         virtual ~Communication();
29         //! Returns the response of a request identified by aRequestId.
30         /*! 
31          *  \param aRequestId Request id number.
32         */
33         QByteArray* response( int aRequestId );
34
35         //! Makes a HTTP request to the server defined in the constructor.
36         /*! 
37          *  Returns a request id number if successful, otherwise zero.
38          *  \param aCommand Content type string of the HTTP header.
39          *  \param aContent Content body of the HTTP POST request.
40         */
41         int request( const QString &aCommand, const QByteArray &aContent );
42
43
44
45 signals:
46         //! Emitted when a request ongoing. Reports the bytes read from the server.
47         /*! 
48         *   \param aRequestId Request id number.
49         *   \param aDone Bytes read from the server.
50         *   \param aTotal Bytes total of the response.
51         */
52         void readProgress( int aRequestId, int aDone, int aTotal );
53         //! Emitted when a request is started.
54         /*! 
55         *   \param aRequestId Request id number.
56         */
57         void requestStarted( int aRequestId );
58         //! Emitted when a request is finished.
59         /*! 
60         *   \param aRequestId Request id number.
61         *   \param aError Error code of the request finished.
62         */
63         void requestFinished( int aRequestId, int aError );
64
65 protected slots:
66         //! Connected to QHttp::readyRead to read the response buffer.
67         void processResponse( const QHttpResponseHeader& aHeader );
68         //! Connected to QHttp::authenticationRequired to provide the user name and password defined in ConnectionSettings
69         void handleAuthentication( const QString& aHost, quint16 aPort, QAuthenticator* aAuthenticator );
70         //! Connected to QHttp::requestFinished 
71         void handleResults( int aId, bool aError );
72         //! Connected to QHttp::requestStarted
73         void handleRequestStarted( int aRequestId );
74         //! Connected to QHttp::dataReadProgress
75         void handleReadProgress( int aDone, int aTotal );
76         //!Called when the settings are changed by the user
77         void configurationChanged();
78
79
80 private:
81         /*!
82          * Instance of Connection settings of the communication
83         */
84         //ConnectionSettings *iConnectionSettings;
85         /*!
86          * Instance of QHttp
87         */
88         QHttp* iHttp;
89         /*!
90          * QHash of requests and response buffers
91         */
92         QHash<int, QByteArray*> iResponses;
93         /*!
94          * ID number of a request currently ongoing
95         */
96         int iCurrentRequest;
97         /*!
98          * Counter how many times auhentication was failed to the server
99         */
100         int iAuthFailCount;
101 };
102
103 #endif /*COMMUNICATION_H_*/