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