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(); splitterState = s.value("splitterState", QByteArray()).toByteArray();
s.endGroup(); 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"); s.beginGroup("Audio");
inDev = s.value("inDev", "").toString(); inDev = s.value("inDev", "").toString();
outDev = s.value("outDev", "").toString(); outDev = s.value("outDev", "").toString();
@ -222,38 +215,45 @@ void Settings::load()
loaded = true; loaded = true;
if (currentProfile.isEmpty()) // new profile in Core::switchConfiguration if (!currentProfile.isEmpty()) // new profile in Core::switchConfiguration
return; {
// 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 QSettings ps(filePath, QSettings::IniFormat);
QString tmp = dir.filePath(currentProfile + ".ini"); friendLst.clear();
if (QFile(tmp).exists()) ps.beginGroup("Friends");
filePath = tmp; 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); ps.beginGroup("Privacy");
friendLst.clear(); typingNotification = ps.value("typingNotification", false).toBool();
fs.beginGroup("Friends"); enableLogging = ps.value("enableLogging", false).toBool();
int size = fs.beginReadArray("Friend"); encryptLogs = ps.value("encryptLogs", false).toBool();
for (int i = 0; i < size; i ++) encryptTox = ps.value("encryptTox", false).toBool();
{ ps.endGroup();
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();
} }
void Settings::save(bool writeFriends) void Settings::save(bool writePersonal)
{ {
QString filePath = QDir(getSettingsDirPath()).filePath(FILENAME); 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; qDebug() << "Settings: Saving in "<<path;
@ -330,35 +330,35 @@ void Settings::save(QString path, bool writeFriends)
s.setValue("splitterState", splitterState); s.setValue("splitterState", splitterState);
s.endGroup(); 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.beginGroup("Audio");
s.setValue("inDev", inDev); s.setValue("inDev", inDev);
s.setValue("outDev", outDev); s.setValue("outDev", outDev);
s.endGroup(); s.endGroup();
if (!writeFriends || currentProfile.isEmpty()) // Core::switchConfiguration if (writePersonal && !currentProfile.isEmpty()) // Core::switchConfiguration
return; {
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); ps.beginGroup("Privacy");
fs.beginGroup("Friends"); ps.setValue("typingNotification", typingNotification);
fs.beginWriteArray("Friend", friendLst.size()); ps.setValue("enableLogging", enableLogging);
int index = 0; ps.setValue("encryptLogs", encryptLogs);
for (auto& frnd : friendLst) ps.setValue("encryptTox", encryptTox);
{ ps.endGroup();
fs.setArrayIndex(index); }
fs.setValue("addr", frnd.addr);
fs.setValue("alias", frnd.alias);
fs.setValue("autoAcceptDir", frnd.autoAcceptDir);
index++;
}
fs.endArray();
fs.endGroup();
} }
QString Settings::getSettingsDirPath() QString Settings::getSettingsDirPath()

View File

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