Log connection state transitions.
[yandex-traffic] / http_fetcher.cpp
1 #include <QtCore>
2 #include <QtNetwork>
3
4 #include "http_fetcher.hpp"
5
6 // --------------------------------------------------
7 // HttpFetcher
8 // --------------------------------------------------
9 HttpFetcher::HttpFetcher ()
10     : QObject ()
11 {
12     connect (&_http, SIGNAL (done (bool)), SLOT (requestDone (bool)));
13 }
14
15
16 bool HttpFetcher::busy () const
17 {
18     return _http.currentId () != 0;
19 }
20
21
22 void HttpFetcher::fetch (const QString& url)
23 {
24     QUrl u (url);
25
26     if (u.isValid ()) {
27         _http.setHost (u.host ());
28         _http.get (u.encodedPath (), &_buffer);
29     }
30 }
31
32
33 void HttpFetcher::requestDone (bool err)
34 {
35     if (err)
36         error (_http.error ());
37     else
38         done (_buffer.buffer ());
39     _buffer.close ();
40     _buffer.setBuffer (NULL);
41 }