|
|
@ -51,16 +51,16 @@ namespace |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QVariantHash read(); |
|
|
|
QVariantHash read() const; |
|
|
|
bool write(const QVariantHash &data); |
|
|
|
bool write(const QVariantHash &data) const; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
// we return actual file names used by QSettings because
|
|
|
|
// we return actual file names used by QSettings because
|
|
|
|
// there is no other way to get that name except
|
|
|
|
// there is no other way to get that name except
|
|
|
|
// actually create a QSettings object.
|
|
|
|
// actually create a QSettings object.
|
|
|
|
// if serialization operation was not successful we return empty string
|
|
|
|
// if serialization operation was not successful we return empty string
|
|
|
|
QString deserialize(const QString &name, QVariantHash &data); |
|
|
|
QString deserialize(const QString &name, QVariantHash &data) const; |
|
|
|
QString serialize(const QString &name, const QVariantHash &data); |
|
|
|
QString serialize(const QString &name, const QVariantHash &data) const; |
|
|
|
|
|
|
|
|
|
|
|
const QString m_name; |
|
|
|
const QString m_name; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -187,10 +187,10 @@ SettingsStorage *SettingsStorage::instance() |
|
|
|
bool SettingsStorage::save() |
|
|
|
bool SettingsStorage::save() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_dirty) return false; // Obtaining the lock is expensive, let's check early
|
|
|
|
if (!m_dirty) return false; // Obtaining the lock is expensive, let's check early
|
|
|
|
QWriteLocker locker(&m_lock); |
|
|
|
const QWriteLocker locker(&m_lock); |
|
|
|
if (!m_dirty) return false; // something might have changed while we were getting the lock
|
|
|
|
if (!m_dirty) return false; // something might have changed while we were getting the lock
|
|
|
|
|
|
|
|
|
|
|
|
TransactionalSettings settings(QLatin1String("qBittorrent")); |
|
|
|
const TransactionalSettings settings(QLatin1String("qBittorrent")); |
|
|
|
if (settings.write(m_data)) { |
|
|
|
if (settings.write(m_data)) { |
|
|
|
m_dirty = false; |
|
|
|
m_dirty = false; |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -229,7 +229,7 @@ void SettingsStorage::removeValue(const QString &key) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QVariantHash TransactionalSettings::read() |
|
|
|
QVariantHash TransactionalSettings::read() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
QVariantHash res; |
|
|
|
QVariantHash res; |
|
|
|
|
|
|
|
|
|
|
@ -257,7 +257,7 @@ QVariantHash TransactionalSettings::read() |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool TransactionalSettings::write(const QVariantHash &data) |
|
|
|
bool TransactionalSettings::write(const QVariantHash &data) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
// QSettings deletes the file before writing it out. This can result in problems
|
|
|
|
// QSettings deletes the file before writing it out. This can result in problems
|
|
|
|
// if the disk is full or a power outage occurs. Those events might occur
|
|
|
|
// if the disk is full or a power outage occurs. Those events might occur
|
|
|
@ -278,7 +278,7 @@ bool TransactionalSettings::write(const QVariantHash &data) |
|
|
|
return QFile::rename(newPath, finalPath); |
|
|
|
return QFile::rename(newPath, finalPath); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString TransactionalSettings::deserialize(const QString &name, QVariantHash &data) |
|
|
|
QString TransactionalSettings::deserialize(const QString &name, QVariantHash &data) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
SettingsPtr settings = Profile::instance().applicationSettings(name); |
|
|
|
SettingsPtr settings = Profile::instance().applicationSettings(name); |
|
|
|
|
|
|
|
|
|
|
@ -294,7 +294,7 @@ QString TransactionalSettings::deserialize(const QString &name, QVariantHash &da |
|
|
|
return settings->fileName(); |
|
|
|
return settings->fileName(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString TransactionalSettings::serialize(const QString &name, const QVariantHash &data) |
|
|
|
QString TransactionalSettings::serialize(const QString &name, const QVariantHash &data) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
SettingsPtr settings = Profile::instance().applicationSettings(name); |
|
|
|
SettingsPtr settings = Profile::instance().applicationSettings(name); |
|
|
|
for (auto i = data.begin(); i != data.end(); ++i) |
|
|
|
for (auto i = data.begin(); i != data.end(); ++i) |
|
|
|