summaryrefslogtreecommitdiffstats
path: root/src/libs/kdtools/kdupdaterfiledownloader.cpp
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2012-11-22 21:44:38 +0100
committerKarsten Heimrich <karsten.heimrich@digia.com>2012-11-26 12:27:06 +0100
commitfd4c75df63d65e5a97ebc71c8247713ace45ffc9 (patch)
tree56b94a6dc443b78ffa24d25ddffec4d28d3530cc /src/libs/kdtools/kdupdaterfiledownloader.cpp
parent839f9f4d8a2aa41a8957e3c4337e3502baa927b7 (diff)
Get rid of QFtp in favour of QNetworkAccessManager. Qt5 related.
Change-Id: I13f33b137d8f1bb8d51979973be3be665cb6d681 Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
Diffstat (limited to 'src/libs/kdtools/kdupdaterfiledownloader.cpp')
-rw-r--r--src/libs/kdtools/kdupdaterfiledownloader.cpp231
1 files changed, 0 insertions, 231 deletions
diff --git a/src/libs/kdtools/kdupdaterfiledownloader.cpp b/src/libs/kdtools/kdupdaterfiledownloader.cpp
index e9adb42b3..a026fc3c4 100644
--- a/src/libs/kdtools/kdupdaterfiledownloader.cpp
+++ b/src/libs/kdtools/kdupdaterfiledownloader.cpp
@@ -28,7 +28,6 @@
#include <QDialog>
#include <QFile>
-#include <QtNetwork/QFtp>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkProxyFactory>
#include <QPointer>
@@ -749,236 +748,6 @@ void KDUpdater::ResourceFileDownloader::onError()
}
-// -- KDUpdater::FtpFileDownloader
-
-struct KDUpdater::FtpDownloader::Private
-{
- Private()
- : ftp(0)
- , destination(0)
- , downloaded(false)
- , ftpCmdId(-1)
- , aborted(false)
- {}
-
- QFtp *ftp;
- QFile *destination;
- QString destFileName;
- bool downloaded;
- int ftpCmdId;
- bool aborted;
-};
-
-KDUpdater::FtpDownloader::FtpDownloader(QObject *parent)
- : KDUpdater::FileDownloader(QLatin1String("ftp"), parent)
- , d(new Private)
-{
-}
-
-KDUpdater::FtpDownloader::~FtpDownloader()
-{
- if (this->isAutoRemoveDownloadedFile() && !d->destFileName.isEmpty())
- QFile::remove(d->destFileName);
-
- delete d;
-}
-
-bool KDUpdater::FtpDownloader::canDownload() const
-{
- // TODO: Check whether the ftp file actually exists or not.
- return true;
-}
-
-bool KDUpdater::FtpDownloader::isDownloaded() const
-{
- return d->downloaded;
-}
-
-void KDUpdater::FtpDownloader::doDownload()
-{
- if (d->downloaded)
- return;
-
- if (d->ftp)
- return;
-
- d->ftp = new QFtp(this);
- connect(d->ftp, SIGNAL(done(bool)), this, SLOT(ftpDone(bool)));
- connect(d->ftp, SIGNAL(commandStarted(int)), this, SLOT(ftpCmdStarted(int)));
- connect(d->ftp, SIGNAL(commandFinished(int, bool)), this, SLOT(ftpCmdFinished(int, bool)));
- connect(d->ftp, SIGNAL(stateChanged(int)), this, SLOT(ftpStateChanged(int)));
- connect(d->ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this,
- SLOT(ftpDataTransferProgress(qint64, qint64)));
- connect(d->ftp, SIGNAL(readyRead()), this, SLOT(ftpReadyRead()));
-
- if (FileDownloaderProxyFactory *factory = proxyFactory()) {
- const QList<QNetworkProxy> proxies = factory->queryProxy(QNetworkProxyQuery(url()));
- if (!proxies.isEmpty())
- d->ftp->setProxy(proxies.at(0).hostName(), proxies.at(0).port());
- delete factory;
- }
-
- d->ftp->connectToHost(url().host(), url().port(21));
- d->ftp->login(authenticator().user(), authenticator().password());
-}
-
-QString KDUpdater::FtpDownloader::downloadedFileName() const
-{
- return d->destFileName;
-}
-
-void KDUpdater::FtpDownloader::setDownloadedFileName(const QString &name)
-{
- d->destFileName = name;
-}
-
-KDUpdater::FtpDownloader *KDUpdater::FtpDownloader::clone(QObject *parent) const
-{
- return new FtpDownloader(parent);
-}
-
-void KDUpdater::FtpDownloader::cancelDownload()
-{
- if (d->ftp) {
- d->aborted = true;
- d->ftp->abort();
- }
-}
-
-void KDUpdater::FtpDownloader::ftpDone(bool error)
-{
- if (error) {
- QString errorString;
- if (d->ftp) {
- errorString = d->ftp->errorString();
- d->ftp->deleteLater();
- d->ftp = 0;
- d->ftpCmdId = -1;
- }
-
- onError();
-
- if (d->aborted) {
- d->aborted = false;
- setDownloadCanceled();
- } else {
- setDownloadAborted(errorString);
- }
- }
- //PENDING what about the non-error case??
-}
-
-void KDUpdater::FtpDownloader::ftpCmdStarted(int id)
-{
- if (id != d->ftpCmdId)
- return;
-
- emit downloadStarted();
- emit downloadProgress(0);
-}
-
-void KDUpdater::FtpDownloader::ftpCmdFinished(int id, bool error)
-{
- if (id != d->ftpCmdId || error) // PENDING why error -> return??
- return;
-
- disconnect(d->ftp, 0, this, 0);
- d->ftp->deleteLater();
- d->ftp = 0;
- d->ftpCmdId = -1;
- d->destination->flush();
-
- setDownloadCompleted();
-}
-
-void FtpDownloader::onSuccess()
-{
- d->downloaded = true;
- d->destFileName = d->destination->fileName();
- if (QTemporaryFile *file = dynamic_cast<QTemporaryFile *>(d->destination))
- file->setAutoRemove(false);
- delete d->destination;
- d->destination = 0;
- stopDownloadSpeedTimer();
-
-}
-
-void FtpDownloader::onError()
-{
- d->downloaded = false;
- d->destFileName.clear();
- delete d->destination;
- d->destination = 0;
- stopDownloadSpeedTimer();
-}
-
-void KDUpdater::FtpDownloader::ftpStateChanged(int state)
-{
- switch(state) {
- case QFtp::Connected: {
- // begin the download
- if (d->destFileName.isEmpty()) {
- QTemporaryFile *file = new QTemporaryFile(this);
- file->open(); //PENDING handle error
- d->destination = file;
- } else {
- d->destination = new QFile(d->destFileName, this);
- d->destination->open(QIODevice::ReadWrite | QIODevice::Truncate);
- }
- runDownloadSpeedTimer();
- d->ftpCmdId = d->ftp->get(url().path());
- } break;
-
- case QFtp::Unconnected: {
- // download was unconditionally aborted
- disconnect(d->ftp, 0, this, 0);
- d->ftp->deleteLater();
- d->ftp = 0;
- d->ftpCmdId = -1;
- onError();
- setDownloadAborted(tr("Download was aborted due to network errors."));
- } break;
- }
-}
-
-void KDUpdater::FtpDownloader::ftpDataTransferProgress(qint64 done, qint64 total)
-{
- setProgress(done, total);
- emit downloadProgress(calcProgress(done, total));
-}
-
-void KDUpdater::FtpDownloader::ftpReadyRead()
-{
- static QByteArray buffer(16384, '\0');
- while (d->ftp->bytesAvailable()) {
- const qint64 read = d->ftp->read(buffer.data(), buffer.size());
- qint64 written = 0;
- while (written < read) {
- const qint64 numWritten = d->destination->write(buffer.data() + written, read - written);
- if (numWritten < 0) {
- onError();
- setDownloadAborted(tr("Cannot download %1: Writing to temporary file failed: %2")
- .arg(url().toString(), d->destination->errorString()));
- return;
- }
- written += numWritten;
- }
- addSample(written);
- addCheckSumData(buffer.data(), read);
- }
-}
-
-void KDUpdater::FtpDownloader::timerEvent(QTimerEvent *event)
-{
- if (event->timerId() == downloadSpeedTimerId()) {
- emitDownloadSpeed();
- emitDownloadStatus();
- emitDownloadProgress();
- emitEstimatedDownloadTime();
- }
-}
-
-
// -- KDUpdater::HttpDownloader
struct KDUpdater::HttpDownloader::Private