Merge pull request #445 from daleglass-overte/fix-settings-reset

Fix resetting the settings
This commit is contained in:
Dale Glass 2023-06-04 11:41:22 -07:00 committed by GitHub
commit ab7eebae31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 9 deletions

View file

@ -25,14 +25,16 @@
#include "Application.h" #include "Application.h"
#include "Menu.h" #include "Menu.h"
#include <RunningMarker.h> #include <RunningMarker.h>
#include <SettingHandle.h> #include <SettingHandle.h>
#include <SettingHelpers.h> #include <SettingHelpers.h>
#include <SettingManager.h>
#include <DependencyManager.h>
bool CrashRecoveryHandler::checkForResetSettings(bool wasLikelyCrash, bool suppressPrompt) { bool CrashRecoveryHandler::checkForResetSettings(bool wasLikelyCrash, bool suppressPrompt) {
QSettings::setDefaultFormat(JSON_FORMAT); Settings settings;
QSettings settings;
settings.beginGroup("Developer"); settings.beginGroup("Developer");
QVariant displayCrashOptions = settings.value(MenuOption::DisplayCrashOptions); QVariant displayCrashOptions = settings.value(MenuOption::DisplayCrashOptions);
settings.endGroup(); settings.endGroup();
@ -111,7 +113,8 @@ void CrashRecoveryHandler::handleCrash(CrashRecoveryHandler::Action action) {
return; return;
} }
QSettings settings; Settings settings;
const QString ADDRESS_MANAGER_GROUP = "AddressManager"; const QString ADDRESS_MANAGER_GROUP = "AddressManager";
const QString ADDRESS_KEY = "address"; const QString ADDRESS_KEY = "address";
const QString AVATAR_GROUP = "Avatar"; const QString AVATAR_GROUP = "Avatar";
@ -145,11 +148,8 @@ void CrashRecoveryHandler::handleCrash(CrashRecoveryHandler::Action action) {
tutorialComplete = settings.value(TUTORIAL_COMPLETE_FLAG_KEY).toBool(); tutorialComplete = settings.value(TUTORIAL_COMPLETE_FLAG_KEY).toBool();
} }
// Delete Interface.ini // Reset everything
QFile settingsFile(settings.fileName()); settings.clear();
if (settingsFile.exists()) {
settingsFile.remove();
}
if (action == CrashRecoveryHandler::RETAIN_IMPORTANT_INFO) { if (action == CrashRecoveryHandler::RETAIN_IMPORTANT_INFO) {
// Write avatar info // Write avatar info

View file

@ -199,4 +199,8 @@ QString Settings::getPath(const QString &key) const {
ret.append(key); ret.append(key);
return ret; return ret;
} }
void Settings::clear() {
_manager->clearAllSettings();
}

View file

@ -110,6 +110,8 @@ public:
void setQuatValue(const QString& name, const glm::quat& quatValue); void setQuatValue(const QString& name, const glm::quat& quatValue);
void getQuatValueIfValid(const QString& name, glm::quat& quatValue); void getQuatValueIfValid(const QString& name, glm::quat& quatValue);
void clear();
private: private:
QString getGroupPrefix() const; QString getGroupPrefix() const;
QString getPath(const QString &value) const; QString getPath(const QString &value) const;

View file

@ -45,6 +45,12 @@ namespace Setting {
_qSettings->remove(key); _qSettings->remove(key);
} }
void WriteWorker::clearAllSettings() {
init();
_qSettings->clear();
sync();
}
void WriteWorker::sync() { void WriteWorker::sync() {
//qCDebug(settings_writer) << "Forcing settings sync"; //qCDebug(settings_writer) << "Forcing settings sync";
init(); init();
@ -81,6 +87,7 @@ namespace Setting {
connect(this, &Manager::valueChanged, worker, &WriteWorker::setValue, Qt::QueuedConnection); connect(this, &Manager::valueChanged, worker, &WriteWorker::setValue, Qt::QueuedConnection);
connect(this, &Manager::keyRemoved, worker, &WriteWorker::removeKey, Qt::QueuedConnection); connect(this, &Manager::keyRemoved, worker, &WriteWorker::removeKey, Qt::QueuedConnection);
connect(this, &Manager::syncRequested, worker, &WriteWorker::sync, Qt::QueuedConnection); connect(this, &Manager::syncRequested, worker, &WriteWorker::sync, Qt::QueuedConnection);
connect(this, &Manager::clearAllSettingsRequested, worker, &WriteWorker::clearAllSettings, Qt::QueuedConnection);
// This one is blocking because we want to wait until it's actually processed. // This one is blocking because we want to wait until it's actually processed.
connect(this, &Manager::terminationRequested, worker, &WriteWorker::terminate, Qt::BlockingQueuedConnection); connect(this, &Manager::terminationRequested, worker, &WriteWorker::terminate, Qt::BlockingQueuedConnection);
@ -209,4 +216,12 @@ namespace Setting {
return _settings.value(key, defaultValue); return _settings.value(key, defaultValue);
}); });
} }
void Manager::clearAllSettings() {
withWriteLock([&] {
_settings.clear();
});
emit clearAllSettingsRequested();
}
} }

View file

@ -75,6 +75,12 @@ namespace Setting {
*/ */
void removeKey(const QString key); void removeKey(const QString key);
/**
* @brief Remove all values from the configuration.
*
*/
void clearAllSettings();
/** /**
* @brief Force writing the config to disk * @brief Force writing the config to disk
* *
@ -172,6 +178,13 @@ namespace Setting {
*/ */
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
/**
* @brief Clear all the settings
*
* Removes the entire configuration, resetting everything to "factory default"
*
*/
void clearAllSettings();
protected: protected:
/** /**
* @brief How long to wait for writer thread termination * @brief How long to wait for writer thread termination
@ -204,9 +217,39 @@ namespace Setting {
void terminateThread(); void terminateThread();
signals: signals:
/**
* @brief The value of a setting was changed
*
* @param key Setting key
* @param value New value
*/
void valueChanged(const QString key, QVariant value); void valueChanged(const QString key, QVariant value);
/**
* @brief A setting was removed
*
* @param key Setting key
*/
void keyRemoved(const QString key); void keyRemoved(const QString key);
/**
* @brief A request to synchronize the settings to permanent storage was made
*
*/
void syncRequested(); void syncRequested();
/**
* @brief A request to clear all the settings was made
*
*/
void clearAllSettingsRequested();
/**
* @brief The termination of the settings system was requested
*
* This happens on shutdown. All pending changes should be serialized to disk.
*
*/
void terminationRequested(); void terminationRequested();
private: private: