~george-edison55/twistload/trunk

« back to all changes in this revision

Viewing changes to src/download/fragment.cpp

  • Committer: Nathan Osman
  • Date: 2017-07-21 19:02:24 UTC
  • Revision ID: git-v1:dc9f552f566f371322850cb781c53413250107a0
Nearly finish initial implementation of Download class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 */
24
24
 
25
25
#include <QNetworkAccessManager>
26
 
#include <QNetworkReply>
27
 
#include <QNetworkRequest>
28
26
#include <QUrl>
29
27
 
30
28
#include "fragment.h"
48
46
 
49
47
void Fragment::start()
50
48
{
51
 
    QString range = QString("bytes=%1-%2").arg(mOffset).arg(mEnd);
52
 
    mRequest.setRawHeader("Range", range.toUtf8());
 
49
    // If a valid end was specified, set the request's range
 
50
    if (mEnd) {
 
51
        QString range = QString("bytes=%1-%2").arg(mOffset).arg(mEnd);
 
52
        mRequest.setRawHeader("Range", range.toUtf8());
 
53
    }
 
54
 
53
55
    mReply = mManager->get(mRequest);
54
56
    connect(mReply, &QNetworkReply::readyRead, this, &Fragment::onReadyRead);
55
57
    connect(mReply, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &Fragment::onError);
56
58
    connect(mReply, &QNetworkReply::finished, this, &Fragment::finished);
57
59
}
58
60
 
 
61
void Fragment::stop()
 
62
{
 
63
    mReply->close();
 
64
}
 
65
 
59
66
void Fragment::onReadyRead()
60
67
{
61
68
    QByteArray data = mReply->readAll();