mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-18 20:34:39 +01:00
Load images from Google Maps API for Songkick concerts.
This commit is contained in:
parent
0bacedf465
commit
8452c5428e
@ -282,6 +282,7 @@
|
||||
<file>providers/mtvmusic.png</file>
|
||||
<file>providers/cdbaby.png</file>
|
||||
<file>providers/echonest.png</file>
|
||||
<file>providers/songkick.png</file>
|
||||
<file>lumberjacksong.txt</file>
|
||||
<file>schema/schema-18.sql</file>
|
||||
<file>star-off.png</file>
|
||||
|
BIN
data/providers/songkick.png
Normal file
BIN
data/providers/songkick.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 898 B |
@ -23,12 +23,15 @@
|
||||
#include <QWheelEvent>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "core/logging.h"
|
||||
|
||||
const qreal SongInfoTextView::kDefaultFontSize = 8.5;
|
||||
const char* SongInfoTextView::kSettingsGroup = "SongInfo";
|
||||
|
||||
SongInfoTextView::SongInfoTextView(QWidget* parent)
|
||||
: QTextBrowser(parent),
|
||||
last_width_(-1)
|
||||
last_width_(-1),
|
||||
recursion_filter_(false)
|
||||
{
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
@ -88,3 +91,19 @@ void SongInfoTextView::SetHtml(const QString& html) {
|
||||
|
||||
setHtml(copy);
|
||||
}
|
||||
|
||||
// Prevents QTextDocument from trying to load remote images before they are
|
||||
// ready.
|
||||
QVariant SongInfoTextView::loadResource(int type, const QUrl& name) {
|
||||
if (recursion_filter_) {
|
||||
recursion_filter_ = false;
|
||||
return QVariant();
|
||||
}
|
||||
recursion_filter_ = true;
|
||||
if (type == QTextDocument::ImageResource && name.scheme() == "http") {
|
||||
if (document()->resource(type, name).isNull()) {
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
return QTextBrowser::loadResource(type, name);
|
||||
}
|
||||
|
@ -42,9 +42,11 @@ protected:
|
||||
void resizeEvent(QResizeEvent* e);
|
||||
void wheelEvent(QWheelEvent* e);
|
||||
void contextMenuEvent(QContextMenuEvent* e);
|
||||
QVariant loadResource(int type, const QUrl& name);
|
||||
|
||||
private:
|
||||
int last_width_;
|
||||
bool recursion_filter_;
|
||||
};
|
||||
|
||||
#endif // SONGINFOTEXTVIEW_H
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "songkickconcerts.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include <echonest/Artist.h>
|
||||
@ -110,6 +111,7 @@ void SongkickConcerts::CalendarRequestFinished(QNetworkReply* reply, int id) {
|
||||
|
||||
QString html;
|
||||
QXmlStreamWriter writer(&html);
|
||||
SongInfoTextView* text_view = new SongInfoTextView;
|
||||
|
||||
QVariantMap root = result.toMap();
|
||||
QVariantMap results_page = root["resultsPage"].toMap();
|
||||
@ -126,14 +128,21 @@ void SongkickConcerts::CalendarRequestFinished(QNetworkReply* reply, int id) {
|
||||
writer.writeEndElement();
|
||||
}
|
||||
QVariantMap venue = event["venue"].toMap();
|
||||
if (venue.contains("lng") && venue.contains("lat")) {
|
||||
if (venue["lng"].isValid() && venue["lat"].isValid()) {
|
||||
writer.writeStartElement("img");
|
||||
QString maps_url = QString(kStaticMapUrl).arg(
|
||||
venue["lat"].toString(),
|
||||
venue["lng"].toString());
|
||||
writer.writeAttribute("src", maps_url);
|
||||
writer.writeEndElement();
|
||||
qLog(Debug) << maps_url;
|
||||
|
||||
// QTextDocument does not support loading remote images, so we load
|
||||
// them here and then inject them into the document later.
|
||||
QNetworkRequest request(maps_url);
|
||||
QNetworkReply* reply = network_.get(request);
|
||||
NewClosure(reply, SIGNAL(finished()), this,
|
||||
SLOT(InjectImage(QNetworkReply*, SongInfoTextView*)),
|
||||
reply, text_view);
|
||||
}
|
||||
writer.writeEndElement();
|
||||
}
|
||||
@ -143,12 +152,21 @@ void SongkickConcerts::CalendarRequestFinished(QNetworkReply* reply, int id) {
|
||||
data.type_ = CollapsibleInfoPane::Data::Type_Biography;
|
||||
data.id_ = QString("songkick/%1").arg(id);
|
||||
data.title_ = tr("Upcoming Concerts");
|
||||
data.icon_ = QIcon();
|
||||
data.icon_ = QIcon(":providers/songkick.png");
|
||||
|
||||
SongInfoTextView* text_view = new SongInfoTextView;
|
||||
text_view->SetHtml(html);
|
||||
data.contents_ = text_view;
|
||||
|
||||
emit InfoReady(id, data);
|
||||
emit Finished(id);
|
||||
}
|
||||
|
||||
void SongkickConcerts::InjectImage(
|
||||
QNetworkReply* reply, SongInfoTextView* text_view) {
|
||||
QImage image;
|
||||
image.load(reply, "png");
|
||||
text_view->document()->addResource(
|
||||
QTextDocument::ImageResource,
|
||||
reply->request().url(),
|
||||
QVariant(image));
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "core/network.h"
|
||||
|
||||
class QNetworkReply;
|
||||
class SongInfoTextView;
|
||||
|
||||
class SongkickConcerts : public SongInfoProvider {
|
||||
Q_OBJECT
|
||||
@ -34,6 +35,7 @@ class SongkickConcerts : public SongInfoProvider {
|
||||
private slots:
|
||||
void ArtistSearchFinished(QNetworkReply* reply, int id);
|
||||
void CalendarRequestFinished(QNetworkReply* reply, int id);
|
||||
void InjectImage(QNetworkReply* reply, SongInfoTextView* text_view);
|
||||
|
||||
private:
|
||||
void FetchSongkickCalendar(const QString& artist_id, int id);
|
||||
|
Loading…
Reference in New Issue
Block a user