- Also need to copy covers if we are transcoding tracks!
- Initial work to support cover-scaling to devices
This commit is contained in:
@@ -101,7 +101,7 @@ void CopyJob::run()
|
||||
return;
|
||||
}
|
||||
|
||||
bool copyCover = Device::constNoCover!=coverFileName;
|
||||
bool copyCover = Device::constNoCover!=coverOpts.name;
|
||||
char buffer[constChunkSize];
|
||||
qint64 totalBytes = src.size();
|
||||
qint64 readPos = 0;
|
||||
@@ -147,7 +147,7 @@ void CopyJob::run()
|
||||
|
||||
if (copyCover) {
|
||||
song.file=destFile;
|
||||
Covers::copyCover(song, Utils::getDir(srcFile), Utils::getDir(destFile), coverFileName);
|
||||
Covers::copyCover(song, Utils::getDir(srcFile), Utils::getDir(destFile), coverOpts.name, coverOpts.maxSize);
|
||||
}
|
||||
setPercent(100);
|
||||
emit result(StatusOk);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QSet>
|
||||
#include "song.h"
|
||||
#include "fsdevice.h"
|
||||
|
||||
class QThread;
|
||||
class FileJob;
|
||||
@@ -84,10 +85,10 @@ protected:
|
||||
class CopyJob : public FileJob
|
||||
{
|
||||
public:
|
||||
CopyJob(const QString &src, const QString &dest, const QString &cf, const Song &s)
|
||||
CopyJob(const QString &src, const QString &dest, const FsDevice::CoverOptions &c, const Song &s)
|
||||
: srcFile(src)
|
||||
, destFile(dest)
|
||||
, coverFileName(cf)
|
||||
, coverOpts(c)
|
||||
, song(s) {
|
||||
}
|
||||
private:
|
||||
@@ -95,7 +96,7 @@ private:
|
||||
private:
|
||||
QString srcFile;
|
||||
QString destFile;
|
||||
QString coverFileName;
|
||||
FsDevice::CoverOptions coverOpts;
|
||||
Song song;
|
||||
};
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "transcodingjob.h"
|
||||
#include "actiondialog.h"
|
||||
#include "localize.h"
|
||||
#include "covers.h"
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QFileInfo>
|
||||
@@ -244,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, coverFileName, currentSong);
|
||||
CopyJob *job=new CopyJob(s.file, destFile, coverOpts, currentSong);
|
||||
connect(job, SIGNAL(result(int)), SLOT(addSongResult(int)));
|
||||
connect(job, SIGNAL(percent(int)), SLOT(percent(int)));
|
||||
job->start();
|
||||
@@ -301,7 +302,7 @@ void FsDevice::copySongTo(const Song &s, const QString &baseDir, const QString &
|
||||
}
|
||||
|
||||
currentSong=s;
|
||||
CopyJob *job=new CopyJob(source, dest, QString(), currentSong);
|
||||
CopyJob *job=new CopyJob(source, dest, CoverOptions(), currentSong);
|
||||
connect(job, SIGNAL(result(int)), SLOT(copySongToResult(int)));
|
||||
connect(job, SIGNAL(percent(int)), SLOT(percent(int)));
|
||||
job->start();
|
||||
@@ -328,7 +329,7 @@ void FsDevice::removeSong(const Song &s)
|
||||
|
||||
void FsDevice::cleanDirs(const QSet<QString> &dirs)
|
||||
{
|
||||
CleanJob *job=new CleanJob(dirs, audioFolder, coverFileName);
|
||||
CleanJob *job=new CleanJob(dirs, audioFolder, coverOpts.name);
|
||||
connect(job, SIGNAL(result(int)), SLOT(cleanDirsResult(int)));
|
||||
connect(job, SIGNAL(percent(int)), SLOT(percent(int)));
|
||||
job->start();
|
||||
@@ -339,8 +340,8 @@ void FsDevice::requestCover(const Song &s)
|
||||
QString songFile=audioFolder+s.file;
|
||||
QString dirName=Utils::getDir(songFile);
|
||||
|
||||
if (QFile::exists(dirName+coverFileName)) {
|
||||
QImage img(dirName+coverFileName);
|
||||
if (QFile::exists(dirName+coverOpts.name)) {
|
||||
QImage img(dirName+coverOpts.name);
|
||||
if (!img.isNull()) {
|
||||
emit cover(s, img);
|
||||
return;
|
||||
@@ -387,6 +388,10 @@ void FsDevice::addSongResult(int status)
|
||||
if (FileJob::StatusOk!=status) {
|
||||
emit actionStatus(transcoding ? TranscodeFailed : Failed);
|
||||
} else {
|
||||
if (transcoding && Device::constNoCover!=coverOpts.name) {
|
||||
// This copy should really be in transcoding thread - but it should be quick enough in the GUI thread anyway...
|
||||
Covers::copyCover(currentSong, Utils::getDir(currentSong.file), Utils::getDir(destFileName), coverOpts.name, coverOpts.maxSize);
|
||||
}
|
||||
currentSong.file=destFileName;
|
||||
if (needToFixVa) {
|
||||
Device::fixVariousArtists(audioFolder+destFileName, currentSong, true);
|
||||
|
||||
@@ -71,6 +71,21 @@ class FsDevice : public Device
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct CoverOptions
|
||||
{
|
||||
CoverOptions() : maxSize(0) { }
|
||||
void checkSize() {
|
||||
if (0==maxSize || maxSize>=400) {
|
||||
maxSize=0;
|
||||
} else {
|
||||
maxSize=((int)(maxSize/100))*100;
|
||||
}
|
||||
}
|
||||
|
||||
QString name;
|
||||
unsigned short maxSize;
|
||||
};
|
||||
|
||||
FsDevice(DevicesModel *m, Solid::Device &dev);
|
||||
FsDevice(DevicesModel *m, const QString &name, const QString &id);
|
||||
virtual ~FsDevice();
|
||||
@@ -78,7 +93,7 @@ public:
|
||||
void rescan(bool full=true);
|
||||
bool isRefreshing() const { return 0!=scanner; }
|
||||
QString path() const { return audioFolder; }
|
||||
QString coverFile() const { return coverFileName; }
|
||||
QString coverFile() const { return coverOpts.name; }
|
||||
void addSong(const Song &s, bool overwrite);
|
||||
void copySongTo(const Song &s, const QString &baseDir, const QString &musicPath, bool overwrite);
|
||||
void removeSong(const Song &s);
|
||||
@@ -109,7 +124,7 @@ protected:
|
||||
bool scanned;
|
||||
MusicScanner *scanner;
|
||||
mutable QString audioFolder;
|
||||
QString coverFileName;
|
||||
CoverOptions coverOpts;
|
||||
FreeSpaceInfo spaceInfo;
|
||||
};
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ RemoteFsDevice::RemoteFsDevice(DevicesModel *m, const QString &cover, const Devi
|
||||
, details(d)
|
||||
, proc(0)
|
||||
{
|
||||
coverFileName=cover;
|
||||
coverOpts.name=cover;
|
||||
opts=options;
|
||||
details.path=Utils::fixPath(details.path);
|
||||
load();
|
||||
@@ -453,11 +453,14 @@ void RemoteFsDevice::setup()
|
||||
cfg.beginGroup(key);
|
||||
#endif
|
||||
opts.useCache=GET_BOOL("useCache", true);
|
||||
coverFileName=GET_STRING("coverFileName", "cover.jpg");
|
||||
coverOpts.name=GET_STRING("coverFileName", "cover.jpg");
|
||||
coverOpts.maxSize=GET_INT("coverMaxSize", 0);
|
||||
coverOpts.checkSize();
|
||||
configured=true;
|
||||
} else {
|
||||
opts.useCache=true;
|
||||
coverFileName=QLatin1String("cover.jpg");
|
||||
coverOpts.name=QLatin1String("cover.jpg");
|
||||
coverOpts.maxSize=0;
|
||||
configured=false;
|
||||
}
|
||||
load();
|
||||
@@ -480,7 +483,7 @@ void RemoteFsDevice::configure(QWidget *parent)
|
||||
if (!configured) {
|
||||
connect(dlg, SIGNAL(cancelled()), SLOT(saveProperties()));
|
||||
}
|
||||
dlg->show(coverFileName, opts, details,
|
||||
dlg->show(coverOpts.name, opts, details,
|
||||
DevicePropertiesWidget::Prop_All-(DevicePropertiesWidget::Prop_Folder+DevicePropertiesWidget::Prop_AutoScan),
|
||||
false, isConnected());
|
||||
}
|
||||
@@ -502,12 +505,12 @@ void RemoteFsDevice::saveOptions()
|
||||
|
||||
void RemoteFsDevice::saveProperties()
|
||||
{
|
||||
saveProperties(coverFileName, opts, details);
|
||||
saveProperties(coverOpts.name, opts, details);
|
||||
}
|
||||
|
||||
void RemoteFsDevice::saveProperties(const QString &newCoverFileName, const DeviceOptions &newOpts, Details newDetails)
|
||||
{
|
||||
if (configured && opts==newOpts && newCoverFileName==coverFileName && details==newDetails) {
|
||||
if (configured && opts==newOpts && newCoverFileName==coverOpts.name && details==newDetails) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -533,7 +536,7 @@ void RemoteFsDevice::saveProperties(const QString &newCoverFileName, const Devic
|
||||
|
||||
opts=newOpts;
|
||||
details=newDetails;
|
||||
coverFileName=newCoverFileName;
|
||||
coverOpts.name=newCoverFileName;
|
||||
QString key=udi();
|
||||
details.save();
|
||||
opts.save(key);
|
||||
@@ -544,7 +547,8 @@ void RemoteFsDevice::saveProperties(const QString &newCoverFileName, const Devic
|
||||
cfg.beginGroup(key);
|
||||
#endif
|
||||
SET_VALUE("useCache", opts.useCache);
|
||||
SET_VALUE("coverFileName", coverFileName);
|
||||
SET_VALUE("coverFileName", coverOpts.name);
|
||||
SET_VALUE("coverMaxSize", coverOpts.maxSize);
|
||||
|
||||
if (newName) {
|
||||
QString oldMount=mountPoint(oldDetails, false);
|
||||
|
||||
@@ -44,6 +44,7 @@ static const QLatin1String constReplaceSpacesKey("replace_spaces");
|
||||
static const QLatin1String constCantataSettingsFile("/.cantata");
|
||||
static const QLatin1String constCantataCacheFile("/.cache.xml");
|
||||
static const QLatin1String constCoverFileNameKey("cover_filename"); // Cantata extension!
|
||||
static const QLatin1String constCoverMaxSizeKey("cover_maxsize"); // Cantata extension!
|
||||
static const QLatin1String constVariousArtistsFixKey("fix_various_artists"); // Cantata extension!
|
||||
static const QLatin1String constTranscoderKey("transcoder"); // Cantata extension!
|
||||
static const QLatin1String constUseCacheKey("use_cache"); // Cantata extension!
|
||||
@@ -165,7 +166,7 @@ void UmsDevice::setup()
|
||||
// } else if (line.startsWith(constUseAutomaticallyKey+"=")) {
|
||||
// useAutomatically = QLatin1String("true")==line.section('=', 1, 1);
|
||||
// } else if (line.startsWith(constCoverFileNameKey+"=")) {
|
||||
// coverFileName=line.section('=', 1, 1);
|
||||
// coverOpts.name=line.section('=', 1, 1);
|
||||
// configured=true;
|
||||
// } else if(line.startsWith(constVariousArtistsFixKey+"=")) {
|
||||
// opts.fixVariousArtists=QLatin1String("true")==line.section('=', 1, 1);
|
||||
@@ -184,7 +185,10 @@ void UmsDevice::setup()
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
if (line.startsWith(constCoverFileNameKey+"=")) {
|
||||
coverFileName=line.section('=', 1, 1);
|
||||
coverOpts.name=line.section('=', 1, 1);
|
||||
} if (line.startsWith(constCoverMaxSizeKey+"=")) {
|
||||
coverOpts.maxSize=line.section('=', 1, 1).toUInt();
|
||||
coverOpts.checkSize();
|
||||
} else if(line.startsWith(constVariousArtistsFixKey+"=")) {
|
||||
opts.fixVariousArtists=QLatin1String("true")==line.section('=', 1, 1);
|
||||
} else if (line.startsWith(constTranscoderKey+"=")) {
|
||||
@@ -202,8 +206,8 @@ void UmsDevice::setup()
|
||||
}
|
||||
}
|
||||
|
||||
if (coverFileName.isEmpty()) {
|
||||
coverFileName=constDefCoverFileName;
|
||||
if (coverOpts.name.isEmpty()) {
|
||||
coverOpts.name=constDefCoverFileName;
|
||||
}
|
||||
|
||||
// No setting, see if any standard dirs exist in path...
|
||||
@@ -243,14 +247,14 @@ void UmsDevice::configure(QWidget *parent)
|
||||
if (!configured) {
|
||||
connect(dlg, SIGNAL(cancelled()), SLOT(saveProperties()));
|
||||
}
|
||||
dlg->show(audioFolder, coverFileName, opts,
|
||||
dlg->show(audioFolder, coverOpts.name, opts,
|
||||
qobject_cast<ActionDialog *>(parent) ? (DevicePropertiesWidget::Prop_All-DevicePropertiesWidget::Prop_Folder)
|
||||
: DevicePropertiesWidget::Prop_All);
|
||||
}
|
||||
|
||||
void UmsDevice::saveProperties()
|
||||
{
|
||||
saveProperties(audioFolder, coverFileName, opts);
|
||||
saveProperties(audioFolder, coverOpts.name, opts);
|
||||
}
|
||||
|
||||
static inline QString toString(bool b)
|
||||
@@ -303,8 +307,8 @@ void UmsDevice::saveOptions()
|
||||
foreach (const QString &u, unusedParams) {
|
||||
out << u << '\n';
|
||||
}
|
||||
// if (coverFileName!=constDefCoverFileName) {
|
||||
// out << constCoverFileNameKey << '=' << coverFileName << '\n';
|
||||
// if (coverOpts.name!=constDefCoverFileName) {
|
||||
// out << constCoverFileNameKey << '=' << coverOpts.name << '\n';
|
||||
// }
|
||||
// out << constVariousArtistsFixKey << '=' << toString(opts.fixVariousArtists) << '\n';
|
||||
}
|
||||
@@ -313,7 +317,7 @@ void UmsDevice::saveOptions()
|
||||
void UmsDevice::saveProperties(const QString &newPath, const QString &newCoverFileName, const DeviceOptions &newOpts)
|
||||
{
|
||||
QString nPath=Utils::fixPath(newPath);
|
||||
if (configured && opts==newOpts && nPath==audioFolder && newCoverFileName==coverFileName) {
|
||||
if (configured && opts==newOpts && nPath==audioFolder && newCoverFileName==coverOpts.name) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -327,7 +331,7 @@ void UmsDevice::saveProperties(const QString &newPath, const QString &newCoverFi
|
||||
removeCache();
|
||||
}
|
||||
}
|
||||
coverFileName=newCoverFileName;
|
||||
coverOpts.name=newCoverFileName;
|
||||
QString oldPath=audioFolder;
|
||||
if (!isConnected()) {
|
||||
return;
|
||||
@@ -341,8 +345,11 @@ void UmsDevice::saveProperties(const QString &newPath, const QString &newCoverFi
|
||||
|
||||
if (extra.open(QIODevice::WriteOnly|QIODevice::Text)) {
|
||||
QTextStream out(&extra);
|
||||
if (coverFileName!=constDefCoverFileName) {
|
||||
out << constCoverFileNameKey << '=' << coverFileName << '\n';
|
||||
if (coverOpts.name!=constDefCoverFileName) {
|
||||
out << constCoverFileNameKey << '=' << coverOpts.name << '\n';
|
||||
}
|
||||
if (0!=coverOpts.maxSize) {
|
||||
out << constCoverMaxSizeKey << '=' << coverOpts.maxSize << '\n';
|
||||
}
|
||||
if (opts.fixVariousArtists) {
|
||||
out << constVariousArtistsFixKey << '=' << toString(opts.fixVariousArtists) << '\n';
|
||||
|
||||
@@ -251,8 +251,9 @@ static void fCopy(const QString &sDir, const QString &sFile, const QString &dDir
|
||||
QFile::copy(sDir+sFile, dDir+dFile);
|
||||
}
|
||||
|
||||
void Covers::copyCover(const Song &song, const QString &sourceDir, const QString &destDir, const QString &name)
|
||||
void Covers::copyCover(const Song &song, const QString &sourceDir, const QString &destDir, const QString &name, unsigned short maxSize)
|
||||
{
|
||||
Q_UNUSED(maxSize) // TODO!!!
|
||||
// First, check if dir already has a cover file!
|
||||
initCoverNames();
|
||||
QStringList names=coverFileNames;
|
||||
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
|
||||
static Covers * self();
|
||||
static bool isCoverFile(const QString &file);
|
||||
static void copyCover(const Song &song, const QString &sourceDir, const QString &destDir, const QString &name=QString());
|
||||
static void copyCover(const Song &song, const QString &sourceDir, const QString &destDir, const QString &name=QString(), unsigned short maxSize=0);
|
||||
static QStringList standardNames();
|
||||
|
||||
Covers();
|
||||
|
||||
Reference in New Issue
Block a user