void SpotifyDownloadDialog::tryDownloadResolver() { debug() << "Trying to download: " << Collections::SpotifyCollection::resolverDownloadUrl(); NetworkAccessManagerProxy* manager = The::networkAccessManager(); QNetworkRequest request( Collections::SpotifyCollection::resolverDownloadUrl() ); QNetworkReply* reply = manager->get( request ); m_downloadReply = reply; connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( slotDownloadError( QNetworkReply::NetworkError ) ) ); connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( slotDownloadProgress( qint64, qint64 ) ) ); connect( reply, SIGNAL( finished() ), this, SLOT( slotDownloadFinished() ) ); //set-up progress bar m_ui->progDownload->setMinimum( 0 ); m_ui->progDownload->setMaximum( 1000 ); m_ui->progDownload->setValue( 0 ); }
bool SongDownloader::downloadFromQueue() { QUrl downloadUrl = m_downloadQueue.dequeue(); //Extract the filename from the URL path QString filename = downloadUrl.path(); QFileInfo fileInfo(filename); filename = fileInfo.fileName(); m_pDownloadedFile = new QFile(filename + TEMP_EXTENSION); if (!m_pDownloadedFile->open(QIODevice::WriteOnly)) { //TODO: Error qDebug() << "Failed to open" << m_pDownloadedFile->fileName(); return false; } qDebug() << "SongDownloader: setting up download stuff"; m_pRequest = new QNetworkRequest(downloadUrl); //Set up user agent for great justice QString mixxxUA = QString("%1 %2").arg(QApplication::applicationName(), Version::version()); // HTTP request headers must be latin1. QByteArray mixxxUABA = mixxxUA.toLatin1(); m_pRequest->setRawHeader("User-Agent", mixxxUABA); m_pReply = m_pNetwork->get(*m_pRequest); connect(m_pReply, SIGNAL(readyRead()), this, SLOT(slotReadyRead())); connect(m_pReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError))); connect(m_pReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(slotProgress(qint64, qint64))); connect(m_pReply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(downloadProgress(qint64, qint64))); connect(m_pReply, SIGNAL(finished()), this, SLOT(slotDownloadFinished())); return true; }
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) { qDebug() << "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, SIGNAL(readyRead()), SLOT(slotWriteFile())); connect(reply, SIGNAL(finished()), SLOT(slotDownloadFinished())); setDownloadState(Downloading); _file.reset(new QTemporaryFile); _file->setAutoRemove(true); _file->open(); } } } }