|
|
|
@ -38,6 +38,7 @@
@@ -38,6 +38,7 @@
|
|
|
|
|
|
|
|
|
|
const QString Settings::OLDFILENAME = "settings.ini"; |
|
|
|
|
const QString Settings::FILENAME = "qtox.ini"; |
|
|
|
|
Settings* Settings::settings{nullptr}; |
|
|
|
|
bool Settings::makeToxPortable{false}; |
|
|
|
|
|
|
|
|
|
Settings::Settings() : |
|
|
|
@ -48,12 +49,20 @@ Settings::Settings() :
@@ -48,12 +49,20 @@ Settings::Settings() :
|
|
|
|
|
|
|
|
|
|
Settings& Settings::getInstance() |
|
|
|
|
{ |
|
|
|
|
static Settings* settings{nullptr}; |
|
|
|
|
if (!settings) |
|
|
|
|
settings = new Settings(); |
|
|
|
|
return *settings; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Settings::resetInstance() |
|
|
|
|
{ |
|
|
|
|
if (settings) |
|
|
|
|
{ |
|
|
|
|
delete settings; |
|
|
|
|
settings = nullptr; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Settings::load() |
|
|
|
|
{ |
|
|
|
|
if (loaded) |
|
|
|
@ -113,21 +122,6 @@ void Settings::load()
@@ -113,21 +122,6 @@ void Settings::load()
|
|
|
|
|
useCustomDhtList=false; |
|
|
|
|
s.endGroup(); |
|
|
|
|
|
|
|
|
|
friendLst.clear(); |
|
|
|
|
s.beginGroup("Friends"); |
|
|
|
|
int size = s.beginReadArray("Friend"); |
|
|
|
|
for (int i = 0; i < size; i ++) |
|
|
|
|
{ |
|
|
|
|
s.setArrayIndex(i); |
|
|
|
|
friendProp fp; |
|
|
|
|
fp.addr = s.value("addr").toString(); |
|
|
|
|
fp.alias = s.value("alias").toString(); |
|
|
|
|
fp.autoAcceptDir = s.value("autoAcceptDir").toString(); |
|
|
|
|
friendLst[ToxID::fromString(fp.addr).publicKey] = fp; |
|
|
|
|
} |
|
|
|
|
s.endArray(); |
|
|
|
|
s.endGroup(); |
|
|
|
|
|
|
|
|
|
s.beginGroup("General"); |
|
|
|
|
enableIPv6 = s.value("enableIPv6", true).toBool(); |
|
|
|
|
translation = s.value("translation", "en").toString(); |
|
|
|
@ -227,15 +221,39 @@ void Settings::load()
@@ -227,15 +221,39 @@ void Settings::load()
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
loaded = true; |
|
|
|
|
|
|
|
|
|
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()) |
|
|
|
|
filePath = tmp; |
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Settings::save() |
|
|
|
|
void Settings::save(bool writeFriends) |
|
|
|
|
{ |
|
|
|
|
QString filePath = QDir(getSettingsDirPath()).filePath(FILENAME); |
|
|
|
|
save(filePath); |
|
|
|
|
save(filePath, writeFriends); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Settings::save(QString path) |
|
|
|
|
void Settings::save(QString path, bool writeFriends) |
|
|
|
|
{ |
|
|
|
|
qDebug() << "Settings: Saving in "<<path; |
|
|
|
|
|
|
|
|
@ -256,20 +274,6 @@ void Settings::save(QString path)
@@ -256,20 +274,6 @@ void Settings::save(QString path)
|
|
|
|
|
s.endArray(); |
|
|
|
|
s.endGroup(); |
|
|
|
|
|
|
|
|
|
s.beginGroup("Friends"); |
|
|
|
|
s.beginWriteArray("Friend", friendLst.size()); |
|
|
|
|
int index = 0; |
|
|
|
|
for (auto &frnd : friendLst) |
|
|
|
|
{ |
|
|
|
|
s.setArrayIndex(index); |
|
|
|
|
s.setValue("addr", frnd.addr); |
|
|
|
|
s.setValue("alias", frnd.alias); |
|
|
|
|
s.setValue("autoAcceptDir", frnd.autoAcceptDir); |
|
|
|
|
index++; |
|
|
|
|
} |
|
|
|
|
s.endArray(); |
|
|
|
|
s.endGroup(); |
|
|
|
|
|
|
|
|
|
s.beginGroup("General"); |
|
|
|
|
s.setValue("enableIPv6", enableIPv6); |
|
|
|
|
s.setValue("translation",translation); |
|
|
|
@ -337,6 +341,24 @@ void Settings::save(QString path)
@@ -337,6 +341,24 @@ void Settings::save(QString path)
|
|
|
|
|
s.setValue("inDev", inDev); |
|
|
|
|
s.setValue("outDev", outDev); |
|
|
|
|
s.endGroup(); |
|
|
|
|
|
|
|
|
|
if (!writeFriends || currentProfile.isEmpty()) // Core::switchConfiguration
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString Settings::getSettingsDirPath() |
|
|
|
|