Added cancel download
This commit is contained in:
parent
8503833e3d
commit
376c983d21
|
@ -24,7 +24,7 @@ DataDownloader::DataDownloader(QUrl url, QObject* parent) :
|
|||
SLOT(fileDownloaded(QNetworkReply*)));
|
||||
|
||||
QNetworkRequest request(url);
|
||||
m_WebCtrl.get(request);
|
||||
m_pReply = m_WebCtrl.get(request);
|
||||
}
|
||||
|
||||
DataDownloader::~DataDownloader()
|
||||
|
@ -36,10 +36,18 @@ void DataDownloader::fileDownloaded(QNetworkReply* reply)
|
|||
{
|
||||
m_DownloadedData = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
if (!m_DownloadedData.isEmpty()) {
|
||||
emit downloaded();
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray DataDownloader::downloadedData() const
|
||||
{
|
||||
return m_DownloadedData;
|
||||
}
|
||||
|
||||
void DataDownloader::cancelDownload()
|
||||
{
|
||||
m_pReply->abort();
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
virtual ~DataDownloader();
|
||||
|
||||
QByteArray downloadedData() const;
|
||||
void cancelDownload();
|
||||
|
||||
signals:
|
||||
void downloaded();
|
||||
|
@ -43,6 +44,7 @@ private:
|
|||
|
||||
QNetworkAccessManager m_WebCtrl;
|
||||
QByteArray m_DownloadedData;
|
||||
QNetworkReply* m_pReply;
|
||||
};
|
||||
|
||||
#endif // DATADOWNLOADER_H
|
||||
|
|
|
@ -82,7 +82,8 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
|
|||
m_pMenuHelp(NULL),
|
||||
m_pZeroconfService(NULL),
|
||||
m_pDataDownloader(NULL),
|
||||
m_DownloadMessageBox(NULL)
|
||||
m_DownloadMessageBox(NULL),
|
||||
m_pCancelButton(NULL)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
|
@ -988,18 +989,21 @@ void MainWindow::downloadBonjour()
|
|||
}
|
||||
|
||||
m_pDataDownloader = new DataDownloader(url, this);
|
||||
connect(m_pDataDownloader, SIGNAL(downloaded()), SLOT(installBonjour()));
|
||||
|
||||
if (m_DownloadMessageBox == NULL) {
|
||||
m_DownloadMessageBox = new QMessageBox();
|
||||
m_DownloadMessageBox->setModal(false);
|
||||
m_DownloadMessageBox->setStandardButtons(0);
|
||||
m_DownloadMessageBox->setText("Installing Bonjour");
|
||||
m_DownloadMessageBox->resize(100, 10);
|
||||
m_DownloadMessageBox->setStandardButtons(0);
|
||||
m_pCancelButton = m_DownloadMessageBox->addButton(
|
||||
tr("Cancel"), QMessageBox::RejectRole);
|
||||
}
|
||||
|
||||
m_DownloadMessageBox->show();
|
||||
m_DownloadMessageBox->exec();
|
||||
|
||||
connect(m_pDataDownloader, SIGNAL(downloaded()), SLOT(installBonjour()));
|
||||
if (m_DownloadMessageBox->clickedButton() == m_pCancelButton) {
|
||||
m_pDataDownloader->cancelDownload();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ class QCheckBox;
|
|||
class QRadioButton;
|
||||
class QTemporaryFile;
|
||||
class QMessageBox;
|
||||
class QAbstractButton;
|
||||
|
||||
class LogDialog;
|
||||
class QSynergyApplication;
|
||||
|
@ -173,6 +174,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
|||
ZeroconfService* m_pZeroconfService;
|
||||
DataDownloader* m_pDataDownloader;
|
||||
QMessageBox* m_DownloadMessageBox;
|
||||
QAbstractButton* m_pCancelButton;
|
||||
|
||||
private slots:
|
||||
void on_m_pAutoConnectCheckBox_toggled(bool checked);
|
||||
|
|
Loading…
Reference in New Issue