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