From 7e9ad0e26cba6a8be51f371b95481e2071e603d4 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 4 Jan 2017 21:47:50 +0400 Subject: [PATCH] Migration fixes (#1247) * clean some network specific qt settings on migration * ask user to choose datadir if default dir is not the one we expected --- src/qt/guiutil.cpp | 12 ++++++++++++ src/qt/guiutil.h | 3 +++ src/qt/intro.cpp | 15 +++++++++------ src/qt/networkstyle.cpp | 2 ++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 7da7710b5..521955d3e 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -864,6 +864,18 @@ bool SetStartOnSystemStartup(bool fAutoStart) { return false; } #endif +void migrateQtSettings() +{ + // Migration (12.1) + QSettings settings; + if(!settings.value("fMigrationDone121", false).toBool()) { + settings.remove("theme"); + settings.remove("nWindowPos"); + settings.remove("nWindowSize"); + settings.setValue("fMigrationDone121", true); + } +} + void saveWindowGeometry(const QString& strSetting, QWidget *parent) { QSettings settings; diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 8a79f43f1..a937f6c1a 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -186,6 +186,9 @@ namespace GUIUtil bool GetStartOnSystemStartup(); bool SetStartOnSystemStartup(bool fAutoStart); + /** Modify Qt network specific settings on migration */ + void migrateQtSettings(); + /** Save window size and position */ void saveWindowGeometry(const QString& strSetting, QWidget *parent); /** Restore window size and position */ diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index de88cbd36..6ec25f492 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -169,15 +169,17 @@ void Intro::pickDataDirectory() if(!GetArg("-datadir", "").empty()) return; /* 1) Default data directory for operating system */ - QString dataDir = getDefaultDataDirectory(); + QString dataDirDefaultCurrent = getDefaultDataDirectory(); /* 2) Allow QSettings to override default dir */ - dataDir = settings.value("strDataDir", dataDir).toString(); + QString dataDir = settings.value("strDataDir", dataDirDefaultCurrent).toString(); + /* 3) Check to see if default datadir is the one we expect */ + QString dataDirDefaultSettings = settings.value("strDataDirDefault", dataDirDefaultCurrent).toString(); - if(!fs::exists(GUIUtil::qstringToBoostPath(dataDir)) || GetBoolArg("-choosedatadir", DEFAULT_CHOOSE_DATADIR)) + if(!fs::exists(GUIUtil::qstringToBoostPath(dataDir)) || GetBoolArg("-choosedatadir", DEFAULT_CHOOSE_DATADIR) || dataDirDefaultCurrent != dataDirDefaultSettings) { - /* If current default data directory does not exist, let the user choose one */ + /* Let the user choose one */ Intro intro; - intro.setDataDirectory(dataDir); + intro.setDataDirectory(dataDirDefaultCurrent); intro.setWindowIcon(QIcon(":icons/bitcoin")); while(true) @@ -199,12 +201,13 @@ void Intro::pickDataDirectory() } settings.setValue("strDataDir", dataDir); + settings.setValue("strDataDirDefault", dataDirDefaultCurrent); } /* Only override -datadir if different from the default, to make it possible to * override -datadir in the dash.conf file in the default data directory * (to be consistent with dashd behavior) */ - if(dataDir != getDefaultDataDirectory()) + if(dataDir != dataDirDefaultCurrent) SoftSetArg("-datadir", GUIUtil::qstringToBoostPath(dataDir).string()); // use OS locale for path setting } diff --git a/src/qt/networkstyle.cpp b/src/qt/networkstyle.cpp index 171804fbb..4325db39d 100644 --- a/src/qt/networkstyle.cpp +++ b/src/qt/networkstyle.cpp @@ -64,6 +64,8 @@ NetworkStyle::NetworkStyle(const QString &appName, const int iconColorHueShift, { // Allow for separate UI settings for testnets QApplication::setApplicationName(appName); + // Make sure settings migrated properly + GUIUtil::migrateQtSettings(); // Grab theme from settings QString theme = GUIUtil::getThemeName(); // load pixmap