Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(core): set username and status on new profile
Browse files Browse the repository at this point in the history
Fix #5369
  • Loading branch information
anthonybilinski committed Oct 13, 2018
1 parent aa7542f commit 109a4ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
29 changes: 19 additions & 10 deletions src/persistence/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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!";
Expand Down Expand Up @@ -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";
Expand Down
4 changes: 1 addition & 3 deletions src/persistence/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Profile : public QObject

void startCore();
void restartCore();
bool isNewProfile();
bool isEncrypted() const;
QString setPassword(const QString& newPassword);
const ToxEncrypt* getPasskey() const;
Expand Down Expand Up @@ -103,15 +102,14 @@ private slots:
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;
QString name;
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;
Expand Down

0 comments on commit 109a4ff

Please sign in to comment.