void CFrmUpdater::slotDownloadError(int nErr, const QString szError)
{
ui->progressBar->hide();
ui->progressBar->setRange(0, 100);;
QString szMsg;
szMsg = tr("Failed:") + tr("Download file is Failed.");
if(!szError.isEmpty())
szMsg += "(" + szError + ")";
ui->lbState->setText(szMsg);
qCritical(log) << szMsg << nErr;
emit sigError();
}
void CFrmUpdater::slotDownloadFileFinished(const QString szFile)
{
qDebug(log) << "slotDownloadFileFinished:" << szFile;
ui->progressBar->hide();
ui->progressBar->setRange(0, 100);;
if(m_DownloadFile.isOpen())
m_DownloadFile.close();
QString szTmp
= QStandardPaths::writableLocation(QStandardPaths::TempLocation);
szTmp = szTmp + QDir::separator() + "Rabbit"
+ QDir::separator() + qApp->applicationName();
QString szFileName(m_ConfigFile.szFileName);
if(szFileName.isEmpty())
{
szFileName = szFile.mid(szFile.lastIndexOf("/"));
}
if(szFileName.left(1) != "/" && szFileName.left(1) != "\\")
szFileName = QDir::separator() + szFileName;
QString f = szTmp + szFileName;
if(QFile::exists(f))
QFile::remove(f);
#if HAVE_TEST
if(QFile::copy(szFile, f))
#else
if(QFile::rename(szFile, f))
#endif
{
m_DownloadFile.setFileName(f);
qInfo(log) << "Download finished: rename"
<< szFile << "to" << f;
} else {
qCritical(log) << "Download finished. rename fail from"
<< szFile << "to" << f;
m_DownloadFile.setFileName(szFile);
}
}
void CFrmUpdater::slotDownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
if(ui->progressBar->isHidden())
{
ui->progressBar->show();
ui->progressBar->setRange(0, static_cast<int>(bytesTotal));
}
if(ui->progressBar->maximum() != bytesTotal)
ui->progressBar->setRange(0, static_cast<int>(bytesTotal));
ui->progressBar->setValue(static_cast<int>(bytesReceived));
if(bytesTotal > 0) {
QString szInfo = tr("Downloading %1% [%2/%3]")
.arg(QString::number(bytesReceived * 100 / bytesTotal))
.arg(QString::number(bytesReceived)).arg(QString::number(bytesTotal));
m_TrayIcon.setToolTip(windowTitle() + " - "
+ qApp->applicationDisplayName()
+ ": " + szInfo);
}
}