2012-08-27 13:24:28 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "songkickconcertwidget.h"
|
|
|
|
|
|
|
|
#include <QDate>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QTextDocument>
|
2015-04-11 22:52:31 +02:00
|
|
|
#include <QUrlQuery>
|
2012-08-27 13:24:28 +02:00
|
|
|
|
2012-11-22 15:15:07 +01:00
|
|
|
#include "core/closure.h"
|
|
|
|
#include "core/logging.h"
|
|
|
|
#include "core/network.h"
|
|
|
|
#include "core/utilities.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "songinfotextview.h"
|
|
|
|
#include "ui_songkickconcertwidget.h"
|
2012-11-22 15:15:07 +01:00
|
|
|
|
2012-08-27 13:24:28 +02:00
|
|
|
const int SongKickConcertWidget::kStaticMapWidth = 100;
|
|
|
|
const int SongKickConcertWidget::kStaticMapHeight = 100;
|
|
|
|
|
|
|
|
SongKickConcertWidget::SongKickConcertWidget(QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QWidget(parent),
|
|
|
|
ui_(new Ui_SongKickConcertWidget),
|
|
|
|
network_(new NetworkAccessManager(this)) {
|
2012-08-27 13:24:28 +02:00
|
|
|
ui_->setupUi(this);
|
|
|
|
|
|
|
|
// Hide the map by default
|
|
|
|
ui_->map->hide();
|
|
|
|
ui_->map->setFixedSize(kStaticMapWidth, kStaticMapHeight);
|
|
|
|
ui_->map->installEventFilter(this);
|
|
|
|
|
|
|
|
ReloadSettings();
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
SongKickConcertWidget::~SongKickConcertWidget() { delete ui_; }
|
2012-08-27 13:24:28 +02:00
|
|
|
|
|
|
|
void SongKickConcertWidget::ReloadSettings() {
|
|
|
|
QFont font(SongInfoTextView::Font());
|
|
|
|
ui_->title->setFont(font);
|
|
|
|
ui_->date->setFont(font);
|
|
|
|
ui_->location->setFont(font);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SongKickConcertWidget::Init(const QString& title, const QString& url,
|
|
|
|
const QString& date, const QString& location) {
|
2020-09-18 16:15:19 +02:00
|
|
|
ui_->title->setText(QString("<a href=\"%1\">%2</a>")
|
|
|
|
.arg(url.toHtmlEscaped(), title.toHtmlEscaped()));
|
2012-08-27 13:24:28 +02:00
|
|
|
|
|
|
|
if (!location.isEmpty()) {
|
|
|
|
ui_->location->setText(location);
|
|
|
|
} else {
|
|
|
|
ui_->location->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!date.isEmpty()) {
|
|
|
|
QDate parsed_date(QDate::fromString(date, Qt::ISODate));
|
|
|
|
QString date_text = Utilities::PrettyFutureDate(parsed_date);
|
|
|
|
|
|
|
|
if (date_text.isEmpty()) {
|
|
|
|
date_text = date;
|
|
|
|
} else {
|
|
|
|
date_text += " (" + date + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_->date->setText(date_text);
|
|
|
|
} else {
|
|
|
|
ui_->date->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SongKickConcertWidget::SetMap(const QString& lat, const QString& lng,
|
|
|
|
const QString& venue_name) {
|
|
|
|
static const char* kStaticMapUrl =
|
2014-01-28 12:57:05 +01:00
|
|
|
"https://maps.googleapis.com/maps/api/staticmap"
|
2012-08-27 13:24:28 +02:00
|
|
|
"?key=AIzaSyDDJqmLOeE1mY_EBONhnQmdXbKtasgCtqg"
|
|
|
|
"&sensor=false"
|
|
|
|
"&size=%1x%2"
|
|
|
|
"&zoom=12"
|
|
|
|
"¢er=%3,%4"
|
|
|
|
"&markers=%3,%4";
|
|
|
|
|
|
|
|
ui_->map->show();
|
|
|
|
|
|
|
|
map_url_ = QUrl("https://maps.google.com/");
|
2015-04-11 22:52:31 +02:00
|
|
|
QUrlQuery map_url_query;
|
|
|
|
map_url_query.addQueryItem("ll", QString("%1,%2").arg(lat, lng));
|
2012-08-27 13:24:28 +02:00
|
|
|
if (!venue_name.isEmpty()) {
|
2015-04-11 22:52:31 +02:00
|
|
|
map_url_query.addQueryItem("q", venue_name);
|
2012-08-27 13:24:28 +02:00
|
|
|
}
|
2015-04-11 22:52:31 +02:00
|
|
|
map_url_.setQuery(map_url_query);
|
2012-08-27 13:24:28 +02:00
|
|
|
|
|
|
|
// Request the static map image
|
2020-09-18 16:15:19 +02:00
|
|
|
const QUrl url(QString(kStaticMapUrl)
|
|
|
|
.arg(QString::number(kStaticMapWidth),
|
|
|
|
QString::number(kStaticMapHeight), lat, lng));
|
2012-08-27 13:24:28 +02:00
|
|
|
QNetworkReply* reply = network_->get(QNetworkRequest(url));
|
2014-02-07 16:34:20 +01:00
|
|
|
NewClosure(reply, SIGNAL(finished()), this, SLOT(MapLoaded(QNetworkReply*)),
|
2012-08-27 13:24:28 +02:00
|
|
|
reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SongKickConcertWidget::MapLoaded(QNetworkReply* reply) {
|
|
|
|
reply->deleteLater();
|
|
|
|
|
|
|
|
QImage image;
|
|
|
|
if (!image.load(reply, "PNG")) {
|
|
|
|
qLog(Warning) << "Failed to load static map image" << reply->url();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scale it if it was the wrong size.
|
|
|
|
if (image.width() != kStaticMapWidth || image.height() != kStaticMapHeight) {
|
|
|
|
qLog(Warning) << "Scaling static map image" << image.size();
|
|
|
|
image = image.scaled(kStaticMapWidth, kStaticMapHeight, Qt::KeepAspectRatio,
|
|
|
|
Qt::SmoothTransformation);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_->map->setPixmap(QPixmap::fromImage(image));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SongKickConcertWidget::eventFilter(QObject* object, QEvent* event) {
|
|
|
|
if (object == ui_->map && event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
QMouseEvent* e = dynamic_cast<QMouseEvent*>(event);
|
|
|
|
if (e->button() == Qt::LeftButton) {
|
|
|
|
QDesktopServices::openUrl(map_url_);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::eventFilter(object, event);
|
|
|
|
}
|