void NSISUpdater::versionInfoArrived(const UpdateInfo &info) { ConfigFile cfg; QSettings settings(cfg.configFile(), QSettings::IniFormat); qint64 infoVersion = Helper::stringVersionToInt(info.version()); qint64 seenVersion = Helper::stringVersionToInt(settings.value(seenVersionC).toString()); qint64 currVersion = Helper::currentVersionToInt(); if (info.version().isEmpty() || infoVersion <= currVersion || infoVersion <= seenVersion) { qCInfo(lcUpdater) << "Client is on latest version!"; setDownloadState(UpToDate); } else { QString url = info.downloadUrl(); qint64 autoUpdateFailedVersion = Helper::stringVersionToInt(settings.value(autoUpdateFailedVersionC).toString()); if (url.isEmpty() || _showFallbackMessage || infoVersion == autoUpdateFailedVersion) { showDialog(info); } if (!url.isEmpty()) { _targetFile = cfg.configPath() + url.mid(url.lastIndexOf('/')); if (QFile(_targetFile).exists()) { setDownloadState(DownloadComplete); } else { QNetworkReply *reply = qnam()->get(QNetworkRequest(QUrl(url))); connect(reply, &QIODevice::readyRead, this, &NSISUpdater::slotWriteFile); connect(reply, &QNetworkReply::finished, this, &NSISUpdater::slotDownloadFinished); setDownloadState(Downloading); _file.reset(new QTemporaryFile); _file->setAutoRemove(true); _file->open(); } } } }
void FileTransfersPage::handleNetworkReply(QNetworkReply *networkReply) { if(networkReply == downloadNetworkReply) { if(networkReply->error() != QNetworkReply::NoError) setDownloadState(NOT_FINISHED); else setDownloadState(FINISHED); } else if(networkReply == uploadNetworkReply) { if(networkReply->error() != QNetworkReply::NoError) { setUploadState(NOT_FINISHED); } else { setUploadState(FINISHED); QVariantMap metadataMap = QtJson::Json::parse( networkReply->readAll() ).toMap(); emit fileUploaded(metadataMap); } } }
void PassiveUpdateNotifier::versionInfoArrived(const UpdateInfo &info) { if( info.version().isEmpty() || Helper::stringVersionToInt(info.version()) >= Helper::currentVersionToInt() ) { qDebug() << "Client is on latest version!"; setDownloadState(UpToDate); } else { setDownloadState(UpdateOnlyAvailableThroughSystem); } }
void PassiveUpdateNotifier::versionInfoArrived(const UpdateInfo &info) { qint64 currentVer = Helper::currentVersionToInt(); qint64 remoteVer = Helper::stringVersionToInt(info.version()); if (info.version().isEmpty() || currentVer >= remoteVer) { qCInfo(lcUpdater) << "Client is on latest version!"; setDownloadState(UpToDate); } else { setDownloadState(UpdateOnlyAvailableThroughSystem); } }
void NSISUpdater::slotDownloadFinished() { QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); if (reply->error() != QNetworkReply::NoError) { setDownloadState(DownloadFailed); return; } QUrl url(reply->url()); _file->close(); QFile::copy(_file->fileName(), _targetFile); setDownloadState(DownloadComplete); qDebug() << "Downloaded" << url.toString() << "to" << _targetFile; ConfigFile cfg; QSettings settings(cfg.configFile(), QSettings::IniFormat); settings.setValue(updateTargetVersionC, updateInfo().version()); settings.setValue(updateAvailableC, _targetFile); }
void OCUpdater::checkForUpdate() { QNetworkReply *reply = _accessManager->get(QNetworkRequest(_updateUrl)); connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimedOut())); _timer->start(30*1000); connect(reply, SIGNAL(finished()), this, SLOT(slotVersionInfoArrived())); setDownloadState(CheckingServer); }
void OCUpdater::checkForUpdate() { QNetworkReply *reply = _accessManager->get(QNetworkRequest(_updateUrl)); connect(_timeoutWatchdog, &QTimer::timeout, this, &OCUpdater::slotTimedOut); _timeoutWatchdog->start(30 * 1000); connect(reply, &QNetworkReply::finished, this, &OCUpdater::slotVersionInfoArrived); setDownloadState(CheckingServer); }
FileTransfersPage::FileTransfersPage(QWidget *parent) : QWidget(parent), ui(new Ui::FileTransfersPage) { // private data members initialization ui->setupUi(this); // actions setup setupActions(); // initialize the state setDownloadState(INITIAL); setUploadState(INITIAL); }
void FileTransfersPage::on_downloadStartStopRestartAction_triggered() { switch(downloadState) { case TRANSFERRING: downloadNetworkReply->abort(); break; case NOT_FINISHED: setDownloadState(TRANSFERRING); break; default: break; } }
void OCUpdater::slotTimedOut() { setDownloadState(DownloadTimedOut); }
void FileTransfersPage::setDownloadState(FileTransfersPage::State state) { downloadState = state; switch(downloadState) { case INITIAL: ui->downloadInfoLabel->setText("---"); ui->downloadProgressBar->setValue(0); ui->downloadProgressBar->setFormat("No Active Download"); ui->downloadStartStopRestartAction->setVisible(false); if(!Util::s60v3()) { ui->downloadStartStopRestartToolButton->setVisible(false); } break; case TRANSFERRING: ui->downloadInfoLabel->setText( this->fontMetrics().elidedText( QString("%1 (%2) to %3") .arg(downloadFileName) .arg(downloadFileSize) .arg(downloadFolderName), Qt::ElideMiddle, QApplication::desktop()->screenGeometry().width() - 10 ) ); ui->downloadProgressBar->setValue(0); ui->downloadProgressBar->setFormat("%p% Downloading"); ui->downloadStartStopRestartAction->setText("Stop Download"); ui->downloadStartStopRestartAction->setVisible(true); if(!Util::s60v3()) { ui->downloadStartStopRestartToolButton->setVisible(true); } downloadTime.start(); // prepare the local file downloadFile.setFileName(downloadFolderPath + "/" + downloadFileName); // check whether the file can be opened for writing, // opening it in the process if(!downloadFile.open(QFile::WriteOnly)) { QMessageBox::critical( this, "Droper", "Failed to open the file for writing." ); setDownloadState(NOT_FINISHED); return; } // request the content of the remote file { QUrl url = Common::dropbox->apiToUrl( Dropbox::FILES ).toString() + downloadFilePath; QNetworkRequest networkRequest(url); Common::oAuth->signRequestHeader("GET", &networkRequest); emit networkRequestGetNeeded(&networkRequest); } break; case FINISHED: ui->downloadProgressBar->setFormat("Finished"); ui->downloadStartStopRestartAction->setText("---"); ui->downloadStartStopRestartAction->setVisible(false); if(!Util::s60v3()) { ui->downloadStartStopRestartToolButton->setVisible(false); } downloadFile.close(); break; case NOT_FINISHED: ui->downloadProgressBar->setFormat("Not Finished"); ui->downloadStartStopRestartAction->setText("Restart Download"); ui->downloadStartStopRestartAction->setVisible(true); if(!Util::s60v3()) { ui->downloadStartStopRestartToolButton->setVisible(true); } downloadFile.remove(); break; default: break; } }