diff --git a/src/core.cpp b/src/core.cpp index 3241969eb..440ee952a 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -1150,8 +1150,8 @@ QString Core::sanitize(QString name) bool Core::loadConfiguration(QString path) { - loadPath = ""; // if not empty, then user forgot a password - // setting the profile is now the responsibility of the caller + loadPath = ""; // if not empty upon return, then user forgot a password and is switching + QFile configurationFile(path); qDebug() << "Core::loadConfiguration: reading from " << path; @@ -1183,17 +1183,17 @@ bool Core::loadConfiguration(QString path) QMetaObject::invokeMethod(Widget::getInstance(), "askProfiles", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QString, profile)); if (!profile.isEmpty()) + { loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT); + Settings::getInstance().switchProfile(profile); + HistoryKeeper::getInstance()->resetInstance(); + } return false; } } } configurationFile.close(); - Settings::getInstance().setCurrentProfile(QFileInfo(path).completeBaseName()); - // this is necessary for anything that doesn't call switchConfiguration, i.e. - // forgetting a password and choosing a different profile - // set GUI with user and statusmsg QString name = getUsername(); if (!name.isEmpty()) @@ -1233,7 +1233,7 @@ void Core::saveConfiguration() if (profile == "") // happens on creation of a new Tox ID profile = getIDString(); - Settings::getInstance().setCurrentProfile(profile); + Settings::getInstance().switchProfile(profile); } QString path = directory.filePath(profile + TOX_EXT); @@ -1266,11 +1266,7 @@ void Core::switchConfiguration(const QString& profile) else loadPath = QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT); - // the new profile needs to be set before resetting the settings, so that - // we don't load the old profile's profile.ini - Settings::getInstance().setCurrentProfile(profile); - Settings::getInstance().save(false); // save new profile, but don't write old profile info to newprofile.ini - Settings::resetInstance(); + Settings::getInstance().switchProfile(profile); HistoryKeeper::getInstance()->resetInstance(); start(); diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index 257f9cefe..d90080b6d 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -63,6 +63,13 @@ void Settings::resetInstance() } } +void Settings::switchProfile(const QString& profile) +{ + setCurrentProfile(profile); + save(false); + resetInstance(); +} + void Settings::load() { if (loaded) diff --git a/src/misc/settings.h b/src/misc/settings.h index 1ed006f8d..c99fea311 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -30,6 +30,7 @@ class Settings : public QObject public: static Settings& getInstance(); static void resetInstance(); + void switchProfile(const QString& profile); ~Settings() = default; void executeSettingsDialog(QWidget* parent); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index cc38323e5..4b468c89d 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -402,7 +402,10 @@ QString Widget::detectProfile() if (profile.isEmpty()) return ""; else + { + Settings::getInstance().setCurrentProfile(profile); return dir.filePath(profile + Core::TOX_EXT); + } } } else