Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 0551ea2c authored by Michael Pyne's avatar Michael Pyne

Fix bug 157987 (JuK unnecessarily converts all cover art to PNG) in trunk. ...

Fix bug 157987 (JuK unnecessarily converts all cover art to PNG) in trunk.  Now when JuK downloads cover
art it will simply copy it in place instead of converting it to PNG en route.

CCBUG:157987

svn path=/trunk/KDE/kdemultimedia/juk/; revision=806109
parent dc6aea3d
......@@ -28,8 +28,11 @@
#include <kdebug.h>
#include <k3staticdeleter.h>
#include <ktemporaryfile.h>
#include <kurl.h>
#include <kstandarddirs.h>
#include <kglobal.h>
#include <kio/netaccess.h>
// This is a dictionary to map the track path to their ID. Otherwise we'd have
// to store this info with each CollectionListItem, which would break the cache
......@@ -383,26 +386,56 @@ QPixmap CoverManager::coverFromData(const CoverData &coverData, Size size)
coverKey CoverManager::addCover(const QPixmap &large, const QString &artist, const QString &album)
{
kDebug() ;
coverKey id = data()->nextId();
CoverDataPtr coverData(new CoverData);
kDebug() << "Adding new pixmap to cover database.\n";
if(large.isNull()) {
kDebug() << "The pixmap you're trying to add is NULL!\n";
return NoMatch;
}
// Save it to file first!
KTemporaryFile tempFile;
if(!tempFile.open()) {
kError() << "Unable to open file for pixmap cover, unable to add cover to DB\n";
return NoMatch;
}
// Now that file is open, file name will be available, which is where we want
// to save the pixmap as a .png.
if(!large.save(tempFile.fileName(), "PNG")) {
kError() << "Unable to save pixmap to " << tempFile.fileName() << endl;
return NoMatch;
}
return addCover(KUrl::fromPath(tempFile.fileName()), artist, album);
}
QString ext = QString("/coverdb/coverID-%1.png").arg(id);
coverKey CoverManager::addCover(const KUrl &path, const QString &artist, const QString &album)
{
coverKey id = data()->nextId();
CoverDataPtr coverData(new CoverData);
QString fileNameExt = path.fileName();
int extPos = fileNameExt.lastIndexOf('.');
fileNameExt = fileNameExt.mid(extPos);
if(extPos == -1)
fileNameExt = "";
// Copy it to a local file first.
QString ext = QString("/coverdb/coverID-%1%2").arg(id).arg(fileNameExt);
coverData->path = KGlobal::dirs()->saveLocation("appdata") + ext;
kDebug() << "Saving pixmap to " << coverData->path;
data()->createDataDir();
if(!large.save(coverData->path, "PNG")) {
kError() << "Unable to save pixmap to " << coverData->path << endl;
// Can't use NetAccess::download() since if path is already a local file
// (which is possible) then that function will return without copying, since
// it assumes we merely want the file on the hard disk somewhere.
if(!KIO::NetAccess::file_copy(path, KUrl::fromPath(coverData->path))) {
kError() << "Failed to download cover from " << path << endl;
return NoMatch;
}
......@@ -419,11 +452,6 @@ coverKey CoverManager::addCover(const QPixmap &large, const QString &artist, con
return id;
}
coverKey CoverManager::addCover(const QString &path, const QString &artist, const QString &album)
{
return addCover(QPixmap(path), artist, album);
}
bool CoverManager::hasCover(coverKey id)
{
return data()->covers.contains(id);
......
......@@ -30,6 +30,8 @@ class QMap;
template<class T>
class QList;
class KUrl;
/**
* This class holds the data on a cover. This includes the path to the cover
* representation on-disk, and the artist and album associated with the cover.
......@@ -177,7 +179,7 @@ public:
* @param artist The artist of the new cover.
* @param album The album of the new cover.
*/
static coverKey addCover(const QString &path, const QString &artist = "", const QString &album = "");
static coverKey addCover(const KUrl &path, const QString &artist = "", const QString &album = "");
/**
* Function to determine if @p id matches any covers in the database.
......
......@@ -830,27 +830,22 @@ void Playlist::slotAddCover(bool retrieveLocal)
if(items.isEmpty())
return;
QPixmap newCover;
if(retrieveLocal) {
KUrl file = KFileDialog::getImageOpenUrl(
KUrl( "kfiledialog://homedir" ), this, i18n("Select Cover Image File"));
newCover = QPixmap(file.directory() + '/' + file.fileName());
}
else {
if(!retrieveLocal) {
m_fetcher->setFile((*items.begin())->file());
m_fetcher->chooseCover();
return;
}
if(newCover.isNull())
return;
KUrl file = KFileDialog::getImageOpenUrl(
KUrl( "kfiledialog://homedir" ), this, i18n("Select Cover Image File"));
QString artist = items.front()->file().tag()->artist();
QString album = items.front()->file().tag()->album();
coverKey newId = CoverManager::addCover(newCover, artist, album);
refreshAlbums(items, newId);
coverKey newId = CoverManager::addCover(file, artist, album);
if(newId != CoverManager::NoMatch)
refreshAlbums(items, newId);
}
// Called when image fetcher has added a new cover.
......
......@@ -201,7 +201,7 @@ void WebImageFetcher::slotWebRequestFinished(KJob *job)
d->dialog = new WebImageFetcherDialog(d->imageList, d->file, 0);
d->dialog->setModal(true);
connect(d->dialog, SIGNAL(coverSelected()), SLOT(slotCoverChosen()));
connect(d->dialog, SIGNAL(coverSelected(const KUrl &)), SLOT(slotCoverChosen(const KUrl &)));
connect(d->dialog, SIGNAL(newSearchRequested()), SLOT(slotNewSearch()));
}
......@@ -209,17 +209,17 @@ void WebImageFetcher::slotWebRequestFinished(KJob *job)
d->dialog->show();
}
void WebImageFetcher::slotCoverChosen()
void WebImageFetcher::slotCoverChosen(const KUrl &path)
{
QPixmap pixmap = d->dialog->result();
if(pixmap.isNull()) {
kError(65432) << "Selected pixmap is null for some reason.\n";
return;
}
kDebug(65432) << "Adding new cover for " << d->file.tag()->fileName()
<< "from URL" << path << endl;
kDebug(65432) << "Adding new cover for " << d->file.tag()->fileName();
coverKey newId = CoverManager::addCover(pixmap, d->file.tag()->artist(), d->file.tag()->album());
emit signalCoverChanged(newId);
coverKey newId = CoverManager::addCover(path, d->file.tag()->artist(), d->file.tag()->album());
if(newId != CoverManager::NoMatch) {
emit signalCoverChanged(newId);
d->dialog->close();
}
}
void WebImageFetcher::slotNewSearch()
......
......@@ -27,6 +27,7 @@ template<class T>
class QList;
class KJob;
class KUrl;
class FileHandle;
......@@ -76,7 +77,7 @@ private:
private slots:
void slotLoadImageURLs();
void slotWebRequestFinished(KJob *job);
void slotCoverChosen();
void slotCoverChosen(const KUrl &);
void slotNewSearch();
private:
......
......@@ -160,19 +160,7 @@ void WebImageFetcherDialog::slotOk()
void WebImageFetcherDialog::slotActivated(const QModelIndex &index)
{
m_pixmap = pixmapFromURL(m_imageList[index.row()].imageURL());
if(m_pixmap.isNull()) {
KMessageBox::sorry(this,
i18n("The cover you have selected is unavailable. Please select another."),
i18n("Cover Unavailable"));
QTimer::singleShot(0, this, SLOT(selectedItemIsBad()));
return;
}
accept();
emit coverSelected();
emit coverSelected(m_imageList[index.row()].imageURL());
}
void WebImageFetcherDialog::selectedItemIsBad()
......
......@@ -49,7 +49,7 @@ public:
void setFile(const FileHandle &file);
signals:
void coverSelected();
void coverSelected(const KUrl &);
void newSearchRequested();
public slots:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment