2010-12-04 23:27:58 +01:00
|
|
|
/* This file is part of Clementine.
|
2014-12-26 13:34:53 +01:00
|
|
|
Copyright 2010-2012, 2014, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2010-12-04 23:27:58 +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.
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2012-02-13 21:44:04 +01:00
|
|
|
#include "currentartloader.h"
|
2010-12-04 23:27:58 +01:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QTemporaryFile>
|
2011-11-28 14:51:35 +01:00
|
|
|
#include <QUrl>
|
2010-12-04 23:27:58 +01:00
|
|
|
|
2014-12-26 14:57:02 +01:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "covers/albumcoverloader.h"
|
|
|
|
#include "playlist/playlistmanager.h"
|
2016-01-14 10:40:26 +01:00
|
|
|
#include "ui/iconloader.h"
|
2014-12-26 14:57:02 +01:00
|
|
|
|
2012-02-13 21:44:04 +01:00
|
|
|
CurrentArtLoader::CurrentArtLoader(Application* app, QObject* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QObject(parent),
|
|
|
|
app_(app),
|
|
|
|
temp_file_pattern_(QDir::tempPath() + "/clementine-art-XXXXXX.jpg"),
|
|
|
|
id_(0) {
|
2012-02-13 21:44:04 +01:00
|
|
|
options_.scale_output_image_ = false;
|
|
|
|
options_.pad_output_image_ = false;
|
2016-02-11 11:41:37 +01:00
|
|
|
QIcon nocover = IconLoader::Load("nocover", IconLoader::Other);
|
2020-09-18 16:15:19 +02:00
|
|
|
options_.default_output_image_ =
|
|
|
|
nocover.pixmap(nocover.availableSizes().last()).toImage();
|
2012-02-13 21:44:04 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage)),
|
|
|
|
SLOT(TempArtLoaded(quint64, QImage)));
|
2010-12-04 23:27:58 +01:00
|
|
|
|
2012-02-13 21:44:04 +01:00
|
|
|
connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)),
|
|
|
|
SLOT(LoadArt(Song)));
|
2010-12-04 23:27:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
CurrentArtLoader::~CurrentArtLoader() {}
|
2010-12-04 23:27:58 +01:00
|
|
|
|
2012-02-13 21:44:04 +01:00
|
|
|
void CurrentArtLoader::LoadArt(const Song& song) {
|
2010-12-04 23:27:58 +01:00
|
|
|
last_song_ = song;
|
2012-02-13 21:44:04 +01:00
|
|
|
id_ = app_->album_cover_loader()->LoadImageAsync(options_, last_song_);
|
2010-12-04 23:27:58 +01:00
|
|
|
}
|
|
|
|
|
2012-02-13 21:44:04 +01:00
|
|
|
void CurrentArtLoader::TempArtLoaded(quint64 id, const QImage& image) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (id != id_) return;
|
2010-12-04 23:27:58 +01:00
|
|
|
id_ = 0;
|
|
|
|
|
|
|
|
QString uri;
|
2010-12-19 16:04:22 +01:00
|
|
|
QString thumbnail_uri;
|
2011-02-19 19:24:11 +01:00
|
|
|
QImage thumbnail;
|
2010-12-04 23:27:58 +01:00
|
|
|
|
2017-10-18 02:53:45 +02:00
|
|
|
if (image != options_.default_output_image_) {
|
2010-12-19 16:04:22 +01:00
|
|
|
temp_art_.reset(new QTemporaryFile(temp_file_pattern_));
|
2014-05-15 08:21:19 +02:00
|
|
|
temp_art_->setAutoRemove(true);
|
2010-12-04 23:27:58 +01:00
|
|
|
temp_art_->open();
|
|
|
|
image.save(temp_art_->fileName(), "JPEG");
|
|
|
|
|
2010-12-19 16:04:22 +01:00
|
|
|
// Scale the image down to make a thumbnail. It's a bit crap doing it here
|
|
|
|
// since it's the GUI thread, but the alternative is hard.
|
|
|
|
temp_art_thumbnail_.reset(new QTemporaryFile(temp_file_pattern_));
|
|
|
|
temp_art_thumbnail_->open();
|
2014-05-15 08:21:19 +02:00
|
|
|
temp_art_thumbnail_->setAutoRemove(true);
|
2011-02-19 19:24:11 +01:00
|
|
|
thumbnail = image.scaledToHeight(120, Qt::SmoothTransformation);
|
|
|
|
thumbnail.save(temp_art_thumbnail_->fileName(), "JPEG");
|
2010-12-19 16:04:22 +01:00
|
|
|
|
2010-12-04 23:27:58 +01:00
|
|
|
uri = "file://" + temp_art_->fileName();
|
2010-12-19 16:04:22 +01:00
|
|
|
thumbnail_uri = "file://" + temp_art_thumbnail_->fileName();
|
2010-12-04 23:27:58 +01:00
|
|
|
}
|
|
|
|
|
2011-02-19 19:24:11 +01:00
|
|
|
emit ArtLoaded(last_song_, uri, image);
|
|
|
|
emit ThumbnailLoaded(last_song_, thumbnail_uri, thumbnail);
|
2010-12-04 23:27:58 +01:00
|
|
|
}
|