void Settings::setMakeToxPortable(bool newValue) { QMutexLocker locker{&bigLock}; QFile(getSettingsDirPath()+globalSettingsFile).remove(); makeToxPortable = newValue; saveGlobal(); }
void Settings::saveAvatar(QPixmap& pic, const QString& ownerId) { QDir dir(getSettingsDirPath()); dir.mkdir("avatars/"); // ignore nospam (good idea, and also the addFriend funcs which call getAvatar don't have it) QString filePath = dir.filePath("avatars/"+ownerId.left(64)+".png"); pic.save(filePath, "png"); }
void Settings::savePersonal(QString profileName, QString password) { if (QThread::currentThread() != settingsThread) return (void) QMetaObject::invokeMethod(&getInstance(), "savePersonal", Q_ARG(QString, profileName), Q_ARG(QString, password)); QMutexLocker locker{&bigLock}; QString path = getSettingsDirPath() + profileName + ".ini"; qDebug() << "Saving personal settings at " << path; SettingsSerializer ps(path, password); 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("note", frnd.note); ps.setValue("autoAcceptDir", frnd.autoAcceptDir); ps.setValue("circle", frnd.circleID); if (getEnableLogging()) ps.setValue("activity", frnd.activity); index++; } ps.endArray(); ps.endGroup(); ps.beginGroup("General"); ps.setValue("compactLayout", compactLayout); ps.endGroup(); ps.beginGroup("Circles"); ps.beginWriteArray("Circle", circleLst.size()); index = 0; for (auto& circle : circleLst) { ps.setArrayIndex(index); ps.setValue("name", circle.name); ps.setValue("expanded", circle.expanded); index++; } ps.endArray(); ps.endGroup(); ps.beginGroup("Privacy"); ps.setValue("typingNotification", typingNotification); ps.setValue("enableLogging", enableLogging); ps.endGroup(); ps.save(); }
void Settings::save() { QString filePath = getSettingsDirPath() + '/' + FILENAME; QSettings s(filePath, QSettings::IniFormat); s.clear(); s.beginGroup("DHT Server"); s.beginWriteArray("dhtServerList", dhtServerList.size()); for (int i = 0; i < dhtServerList.size(); i ++) { s.setArrayIndex(i); s.setValue("name", dhtServerList[i].name); s.setValue("userId", dhtServerList[i].userId); s.setValue("address", dhtServerList[i].address); s.setValue("port", dhtServerList[i].port); } s.endArray(); s.endGroup(); //NOTE: uncomment when logging will be implemented /* s.beginGroup("Logging"); s.setValue("storeLogs", enableLogging); s.setValue("encryptLogs", encryptLogs); s.endGroup(); */ s.beginGroup("General"); s.setValue("username", username); s.setValue("statusMessage", statusMessage); s.setValue("enableIPv6", enableIPv6); s.endGroup(); s.beginGroup("Widgets"); const QList<QString> widgetNames = widgetSettings.keys(); for (const QString& name : widgetNames) { s.setValue(name, widgetSettings.value(name)); } s.endGroup(); s.beginGroup("GUI"); s.setValue("smoothAnimation", enableSmoothAnimation); s.setValue("smileyPack", smileyPack); s.setValue("customEmojiFont", customEmojiFont); s.setValue("emojiFontFamily", emojiFontFamily); s.setValue("emojiFontPointSize", emojiFontPointSize); s.setValue("firstColumnHandlePos", firstColumnHandlePos); s.setValue("secondColumnHandlePosFromRight", secondColumnHandlePosFromRight); s.setValue("timestampFormat", timestampFormat); s.setValue("minimizeOnClose", minimizeOnClose); s.endGroup(); s.beginGroup("Privacy"); s.setValue("typingNotification", typingNotification); s.endGroup(); }
void Settings::saveAvatarHash(const QByteArray& hash, const QString& ownerId) { QDir dir(getSettingsDirPath()); dir.mkdir("avatars/"); QFile file(dir.filePath("avatars/"+ownerId.left(64)+".hash")); if (!file.open(QIODevice::WriteOnly)) return; file.write(hash); file.close(); }
QByteArray Settings::getAvatarHash(const QString& ownerId) { QDir dir(getSettingsDirPath()); dir.mkdir("avatars/"); QFile file(dir.filePath("avatars/"+ownerId.left(64)+".hash")); if (!file.open(QIODevice::ReadOnly)) return QByteArray(); QByteArray out = file.readAll(); file.close(); return out; }
void Settings::createPersonal(QString basename) { QString path = getSettingsDirPath() + QDir::separator() + basename + ".ini"; qDebug() << "Creating new profile settings in " << path; QSettings ps(path, QSettings::IniFormat); ps.setIniCodec("UTF-8"); ps.beginGroup("Friends"); ps.beginWriteArray("Friend", 0); ps.endArray(); ps.endGroup(); ps.beginGroup("Privacy"); ps.endGroup(); }
QPixmap Settings::getSavedAvatar(const QString &ownerId) { QDir dir(getSettingsDirPath()); QString filePath = dir.filePath("avatars/"+ownerId.left(64)+".png"); QFileInfo info(filePath); QPixmap pic; if (!info.exists()) { QString filePath = dir.filePath("avatar_"+ownerId.left(64)); if (!QFileInfo(filePath).exists()) // try without truncation, for old self avatars filePath = dir.filePath("avatar_"+ownerId); pic.load(filePath); saveAvatar(pic, ownerId); QFile::remove(filePath); } else pic.load(filePath); return pic; }
void Settings::load() { if (loaded) { return; } QFile portableSettings(FILENAME); if (portableSettings.exists()) makeToxPortable=true; QString filePath = getSettingsDirPath() + '/' + FILENAME; //if no settings file exist -- use the default one QFile file(filePath); if (!file.exists()) { qDebug() << "No settings file found, using defaults"; filePath = ":/conf/" + FILENAME; } QSettings s(filePath, QSettings::IniFormat); s.beginGroup("DHT Server"); int serverListSize = s.beginReadArray("dhtServerList"); for (int i = 0; i < serverListSize; i ++) { s.setArrayIndex(i); DhtServer server; server.name = s.value("name").toString(); server.userId = s.value("userId").toString(); server.address = s.value("address").toString(); server.port = s.value("port").toInt(); dhtServerList << server; } s.endArray(); s.endGroup(); s.beginGroup("General"); enableIPv6 = s.value("enableIPv6", true).toBool(); useTranslations = s.value("useTranslations", true).toBool(); makeToxPortable = s.value("makeToxPortable", false).toBool(); s.endGroup(); s.beginGroup("Widgets"); QList<QString> objectNames = s.childKeys(); for (const QString& name : objectNames) { widgetSettings[name] = s.value(name).toByteArray(); } s.endGroup(); s.beginGroup("GUI"); enableSmoothAnimation = s.value("smoothAnimation", true).toBool(); smileyPack = s.value("smileyPack", QString()).toString(); customEmojiFont = s.value("customEmojiFont", true).toBool(); emojiFontFamily = s.value("emojiFontFamily", "DejaVu Sans").toString(); emojiFontPointSize = s.value("emojiFontPointSize", QApplication::font().pointSize()).toInt(); firstColumnHandlePos = s.value("firstColumnHandlePos", 50).toInt(); secondColumnHandlePosFromRight = s.value("secondColumnHandlePosFromRight", 50).toInt(); timestampFormat = s.value("timestampFormat", "hh:mm").toString(); minimizeOnClose = s.value("minimizeOnClose", false).toBool(); useNativeStyle = s.value("nativeStyle", false).toBool(); useNativeDecoration = s.value("nativeDecoration", true).toBool(); s.endGroup(); s.beginGroup("State"); windowGeometry = s.value("windowGeometry", QByteArray()).toByteArray(); windowState = s.value("windowState", QByteArray()).toByteArray(); splitterState = s.value("splitterState", QByteArray()).toByteArray(); s.endGroup(); s.beginGroup("Privacy"); typingNotification = s.value("typingNotification", false).toBool(); s.endGroup(); // try to set a smiley pack if none is selected if (!SmileyPack::isValid(smileyPack) && !SmileyPack::listSmileyPacks().isEmpty()) smileyPack = SmileyPack::listSmileyPacks()[0].second; loaded = true; }
void Settings::save(bool writeFriends) { QString filePath = QDir(getSettingsDirPath()).filePath(FILENAME); save(filePath, writeFriends); }
void Widget::update() { /// 1. Find and parse the update (0-5%) // Check that the dir exists QString updateDirStr = getSettingsDirPath()+"/update/"; QDir updateDir(updateDirStr); if (!updateDir.exists()) fatalError(tr("No update found.")); // Check that we have a flist and that every file on the diff exists QFile updateFlistFile(updateDirStr+"flist"); if (!updateFlistFile.open(QIODevice::ReadOnly)) fatalError(tr("The update is incomplete.")); QByteArray updateFlistData = updateFlistFile.readAll(); updateFlistFile.close(); setProgress(1); QList<UpdateFileMeta> updateFlist = parseFlist(updateFlistData); setProgress(2); QList<UpdateFileMeta> diff = genUpdateDiff(updateFlist); setProgress(4); for (UpdateFileMeta fileMeta : diff) if (!QFile::exists(updateDirStr+fileMeta.installpath)) fatalError(tr("The update is incomplete.")); if (diff.size() == 0) fatalError(tr("The diff list is empty.")); setProgress(5); /// 2. Check the update (5-50%) float checkProgressStep = 45.0/(float)diff.size(); float checkProgress = 5; for (UpdateFileMeta fileMeta : diff) { UpdateFile file; file.metadata = fileMeta; QFile fileFile(updateDirStr+fileMeta.installpath); if (!fileFile.open(QIODevice::ReadOnly)) fatalError(tr("Update files are unreadable.")); file.data = fileFile.readAll(); fileFile.close(); if (file.data.size() != (int)fileMeta.size) fatalError(tr("Update files are corrupted.")); if (crypto_sign_verify_detached(file.metadata.sig, (unsigned char*)file.data.data(), file.data.size(), key) != 0) fatalError(tr("Update files are corrupted.")); checkProgress += checkProgressStep; setProgress(checkProgress); } setProgress(50); /// 3. Install the update (50-95%) float installProgressStep = 45.0/(float)diff.size(); float installProgress = 50; for (UpdateFileMeta fileMeta : diff) { // Backup old files if (QFile(fileMeta.installpath).exists()) { QFile(fileMeta.installpath+".bak").remove(); QFile(fileMeta.installpath).rename(fileMeta.installpath+".bak"); backups.append(fileMeta.installpath); } // Install new ones QDir().mkpath(QFileInfo(fileMeta.installpath).absolutePath()); QFile fileFile(updateDirStr+fileMeta.installpath); if (!fileFile.copy(fileMeta.installpath)) fatalError(tr("Unable to copy the update's files from ")+(updateDirStr+fileMeta.installpath)+" to "+fileMeta.installpath); installProgress += installProgressStep; setProgress(installProgress); } setProgress(95); /// 4. Delete the update and backups (95-100%) deleteUpdate(); setProgress(97); deleteBackups(); setProgress(100); /// 5. Start qTox and exit startQToxAndExit(); }
void Widget::deleteUpdate() { QDir updateDir(getSettingsDirPath()+"/update/"); updateDir.removeRecursively(); }
void Settings::load() { if (loaded) { return; } QString filePath = getSettingsDirPath() + '/' + FILENAME; //if no settings file exist -- use the default one QFile file(filePath); if (!file.exists()) { qDebug() << "No settings file found, using defaults"; filePath = ":/conf/" + FILENAME; } QSettings s(filePath, QSettings::IniFormat); s.beginGroup("DHT Server"); int serverListSize = s.beginReadArray("dhtServerList"); for (int i = 0; i < serverListSize; i ++) { s.setArrayIndex(i); DhtServer server; server.name = s.value("name").toString(); server.userId = s.value("userId").toString(); server.address = s.value("address").toString(); server.port = s.value("port").toInt(); dhtServerList << server; } s.endArray(); s.endGroup(); //NOTE: uncomment when logging will be implemented /* s.beginGroup("Logging"); enableLogging = s.value("enableLogging", false).toBool(); encryptLogs = s.value("encryptLogs", true).toBool(); s.endGroup(); */ s.beginGroup("General"); username = s.value("username", "My name").toString(); statusMessage = s.value("statusMessage", "My status").toString(); enableIPv6 = s.value("enableIPv6", true).toBool(); s.endGroup(); s.beginGroup("Widgets"); QList<QString> objectNames = s.childKeys(); for (const QString& name : objectNames) { widgetSettings[name] = s.value(name).toByteArray(); } s.endGroup(); s.beginGroup("GUI"); enableSmoothAnimation = s.value("smoothAnimation", true).toBool(); smileyPack = s.value("smileyPack").toByteArray(); customEmojiFont = s.value("customEmojiFont", true).toBool(); emojiFontFamily = s.value("emojiFontFamily", "DejaVu Sans").toString(); emojiFontPointSize = s.value("emojiFontPointSize", QApplication::font().pointSize()).toInt(); firstColumnHandlePos = s.value("firstColumnHandlePos", 50).toInt(); secondColumnHandlePosFromRight = s.value("secondColumnHandlePosFromRight", 50).toInt(); timestampFormat = s.value("timestampFormat", "hh:mm").toString(); minimizeOnClose = s.value("minimizeOnClose", false).toBool(); s.endGroup(); s.beginGroup("Privacy"); typingNotification = s.value("typingNotification", false).toBool(); s.endGroup(); loaded = true; }
void Settings::save() { QString filePath = QDir(getSettingsDirPath()).filePath(FILENAME); save(filePath); }
void Settings::save() { QString filePath = getSettingsDirPath() + '/' + FILENAME; save(filePath); }
void Settings::loadGlobal() { QMutexLocker locker{&bigLock}; if (loaded) return; createSettingsDir(); if (QFile(globalSettingsFile).exists()) { QSettings ps(globalSettingsFile, QSettings::IniFormat); ps.setIniCodec("UTF-8"); ps.beginGroup("General"); makeToxPortable = ps.value("makeToxPortable", false).toBool(); ps.endGroup(); } else { makeToxPortable = false; } QDir dir(getSettingsDirPath()); QString filePath = dir.filePath(globalSettingsFile); // If no settings file exist -- use the default one if (!QFile(filePath).exists()) { qDebug() << "No settings file found, using defaults"; filePath = ":/conf/" + globalSettingsFile; } qDebug() << "Loading settings from " + filePath; QSettings s(filePath, QSettings::IniFormat); s.setIniCodec("UTF-8"); s.beginGroup("Login"); autoLogin = s.value("autoLogin", false).toBool(); s.endGroup(); s.beginGroup("DHT Server"); if (s.value("useCustomList").toBool()) { useCustomDhtList = true; qDebug() << "Using custom bootstrap nodes list"; int serverListSize = s.beginReadArray("dhtServerList"); for (int i = 0; i < serverListSize; i ++) { s.setArrayIndex(i); DhtServer server; server.name = s.value("name").toString(); server.userId = s.value("userId").toString(); server.address = s.value("address").toString(); server.port = s.value("port").toInt(); dhtServerList << server; } s.endArray(); } else { useCustomDhtList=false; } s.endGroup(); s.beginGroup("General"); enableIPv6 = s.value("enableIPv6", true).toBool(); translation = s.value("translation", "en").toString(); showSystemTray = s.value("showSystemTray", SHOW_SYSTEM_TRAY_DEFAULT).toBool(); makeToxPortable = s.value("makeToxPortable", false).toBool(); autostartInTray = s.value("autostartInTray", false).toBool(); closeToTray = s.value("closeToTray", false).toBool(); forceTCP = s.value("forceTCP", false).toBool(); setProxyType(s.value("proxyType", static_cast<int>(ProxyType::ptNone)).toInt()); proxyAddr = s.value("proxyAddr", "").toString(); proxyPort = s.value("proxyPort", 0).toInt(); if (currentProfile.isEmpty()) { currentProfile = s.value("currentProfile", "").toString(); currentProfileId = makeProfileId(currentProfile); } autoAwayTime = s.value("autoAwayTime", 10).toInt(); checkUpdates = s.value("checkUpdates", true).toBool(); showWindow = s.value("showWindow", true).toBool(); showInFront = s.value("showInFront", false).toBool(); notifySound = s.value("notifySound", true).toBool(); groupAlwaysNotify = s.value("groupAlwaysNotify", false).toBool(); fauxOfflineMessaging = s.value("fauxOfflineMessaging", true).toBool(); autoSaveEnabled = s.value("autoSaveEnabled", false).toBool(); globalAutoAcceptDir = s.value("globalAutoAcceptDir", QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory) ).toString(); separateWindow = s.value("separateWindow", false).toBool(); dontGroupWindows = s.value("dontGroupWindows", true).toBool(); groupchatPosition = s.value("groupchatPosition", true).toBool(); markdownPreference = static_cast<MarkdownType>(s.value("markdownPreference", 1).toInt()); s.endGroup(); s.beginGroup("Advanced"); int sType = s.value("dbSyncType", static_cast<int>(Db::syncType::stFull)).toInt(); setDbSyncType(sType); s.endGroup(); s.beginGroup("Widgets"); QList<QString> objectNames = s.childKeys(); for (const QString& name : objectNames) widgetSettings[name] = s.value(name).toByteArray(); s.endGroup(); s.beginGroup("GUI"); const QString DEFAULT_SMILEYS = ":/smileys/Universe/emoticons.xml"; smileyPack = s.value("smileyPack", DEFAULT_SMILEYS).toString(); if (!SmileyPack::isValid(smileyPack)) { smileyPack = DEFAULT_SMILEYS; } emojiFontPointSize = s.value("emojiFontPointSize", 16).toInt(); firstColumnHandlePos = s.value("firstColumnHandlePos", 50).toInt(); secondColumnHandlePosFromRight = s.value("secondColumnHandlePosFromRight", 50).toInt(); timestampFormat = s.value("timestampFormat", "hh:mm:ss").toString(); dateFormat = s.value("dateFormat", "dddd, MMMM d, yyyy").toString(); minimizeOnClose = s.value("minimizeOnClose", false).toBool(); minimizeToTray = s.value("minimizeToTray", false).toBool(); lightTrayIcon = s.value("lightTrayIcon", false).toBool(); useEmoticons = s.value("useEmoticons", true).toBool(); statusChangeNotificationEnabled = s.value("statusChangeNotificationEnabled", false).toBool(); themeColor = s.value("themeColor", 0).toInt(); style = s.value("style", "").toString(); if (style == "") // Default to Fusion if available, otherwise no style { if (QStyleFactory::keys().contains("Fusion")) style = "Fusion"; else style = "None"; } s.endGroup(); s.beginGroup("State"); windowGeometry = s.value("windowGeometry", QByteArray()).toByteArray(); windowState = s.value("windowState", QByteArray()).toByteArray(); splitterState = s.value("splitterState", QByteArray()).toByteArray(); dialogGeometry = s.value("dialogGeometry", QByteArray()).toByteArray(); dialogSplitterState = s.value("dialogSplitterState", QByteArray()).toByteArray(); dialogSettingsGeometry = s.value("dialogSettingsGeometry", QByteArray()).toByteArray(); s.endGroup(); s.beginGroup("Audio"); inDev = s.value("inDev", "").toString(); outDev = s.value("outDev", "").toString(); inVolume = s.value("inVolume", 100).toInt(); outVolume = s.value("outVolume", 100).toInt(); filterAudio = s.value("filterAudio", false).toBool(); s.endGroup(); s.beginGroup("Video"); videoDev = s.value("videoDev", "").toString(); camVideoRes = s.value("camVideoRes",QSize()).toSize(); camVideoFPS = s.value("camVideoFPS", 0).toUInt(); s.endGroup(); // Read the embedded DHT bootstrap nodes list if needed if (dhtServerList.isEmpty()) { QSettings rcs(":/conf/settings.ini", QSettings::IniFormat); rcs.setIniCodec("UTF-8"); rcs.beginGroup("DHT Server"); int serverListSize = rcs.beginReadArray("dhtServerList"); for (int i = 0; i < serverListSize; i ++) { rcs.setArrayIndex(i); DhtServer server; server.name = rcs.value("name").toString(); server.userId = rcs.value("userId").toString(); server.address = rcs.value("address").toString(); server.port = rcs.value("port").toInt(); dhtServerList << server; } rcs.endArray(); rcs.endGroup(); } loaded = true; }
void Settings::loadPersonal(Profile* profile) { QMutexLocker locker{&bigLock}; QDir dir(getSettingsDirPath()); QString filePath = dir.filePath(globalSettingsFile); // load from a profile specific friend data list if possible QString tmp = dir.filePath(profile->getName() + ".ini"); if (QFile(tmp).exists()) // otherwise, filePath remains the global file filePath = tmp; qDebug()<<"Loading personal settings from"<<filePath; SettingsSerializer ps(filePath, profile->getPassword()); ps.load(); friendLst.clear(); ps.beginGroup("Privacy"); typingNotification = ps.value("typingNotification", true).toBool(); enableLogging = ps.value("enableLogging", true).toBool(); ps.endGroup(); ps.beginGroup("Friends"); int size = ps.beginReadArray("Friend"); friendLst.reserve(size); 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.note = ps.value("note").toString(); fp.autoAcceptDir = ps.value("autoAcceptDir").toString(); fp.circleID = ps.value("circle", -1).toInt(); if (getEnableLogging()) fp.activity = ps.value("activity", QDate()).toDate(); friendLst[ToxId(fp.addr).publicKey] = fp; } ps.endArray(); ps.endGroup(); ps.beginGroup("General"); compactLayout = ps.value("compactLayout", true).toBool(); ps.endGroup(); ps.beginGroup("Circles"); size = ps.beginReadArray("Circle"); circleLst.clear(); circleLst.reserve(size); for (int i = 0; i < size; i ++) { ps.setArrayIndex(i); circleProp cp; cp.name = ps.value("name").toString(); cp.expanded = ps.value("expanded", true).toBool(); circleLst.push_back(cp); } ps.endArray(); ps.endGroup(); }
void Settings::saveGlobal() { if (QThread::currentThread() != settingsThread) return (void) QMetaObject::invokeMethod(&getInstance(), "saveGlobal"); QMutexLocker locker{&bigLock}; QString path = getSettingsDirPath() + globalSettingsFile; qDebug() << "Saving global settings at " + path; QSettings s(path, QSettings::IniFormat); s.setIniCodec("UTF-8"); s.clear(); s.beginGroup("Login"); s.setValue("autoLogin", autoLogin); s.endGroup(); s.beginGroup("DHT Server"); s.setValue("useCustomList", useCustomDhtList); s.beginWriteArray("dhtServerList", dhtServerList.size()); for (int i = 0; i < dhtServerList.size(); i ++) { s.setArrayIndex(i); s.setValue("name", dhtServerList[i].name); s.setValue("userId", dhtServerList[i].userId); s.setValue("address", dhtServerList[i].address); s.setValue("port", dhtServerList[i].port); } s.endArray(); s.endGroup(); s.beginGroup("General"); s.setValue("enableIPv6", enableIPv6); s.setValue("translation",translation); s.setValue("makeToxPortable",makeToxPortable); s.setValue("showSystemTray", showSystemTray); s.setValue("autostartInTray",autostartInTray); s.setValue("closeToTray", closeToTray); s.setValue("proxyType", static_cast<int>(proxyType)); s.setValue("forceTCP", forceTCP); s.setValue("proxyAddr", proxyAddr); s.setValue("proxyPort", proxyPort); s.setValue("currentProfile", currentProfile); s.setValue("autoAwayTime", autoAwayTime); s.setValue("checkUpdates", checkUpdates); s.setValue("showWindow", showWindow); s.setValue("showInFront", showInFront); s.setValue("notifySound", notifySound); s.setValue("groupAlwaysNotify", groupAlwaysNotify); s.setValue("fauxOfflineMessaging", fauxOfflineMessaging); s.setValue("separateWindow", separateWindow); s.setValue("dontGroupWindows", dontGroupWindows); s.setValue("groupchatPosition", groupchatPosition); s.setValue("autoSaveEnabled", autoSaveEnabled); s.setValue("globalAutoAcceptDir", globalAutoAcceptDir); s.setValue("markdownPreference", static_cast<int>(markdownPreference)); s.endGroup(); s.beginGroup("Advanced"); s.setValue("dbSyncType", static_cast<int>(dbSyncType)); s.endGroup(); s.beginGroup("Widgets"); const QList<QString> widgetNames = widgetSettings.keys(); for (const QString& name : widgetNames) s.setValue(name, widgetSettings.value(name)); s.endGroup(); s.beginGroup("GUI"); s.setValue("smileyPack", smileyPack); s.setValue("emojiFontPointSize", emojiFontPointSize); s.setValue("firstColumnHandlePos", firstColumnHandlePos); s.setValue("secondColumnHandlePosFromRight", secondColumnHandlePosFromRight); s.setValue("timestampFormat", timestampFormat); s.setValue("dateFormat", dateFormat); s.setValue("minimizeOnClose", minimizeOnClose); s.setValue("minimizeToTray", minimizeToTray); s.setValue("lightTrayIcon", lightTrayIcon); s.setValue("useEmoticons", useEmoticons); s.setValue("themeColor", themeColor); s.setValue("style", style); s.setValue("statusChangeNotificationEnabled", statusChangeNotificationEnabled); s.endGroup(); s.beginGroup("State"); s.setValue("windowGeometry", windowGeometry); s.setValue("windowState", windowState); s.setValue("splitterState", splitterState); s.setValue("dialogGeometry", dialogGeometry); s.setValue("dialogSplitterState", dialogSplitterState); s.setValue("dialogSettingsGeometry", dialogSettingsGeometry); s.endGroup(); s.beginGroup("Audio"); s.setValue("inDev", inDev); s.setValue("outDev", outDev); s.setValue("inVolume", inVolume); s.setValue("outVolume", outVolume); s.setValue("filterAudio", filterAudio); s.endGroup(); s.beginGroup("Video"); s.setValue("videoDev", videoDev); s.setValue("camVideoRes",camVideoRes); s.setValue("camVideoFPS",camVideoFPS); s.endGroup(); }
void Settings::load() { if (loaded) return; if (QFile(FILENAME).exists()) { QSettings ps(FILENAME, QSettings::IniFormat); ps.beginGroup("General"); makeToxPortable = ps.value("makeToxPortable", false).toBool(); ps.endGroup(); } else if (QFile(OLDFILENAME).exists()) { QSettings ps(OLDFILENAME, QSettings::IniFormat); ps.beginGroup("General"); makeToxPortable = ps.value("makeToxPortable", false).toBool(); ps.endGroup(); } else makeToxPortable = false; QDir dir(getSettingsDirPath()); QString filePath = dir.filePath(FILENAME); //if no settings file exist -- use the default one if (!QFile(filePath).exists()) { if (!QFile(filePath = dir.filePath(OLDFILENAME)).exists()) { qDebug() << "No settings file found, using defaults"; filePath = ":/conf/" + FILENAME; } } qDebug() << "Settings: Loading from "<<filePath; QSettings s(filePath, QSettings::IniFormat); s.beginGroup("DHT Server"); if (s.value("useCustomList").toBool()) { useCustomDhtList = true; qDebug() << "Using custom bootstrap nodes list"; int serverListSize = s.beginReadArray("dhtServerList"); for (int i = 0; i < serverListSize; i ++) { s.setArrayIndex(i); DhtServer server; server.name = s.value("name").toString(); server.userId = s.value("userId").toString(); server.address = s.value("address").toString(); server.port = s.value("port").toInt(); dhtServerList << server; } s.endArray(); } else useCustomDhtList=false; s.endGroup(); s.beginGroup("General"); enableIPv6 = s.value("enableIPv6", true).toBool(); translation = s.value("translation", "en").toString(); showSystemTray = s.value("showSystemTray", SHOW_SYSTEM_TRAY_DEFAULT).toBool(); makeToxPortable = s.value("makeToxPortable", false).toBool(); autostartInTray = s.value("autostartInTray", false).toBool(); closeToTray = s.value("closeToTray", false).toBool(); forceTCP = s.value("forceTCP", false).toBool(); useProxy = s.value("useProxy", false).toBool(); proxyAddr = s.value("proxyAddr", "").toString(); proxyPort = s.value("proxyPort", 0).toInt(); currentProfile = s.value("currentProfile", "").toString(); autoAwayTime = s.value("autoAwayTime", 10).toInt(); checkUpdates = s.value("checkUpdates", false).toBool(); showInFront = s.value("showInFront", false).toBool(); fauxOfflineMessaging = s.value("fauxOfflineMessaging", true).toBool(); autoSaveEnabled = s.value("autoSaveEnabled", false).toBool(); globalAutoAcceptDir = s.value("globalAutoAcceptDir", QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory) ).toString(); s.endGroup(); s.beginGroup("Advanced"); int sType = s.value("dbSyncType", static_cast<int>(Db::syncType::stFull)).toInt(); setDbSyncType(sType); s.endGroup(); s.beginGroup("Widgets"); QList<QString> objectNames = s.childKeys(); for (const QString& name : objectNames) { widgetSettings[name] = s.value(name).toByteArray(); } s.endGroup(); s.beginGroup("GUI"); enableSmoothAnimation = s.value("smoothAnimation", true).toBool(); smileyPack = s.value("smileyPack", ":/smileys/cylgom/emoticons.xml").toString(); customEmojiFont = s.value("customEmojiFont", true).toBool(); emojiFontFamily = s.value("emojiFontFamily", "DejaVu Sans").toString(); emojiFontPointSize = s.value("emojiFontPointSize", 12).toInt(); firstColumnHandlePos = s.value("firstColumnHandlePos", 50).toInt(); secondColumnHandlePosFromRight = s.value("secondColumnHandlePosFromRight", 50).toInt(); timestampFormat = s.value("timestampFormat", "hh:mm").toString(); minimizeOnClose = s.value("minimizeOnClose", false).toBool(); minimizeToTray = s.value("minimizeToTray", false).toBool(); lightTrayIcon = s.value("lightTrayIcon", false).toBool(); useNativeStyle = s.value("nativeStyle", false).toBool(); useEmoticons = s.value("useEmoticons", true).toBool(); statusChangeNotificationEnabled = s.value("statusChangeNotificationEnabled", false).toBool(); themeColor = s.value("themeColor", 0).toInt(); style = s.value("style", "").toString(); if (style == "") // Default to Fusion if available, otherwise no style { if (QStyleFactory::keys().contains("Fusion")) style = "Fusion"; else style = "None"; } s.endGroup(); s.beginGroup("State"); windowGeometry = s.value("windowGeometry", QByteArray()).toByteArray(); windowState = s.value("windowState", QByteArray()).toByteArray(); 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(); s.endGroup(); // Read the embedded DHT bootsrap nodes list if needed if (dhtServerList.isEmpty()) { qDebug() << "Using embeded bootstrap nodes list"; QSettings rcs(":/conf/settings.ini", QSettings::IniFormat); rcs.beginGroup("DHT Server"); int serverListSize = rcs.beginReadArray("dhtServerList"); for (int i = 0; i < serverListSize; i ++) { rcs.setArrayIndex(i); DhtServer server; server.name = rcs.value("name").toString(); server.userId = rcs.value("userId").toString(); server.address = rcs.value("address").toString(); server.port = rcs.value("port").toInt(); dhtServerList << server; } rcs.endArray(); rcs.endGroup(); } 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::load() { if (loaded) { return; } QFile portableSettings(FILENAME); if (portableSettings.exists()) { QSettings ps(FILENAME, QSettings::IniFormat); ps.beginGroup("General"); makeToxPortable = ps.value("makeToxPortable", false).toBool(); ps.endGroup(); } else makeToxPortable = false; QString filePath = QDir(getSettingsDirPath()).filePath(FILENAME); //if no settings file exist -- use the default one QFile file(filePath); if (!file.exists()) { qDebug() << "No settings file found, using defaults"; filePath = ":/conf/" + FILENAME; } qDebug() << "Settings: Loading from "<<filePath; QSettings s(filePath, QSettings::IniFormat); s.beginGroup("DHT Server"); if (s.value("useCustomList").toBool()) { useCustomDhtList = true; qDebug() << "Using custom bootstrap nodes list"; int serverListSize = s.beginReadArray("dhtServerList"); for (int i = 0; i < serverListSize; i ++) { s.setArrayIndex(i); DhtServer server; server.name = s.value("name").toString(); server.userId = s.value("userId").toString(); server.address = s.value("address").toString(); server.port = s.value("port").toInt(); dhtServerList << server; } s.endArray(); } else useCustomDhtList=false; s.endGroup(); friendAddresses.clear(); s.beginGroup("Friends"); int size = s.beginReadArray("fullAddresses"); for (int i = 0; i < size; i ++) { s.setArrayIndex(i); friendAddresses.append(s.value("addr").toString()); } s.endArray(); s.endGroup(); s.beginGroup("General"); enableIPv6 = s.value("enableIPv6", true).toBool(); translation = s.value("translation", "").toString(); makeToxPortable = s.value("makeToxPortable", false).toBool(); autostartInTray = s.value("autostartInTray", false).toBool(); closeToTray = s.value("closeToTray", false).toBool(); forceTCP = s.value("forceTCP", false).toBool(); useProxy = s.value("useProxy", false).toBool(); proxyAddr = s.value("proxyAddr", "").toString(); proxyPort = s.value("proxyPort", 0).toInt(); currentProfile = s.value("currentProfile", "").toString(); autoAwayTime = s.value("autoAwayTime", 10).toInt(); autoSaveEnabled = s.value("autoSaveEnabled", false).toBool(); autoSaveDir = s.value("autoSaveDir", QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory)).toString(); s.endGroup(); s.beginGroup("Widgets"); QList<QString> objectNames = s.childKeys(); for (const QString& name : objectNames) { widgetSettings[name] = s.value(name).toByteArray(); } s.endGroup(); s.beginGroup("GUI"); enableSmoothAnimation = s.value("smoothAnimation", true).toBool(); smileyPack = s.value("smileyPack", ":/smileys/cylgom/emoticons.xml").toString(); customEmojiFont = s.value("customEmojiFont", true).toBool(); emojiFontFamily = s.value("emojiFontFamily", "DejaVu Sans").toString(); emojiFontPointSize = s.value("emojiFontPointSize", QApplication::font().pointSize()).toInt(); firstColumnHandlePos = s.value("firstColumnHandlePos", 50).toInt(); secondColumnHandlePosFromRight = s.value("secondColumnHandlePosFromRight", 50).toInt(); timestampFormat = s.value("timestampFormat", "hh:mm").toString(); minimizeOnClose = s.value("minimizeOnClose", false).toBool(); minimizeToTray = s.value("minimizeToTray", false).toBool(); useNativeStyle = s.value("nativeStyle", false).toBool(); useEmoticons = s.value("useEmoticons", true).toBool(); style = s.value("style", "None").toString(); statusChangeNotificationEnabled = s.value("statusChangeNotificationEnabled", false).toBool(); s.endGroup(); s.beginGroup("State"); windowGeometry = s.value("windowGeometry", QByteArray()).toByteArray(); windowState = s.value("windowState", QByteArray()).toByteArray(); 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("AutoAccept"); globalAutoAcceptDir = s.value("globalAutoAcceptDir", "").toString(); for (auto& key : s.childKeys()) autoAccept[key] = s.value(key).toString(); s.endGroup(); s.beginGroup("Audio"); inDev = s.value("inDev", "").toString(); outDev = s.value("outDev", "").toString(); s.endGroup(); // try to set a smiley pack if none is selected if (!SmileyPack::isValid(smileyPack) && !SmileyPack::listSmileyPacks().isEmpty()) smileyPack = SmileyPack::listSmileyPacks()[0].second; // Read the embedded DHT bootsrap nodes list if needed if (dhtServerList.isEmpty()) { qDebug() << "Using embeded bootstrap nodes list"; QSettings rcs(":/conf/settings.ini", QSettings::IniFormat); rcs.beginGroup("DHT Server"); int serverListSize = rcs.beginReadArray("dhtServerList"); for (int i = 0; i < serverListSize; i ++) { rcs.setArrayIndex(i); DhtServer server; server.name = rcs.value("name").toString(); server.userId = rcs.value("userId").toString(); server.address = rcs.value("address").toString(); server.port = rcs.value("port").toInt(); dhtServerList << server; } rcs.endArray(); rcs.endGroup(); } loaded = true; }