Skip to content

Commit

Permalink
Optionsmodel #2
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Nov 27, 2020
1 parent 6c9964e commit eaa9373
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
50 changes: 48 additions & 2 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "optionsmodel.h"
#include "bitcoinunits.h"

#include <QDebug>
#include <QSettings>

#include "init.h"
Expand Down Expand Up @@ -70,11 +72,55 @@ void OptionsModel::Init()
if (settings.contains("fDisableUpdateCheck")) {
SoftSetBoolArg("-disableupdatecheck", settings.value("fDisableUpdateCheck").toBool());
}
if (settings.contains("dataDir")) {
SoftSetArg("-datadir", settings.value("dataDir").toString().toStdString());
if (settings.contains("dataDir") && dataDir != GUIUtil::getDefaultDataDirectory()) {
SoftSetArg("-datadir", GUIUtil::qstringToBoostPath(settings.value("dataDir").toString()).string());
}
}

/** Helper function to copy contents from one QSettings to another.
* By using allKeys this also covers nested settings in a hierarchy.
*/
static void CopySettings(QSettings& dst, const QSettings& src)
{
for (const QString& key : src.allKeys()) {
dst.setValue(key, src.value(key));
}
}

/** Back up a QSettings to an ini-formatted file. */
static void BackupSettings(const fs::path& filename, const QSettings& src)
{
qInfo() << "Backing up GUI settings to" << GUIUtil::boostPathToQString(filename);
QSettings dst(GUIUtil::boostPathToQString(filename), QSettings::IniFormat);
dst.clear();
CopySettings(dst, src);
}

void OptionsModel::Reset()
{
QSettings settings;

// Backup old settings to chain-specific datadir for troubleshooting
BackupSettings(GetDataDir(true) / "guisettings.ini.bak", settings);

// Save the strDataDir setting
QString dataDir = GUIUtil::getDefaultDataDirectory();
dataDir = settings.value("strDataDir", dataDir).toString();

// Remove all entries from our QSettings object
settings.clear();

// Set strDataDir
settings.setValue("strDataDir", dataDir);

// Set that this was reset
settings.setValue("fReset", true);

// default setting for OptionsModel::StartAtStartup - disabled
if (GUIUtil::GetStartOnSystemStartup())
GUIUtil::SetStartOnSystemStartup(false, true);
}

int OptionsModel::rowCount(const QModelIndex & parent) const
{
return OptionIDRowCount;
Expand Down
1 change: 1 addition & 0 deletions src/qt/optionsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class OptionsModel : public QAbstractListModel
};

void Init();
void Reset();

int rowCount(const QModelIndex & parent = QModelIndex()) const;
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
Expand Down

0 comments on commit eaa9373

Please sign in to comment.