54 QVariantHash read()
const;
55 bool write(
const QVariantHash &data)
const;
62 QString deserialize(
const QString &name, QVariantHash &data)
const;
63 QString
serialize(
const QString &name,
const QVariantHash &data)
const;
72 : m_data {TransactionalSettings(QLatin1String(
"qBittorrent")).read()}
103 const QWriteLocker locker(&
m_lock);
106 const TransactionalSettings
settings(QLatin1String(
"qBittorrent"));
119 const QReadLocker locker(&
m_lock);
120 return m_data.value(key, defaultValue);
125 const QWriteLocker locker(&
m_lock);
126 QVariant ¤tValue =
m_data[key];
127 if (currentValue !=
value)
130 currentValue =
value;
137 const QWriteLocker locker(&
m_lock);
138 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
141 if (
m_data.remove(key) > 0)
151 const QReadLocker locker {&
m_lock};
152 return m_data.contains(key);
155 QVariantHash TransactionalSettings::read()
const
159 const QString newPath = deserialize(m_name + QLatin1String(
"_new"), res);
160 if (!newPath.isEmpty())
170 QString finalPath = newPath;
171 int index = finalPath.lastIndexOf(
"_new", -1, Qt::CaseInsensitive);
172 finalPath.remove(index, 4);
175 QFile::rename(newPath, finalPath);
179 deserialize(m_name, res);
185 bool TransactionalSettings::write(
const QVariantHash &data)
const
192 const QString newPath =
serialize(m_name + QLatin1String(
"_new"), data);
193 if (newPath.isEmpty())
199 QString finalPath = newPath;
200 int index = finalPath.lastIndexOf(
"_new", -1, Qt::CaseInsensitive);
201 finalPath.remove(index, 4);
204 return QFile::rename(newPath, finalPath);
207 QString TransactionalSettings::deserialize(
const QString &name, QVariantHash &data)
const
230 for (
auto i = data.begin(); i != data.end(); ++i)
231 settings->setValue(i.key(), i.value());
237 case QSettings::NoError:
239 case QSettings::AccessError:
242 case QSettings::FormatError:
void addMessage(const QString &message, const Log::MsgType &type=Log::NORMAL)
static Logger * instance()
SettingsPtr applicationSettings(const QString &name) const
static const Profile * instance()
static SettingsStorage * instance()
void storeValueImpl(const QString &key, const QVariant &value)
void removeValue(const QString &key)
static SettingsStorage * m_instance
static void freeInstance()
static void initInstance()
bool hasKey(const QString &key) const
QVariant loadValueImpl(const QString &key, const QVariant &defaultValue={}) const
TransactionalSettings(const QString &name)
constexpr std::add_const_t< T > & asConst(T &t) noexcept
bool forceRemove(const QString &filePath)
QString toNativePath(const QString &path)
SettingsStorage * settings()
T value(const QString &key, const T &defaultValue={})
std::unique_ptr< QSettings > SettingsPtr
QVariantMap serialize(const BitTorrent::Torrent &torrent)