void Source::start() { NetworkAccessManager* accessManager = manager()->networkAccessManager(); QNetworkRequest request(page()->currentFrame()->url()); reply = accessManager->get(request); connect(reply, SIGNAL(finished()), this, SLOT(sourceLoaded())); }
bool SongLoader::LoadRemotePlaylist(const QUrl& url) { // This function makes a remote request for the given URL and, if its MIME // type corresponds to a known playlist type, saves the content to a // temporary file, loads it, and returns true. // If the URL does not point to a playlist file we could handle, // it returns false. NetworkAccessManager manager; QNetworkRequest req = QNetworkRequest(url); // Getting headers: QNetworkReply* const headers_reply = manager.head(req); WaitForSignal(headers_reply, SIGNAL(finished())); if (headers_reply->error() != QNetworkReply::NoError) { qLog(Error) << url.toString() << headers_reply->errorString(); return false; } // Now we check if there is a parser that can handle that MIME type. QString mime_type = headers_reply->header(QNetworkRequest::ContentTypeHeader).toString(); ParserBase* const parser = playlist_parser_->ParserForMimeType(mime_type); if (parser == nullptr) { qLog(Debug) << url.toString() << "seems to not be a playlist"; return false; } // We know it is a playlist! // Getting its contents: QNetworkReply* const data_reply = manager.get(req); WaitForSignal(data_reply, SIGNAL(finished())); if (data_reply->error() != QNetworkReply::NoError) { qLog(Error) << url.toString() << data_reply->errorString(); return false; } // Save them to a temporary file... QString playlist_filename = Utilities::SaveToTemporaryFile(data_reply->readAll()); if (playlist_filename.isEmpty()) { qLog(Error) << url.toString() << "could not write contents to temporary file"; return false; } qLog(Debug) << url.toString() << "with MIME" << mime_type << "loading from" << playlist_filename; // ...and load it. LoadPlaylist(parser, playlist_filename); QFile(playlist_filename).remove(); return true; }
DownloadItem * DownloadManager::download(const QUrl & from, const QUrl & to) { NetworkAccessManager * manager = NetworkAccessManager::networkAccessManager(); DownloadItem * item = new DownloadItem(manager->get(QNetworkRequest(from)), to, this); beginInsertRows(QModelIndex(), 0, 0); m_items.prepend(item); endInsertRows(); emit newItem(); return item; }