forked from mrampersad/phantomjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for downloading unsupported content.
Unsupported content calls the onFilePicker callback, if a filename is returned, the download begins. onDownloadFinished is called when the download completes. ariya#10052
- Loading branch information
1 parent
dca6f77
commit 55230b6
Showing
6 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "downloader.h" | ||
|
||
#include <QNetworkReply> | ||
#include <QUrl> | ||
#include <QDateTime> | ||
#include <QFile> | ||
#include <QDebug> | ||
|
||
#include "phantom.h" | ||
|
||
Downloader::Downloader(QObject *parent, QFile *file, QNetworkReply *reply) : | ||
QObject(parent), m_file(file), m_reply(reply) | ||
{ | ||
qDebug() << "Downloader: Downloader"; | ||
|
||
m_file->setParent(this); | ||
m_reply->setParent(this); | ||
|
||
connect(reply, SIGNAL(readyRead()), this, SLOT(handleReadyRead()), Qt::QueuedConnection); | ||
connect(reply, SIGNAL(finished()), this, SLOT(handleFinished()), Qt::QueuedConnection); | ||
} | ||
|
||
void Downloader::startDownload() { | ||
handleReadyRead(); | ||
|
||
if( m_reply->isFinished() ) { | ||
handleFinished(); | ||
} | ||
} | ||
|
||
void Downloader::handleReadyRead() | ||
{ | ||
qDebug() << "Downloader: handleReadyRead" << m_reply->bytesAvailable(); | ||
|
||
m_file->write(m_reply->readAll()); | ||
} | ||
|
||
void Downloader::handleFinished() | ||
{ | ||
qDebug() << "Downloader: handleFinished"; | ||
|
||
m_file->close(); | ||
this->deleteLater(); | ||
|
||
emit downloadFinished(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef DOWNLOADER_H | ||
#define DOWNLOADER_H | ||
|
||
#include <QObject> | ||
#include <QNetworkReply> | ||
#include <QFile> | ||
|
||
class Downloader : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
Downloader(QObject *parent, QFile *file, QNetworkReply *reply); | ||
void startDownload(); | ||
|
||
public slots: | ||
void handleReadyRead(); | ||
void handleFinished(); | ||
|
||
signals: | ||
void downloadFinished(bool ok); | ||
|
||
private: | ||
QNetworkReply *m_reply; | ||
QFile *m_file; | ||
}; | ||
|
||
#endif // DOWNLOADER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters