diff --git a/src/nexus.cpp b/src/nexus.cpp index 1f287b236..69655ec46 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -270,7 +270,7 @@ void Nexus::setProfile(Profile* profile) { getInstance().profile = profile; if (profile) - Settings::getInstance().loadPersonal(profile); + Settings::getInstance().loadPersonal(profile->getName(), profile->getPasskey()); } /** diff --git a/src/persistence/profile.cpp b/src/persistence/profile.cpp index 696c6945b..de87c7d99 100644 --- a/src/persistence/profile.cpp +++ b/src/persistence/profile.cpp @@ -84,7 +84,7 @@ void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s, bool isNewPr if (isNewProfile) { core->setStatusMessage(tr("Toxing on qTox")); - core->setUsername(name); + core->setUsername(name); } // save tox file when Core requests it @@ -96,14 +96,16 @@ void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s, bool isNewPr Qt::ConnectionType::QueuedConnection); } -Profile::Profile(QString name, const QString& password, bool isNewProfile, const QByteArray& toxsave) +Profile::Profile(QString name, const QString& password, bool isNewProfile, const QByteArray& toxsave, std::unique_ptr passkey) : name{name} + , passkey{std::move(passkey)} , isRemoved{false} + , encrypted{this->passkey != nullptr} { Settings& s = Settings::getInstance(); s.setCurrentProfile(name); s.saveGlobal(); - + s.loadPersonal(name, passkey.get()); initCore(toxsave, s, isNewProfile); const ToxId& selfId = core->getSelfId(); @@ -180,12 +182,7 @@ Profile* Profile::loadProfile(QString name, const QString& password) } saveFile.close(); - p = new Profile(name, password, false, data); - p->passkey = std::move(tmpKey); - if (p->passkey) { - p->encrypted = true; - } - + p = new Profile(name, password, false, data, std::move(tmpKey)); return p; // cleanup in case of error @@ -230,12 +227,7 @@ Profile* Profile::createProfile(QString name, QString password) } Settings::getInstance().createPersonal(name); - Profile* p = new Profile(name, password, true, QByteArray()); - p->passkey = std::move(tmpKey); - if (p->passkey) { - p->encrypted = true; - } - + Profile* p = new Profile(name, password, true, QByteArray(), std::move(tmpKey)); return p; } diff --git a/src/persistence/profile.h b/src/persistence/profile.h index ac1004b4e..b464b6e55 100644 --- a/src/persistence/profile.h +++ b/src/persistence/profile.h @@ -98,7 +98,7 @@ private slots: void onAvatarOfferReceived(uint32_t friendId, uint32_t fileId, const QByteArray& avatarHash); private: - Profile(QString name, const QString& password, bool newProfile, const QByteArray& toxsave); + Profile(QString name, const QString& password, bool newProfile, const QByteArray& toxsave, std::unique_ptr passKey); static QStringList getFilesByExt(QString extension); QString avatarPath(const ToxPk& owner, bool forceUnencrypted = false); bool saveToxSave(QByteArray data); diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 96b071762..783586cd7 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -273,17 +273,7 @@ void Settings::loadGlobal() loaded = true; } -void Settings::loadPersonal() -{ - Profile* profile = Nexus::getProfile(); - if (!profile) { - qCritical() << "No active profile, couldn't load personal settings"; - return; - } - loadPersonal(profile); -} - -void Settings::loadPersonal(Profile* profile) +void Settings::loadPersonal(QString profileName, const ToxEncrypt* passKey) { QMutexLocker locker{&bigLock}; @@ -291,13 +281,13 @@ void Settings::loadPersonal(Profile* profile) QString filePath = dir.filePath(globalSettingsFile); // load from a profile specific friend data list if possible - QString tmp = dir.filePath(profile->getName() + ".ini"); + QString tmp = dir.filePath(profileName + ".ini"); if (QFile(tmp).exists()) // otherwise, filePath remains the global file filePath = tmp; qDebug() << "Loading personal settings from" << filePath; - SettingsSerializer ps(filePath, profile->getPasskey()); + SettingsSerializer ps(filePath, passKey); ps.load(); friendLst.clear(); diff --git a/src/persistence/settings.h b/src/persistence/settings.h index c0432b3a4..6c04510a3 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -146,8 +146,7 @@ public: void savePersonal(); void loadGlobal(); - void loadPersonal(); - void loadPersonal(Profile* profile); + void loadPersonal(QString profileName, const ToxEncrypt* passKey); void resetToDefault();