1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Move privacy tab settings to per-profile settings file

This may lose the current settings in the tab, but currently only keep history is enabled anyways
This commit is contained in:
Dubslow 2014-12-05 21:13:04 -06:00
parent db2d9321e4
commit e90dfd3083
2 changed files with 56 additions and 56 deletions

View File

@ -188,13 +188,6 @@ void Settings::load()
splitterState = s.value("splitterState", QByteArray()).toByteArray();
s.endGroup();
s.beginGroup("Privacy");
typingNotification = s.value("typingNotification", false).toBool();
enableLogging = s.value("enableLogging", false).toBool();
encryptLogs = s.value("encryptLogs", false).toBool();
encryptTox = s.value("encryptTox", false).toBool();
s.endGroup();
s.beginGroup("Audio");
inDev = s.value("inDev", "").toString();
outDev = s.value("outDev", "").toString();
@ -222,38 +215,45 @@ void Settings::load()
loaded = true;
if (currentProfile.isEmpty()) // new profile in Core::switchConfiguration
return;
if (!currentProfile.isEmpty()) // new profile in Core::switchConfiguration
{
// load from a profile specific friend data list if possible
QString tmp = dir.filePath(currentProfile + ".ini");
if (QFile(tmp).exists()) // otherwise, filePath remains the global file
filePath = tmp;
// load from a profile specific friend data list if possible
QString tmp = dir.filePath(currentProfile + ".ini");
if (QFile(tmp).exists())
filePath = tmp;
QSettings ps(filePath, QSettings::IniFormat);
friendLst.clear();
ps.beginGroup("Friends");
int size = ps.beginReadArray("Friend");
for (int i = 0; i < size; i ++)
{
ps.setArrayIndex(i);
friendProp fp;
fp.addr = ps.value("addr").toString();
fp.alias = ps.value("alias").toString();
fp.autoAcceptDir = ps.value("autoAcceptDir").toString();
friendLst[ToxID::fromString(fp.addr).publicKey] = fp;
}
ps.endArray();
ps.endGroup();
QSettings fs(filePath, QSettings::IniFormat);
friendLst.clear();
fs.beginGroup("Friends");
int size = fs.beginReadArray("Friend");
for (int i = 0; i < size; i ++)
{
fs.setArrayIndex(i);
friendProp fp;
fp.addr = fs.value("addr").toString();
fp.alias = fs.value("alias").toString();
fp.autoAcceptDir = fs.value("autoAcceptDir").toString();
friendLst[ToxID::fromString(fp.addr).publicKey] = fp;
}
fs.endArray();
fs.endGroup();
ps.beginGroup("Privacy");
typingNotification = ps.value("typingNotification", false).toBool();
enableLogging = ps.value("enableLogging", false).toBool();
encryptLogs = ps.value("encryptLogs", false).toBool();
encryptTox = ps.value("encryptTox", false).toBool();
ps.endGroup();
}
}
void Settings::save(bool writeFriends)
void Settings::save(bool writePersonal)
{
QString filePath = QDir(getSettingsDirPath()).filePath(FILENAME);
save(filePath, writeFriends);
save(filePath, writePersonal);
}
void Settings::save(QString path, bool writeFriends)
void Settings::save(QString path, bool writePersonal)
{
qDebug() << "Settings: Saving in "<<path;
@ -330,35 +330,35 @@ void Settings::save(QString path, bool writeFriends)
s.setValue("splitterState", splitterState);
s.endGroup();
s.beginGroup("Privacy");
s.setValue("typingNotification", typingNotification);
s.setValue("enableLogging", enableLogging);
s.setValue("encryptLogs", encryptLogs);
s.setValue("encryptTox", encryptTox);
s.endGroup();
s.beginGroup("Audio");
s.setValue("inDev", inDev);
s.setValue("outDev", outDev);
s.endGroup();
if (!writeFriends || currentProfile.isEmpty()) // Core::switchConfiguration
return;
if (writePersonal && !currentProfile.isEmpty()) // Core::switchConfiguration
{
QSettings ps(QFileInfo(path).dir().filePath(currentProfile + ".ini"), QSettings::IniFormat);
ps.beginGroup("Friends");
ps.beginWriteArray("Friend", friendLst.size());
int index = 0;
for (auto& frnd : friendLst)
{
ps.setArrayIndex(index);
ps.setValue("addr", frnd.addr);
ps.setValue("alias", frnd.alias);
ps.setValue("autoAcceptDir", frnd.autoAcceptDir);
index++;
}
ps.endArray();
ps.endGroup();
QSettings fs(QFileInfo(path).dir().filePath(currentProfile + ".ini"), QSettings::IniFormat);
fs.beginGroup("Friends");
fs.beginWriteArray("Friend", friendLst.size());
int index = 0;
for (auto& frnd : friendLst)
{
fs.setArrayIndex(index);
fs.setValue("addr", frnd.addr);
fs.setValue("alias", frnd.alias);
fs.setValue("autoAcceptDir", frnd.autoAcceptDir);
index++;
}
fs.endArray();
fs.endGroup();
ps.beginGroup("Privacy");
ps.setValue("typingNotification", typingNotification);
ps.setValue("enableLogging", enableLogging);
ps.setValue("encryptLogs", encryptLogs);
ps.setValue("encryptTox", encryptTox);
ps.endGroup();
}
}
QString Settings::getSettingsDirPath()

View File

@ -219,8 +219,8 @@ public:
void setFauxOfflineMessaging(bool value);
public:
void save(bool writeFriends = true);
void save(QString path, bool writeFriends = true);
void save(bool writePersonal = true);
void save(QString path, bool writePersonal = true);
void load();
private: