void AdBlockDownloader::onDownloadFinished(QNetworkReply *reply) { reply->deleteLater(); this->_downloadreply = NULL; this->_filesdownloaded++; this->_tempfile.close(); if(this->_downloadtype == DownloadType::Filters) { if(this->_filesdownloaded == 1) /* Download the second file */ this->downloadFile(AdBlockDownloader::GITHUB_RAW_URL, AdBlockManager::TABLE_FILENAME, this->_adblockmanager->tableFile()); else if(this->_filesdownloaded == AdBlockDownloader::FILES_MAX) { this->_downloading = false; emit downloadingChanged(); emit downloadCompleted(); emit this->_adblockmanager->rulesChanged(); } } else if(this->_downloadtype == DownloadType::Hosts) { AdBlockHostsParser ahp; ahp.parse(this->_adblockmanager->hostsTmpFile(), this->_adblockmanager->hostsRgxFile()); this->_adblockmanager->updateHostsBlackList(); emit downloadingChanged(); emit downloadCompleted(); } }
void CachedImage::_saveData() { Q_ASSERT(_reply); if (!_reply) return; if (_reply->error() != QNetworkReply::NoError ) { _reply->deleteLater(); _reply = nullptr; emit downloadingChanged(); return; } auto data = new QByteArray; *data = _reply->readAll(); if (data->startsWith((char)0x89)) //-V2005 setExtension("png"); else if (data->startsWith((char)0xFF)) //-V2005 setExtension("jpeg"); else if (data->startsWith((char)0x47)) //-V2005 setExtension("gif"); auto future = QtConcurrent::run(this, &CachedImage::_saveFile, data); _saveWatcher.setFuture(future); _reply->deleteLater(); _reply = nullptr; }
void ImageLoader::set_downloading(bool b) { if (m_downloading != b) { m_downloading = b; emit downloadingChanged(); } }
void TelegramFileLocation::setDownloading(bool downloading) { if(p->downloading == downloading) return; p->downloading = downloading; Q_EMIT downloadingChanged(); }
void PodcastChannel::setIsDownloading(bool downloading) { if (downloading != m_isDownloading) { m_isDownloading = downloading; emit channelChanged(); emit downloadingChanged(); } }
void CachedImage::abortDownload() { if (!_reply || !_reply->isRunning()) return; _reply->abort(); emit downloadingChanged(); _kbytesReceived = 0; emit receivedChanged(); }
void AdBlockDownloader::onDownloadProgress(qint64 bytesreceived, qint64 bytestotal) { if(!this->_downloading) { this->_downloading = true; emit downloadingChanged(); } this->_progressvalue = bytesreceived; if(this->_progresstotal != bytestotal) { this->_progresstotal = bytestotal; emit progressTotalChanged(); } emit progressValueChanged(); }
void CachedImage::download() { if (_url.isEmpty() || isDownloading()) return; if (_available) { emit available(); return; } if (_headReply) _headReply->abort(); _reply = _man->web()->get(QNetworkRequest(_url)); Q_TEST(connect(_reply, SIGNAL(finished()), this, SLOT(_saveData()))); Q_TEST(connect(_reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(_changeBytes(qint64,qint64)))); Q_TEST(connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(_printError(QNetworkReply::NetworkError)))); Q_TEST(connect(_reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(_printErrors(QList<QSslError>)))); emit downloadingChanged(); }