2012-03-05 19:15:45 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
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.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
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.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "podcastinfowidget.h"
|
|
|
|
#include "ui_podcastinfowidget.h"
|
|
|
|
#include "core/application.h"
|
|
|
|
#include "covers/albumcoverloader.h"
|
|
|
|
|
|
|
|
PodcastInfoWidget::PodcastInfoWidget(QWidget* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QWidget(parent),
|
|
|
|
ui_(new Ui_PodcastInfoWidget),
|
|
|
|
app_(nullptr),
|
|
|
|
image_id_(0) {
|
2012-03-05 19:15:45 +01:00
|
|
|
ui_->setupUi(this);
|
|
|
|
|
2012-03-06 12:39:29 +01:00
|
|
|
cover_options_.desired_height_ = 180;
|
2012-03-05 19:15:45 +01:00
|
|
|
ui_->image->setFixedSize(cover_options_.desired_height_,
|
|
|
|
cover_options_.desired_height_);
|
|
|
|
|
|
|
|
// Set the colour of all the labels
|
|
|
|
const bool light = palette().color(QPalette::Base).value() > 128;
|
|
|
|
const QColor color = palette().color(QPalette::Dark);
|
|
|
|
QPalette label_palette(palette());
|
2014-02-07 16:34:20 +01:00
|
|
|
label_palette.setColor(QPalette::WindowText,
|
|
|
|
light ? color.darker(150) : color.lighter(125));
|
2012-03-05 19:15:45 +01:00
|
|
|
|
2014-02-10 14:29:07 +01:00
|
|
|
for (QLabel* label : findChildren<QLabel*>()) {
|
2012-03-05 19:15:45 +01:00
|
|
|
if (label->property("field_label").toBool()) {
|
|
|
|
label->setPalette(label_palette);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
PodcastInfoWidget::~PodcastInfoWidget() {}
|
2012-03-05 19:15:45 +01:00
|
|
|
|
|
|
|
void PodcastInfoWidget::SetApplication(Application* app) {
|
|
|
|
app_ = app;
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage)),
|
|
|
|
SLOT(ImageLoaded(quint64, QImage)));
|
2012-03-05 19:15:45 +01:00
|
|
|
}
|
|
|
|
|
2012-03-06 12:39:29 +01:00
|
|
|
namespace {
|
2014-02-07 16:34:20 +01:00
|
|
|
template <typename T>
|
|
|
|
void SetText(const QString& value, T* label, QLabel* buddy_label = nullptr) {
|
|
|
|
const bool visible = !value.isEmpty();
|
2012-03-06 12:39:29 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
label->setVisible(visible);
|
|
|
|
if (buddy_label) {
|
|
|
|
buddy_label->setVisible(visible);
|
|
|
|
}
|
2012-03-06 12:39:29 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (visible) {
|
|
|
|
label->setText(value);
|
2012-03-06 12:39:29 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-07 20:34:34 +01:00
|
|
|
} // namespace
|
2012-03-06 12:39:29 +01:00
|
|
|
|
2012-03-05 19:15:45 +01:00
|
|
|
void PodcastInfoWidget::SetPodcast(const Podcast& podcast) {
|
2012-03-06 12:39:29 +01:00
|
|
|
if (image_id_) {
|
2012-03-05 19:15:45 +01:00
|
|
|
app_->album_cover_loader()->CancelTask(image_id_);
|
2012-03-06 12:39:29 +01:00
|
|
|
image_id_ = 0;
|
2012-03-05 19:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
podcast_ = podcast;
|
|
|
|
|
2012-03-07 13:27:31 +01:00
|
|
|
if (podcast.ImageUrlLarge().isValid()) {
|
2012-03-05 19:15:45 +01:00
|
|
|
// Start loading an image for this item.
|
|
|
|
image_id_ = app_->album_cover_loader()->LoadImageAsync(
|
2014-02-07 16:34:20 +01:00
|
|
|
cover_options_, podcast.ImageUrlLarge().toString(), QString());
|
2012-03-05 19:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ui_->image->hide();
|
|
|
|
|
|
|
|
SetText(podcast.title(), ui_->title);
|
|
|
|
SetText(podcast.description(), ui_->description);
|
|
|
|
SetText(podcast.copyright(), ui_->copyright, ui_->copyright_label);
|
|
|
|
SetText(podcast.author(), ui_->author, ui_->author_label);
|
|
|
|
SetText(podcast.owner_name(), ui_->owner, ui_->owner_label);
|
|
|
|
SetText(podcast.link().toString(), ui_->website, ui_->website_label);
|
2014-02-07 16:34:20 +01:00
|
|
|
SetText(podcast.extra("gpodder:subscribers").toString(), ui_->subscribers,
|
|
|
|
ui_->subscribers_label);
|
2012-03-05 19:15:45 +01:00
|
|
|
|
2012-03-06 12:39:29 +01:00
|
|
|
if (!image_id_) {
|
|
|
|
emit LoadingFinished();
|
2012-03-05 19:15:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PodcastInfoWidget::ImageLoaded(quint64 id, const QImage& image) {
|
|
|
|
if (id != image_id_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
image_id_ = 0;
|
|
|
|
|
|
|
|
if (!image.isNull()) {
|
|
|
|
ui_->image->setPixmap(QPixmap::fromImage(image));
|
|
|
|
ui_->image->show();
|
|
|
|
}
|
2012-03-06 12:39:29 +01:00
|
|
|
|
|
|
|
emit LoadingFinished();
|
2012-03-05 19:15:45 +01:00
|
|
|
}
|