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

refactor(core): reimplement profile saving

This commit is contained in:
sudden6 2018-06-27 16:25:33 +02:00
parent e56ee4a134
commit b647f9291e
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
4 changed files with 18 additions and 20 deletions

View File

@ -552,8 +552,7 @@ void Core::acceptFriendRequest(const ToxPk& friendPk)
if (friendId == std::numeric_limits<uint32_t>::max()) {
emit failedToAddFriend(friendPk);
} else {
// TODO(sudden6): emit save request
//profile.saveToxSave();
emit saveRequest();
emit friendAdded(friendId, friendPk);
}
}
@ -592,8 +591,7 @@ void Core::requestFriendship(const ToxId& friendId, const QString& message)
QString errorMessage = getFriendRequestErrorMessage(friendId, message);
if (!errorMessage.isNull()) {
emit failedToAddFriend(friendPk, errorMessage);
// TODO(sudden6): emit save request
// profile.saveToxSave();
emit saveRequest();
return;
}
@ -609,8 +607,7 @@ void Core::requestFriendship(const ToxId& friendId, const QString& message)
emit requestSent(friendPk, message);
}
// TODO(sudden6): emit save request
// profile.saveToxSave();
emit saveRequest();
}
int Core::sendMessage(uint32_t friendId, const QString& message)
@ -772,8 +769,8 @@ void Core::removeFriend(uint32_t friendId, bool fake)
emit failedToRemoveFriend(friendId);
return;
}
// TODO(sudden6): emit save request
// profile.saveToxSave();
emit saveRequest();
emit friendRemoved(friendId);
}
@ -832,8 +829,7 @@ void Core::setUsername(const QString& username)
}
emit usernameSet(username);
// TODO(sudden6): request saving
emit saveRequest();
}
/**
@ -914,8 +910,7 @@ void Core::setStatusMessage(const QString& message)
return;
}
// TODO(sudden6): request saving
emit saveRequest();
emit statusMessageSet(message);
}
@ -941,8 +936,7 @@ void Core::setStatus(Status status)
}
tox_self_set_status(tox, userstatus);
// TODO(sudden6): emit save request
// profile.saveToxSave();
emit saveRequest();
emit statusSet(status);
}

View File

@ -199,6 +199,8 @@ signals:
void fileSendFailed(uint32_t friendId, const QString& fname);
void saveRequest();
private:
Core(QThread* coreThread);

View File

@ -86,6 +86,9 @@ Profile::Profile(QString name, const QString& password, bool isNewProfile, const
qDebug() << "Self avatar not found, will broadcast empty avatar to friends";
}
// save tox file when Core requests it
connect(core.get(), &Core::saveRequest, this, &Profile::onSaveToxSave);
// TODO(sudden6): check if needed
//setAvatar(data, selfPk);
}
@ -224,7 +227,7 @@ Profile* Profile::createProfile(QString name, QString password)
Profile::~Profile()
{
if (!isRemoved && core->isReady()) {
saveToxSave();
onSaveToxSave();
}
if (!isRemoved) {
@ -306,7 +309,7 @@ bool Profile::isNewProfile()
* @brief Saves the profile's .tox save, encrypted if needed.
* @warning Invalid on deleted profiles.
*/
void Profile::saveToxSave()
void Profile::onSaveToxSave()
{
assert(core->isReady());
QByteArray data = core->getToxSaveData();
@ -756,7 +759,7 @@ QString Profile::setPassword(const QString& newPassword)
}
// apply new encryption
saveToxSave();
onSaveToxSave();
bool dbSuccess = false;

View File

@ -53,9 +53,6 @@ public:
QString setPassword(const QString& newPassword);
const ToxEncrypt* getPasskey() const;
void saveToxSave();
void saveToxSave(QByteArray data);
QPixmap loadAvatar();
QPixmap loadAvatar(const ToxPk& owner);
QByteArray loadAvatarData(const ToxPk& owner);
@ -91,11 +88,13 @@ public slots:
private slots:
void loadDatabase(const ToxId& id, QString password);
void onSaveToxSave();
private:
Profile(QString name, const QString& password, bool newProfile, const QByteArray& toxsave);
static QStringList getFilesByExt(QString extension);
QString avatarPath(const ToxPk& owner, bool forceUnencrypted = false);
void saveToxSave(QByteArray data);
private:
std::unique_ptr<Core> core = nullptr;