Ejemplo n.º 1
0
HttpThread::~HttpThread()
{
  LOG(LDEBUG, ("Destroying HttpThread"));
  disconnect(m_reply, SIGNAL(metaDataChanged()), this, SLOT(OnHeadersReceived()));
  disconnect(m_reply, SIGNAL(readyRead()), this, SLOT(OnChunkDownloaded()));
  disconnect(m_reply, SIGNAL(finished()), this, SLOT(OnDownloadFinished()));

  m_reply->deleteLater();
}
Ejemplo n.º 2
0
HttpThread::HttpThread(string const & url,
                       downloader::IHttpThreadCallback & cb,
                       int64_t beg,
                       int64_t end,
                       int64_t size,
                       string const & pb)
  : m_callback(cb), m_begRange(beg), m_endRange(end), m_downloadedBytes(0), m_expectedSize(size)
{
  QUrl const qUrl(url.c_str());
  QNetworkRequest request(qUrl);

  // use Range header only if we don't download whole file from start
  if (!(beg == 0 && end < 0))
  {
    if (end > 0)
    {
      LOG(LDEBUG, (url, "downloading range [", beg, ",", end, "]"));
      QString const range = QString("bytes=") + QString::number(beg)
                            + '-' + QString::number(end);
      request.setRawHeader("Range", range.toUtf8());
    }
    else
    {
      LOG(LDEBUG, (url, "resuming download from position", beg));
      QString const range = QString("bytes=") + QString::number(beg) + '-';
      request.setRawHeader("Range", range.toUtf8());
    }
  }

  // set user-agent with unique client id only for mapswithme requests
  if (url.find("mapswithme.com") != string::npos)
  {
    static string const uid = GetPlatform().UniqueClientId();
    request.setRawHeader("User-Agent", uid.c_str());
  }

  /// Use single instance for whole app
  static QNetworkAccessManager netManager;

  if (pb.empty())
    m_reply = netManager.get(request);
  else
  {
    request.setRawHeader("Content-Type", "application/json");
    request.setRawHeader("Content-Length", QString::number(pb.size()).toLocal8Bit());
    m_reply = netManager.post(request, pb.c_str());
  }

  connect(m_reply, SIGNAL(metaDataChanged()), this, SLOT(OnHeadersReceived()));
  connect(m_reply, SIGNAL(readyRead()), this, SLOT(OnChunkDownloaded()));
  connect(m_reply, SIGNAL(finished()), this, SLOT(OnDownloadFinished()));
  LOG(LDEBUG, ("Connecting to", url, "[", beg, ",", end, "]", "size=", size));
}
Ejemplo n.º 3
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    this->setWindowTitle(tr("Launcher %1").arg(QString(LAUNCER_VER)));

    m_pInstaller = new Installer(this);
    connect(m_pInstaller, SIGNAL(SoftWareAvailable(AvailableSoftWare)), this, SLOT(AvailableSoftWareUpdated(AvailableSoftWare)));
    connect(m_pInstaller, SIGNAL(StartDownload()), this, SLOT(OnDownloadStarted()));
    connect(m_pInstaller, SIGNAL(DownloadFinished()), this, SLOT(OnDownloadFinished()));
    connect(m_pInstaller, SIGNAL(DownloadProgress(int)), this, SLOT(OnDownloadProgress(int)));

    m_pUpdateTimer = new QTimer(this);
    connect(m_pUpdateTimer, SIGNAL(timeout()), this, SLOT(on_btnRefresh_clicked()));
    m_pUpdateTimer->start(Settings::GetInstance()->GetUpdateTimerInterval());

    ui->stableTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    ui->developmentTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    ui->dependenciesTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);

    connect(ui->stableTable, SIGNAL(itemSelectionChanged()), this, SLOT(UpdateBtn()));
    connect(ui->dependenciesTable, SIGNAL(itemSelectionChanged()), this, SLOT(UpdateBtn()));
    connect(ui->developmentTable, SIGNAL(itemSelectionChanged()), this, SLOT(UpdateBtn()));
    connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(UpdateBtn()));

    connect(ui->stableTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_btnRun_clicked()));
    connect(ui->developmentTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_btnRun_clicked()));

    connect(Logger::GetInstance(), SIGNAL(LogAdded(QString)), this, SLOT(OnLogAdded(QString)));

    ui->downloadProgress->setVisible(false);
    ui->downloadProgress->setRange(0, 100);

    m_bBusy = false;
    UpdateBtn();
    m_pInstaller->Init();
}