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/mtvmusic.png</file>
|
||||||
<file>providers/cdbaby.png</file>
|
<file>providers/cdbaby.png</file>
|
||||||
<file>providers/echonest.png</file>
|
<file>providers/echonest.png</file>
|
||||||
|
<file>providers/songkick.png</file>
|
||||||
<file>lumberjacksong.txt</file>
|
<file>lumberjacksong.txt</file>
|
||||||
<file>schema/schema-18.sql</file>
|
<file>schema/schema-18.sql</file>
|
||||||
<file>star-off.png</file>
|
<file>star-off.png</file>
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 898 B |
|
@ -23,12 +23,15 @@
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
|
#include "core/logging.h"
|
||||||
|
|
||||||
const qreal SongInfoTextView::kDefaultFontSize = 8.5;
|
const qreal SongInfoTextView::kDefaultFontSize = 8.5;
|
||||||
const char* SongInfoTextView::kSettingsGroup = "SongInfo";
|
const char* SongInfoTextView::kSettingsGroup = "SongInfo";
|
||||||
|
|
||||||
SongInfoTextView::SongInfoTextView(QWidget* parent)
|
SongInfoTextView::SongInfoTextView(QWidget* parent)
|
||||||
: QTextBrowser(parent),
|
: QTextBrowser(parent),
|
||||||
last_width_(-1)
|
last_width_(-1),
|
||||||
|
recursion_filter_(false)
|
||||||
{
|
{
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
@ -88,3 +91,19 @@ void SongInfoTextView::SetHtml(const QString& html) {
|
||||||
|
|
||||||
setHtml(copy);
|
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 resizeEvent(QResizeEvent* e);
|
||||||
void wheelEvent(QWheelEvent* e);
|
void wheelEvent(QWheelEvent* e);
|
||||||
void contextMenuEvent(QContextMenuEvent* e);
|
void contextMenuEvent(QContextMenuEvent* e);
|
||||||
|
QVariant loadResource(int type, const QUrl& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int last_width_;
|
int last_width_;
|
||||||
|
bool recursion_filter_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SONGINFOTEXTVIEW_H
|
#endif // SONGINFOTEXTVIEW_H
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "songkickconcerts.h"
|
#include "songkickconcerts.h"
|
||||||
|
|
||||||
|
#include <QImage>
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
|
|
||||||
#include <echonest/Artist.h>
|
#include <echonest/Artist.h>
|
||||||
|
@ -110,6 +111,7 @@ void SongkickConcerts::CalendarRequestFinished(QNetworkReply* reply, int id) {
|
||||||
|
|
||||||
QString html;
|
QString html;
|
||||||
QXmlStreamWriter writer(&html);
|
QXmlStreamWriter writer(&html);
|
||||||
|
SongInfoTextView* text_view = new SongInfoTextView;
|
||||||
|
|
||||||
QVariantMap root = result.toMap();
|
QVariantMap root = result.toMap();
|
||||||
QVariantMap results_page = root["resultsPage"].toMap();
|
QVariantMap results_page = root["resultsPage"].toMap();
|
||||||
|
@ -126,14 +128,21 @@ void SongkickConcerts::CalendarRequestFinished(QNetworkReply* reply, int id) {
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
QVariantMap venue = event["venue"].toMap();
|
QVariantMap venue = event["venue"].toMap();
|
||||||
if (venue.contains("lng") && venue.contains("lat")) {
|
if (venue["lng"].isValid() && venue["lat"].isValid()) {
|
||||||
writer.writeStartElement("img");
|
writer.writeStartElement("img");
|
||||||
QString maps_url = QString(kStaticMapUrl).arg(
|
QString maps_url = QString(kStaticMapUrl).arg(
|
||||||
venue["lat"].toString(),
|
venue["lat"].toString(),
|
||||||
venue["lng"].toString());
|
venue["lng"].toString());
|
||||||
writer.writeAttribute("src", maps_url);
|
writer.writeAttribute("src", maps_url);
|
||||||
writer.writeEndElement();
|
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();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
|
@ -143,12 +152,21 @@ void SongkickConcerts::CalendarRequestFinished(QNetworkReply* reply, int id) {
|
||||||
data.type_ = CollapsibleInfoPane::Data::Type_Biography;
|
data.type_ = CollapsibleInfoPane::Data::Type_Biography;
|
||||||
data.id_ = QString("songkick/%1").arg(id);
|
data.id_ = QString("songkick/%1").arg(id);
|
||||||
data.title_ = tr("Upcoming Concerts");
|
data.title_ = tr("Upcoming Concerts");
|
||||||
data.icon_ = QIcon();
|
data.icon_ = QIcon(":providers/songkick.png");
|
||||||
|
|
||||||
SongInfoTextView* text_view = new SongInfoTextView;
|
|
||||||
text_view->SetHtml(html);
|
text_view->SetHtml(html);
|
||||||
data.contents_ = text_view;
|
data.contents_ = text_view;
|
||||||
|
|
||||||
emit InfoReady(id, data);
|
emit InfoReady(id, data);
|
||||||
emit Finished(id);
|
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"
|
#include "core/network.h"
|
||||||
|
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
class SongInfoTextView;
|
||||||
|
|
||||||
class SongkickConcerts : public SongInfoProvider {
|
class SongkickConcerts : public SongInfoProvider {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -34,6 +35,7 @@ class SongkickConcerts : public SongInfoProvider {
|
||||||
private slots:
|
private slots:
|
||||||
void ArtistSearchFinished(QNetworkReply* reply, int id);
|
void ArtistSearchFinished(QNetworkReply* reply, int id);
|
||||||
void CalendarRequestFinished(QNetworkReply* reply, int id);
|
void CalendarRequestFinished(QNetworkReply* reply, int id);
|
||||||
|
void InjectImage(QNetworkReply* reply, SongInfoTextView* text_view);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void FetchSongkickCalendar(const QString& artist_id, int id);
|
void FetchSongkickCalendar(const QString& artist_id, int id);
|
||||||
|
|
Loading…
Reference in New Issue