Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pagedownloader.cpp « lang_getter - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 87e089e13deb7b9936fd750d200a60fa8928b230 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "pagedownloader.h"
#include "logging.h"

#include <QUrl>
#include <QNetworkReply>


void PageDownloader::ConnectFinished(QObject * obj, char const * slot)
{
  disconnect(SIGNAL(finished(QString const &)));
  connect(this, SIGNAL(finished(QString const &)), obj, slot);
}

void PageDownloader::Download(QUrl const & url)
{
  m_res.clear();

  m_reply = m_manager.get(QNetworkRequest(url));
  connect(m_reply, SIGNAL(finished()), this, SLOT(httpFinished()));
  connect(m_reply, SIGNAL(readyRead()), this, SLOT(httpReadyRead()));
  connect(m_reply, SIGNAL(downloadProgress(qint64,qint64)), this,
          SLOT(updateDataReadProgress(qint64,qint64)));
}

void PageDownloader::Download(QString const & url)
{
  Download(QUrl(url));
}

void PageDownloader::httpFinished()
{
  QString const s = QString::fromUtf8(m_res.constData());
  QString const url = m_reply->url().toString();

  if (s.isEmpty())
  {
    m_log.Print(Logging::WARNING, QString("Downloading of ") +
                                  url +
                                  QString(" failed."));
  }
  else
  {
    m_log.Print(Logging::INFO, QString("Downloading of ") +
                               url +
                               QString(" finished successfully."));
  }

  m_reply->deleteLater();
  m_reply = 0;

  emit finished(s);
}

void PageDownloader::httpReadyRead()
{
  m_res += m_reply->readAll();
}

void PageDownloader::updateDataReadProgress(qint64 read, qint64 total)
{
  m_log.Percent(read, total);
}