- Store properties on remote device
- If no music items, delete cache - If properties are all default, remove file
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
Last.fm and Google are used to find images.
|
||||
16. Use cache by default for devices.
|
||||
17. Compress cache files.
|
||||
18. Save remote device library settings on remote device.
|
||||
|
||||
0.9.2
|
||||
-----
|
||||
|
||||
@@ -33,6 +33,7 @@ DevicePropertiesDialog::DevicePropertiesDialog(QWidget *parent)
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
devProp=new DevicePropertiesWidget(this);
|
||||
devProp->showRemoteConnectionNote(false);
|
||||
setMainWidget(devProp);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
bool isSaveable() const { return saveable; }
|
||||
QString music() const { return musicFolder->text().trimmed(); }
|
||||
QString cover() const;
|
||||
void showRemoteConnectionNote(bool v) { remoteDeviceNote->setVisible(v); }
|
||||
|
||||
Q_SIGNALS:
|
||||
void updated();
|
||||
|
||||
@@ -14,6 +14,16 @@
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="remoteDeviceNote">
|
||||
<property name="text">
|
||||
<string><i><b>NOTE:</b> These settings are only valid and editable when the device is connected.</i></string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
|
||||
@@ -45,7 +45,20 @@
|
||||
#include <QtCore/QTimer>
|
||||
#include <time.h>
|
||||
|
||||
static const QLatin1String constCantataCacheFile("/.cache");
|
||||
const QLatin1String FsDevice::constCantataCacheFile("/.cache");
|
||||
const QLatin1String FsDevice::constCantataSettingsFile("/.cantata");
|
||||
const QLatin1String FsDevice::constMusicFilenameSchemeKey("music_filenamescheme");
|
||||
const QLatin1String FsDevice::constVfatSafeKey("vfat_safe");
|
||||
const QLatin1String FsDevice::constAsciiOnlyKey("ascii_only");
|
||||
const QLatin1String FsDevice::constIgnoreTheKey("ignore_the");
|
||||
const QLatin1String FsDevice::constReplaceSpacesKey("replace_spaces");
|
||||
const QLatin1String FsDevice::constCoverFileNameKey("cover_filename"); // Cantata extension!
|
||||
const QLatin1String FsDevice::constCoverMaxSizeKey("cover_maxsize"); // Cantata extension!
|
||||
const QLatin1String FsDevice::constVariousArtistsFixKey("fix_various_artists"); // Cantata extension!
|
||||
const QLatin1String FsDevice::constTranscoderKey("transcoder"); // Cantata extension!
|
||||
const QLatin1String FsDevice::constUseCacheKey("use_cache"); // Cantata extension!
|
||||
const QLatin1String FsDevice::constDefCoverFileName("cover.jpg");
|
||||
const QLatin1String FsDevice::constAutoScanKey("auto_scan"); // Cantata extension!
|
||||
|
||||
MusicScanner::MusicScanner(const QString &f)
|
||||
: QThread(0)
|
||||
@@ -145,6 +158,120 @@ void MusicScanner::scanFolder(const QString &f, int level)
|
||||
}
|
||||
}
|
||||
|
||||
bool FsDevice::readOpts(const QString &fileName, DeviceOptions &opts, bool readAll)
|
||||
{
|
||||
QFile file(fileName);
|
||||
|
||||
opts=DeviceOptions(constDefCoverFileName);
|
||||
if (file.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
||||
QTextStream in(&file);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
if (line.startsWith(constCoverFileNameKey+"=")) {
|
||||
opts.coverName=line.section('=', 1, 1);
|
||||
} if (line.startsWith(constCoverMaxSizeKey+"=")) {
|
||||
opts.coverMaxSize=line.section('=', 1, 1).toUInt();
|
||||
opts.checkCoverSize();
|
||||
} else if(line.startsWith(constVariousArtistsFixKey+"=")) {
|
||||
opts.fixVariousArtists=QLatin1String("true")==line.section('=', 1, 1);
|
||||
} else if (line.startsWith(constTranscoderKey+"=")) {
|
||||
QStringList parts=line.section('=', 1, 1).split(',');
|
||||
if (3==parts.size()) {
|
||||
opts.transcoderCodec=parts.at(0);
|
||||
opts.transcoderValue=parts.at(1).toInt();
|
||||
opts.transcoderWhenDifferent=QLatin1String("true")==parts.at(2);
|
||||
}
|
||||
} else if (line.startsWith(constUseCacheKey+"=")) {
|
||||
opts.useCache=QLatin1String("true")==line.section('=', 1, 1);
|
||||
} else if (line.startsWith(constAutoScanKey+"=")) {
|
||||
opts.autoScan=QLatin1String("true")==line.section('=', 1, 1);
|
||||
} else if (readAll) {
|
||||
// For UMS these are stored in .is_audio_player - for Amarok compatability!
|
||||
if (line.startsWith(constMusicFilenameSchemeKey+"=")) {
|
||||
QString scheme = line.section('=', 1, 1);
|
||||
//protect against empty setting.
|
||||
if (!scheme.isEmpty() ) {
|
||||
opts.scheme = scheme;
|
||||
}
|
||||
} else if (line.startsWith(constVfatSafeKey+"=")) {
|
||||
opts.vfatSafe = QLatin1String("true")==line.section('=', 1, 1);
|
||||
} else if (line.startsWith(constAsciiOnlyKey+"=")) {
|
||||
opts.asciiOnly = QLatin1String("true")==line.section('=', 1, 1);
|
||||
} else if (line.startsWith(constIgnoreTheKey+"=")) {
|
||||
opts.ignoreThe = QLatin1String("true")==line.section('=', 1, 1);
|
||||
} else if (line.startsWith(constReplaceSpacesKey+"=")) {
|
||||
opts.replaceSpaces = QLatin1String("true")==line.section('=', 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline QString toString(bool b)
|
||||
{
|
||||
return b ? QLatin1String("true") : QLatin1String("false");
|
||||
}
|
||||
|
||||
void FsDevice::writeOpts(const QString &fileName, const DeviceOptions &opts, bool writeAll)
|
||||
{
|
||||
DeviceOptions def(constDefCoverFileName);
|
||||
// If we are just using the defaults, then mayas wel lremove the file!
|
||||
if ( (writeAll && opts==def) ||
|
||||
(!writeAll && opts.coverName==constDefCoverFileName && 0==opts.coverMaxSize && opts.fixVariousArtists!=def.fixVariousArtists &&
|
||||
opts.transcoderCodec.isEmpty() && opts.useCache==def.useCache && opts.autoScan!=def.autoScan)) {
|
||||
if (QFile::exists(fileName)) {
|
||||
QFile::remove(fileName);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::WriteOnly|QIODevice::Text)) {
|
||||
|
||||
QTextStream out(&file);
|
||||
if (writeAll) {
|
||||
if (opts.scheme!=def.scheme) {
|
||||
out << constMusicFilenameSchemeKey << '=' << opts.scheme << '\n';
|
||||
}
|
||||
if (opts.scheme!=def.scheme) {
|
||||
out << constVfatSafeKey << '=' << toString(opts.vfatSafe) << '\n';
|
||||
}
|
||||
if (opts.asciiOnly!=def.asciiOnly) {
|
||||
out << constAsciiOnlyKey << '=' << toString(opts.asciiOnly) << '\n';
|
||||
}
|
||||
if (opts.ignoreThe!=def.ignoreThe) {
|
||||
out << constIgnoreTheKey << '=' << toString(opts.ignoreThe) << '\n';
|
||||
}
|
||||
if (opts.replaceSpaces!=def.replaceSpaces) {
|
||||
out << constReplaceSpacesKey << '=' << toString(opts.replaceSpaces) << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: If any options are added/changed - take care of the "if ( (writeAll..." block above!!!
|
||||
if (opts.coverName!=constDefCoverFileName) {
|
||||
out << constCoverFileNameKey << '=' << opts.coverName << '\n';
|
||||
}
|
||||
if (0!=opts.coverMaxSize) {
|
||||
out << constCoverMaxSizeKey << '=' << opts.coverMaxSize << '\n';
|
||||
}
|
||||
if (opts.fixVariousArtists!=def.fixVariousArtists) {
|
||||
out << constVariousArtistsFixKey << '=' << toString(opts.fixVariousArtists) << '\n';
|
||||
}
|
||||
if (!opts.transcoderCodec.isEmpty()) {
|
||||
out << constTranscoderKey << '=' << opts.transcoderCodec << ',' << opts.transcoderValue << ',' << toString(opts.transcoderWhenDifferent) << '\n';
|
||||
}
|
||||
if (opts.useCache!=def.useCache) {
|
||||
out << constUseCacheKey << '=' << toString(opts.useCache) << '\n';
|
||||
}
|
||||
if (opts.autoScan!=def.autoScan) {
|
||||
out << constAutoScanKey << '=' << toString(opts.autoScan) << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FsDevice::FsDevice(DevicesModel *m, Solid::Device &dev)
|
||||
: Device(m, dev)
|
||||
, scanned(false)
|
||||
@@ -514,11 +641,6 @@ void FsDevice::libraryUpdated()
|
||||
}
|
||||
}
|
||||
|
||||
static inline QString toString(bool b)
|
||||
{
|
||||
return b ? QLatin1String("true") : QLatin1String("false");
|
||||
}
|
||||
|
||||
QString FsDevice::cacheFileName() const
|
||||
{
|
||||
if (audioFolder.isEmpty()) {
|
||||
|
||||
@@ -71,6 +71,24 @@ class FsDevice : public Device
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static const QLatin1String constCantataCacheFile;
|
||||
static const QLatin1String constCantataSettingsFile;
|
||||
static const QLatin1String constMusicFilenameSchemeKey;
|
||||
static const QLatin1String constVfatSafeKey;
|
||||
static const QLatin1String constAsciiOnlyKey;
|
||||
static const QLatin1String constIgnoreTheKey;
|
||||
static const QLatin1String constReplaceSpacesKey;
|
||||
static const QLatin1String constCoverFileNameKey; // Cantata extension!
|
||||
static const QLatin1String constCoverMaxSizeKey; // Cantata extension!
|
||||
static const QLatin1String constVariousArtistsFixKey; // Cantata extension!
|
||||
static const QLatin1String constTranscoderKey; // Cantata extension!
|
||||
static const QLatin1String constUseCacheKey; // Cantata extension!
|
||||
static const QLatin1String constDefCoverFileName;
|
||||
static const QLatin1String constAutoScanKey; // Cantata extension!
|
||||
|
||||
static bool readOpts(const QString &fileName, DeviceOptions &opts, bool readAll);
|
||||
static void writeOpts(const QString &fileName, const DeviceOptions &opts, bool writeAll);
|
||||
|
||||
FsDevice(DevicesModel *m, Solid::Device &dev);
|
||||
FsDevice(DevicesModel *m, const QString &name, const QString &id);
|
||||
virtual ~FsDevice();
|
||||
|
||||
@@ -39,7 +39,7 @@ RemoteDevicePropertiesDialog::RemoteDevicePropertiesDialog(QWidget *parent)
|
||||
setCaption(i18n("Device Properties"));
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
QTabWidget *tab=new QTabWidget(this);
|
||||
tab=new QTabWidget(this);
|
||||
remoteProp=new RemoteDevicePropertiesWidget(tab);
|
||||
devProp=new DevicePropertiesWidget(tab);
|
||||
tab->addTab(remoteProp, QIcon::fromTheme("network-server"), i18n("Connection"));
|
||||
@@ -53,6 +53,14 @@ void RemoteDevicePropertiesDialog::show(const DeviceOptions &opts, const RemoteF
|
||||
if (isCreate) {
|
||||
setCaption(i18n("Add Device"));
|
||||
}
|
||||
|
||||
if (create) {
|
||||
devProp->setVisible(false);
|
||||
} else {
|
||||
tab->setCurrentIndex(isConnected ? 1 : 0);
|
||||
}
|
||||
devProp->setEnabled(!create && isConnected);
|
||||
devProp->showRemoteConnectionNote(!isConnected);
|
||||
devProp->update(QString(), opts, props);
|
||||
remoteProp->update(det, create, isConnected);
|
||||
connect(devProp, SIGNAL(updated()), SLOT(enableOkButton()));
|
||||
@@ -63,8 +71,9 @@ void RemoteDevicePropertiesDialog::show(const DeviceOptions &opts, const RemoteF
|
||||
|
||||
void RemoteDevicePropertiesDialog::enableOkButton()
|
||||
{
|
||||
enableButtonOk(remoteProp->isSaveable() && devProp->isSaveable() &&
|
||||
(isCreate || remoteProp->isModified() || devProp->isModified()));
|
||||
bool useDevProp=devProp->isEnabled();
|
||||
enableButtonOk(remoteProp->isSaveable() && (!useDevProp || devProp->isSaveable()) &&
|
||||
(isCreate || remoteProp->isModified() || !useDevProp || devProp->isModified()));
|
||||
}
|
||||
|
||||
void RemoteDevicePropertiesDialog::slotButtonClicked(int button)
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "dialog.h"
|
||||
#include "remotefsdevice.h"
|
||||
|
||||
class QTabWidget;
|
||||
class FilenameSchemeDialog;
|
||||
class DevicePropertiesWidget;
|
||||
class RemoteDevicePropertiesWidget;
|
||||
@@ -50,6 +51,7 @@ private:
|
||||
void slotButtonClicked(int button);
|
||||
|
||||
private:
|
||||
QTabWidget *tab;
|
||||
RemoteDevicePropertiesWidget *remoteProp;
|
||||
DevicePropertiesWidget *devProp;
|
||||
bool isCreate;
|
||||
|
||||
@@ -70,6 +70,7 @@ void RemoteDevicePropertiesWidget::update(const RemoteFsDevice::Details &d, bool
|
||||
smbPort->setValue(445);
|
||||
#endif
|
||||
|
||||
connectionNote->setVisible(isConnected);
|
||||
sshFolder->setText(QString());
|
||||
sshHost->setText(QString());
|
||||
sshUser->setText(QString());
|
||||
@@ -78,7 +79,9 @@ void RemoteDevicePropertiesWidget::update(const RemoteFsDevice::Details &d, bool
|
||||
switch (t) {
|
||||
case Type_SshFs: {
|
||||
sshFolder->setText(d.url.path());
|
||||
sshPort->setValue(d.url.port());
|
||||
if (0!=d.url.port()) {
|
||||
sshPort->setValue(d.url.port());
|
||||
}
|
||||
sshHost->setText(d.url.host());
|
||||
sshUser->setText(d.url.userName());
|
||||
break;
|
||||
@@ -89,7 +92,9 @@ void RemoteDevicePropertiesWidget::update(const RemoteFsDevice::Details &d, bool
|
||||
#ifdef ENABLE_MOUNTER
|
||||
case Type_Samba: {
|
||||
smbShare->setText(d.url.path());
|
||||
smbPort->setValue(d.url.port());
|
||||
if (0!=d.url.port()) {
|
||||
smbPort->setValue(d.url.port());
|
||||
}
|
||||
smbHost->setText(d.url.host());
|
||||
smbUser->setText(d.url.userName());
|
||||
smbPassword->setText(d.url.password());
|
||||
@@ -129,6 +134,11 @@ void RemoteDevicePropertiesWidget::setType()
|
||||
if (Type_SshFs==type->itemData(type->currentIndex()).toInt() && 0==sshPort->value()) {
|
||||
sshPort->setValue(22);
|
||||
}
|
||||
#ifdef ENABLE_MOUNTER
|
||||
if (Type_Samba==type->itemData(type->currentIndex()).toInt() && 0==smbPort->value()) {
|
||||
smbPort->setValue(445);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void RemoteDevicePropertiesWidget::checkSaveable()
|
||||
|
||||
@@ -11,6 +11,16 @@
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="connectionNote">
|
||||
<property name="text">
|
||||
<string><i><b>NOTE:</b> These settings are only editable when the device is not connected.</i></string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
|
||||
@@ -85,6 +85,7 @@ void RemoteFsDevice::Details::load(const QString &group)
|
||||
if (!u.isEmpty()) {
|
||||
url=QUrl(u);
|
||||
}
|
||||
configured=GET_BOOL("configured", configured);
|
||||
}
|
||||
|
||||
void RemoteFsDevice::Details::save() const
|
||||
@@ -96,6 +97,7 @@ void RemoteFsDevice::Details::save() const
|
||||
cfg.beginGroup(constCfgPrefix+name);
|
||||
#endif
|
||||
SET_VALUE("url", url.toString());
|
||||
SET_VALUE("configured", configured);
|
||||
CFG_SYNC;
|
||||
}
|
||||
|
||||
@@ -549,6 +551,7 @@ void RemoteFsDevice::load()
|
||||
{
|
||||
if (isConnected()) {
|
||||
setAudioFolder();
|
||||
readOpts(settingsFileName(), opts, true);
|
||||
if (!opts.useCache || !readCache()) {
|
||||
rescan();
|
||||
}
|
||||
@@ -558,20 +561,14 @@ void RemoteFsDevice::load()
|
||||
void RemoteFsDevice::setup()
|
||||
{
|
||||
QString key=udi();
|
||||
opts.load(key);
|
||||
details.load(details.name);
|
||||
// details.path=Utils::fixPath(details.path);
|
||||
#ifndef ENABLE_KDE_SUPPORT
|
||||
QSettings cfg;
|
||||
#endif
|
||||
if (HAS_GROUP(key)) {
|
||||
opts.checkCoverSize();
|
||||
configured=true;
|
||||
} else {
|
||||
opts.useCache=true;
|
||||
opts.coverName=QLatin1String("cover.jpg");
|
||||
opts.coverMaxSize=0;
|
||||
configured=false;
|
||||
|
||||
if (isConnected()) {
|
||||
readOpts(settingsFileName(), opts, true);
|
||||
}
|
||||
load();
|
||||
}
|
||||
@@ -620,46 +617,53 @@ void RemoteFsDevice::saveProperties()
|
||||
|
||||
void RemoteFsDevice::saveProperties(const DeviceOptions &newOpts, const Details &nd)
|
||||
{
|
||||
if (configured && opts==newOpts && details==nd) {
|
||||
bool connected=isConnected();
|
||||
if (configured && (!connected || opts==newOpts) && (connected || details==nd)) {
|
||||
return;
|
||||
}
|
||||
|
||||
configured=true;
|
||||
Details newDetails=nd;
|
||||
Details oldDetails=details;
|
||||
// newDetails.path=Utils::fixPath(newDetails.path);
|
||||
bool diffUrl=oldDetails.url!=newDetails.url;
|
||||
|
||||
if (opts.useCache!=newOpts.useCache || diffUrl) { // Cache/url settings changed
|
||||
if (opts.useCache && !diffUrl) {
|
||||
saveCache();
|
||||
} else if (opts.useCache && !newOpts.useCache) {
|
||||
removeCache();
|
||||
if (connected) {
|
||||
if (!configured) {
|
||||
details.configured=configured=true;
|
||||
details.save();
|
||||
}
|
||||
}
|
||||
|
||||
// Name/or URL changed - need to unmount...
|
||||
bool newName=!oldDetails.name.isEmpty() && oldDetails.name!=newDetails.name;
|
||||
if ((newName || diffUrl) && isConnected()) {
|
||||
unmount();
|
||||
}
|
||||
|
||||
opts=newOpts;
|
||||
details=newDetails;
|
||||
QString key=udi();
|
||||
details.save();
|
||||
opts.save(key);
|
||||
|
||||
if (newName) {
|
||||
QString oldMount=mountPoint(oldDetails, false);
|
||||
if (!oldMount.isEmpty() && QDir(oldMount).exists()) {
|
||||
::rmdir(QFile::encodeName(oldMount).constData());
|
||||
if (opts.useCache!=newOpts.useCache) {
|
||||
if (opts.useCache) {
|
||||
saveCache();
|
||||
} else if (opts.useCache && !newOpts.useCache) {
|
||||
removeCache();
|
||||
}
|
||||
}
|
||||
opts=newOpts;
|
||||
writeOpts(settingsFileName(), opts, true);
|
||||
} else {
|
||||
Details newDetails=nd;
|
||||
Details oldDetails=details;
|
||||
bool newName=!oldDetails.name.isEmpty() && oldDetails.name!=newDetails.name;
|
||||
|
||||
details=newDetails;
|
||||
details.configured=configured;
|
||||
details.save();
|
||||
|
||||
if (newName) {
|
||||
QString oldMount=mountPoint(oldDetails, false);
|
||||
if (!oldMount.isEmpty() && QDir(oldMount).exists()) {
|
||||
::rmdir(QFile::encodeName(oldMount).constData());
|
||||
}
|
||||
setData(details.name);
|
||||
renamed(oldDetails.name, details.name);
|
||||
deviceId=createUdi(details.name);
|
||||
emit udiChanged();
|
||||
m_itemData=details.name;
|
||||
setStatusMessage(QString());
|
||||
}
|
||||
setData(details.name);
|
||||
renamed(oldDetails.name, details.name);
|
||||
deviceId=createUdi(details.name);
|
||||
emit udiChanged();
|
||||
m_itemData=details.name;
|
||||
setStatusMessage(QString());
|
||||
}
|
||||
}
|
||||
|
||||
QString RemoteFsDevice::settingsFileName() const
|
||||
{
|
||||
if (audioFolder.isEmpty()) {
|
||||
setAudioFolder();
|
||||
}
|
||||
return audioFolder+constCantataSettingsFile;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public:
|
||||
QString name;
|
||||
QUrl url;
|
||||
int port;
|
||||
bool configured;
|
||||
};
|
||||
|
||||
static const QLatin1String constSshfsProtocol;
|
||||
@@ -111,6 +112,7 @@ private:
|
||||
#ifdef ENABLE_MOUNTER
|
||||
ComGooglecodeCantataMounterInterface * mounter();
|
||||
#endif
|
||||
QString settingsFileName() const;
|
||||
|
||||
protected Q_SLOTS:
|
||||
void saveProperties();
|
||||
|
||||
@@ -34,22 +34,6 @@
|
||||
|
||||
static const QLatin1String constSettingsFile("/.is_audio_player");
|
||||
static const QLatin1String constMusicFolderKey("audio_folder");
|
||||
// static const QLatin1String constPodcastFolderKey("podcast_folder");
|
||||
static const QLatin1String constMusicFilenameSchemeKey("music_filenamescheme");
|
||||
static const QLatin1String constVfatSafeKey("vfat_safe");
|
||||
static const QLatin1String constAsciiOnlyKey("ascii_only");
|
||||
static const QLatin1String constIgnoreTheKey("ignore_the");
|
||||
static const QLatin1String constReplaceSpacesKey("replace_spaces");
|
||||
// static const QLatin1String constUseAutomaticallyKey("use_automatically");
|
||||
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!
|
||||
static const QLatin1String constDefCoverFileName("cover.jpg");
|
||||
static const QLatin1String constAutoScanKey("auto_scan"); // Cantata extension!
|
||||
|
||||
UmsDevice::UmsDevice(DevicesModel *m, Solid::Device &dev)
|
||||
: FsDevice(m, dev)
|
||||
@@ -137,8 +121,8 @@ void UmsDevice::setup()
|
||||
QString audioFolderSetting;
|
||||
|
||||
opts=DeviceOptions();
|
||||
// podcastFolder=QString();
|
||||
if (file.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
||||
configured=true;
|
||||
QTextStream in(&file);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
@@ -147,8 +131,6 @@ void UmsDevice::setup()
|
||||
if (!QDir(audioFolder).exists()) {
|
||||
audioFolder = path;
|
||||
}
|
||||
// } else if (line.startsWith(constPodcastFolderKey+"=")) {
|
||||
// podcastFolder=line.section('=', 1, 1);
|
||||
} else if (line.startsWith(constMusicFilenameSchemeKey+"=")) {
|
||||
QString scheme = line.section('=', 1, 1);
|
||||
//protect against empty setting.
|
||||
@@ -163,47 +145,15 @@ void UmsDevice::setup()
|
||||
opts.ignoreThe = QLatin1String("true")==line.section('=', 1, 1);
|
||||
} else if (line.startsWith(constReplaceSpacesKey+"=")) {
|
||||
opts.replaceSpaces = QLatin1String("true")==line.section('=', 1, 1);
|
||||
// } else if (line.startsWith(constUseAutomaticallyKey+"=")) {
|
||||
// useAutomatically = QLatin1String("true")==line.section('=', 1, 1);
|
||||
// } else if (line.startsWith(constCoverFileNameKey+"=")) {
|
||||
// coverOpts.name=line.section('=', 1, 1);
|
||||
// configured=true;
|
||||
// } else if(line.startsWith(constVariousArtistsFixKey+"=")) {
|
||||
// opts.fixVariousArtists=QLatin1String("true")==line.section('=', 1, 1);
|
||||
// configured=true;
|
||||
} else {
|
||||
unusedParams+=line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QFile extra(path+constCantataSettingsFile);
|
||||
|
||||
if (extra.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
||||
configured=true;
|
||||
QTextStream in(&extra);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
if (line.startsWith(constCoverFileNameKey+"=")) {
|
||||
opts.coverName=line.section('=', 1, 1);
|
||||
} if (line.startsWith(constCoverMaxSizeKey+"=")) {
|
||||
opts.coverMaxSize=line.section('=', 1, 1).toUInt();
|
||||
opts.checkCoverSize();
|
||||
} else if(line.startsWith(constVariousArtistsFixKey+"=")) {
|
||||
opts.fixVariousArtists=QLatin1String("true")==line.section('=', 1, 1);
|
||||
} else if (line.startsWith(constTranscoderKey+"=")) {
|
||||
QStringList parts=line.section('=', 1, 1).split(',');
|
||||
if (3==parts.size()) {
|
||||
opts.transcoderCodec=parts.at(0);
|
||||
opts.transcoderValue=parts.at(1).toInt();
|
||||
opts.transcoderWhenDifferent=QLatin1String("true")==parts.at(2);
|
||||
}
|
||||
} else if(line.startsWith(constUseCacheKey+"=")) {
|
||||
opts.useCache=QLatin1String("true")==line.section('=', 1, 1);
|
||||
} else if(line.startsWith(constAutoScanKey+"=")) {
|
||||
opts.autoScan=QLatin1String("true")==line.section('=', 1, 1);
|
||||
}
|
||||
}
|
||||
bool haveOpts=FsDevice::readOpts(path+constCantataSettingsFile, opts, false);
|
||||
if (!configured) {
|
||||
configured=haveOpts;
|
||||
}
|
||||
|
||||
if (opts.coverName.isEmpty()) {
|
||||
@@ -281,9 +231,6 @@ void UmsDevice::saveOptions()
|
||||
if (!fixedPath.isEmpty()) {
|
||||
out << constMusicFolderKey << '=' << fixedPath << '\n';
|
||||
}
|
||||
// if (!podcastFolder.isEmpty()) {
|
||||
// out << constPodcastFolderKey << '=' << podcastFolder << '\n';
|
||||
// }
|
||||
if (opts.scheme!=def.scheme) {
|
||||
out << constMusicFilenameSchemeKey << '=' << opts.scheme << '\n';
|
||||
}
|
||||
@@ -299,17 +246,10 @@ void UmsDevice::saveOptions()
|
||||
if (opts.replaceSpaces!=def.replaceSpaces) {
|
||||
out << constReplaceSpacesKey << '=' << toString(opts.replaceSpaces) << '\n';
|
||||
}
|
||||
// if (useAutomatically) {
|
||||
// out << constUseAutomaticallyKey << '=' << toString(useAutomatically) << '\n';
|
||||
// }
|
||||
|
||||
foreach (const QString &u, unusedParams) {
|
||||
out << u << '\n';
|
||||
}
|
||||
// if (coverOpts.name!=constDefCoverFileName) {
|
||||
// out << constCoverFileNameKey << '=' << coverOpts.name << '\n';
|
||||
// }
|
||||
// out << constVariousArtistsFixKey << '=' << toString(opts.fixVariousArtists) << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,33 +275,10 @@ void UmsDevice::saveProperties(const QString &newPath, const DeviceOptions &newO
|
||||
return;
|
||||
}
|
||||
|
||||
QString path=spaceInfo.path();
|
||||
QFile extra(path+constCantataSettingsFile);
|
||||
|
||||
audioFolder=nPath;
|
||||
saveOptions();
|
||||
|
||||
if (extra.open(QIODevice::WriteOnly|QIODevice::Text)) {
|
||||
QTextStream out(&extra);
|
||||
if (opts.coverName!=constDefCoverFileName) {
|
||||
out << constCoverFileNameKey << '=' << opts.coverName << '\n';
|
||||
}
|
||||
if (0!=opts.coverMaxSize) {
|
||||
out << constCoverMaxSizeKey << '=' << opts.coverMaxSize << '\n';
|
||||
}
|
||||
if (opts.fixVariousArtists) {
|
||||
out << constVariousArtistsFixKey << '=' << toString(opts.fixVariousArtists) << '\n';
|
||||
}
|
||||
if (!opts.transcoderCodec.isEmpty()) {
|
||||
out << constTranscoderKey << '=' << opts.transcoderCodec << ',' << opts.transcoderValue << ',' << toString(opts.transcoderWhenDifferent) << '\n';
|
||||
}
|
||||
if (opts.useCache) {
|
||||
out << constUseCacheKey << '=' << toString(opts.useCache) << '\n';
|
||||
}
|
||||
if (opts.autoScan) {
|
||||
out << constAutoScanKey << '=' << toString(opts.autoScan) << '\n';
|
||||
}
|
||||
}
|
||||
FsDevice::writeOpts(spaceInfo.path()+constCantataSettingsFile, opts, false);
|
||||
|
||||
if (oldPath!=audioFolder) {
|
||||
rescan();
|
||||
|
||||
@@ -258,6 +258,14 @@ static QLatin1String constTopTag("CantataLibrary");
|
||||
|
||||
void MusicLibraryItemRoot::toXML(const QString &filename, const QDateTime &date) const
|
||||
{
|
||||
// If saving device cache, and we have NO items, then remove cache file...
|
||||
if (0==childCount() && date==QDateTime()) {
|
||||
if (QFile::exists(filename)) {
|
||||
QFile::remove(filename);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user