Browse Source

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

Fix #5369
reviewable/pr5393/r1
Anthony Bilinski 7 years ago
parent
commit
109a4ffd43
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 29
      src/persistence/profile.cpp
  2. 4
      src/persistence/profile.h

29
src/persistence/profile.cpp

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

4
src/persistence/profile.h

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

Loading…
Cancel
Save