Place copycover into copy thread
This commit is contained in:
committed by
craig.p.drummond
parent
7ae0550aa3
commit
603c0ed9d7
@@ -25,6 +25,7 @@
|
||||
#include "utils.h"
|
||||
#include "device.h"
|
||||
#include "lyricspage.h"
|
||||
#include "covers.h"
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QTimer>
|
||||
@@ -100,10 +101,12 @@ void CopyJob::run()
|
||||
return;
|
||||
}
|
||||
|
||||
bool copyCover = Device::constNoCover!=coverFileName;
|
||||
char buffer[constChunkSize];
|
||||
qint64 totalBytes = src.size();
|
||||
qint64 readPos = 0;
|
||||
qint64 bytesRead = 0;
|
||||
qint64 adjustTotal = copyCover ? 16384 : 0;
|
||||
|
||||
do {
|
||||
if (stopRequested) {
|
||||
@@ -136,12 +139,17 @@ void CopyJob::run()
|
||||
writePos+=bytesWritten;
|
||||
} while (writePos<bytesRead);
|
||||
|
||||
setPercent(((readPos+bytesRead)*100.0)/totalBytes);
|
||||
setPercent(((readPos+bytesRead)*100.0)/(totalBytes+adjustTotal));
|
||||
if (src.atEnd()) {
|
||||
break;
|
||||
}
|
||||
} while ((readPos+bytesRead)<totalBytes);
|
||||
|
||||
if (copyCover) {
|
||||
song.file=destFile;
|
||||
Covers::copyCover(song, Utils::getDir(srcFile), Utils::getDir(destFile), coverFileName);
|
||||
}
|
||||
setPercent(100);
|
||||
emit result(StatusOk);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QSet>
|
||||
#include "song.h"
|
||||
|
||||
class QThread;
|
||||
class FileJob;
|
||||
@@ -83,15 +84,19 @@ protected:
|
||||
class CopyJob : public FileJob
|
||||
{
|
||||
public:
|
||||
CopyJob(const QString &src, const QString &dest)
|
||||
CopyJob(const QString &src, const QString &dest, const QString &cf, const Song &s)
|
||||
: srcFile(src)
|
||||
, destFile(dest) {
|
||||
, destFile(dest)
|
||||
, coverFileName(cf)
|
||||
, song(s) {
|
||||
}
|
||||
private:
|
||||
void run();
|
||||
private:
|
||||
QString srcFile;
|
||||
QString destFile;
|
||||
QString coverFileName;
|
||||
Song song;
|
||||
};
|
||||
|
||||
class DeleteJob : public FileJob
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "dirviewmodel.h"
|
||||
#include "devicepropertiesdialog.h"
|
||||
#include "devicepropertieswidget.h"
|
||||
#include "covers.h"
|
||||
#include "utils.h"
|
||||
#include "mpdparseutils.h"
|
||||
#include "encoders.h"
|
||||
@@ -246,7 +245,7 @@ void FsDevice::addSong(const Song &s, bool overwrite)
|
||||
currentSong=s;
|
||||
if (encoder.codec.isEmpty() || (opts.transcoderWhenDifferent && !encoder.isDifferent(s.file))) {
|
||||
transcoding=false;
|
||||
CopyJob *job=new CopyJob(s.file, destFile);
|
||||
CopyJob *job=new CopyJob(s.file, destFile, coverFileName, currentSong);
|
||||
connect(job, SIGNAL(result(int)), SLOT(addSongResult(int)));
|
||||
connect(job, SIGNAL(percent(int)), SLOT(percent(int)));
|
||||
job->start();
|
||||
@@ -303,7 +302,7 @@ void FsDevice::copySongTo(const Song &s, const QString &baseDir, const QString &
|
||||
}
|
||||
|
||||
currentSong=s;
|
||||
CopyJob *job=new CopyJob(source, dest);
|
||||
CopyJob *job=new CopyJob(source, dest, QString(), currentSong);
|
||||
connect(job, SIGNAL(result(int)), SLOT(copySongToResult(int)));
|
||||
connect(job, SIGNAL(percent(int)), SLOT(percent(int)));
|
||||
job->start();
|
||||
@@ -365,13 +364,7 @@ void FsDevice::addSongResult(int status)
|
||||
if (FileJob::StatusOk!=status) {
|
||||
emit actionStatus(transcoding ? TranscodeFailed : Failed);
|
||||
} else {
|
||||
QString sourceDir=Utils::getDir(currentSong.file);
|
||||
|
||||
currentSong.file=destFileName;
|
||||
if (Device::constNoCover!=coverFileName) {
|
||||
Covers::copyCover(currentSong, sourceDir, Utils::getDir(audioFolder+destFileName), coverFileName);
|
||||
}
|
||||
|
||||
if (needToFixVa) {
|
||||
Device::fixVariousArtists(audioFolder+destFileName, currentSong, true);
|
||||
}
|
||||
@@ -393,9 +386,7 @@ void FsDevice::copySongToResult(int status)
|
||||
if (FileJob::StatusOk!=status) {
|
||||
emit actionStatus(Failed);
|
||||
} else {
|
||||
QString sourceDir=Utils::getDir(audioFolder+currentSong.file);
|
||||
currentSong.file=currentMusicPath; // MPD's paths are not full!!!
|
||||
Covers::copyCover(currentSong, sourceDir, currentBaseDir+Utils::getDir(currentMusicPath), QString());
|
||||
if (needToFixVa) {
|
||||
Device::fixVariousArtists(currentBaseDir+currentSong.file, currentSong, false);
|
||||
}
|
||||
|
||||
@@ -253,14 +253,24 @@ static void fCopy(const QString &sDir, const QString &sFile, const QString &dDir
|
||||
|
||||
void Covers::copyCover(const Song &song, const QString &sourceDir, const QString &destDir, const QString &name)
|
||||
{
|
||||
initCoverNames();
|
||||
|
||||
// First, check if dir already has a cover file!
|
||||
initCoverNames();
|
||||
QStringList names=coverFileNames;
|
||||
foreach (const QString &ext, constExtensions) {
|
||||
names+=song.album+ext;
|
||||
}
|
||||
|
||||
QString mpdCover=MPDConnection::self()->getDetails().coverName;
|
||||
if (mpdCover.isEmpty()) {
|
||||
mpdCover=constFileName;
|
||||
}
|
||||
|
||||
foreach (const QString &ext, constExtensions) {
|
||||
if (!names.contains(mpdCover+ext)) {
|
||||
names.prepend(mpdCover+ext);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const QString &ext, constExtensions) {
|
||||
names+=song.albumArtist()+QLatin1String(" - ")+song.album+ext;
|
||||
}
|
||||
@@ -277,7 +287,7 @@ void Covers::copyCover(const Song &song, const QString &sourceDir, const QString
|
||||
if (destName.isEmpty()) { // copying into mpd dir, so we want cover.jpg/png...
|
||||
if (coverFileNames.at(0)!=coverFile) { // source is not 'cover.xxx'
|
||||
QString ext(coverFile.endsWith(constExtensions.at(0)) ? constExtensions.at(0) : constExtensions.at(1));
|
||||
destName=constFileName+ext;
|
||||
destName=mpdCover+ext;
|
||||
} else {
|
||||
destName=coverFile;
|
||||
}
|
||||
@@ -293,15 +303,23 @@ void Covers::copyCover(const Song &song, const QString &sourceDir, const QString
|
||||
}
|
||||
}
|
||||
|
||||
// None in source folder. Do we have a cached cover?
|
||||
QString artist=encodeName(song.albumArtist());
|
||||
QString album=encodeName(song.album);
|
||||
QString dir(Utils::cacheDir(constCoverDir+artist, false));
|
||||
foreach (const QString &ext, constExtensions) {
|
||||
if (QFile::exists(dir+album+ext)) {
|
||||
fCopy(dir, album+ext, destDir, constFileName+ext);
|
||||
Utils::setFilePerms(destDir+constFileName+ext);
|
||||
return;
|
||||
QString destName(name);
|
||||
if (!destName.isEmpty()) {
|
||||
// Copying ONTO a device
|
||||
// None in source folder. Do we have a cached cover?
|
||||
QString artist=encodeName(song.albumArtist());
|
||||
QString album=encodeName(song.album);
|
||||
QString dir(Utils::cacheDir(constCoverDir+artist, false));
|
||||
foreach (const QString &ext, constExtensions) {
|
||||
if (QFile::exists(dir+album+ext)) {
|
||||
if (destName.right(4)!=ext) {
|
||||
QImage(dir+album+ext).save(destDir+destName);
|
||||
} else {
|
||||
fCopy(dir, album+ext, destDir, destName);
|
||||
}
|
||||
Utils::setFilePerms(destDir+destName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user