Fixed: Download of data and client
This commit is contained in:
parent
c84bde0da6
commit
97284e7931
4 changed files with 47 additions and 1 deletions
|
@ -147,6 +147,8 @@ void CDownloader::getFileHead()
|
||||||
{
|
{
|
||||||
// file is already downloaded
|
// file is already downloaded
|
||||||
if (m_listener) m_listener->operationSuccess(m_size);
|
if (m_listener) m_listener->operationSuccess(m_size);
|
||||||
|
|
||||||
|
emit downloadDone();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -339,6 +341,10 @@ void CDownloader::onHeadFinished()
|
||||||
downloadFile();
|
downloadFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit downloadPrepared();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDownloader::onDownloadFinished()
|
void CDownloader::onDownloadFinished()
|
||||||
|
@ -357,6 +363,8 @@ void CDownloader::onDownloadFinished()
|
||||||
bool ok = NLMISC::CFile::setFileModificationDate(m_fullPath.toUtf8().constData(), m_lastModified.toTime_t());
|
bool ok = NLMISC::CFile::setFileModificationDate(m_fullPath.toUtf8().constData(), m_lastModified.toTime_t());
|
||||||
|
|
||||||
if (m_listener) m_listener->operationSuccess(m_size);
|
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;
|
if (!m_listener) return;
|
||||||
|
|
||||||
m_listener->operationProgress(m_offset + current, ""); // TODO: put file
|
m_listener->operationProgress(m_offset + current, m_url);
|
||||||
|
|
||||||
// abort download
|
// abort download
|
||||||
if (m_listener->operationShouldStop() && m_reply) m_reply->abort();
|
if (m_listener->operationShouldStop() && m_reply) m_reply->abort();
|
||||||
|
|
|
@ -42,7 +42,11 @@ public:
|
||||||
|
|
||||||
bool isDownloading() const { return m_file != NULL; }
|
bool isDownloading() const { return m_file != NULL; }
|
||||||
|
|
||||||
|
QString getFileFullPath() const { return m_fullPath; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void downloadPrepared();
|
||||||
|
void downloadDone();
|
||||||
void htmlPageContent(const QString &html);
|
void htmlPageContent(const QString &html);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -54,6 +54,9 @@ COperationDialog::COperationDialog(QWidget *parent):QDialog(parent), m_aborting(
|
||||||
// downloader
|
// downloader
|
||||||
m_downloader = new CDownloader(this, this);
|
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()));
|
connect(operationButtonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(onAbortClicked()));
|
||||||
|
|
||||||
// operations
|
// operations
|
||||||
|
@ -343,6 +346,19 @@ void COperationDialog::onAbortClicked()
|
||||||
m_aborting = true;
|
m_aborting = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void COperationDialog::onDownloadPrepared()
|
||||||
|
{
|
||||||
|
// actually download the file
|
||||||
|
m_downloader->getFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
void COperationDialog::onDownloadDone()
|
||||||
|
{
|
||||||
|
renamePartFile();
|
||||||
|
|
||||||
|
emit done();
|
||||||
|
}
|
||||||
|
|
||||||
void COperationDialog::onProgressPrepare()
|
void COperationDialog::onProgressPrepare()
|
||||||
{
|
{
|
||||||
operationProgressBar->setFormat(tr("%p% (%v/%m KiB)"));
|
operationProgressBar->setFormat(tr("%p% (%v/%m KiB)"));
|
||||||
|
@ -948,3 +964,16 @@ bool COperationDialog::operationShouldStop()
|
||||||
|
|
||||||
return m_aborting;
|
return m_aborting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void COperationDialog::renamePartFile()
|
||||||
|
{
|
||||||
|
QString partFile = m_downloader->getFileFullPath();
|
||||||
|
|
||||||
|
QString finalFile = partFile;
|
||||||
|
finalFile.remove(".part");
|
||||||
|
|
||||||
|
if (partFile != finalFile)
|
||||||
|
{
|
||||||
|
QFile::rename(partFile, finalFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,9 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void onAbortClicked();
|
void onAbortClicked();
|
||||||
|
|
||||||
|
void onDownloadPrepared();
|
||||||
|
void onDownloadDone();
|
||||||
|
|
||||||
void onProgressPrepare();
|
void onProgressPrepare();
|
||||||
void onProgressInit(qint64 current, qint64 total);
|
void onProgressInit(qint64 current, qint64 total);
|
||||||
void onProgressStart();
|
void onProgressStart();
|
||||||
|
@ -117,6 +120,8 @@ protected:
|
||||||
|
|
||||||
virtual bool operationShouldStop();
|
virtual bool operationShouldStop();
|
||||||
|
|
||||||
|
void renamePartFile();
|
||||||
|
|
||||||
QWinTaskbarButton *m_button;
|
QWinTaskbarButton *m_button;
|
||||||
CDownloader *m_downloader;
|
CDownloader *m_downloader;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue