1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(core): set username and status on new profile

Fix #5369
This commit is contained in:
Anthony Bilinski 2018-10-13 11:11:05 -07:00
parent aa7542f729
commit 109a4ffd43
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
2 changed files with 20 additions and 13 deletions

View File

@ -52,8 +52,18 @@
QStringList Profile::profiles;
void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s)
void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s, bool isNewProfile)
{
if (toxsave.isEmpty() && !isNewProfile) {
qCritical() << "Existing toxsave is empty";
emit failedToStart();
}
if (!toxsave.isEmpty() && isNewProfile) {
qCritical() << "New profile has toxsave data";
emit failedToStart();
}
Core::ToxCoreErrors err;
core = Core::makeToxCore(toxsave, &s, &err);
if (!core) {
@ -72,6 +82,11 @@ void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s)
return;
}
if (isNewProfile) {
core->setStatusMessage(tr("Toxing on qTox"));
core->setUsername(name);
}
// save tox file when Core requests it
connect(core.get(), &Core::saveRequest, this, &Profile::onSaveToxSave);
// react to avatar changes
@ -83,14 +98,13 @@ void Profile::initCore(const QByteArray& toxsave, ICoreSettings& s)
Profile::Profile(QString name, const QString& password, bool isNewProfile, const QByteArray& toxsave)
: name{name}
, newProfile{isNewProfile}
, isRemoved{false}
{
Settings& s = Settings::getInstance();
s.setCurrentProfile(name);
s.saveGlobal();
initCore(toxsave, s);
initCore(toxsave, s, isNewProfile);
const ToxId& selfId = core->getSelfId();
loadDatabase(selfId, password);
@ -312,11 +326,6 @@ void Profile::startCore()
setAvatar(data);
}
bool Profile::isNewProfile()
{
return newProfile;
}
/**
* @brief Saves the profile's .tox save, encrypted if needed.
* @warning Invalid on deleted profiles.
@ -371,7 +380,6 @@ bool Profile::saveToxSave(QByteArray data)
// check if everything got written
if (saveFile.flush()) {
saveFile.commit();
newProfile = false;
} else {
saveFile.cancelWriting();
qCritical() << "Failed to write, can't save!";
@ -794,7 +802,8 @@ void Profile::restartCore()
// save to disk just in case
if (saveToxSave(savedata)) {
qDebug() << "Restarting Core";
initCore(savedata, Settings::getInstance());
const bool isNewProfile{false};
initCore(savedata, Settings::getInstance(), isNewProfile);
core->start();
} else {
qCritical() << "Failed to save, not restarting core";

View File

@ -48,7 +48,6 @@ public:
void startCore();
void restartCore();
bool isNewProfile();
bool isEncrypted() const;
QString setPassword(const QString& newPassword);
const ToxEncrypt* getPasskey() const;
@ -103,7 +102,7 @@ private:
static QStringList getFilesByExt(QString extension);
QString avatarPath(const ToxPk& owner, bool forceUnencrypted = false);
bool saveToxSave(QByteArray data);
void initCore(const QByteArray& toxsave, ICoreSettings& s);
void initCore(const QByteArray& toxsave, ICoreSettings& s, bool isNewProfile);
private:
std::unique_ptr<Core> core = nullptr;
@ -111,7 +110,6 @@ private:
std::unique_ptr<ToxEncrypt> passkey = nullptr;
std::shared_ptr<RawDatabase> database;
std::unique_ptr<History> history;
bool newProfile;
bool isRemoved;
bool encrypted = false;
static QStringList profiles;