Esempio n. 1
0
void DownloadHelper::handleDownload(QNetworkReply* pReply, QString fileName)
{
   if (!handleReplyError(pReply))
      return;

   writeReply(pReply, fileName);

   pReply->close();
   pReply->deleteLater();
}
Esempio n. 2
0
void NetworkProgram::makeRequest() {
    QNetworkAccessManager* manager = _cache->getNetworkAccessManager();
    if (manager == NULL) {
        return;
    }
    _reply = manager->get(_request);
    
    connect(_reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(handleDownloadProgress(qint64,qint64)));
    connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleReplyError()));
}
	void PendingRecommendedArtists::request ()
	{
		QList<QPair<QString, QString>> params;
		params << QPair<QString, QString> ("limit", QString::number (NumGet_));
		auto reply = Request ("user.getRecommendedArtists", NAM_, params);
		connect (reply,
				SIGNAL (finished ()),
				this,
				SLOT (handleReplyFinished ()));
		connect (reply,
				SIGNAL (error (QNetworkReply::NetworkError)),
				this,
				SLOT (handleReplyError ()));
	}
Esempio n. 4
0
void DownloadHelper::onDownloadFinished()
{
   QNetworkReply* pReply = static_cast<QNetworkReply*>(sender());

   if (!handleReplyError(pReply))
      return;

   writeReply(pReply, fileName_);

   downloadFinished(fileName_);

   pReply->close();
   pReply->deleteLater();
   deleteLater();
}
	PendingSimilarArtists::PendingSimilarArtists (const QString& name, int num, QObject *parent)
	: QObject (parent)
	, SourceName_ (name)
	, NumGet_ (num)
	, InfosWaiting_ (0)
	{
		auto reply = lastfm::Artist (name).getSimilar ();
		connect (reply,
				SIGNAL (finished ()),
				this,
				SLOT (handleReplyFinished ()));
		connect (reply,
				SIGNAL (error (QNetworkReply::NetworkError)),
				this,
				SLOT (handleReplyError ()));
	}
	RecentReleasesFetcher::RecentReleasesFetcher (bool withRecs, int num, QNetworkAccessManager *nam, QObject *parent)
	: QObject (parent)
	, MaxNum_ (num)
	{
		const auto& user = XmlSettingsManager::Instance ()
				.property ("lastfm.login").toString ();
		QList<QPair<QString, QString>> params;
		params << QPair<QString, QString> ("user", user);
		params << QPair<QString, QString> ("userecs", withRecs ? "1" : "0");
		auto reply = Request ("user.getNewReleases", nam, params);
		connect (reply,
				SIGNAL (finished ()),
				this,
				SLOT (handleReplyFinished ()));
		connect (reply,
				SIGNAL (error (QNetworkReply::NetworkError)),
				this,
				SLOT (handleReplyError ()));
	}
	PendingSimilarArtists::PendingSimilarArtists (const QString& name,
			int num, QNetworkAccessManager *nam, QObject *parent)
	: BaseSimilarArtists (name, num, parent)
	, NAM_ (nam)
	{
		QMap<QString, QString> params;
		params ["artist"] = name;
		params ["autocorrect"] = "1";
		params ["limit"] = QString::number (num);
		auto reply = Request ("artist.getSimilar", nam, params);
		connect (reply,
				SIGNAL (finished ()),
				this,
				SLOT (handleReplyFinished ()));
		connect (reply,
				SIGNAL (error (QNetworkReply::NetworkError)),
				this,
				SLOT (handleReplyError ()));
	}
Esempio n. 8
0
	ConcreteSite::ConcreteSite (const Media::LyricsQuery& query,
			const ConcreteSiteDesc& desc, ICoreProxy_ptr proxy, QObject *parent)
	: QObject (parent)
	, Query_ (query)
	, Desc_ (desc)
	{
		auto replace = [this] (QString str) -> QString
		{
			for (const auto& c : Desc_.Replacements_.keys ())
				str.replace (c, Desc_.Replacements_ [c]);
			return str;
		};

		const auto& artist = replace (query.Artist_.toLower ());
		const auto& album = replace (query.Album_.toLower ());
		const auto& title = replace (query.Title_.toLower ());

		auto urlStr = Desc_.URLTemplate_;
		urlStr.replace ("{artist}", artist);
		urlStr.replace ("{album}", album);
		urlStr.replace ("{title}", title);
		if (!artist.isEmpty ())
			urlStr.replace ("{a}", artist.at (0).toLower ());

		auto cap = [] (QString str) -> QString
		{
			if (!str.isEmpty ())
				str [0] = str [0].toUpper ();
			return str;
		};
		urlStr.replace ("{Artist}", cap (artist));
		urlStr.replace ("{Album}", cap (album));
		urlStr.replace ("{Title}", cap (title));

#ifdef QT_DEBUG
		qDebug () << Q_FUNC_INFO
				<< "requesting"
				<< urlStr
				<< "from"
				<< Desc_.Name_
				<< "for"
				<< artist
				<< album
				<< title;
#endif

		auto nam = proxy->GetNetworkAccessManager ();

		QUrl url { urlStr };
		QNetworkRequest req { url };

		url.setPath ({});
#if QT_VERSION < 0x050000
		url.setQueryItems ({});
#else
		url.setQuery ({});
#endif
		req.setRawHeader ("Referer", url.toString ().toUtf8 ());

		auto reply = nam->get (req);
		connect (reply,
				SIGNAL (finished ()),
				this,
				SLOT (handleReplyFinished ()));
		connect (reply,
				SIGNAL (error (QNetworkReply::NetworkError)),
				this,
				SLOT (handleReplyError ()));
	}