Fixed: Download of data and client

This commit is contained in:
kervala 2016-06-18 19:52:51 +02:00
parent c84bde0da6
commit 97284e7931
4 changed files with 47 additions and 1 deletions

View file

@ -147,6 +147,8 @@ void CDownloader::getFileHead()
{
// file is already downloaded
if (m_listener) m_listener->operationSuccess(m_size);
emit downloadDone();
}
else
{
@ -339,6 +341,10 @@ void CDownloader::onHeadFinished()
downloadFile();
}
}
else
{
emit downloadPrepared();
}
}
void CDownloader::onDownloadFinished()
@ -357,6 +363,8 @@ void CDownloader::onDownloadFinished()
bool ok = NLMISC::CFile::setFileModificationDate(m_fullPath.toUtf8().constData(), m_lastModified.toTime_t());
if (m_listener) m_listener->operationSuccess(m_size);
emit downloadDone();
}
}
@ -380,7 +388,7 @@ void CDownloader::onDownloadProgress(qint64 current, qint64 total)
if (!m_listener) return;
m_listener->operationProgress(m_offset + current, ""); // TODO: put file
m_listener->operationProgress(m_offset + current, m_url);
// abort download
if (m_listener->operationShouldStop() && m_reply) m_reply->abort();

View file

@ -42,7 +42,11 @@ public:
bool isDownloading() const { return m_file != NULL; }
QString getFileFullPath() const { return m_fullPath; }
signals:
void downloadPrepared();
void downloadDone();
void htmlPageContent(const QString &html);
private slots:

View file

@ -54,6 +54,9 @@ COperationDialog::COperationDialog(QWidget *parent):QDialog(parent), m_aborting(
// downloader
m_downloader = new CDownloader(this, this);
connect(m_downloader, SIGNAL(downloadPrepared()), SLOT(onDownloadPrepared()));
connect(m_downloader, SIGNAL(downloadDone()), SLOT(onDownloadDone()));
connect(operationButtonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(onAbortClicked()));
// operations
@ -343,6 +346,19 @@ void COperationDialog::onAbortClicked()
m_aborting = true;
}
void COperationDialog::onDownloadPrepared()
{
// actually download the file
m_downloader->getFile();
}
void COperationDialog::onDownloadDone()
{
renamePartFile();
emit done();
}
void COperationDialog::onProgressPrepare()
{
operationProgressBar->setFormat(tr("%p% (%v/%m KiB)"));
@ -948,3 +964,16 @@ bool COperationDialog::operationShouldStop()
return m_aborting;
}
void COperationDialog::renamePartFile()
{
QString partFile = m_downloader->getFileFullPath();
QString finalFile = partFile;
finalFile.remove(".part");
if (partFile != finalFile)
{
QFile::rename(partFile, finalFile);
}
}

View file

@ -44,6 +44,9 @@ public:
public slots:
void onAbortClicked();
void onDownloadPrepared();
void onDownloadDone();
void onProgressPrepare();
void onProgressInit(qint64 current, qint64 total);
void onProgressStart();
@ -117,6 +120,8 @@ protected:
virtual bool operationShouldStop();
void renamePartFile();
QWinTaskbarButton *m_button;
CDownloader *m_downloader;