Browse Source

Polish previous commit.

adaptive-webui-19844
sledgehammer999 8 years ago
parent
commit
d88ec48468
  1. 2
      src/app/main.cpp
  2. 33
      src/app/upgrade.h
  3. 15
      src/base/settingsstorage.cpp

2
src/app/main.cpp

@ -138,7 +138,7 @@ int main(int argc, char *argv[]) @@ -138,7 +138,7 @@ int main(int argc, char *argv[])
#ifdef Q_OS_MAC
// On macOS 10.12 Sierra, Apple changed the behaviour of CFPreferencesSetValue() https://bugreports.qt.io/browse/QTBUG-56344
// Due to this, we have to move from native plist to IniFormat
macSalvagePlists();
macMigratePlists();
#endif
// Create Application

33
src/app/upgrade.h

@ -230,25 +230,30 @@ bool upgrade(bool ask = true) @@ -230,25 +230,30 @@ bool upgrade(bool ask = true)
#ifdef Q_OS_MAC
bool copyPlistToIni(const char *application)
void migratePlistToIni(const QString &application)
{
QSettings iniFile(QSettings::IniFormat, QSettings::UserScope, "qBittorrent", application);
if (QFile::exists(iniFile.fileName())) return false; // We copy the contents of plist, only if inifile does not exist.
QSettings plistFile("qBittorrent", application);
if (!QFile::exists(plistFile.fileName())) return false;
plistFile.setFallbacksEnabled(false);
const QStringList plist = plistFile.allKeys();
foreach (const QString &key, plist) {
iniFile.setValue(key, plistFile.value(key));
QIniSettings iniFile("qBittorrent", application);
if (iniFile.allKeys().isEmpty()) return; // We copy the contents of plist, only if inifile does not exist(is empty).
QSettings *plistFile = new QSettings("qBittorrent", application);
plistFile->setFallbacksEnabled(false);
const QStringList plist = plistFile->allKeys();
if (!plist.isEmpty()) {
foreach (const QString &key, plist)
iniFile.setValue(key, plistFile->value(key));
plistFile->clear();
}
return true;
QString plistPath = plistFile->fileName();
delete plistFile;
Utils::Fs::forceRemove(plistPath);
}
void macSalvagePlists()
void macMigratePlists()
{
copyPlistToIni("qBittorrent-data");
copyPlistToIni("qBittorrent-rss");
copyPlistToIni("qBittorrent");
migratePlistToIni("qBittorrent-data");
migratePlistToIni("qBittorrent-rss");
migratePlistToIni("qBittorrent");
}
#endif // Q_OS_MAC

15
src/base/settingsstorage.cpp

@ -38,11 +38,6 @@ @@ -38,11 +38,6 @@
#include "logger.h"
#include "utils/fs.h"
#ifdef Q_OS_MAC
// now mac uses ini
//#define QSETTINGS_SYNC_IS_SAVE // whether QSettings::sync() is "atomic"
#endif
namespace
{
// Encapsulates serialization of settings in "atomic" way.
@ -267,9 +262,6 @@ void SettingsStorage::removeValue(const QString &key) @@ -267,9 +262,6 @@ void SettingsStorage::removeValue(const QString &key)
QVariantHash TransactionalSettings::read()
{
QVariantHash res;
#ifdef QSETTINGS_SYNC_IS_SAVE
deserialize(m_name, res);
#else
bool writeBackNeeded = false;
QString newPath = deserialize(m_name + QLatin1String("_new"), res);
if (!newPath.isEmpty()) { // "_new" file is NOT empty
@ -288,15 +280,12 @@ QVariantHash TransactionalSettings::read() @@ -288,15 +280,12 @@ QVariantHash TransactionalSettings::read()
if (writeBackNeeded)
write(res);
#endif
return res;
}
bool TransactionalSettings::write(const QVariantHash &data)
{
#ifdef QSETTINGS_SYNC_IS_SAVE
serialize(m_name, data);
#else
// QSettings delete 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
// between deleting the file and recreating it. This is a safety measure.
@ -313,7 +302,7 @@ bool TransactionalSettings::write(const QVariantHash &data) @@ -313,7 +302,7 @@ bool TransactionalSettings::write(const QVariantHash &data)
finalPath.remove(index, 4);
Utils::Fs::forceRemove(finalPath);
QFile::rename(newPath, finalPath);
#endif
return true;
}

Loading…
Cancel
Save