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 // load from a profile specific friend data list if possible
QString tmp = dir.filePath(currentProfile + ".ini"); QString tmp = dir.filePath(currentProfile + ".ini");
if (QFile(tmp).exists()) if (QFile(tmp).exists()) // otherwise, filePath remains the global file
filePath = tmp; filePath = tmp;
QSettings fs(filePath, QSettings::IniFormat); QSettings ps(filePath, QSettings::IniFormat);
friendLst.clear(); friendLst.clear();
fs.beginGroup("Friends"); ps.beginGroup("Friends");
int size = fs.beginReadArray("Friend"); int size = ps.beginReadArray("Friend");
for (int i = 0; i < size; i ++) for (int i = 0; i < size; i ++)
{ {
fs.setArrayIndex(i); ps.setArrayIndex(i);
friendProp fp; friendProp fp;
fp.addr = fs.value("addr").toString(); fp.addr = ps.value("addr").toString();
fp.alias = fs.value("alias").toString(); fp.alias = ps.value("alias").toString();
fp.autoAcceptDir = fs.value("autoAcceptDir").toString(); fp.autoAcceptDir = ps.value("autoAcceptDir").toString();
friendLst[ToxID::fromString(fp.addr).publicKey] = fp; friendLst[ToxID::fromString(fp.addr).publicKey] = fp;
} }
fs.endArray(); ps.endArray();
fs.endGroup(); ps.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); 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);
QSettings fs(QFileInfo(path).dir().filePath(currentProfile + ".ini"), QSettings::IniFormat); ps.beginGroup("Friends");
fs.beginGroup("Friends"); ps.beginWriteArray("Friend", friendLst.size());
fs.beginWriteArray("Friend", friendLst.size());
int index = 0; int index = 0;
for (auto& frnd : friendLst) for (auto& frnd : friendLst)
{ {
fs.setArrayIndex(index); ps.setArrayIndex(index);
fs.setValue("addr", frnd.addr); ps.setValue("addr", frnd.addr);
fs.setValue("alias", frnd.alias); ps.setValue("alias", frnd.alias);
fs.setValue("autoAcceptDir", frnd.autoAcceptDir); ps.setValue("autoAcceptDir", frnd.autoAcceptDir);
index++; index++;
} }
fs.endArray(); ps.endArray();
fs.endGroup(); ps.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() 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: