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:
parent
e56ee4a134
commit
b647f9291e
|
@ -552,8 +552,7 @@ void Core::acceptFriendRequest(const ToxPk& friendPk)
|
||||||
if (friendId == std::numeric_limits<uint32_t>::max()) {
|
if (friendId == std::numeric_limits<uint32_t>::max()) {
|
||||||
emit failedToAddFriend(friendPk);
|
emit failedToAddFriend(friendPk);
|
||||||
} else {
|
} else {
|
||||||
// TODO(sudden6): emit save request
|
emit saveRequest();
|
||||||
//profile.saveToxSave();
|
|
||||||
emit friendAdded(friendId, friendPk);
|
emit friendAdded(friendId, friendPk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -592,8 +591,7 @@ void Core::requestFriendship(const ToxId& friendId, const QString& message)
|
||||||
QString errorMessage = getFriendRequestErrorMessage(friendId, message);
|
QString errorMessage = getFriendRequestErrorMessage(friendId, message);
|
||||||
if (!errorMessage.isNull()) {
|
if (!errorMessage.isNull()) {
|
||||||
emit failedToAddFriend(friendPk, errorMessage);
|
emit failedToAddFriend(friendPk, errorMessage);
|
||||||
// TODO(sudden6): emit save request
|
emit saveRequest();
|
||||||
// profile.saveToxSave();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,8 +607,7 @@ void Core::requestFriendship(const ToxId& friendId, const QString& message)
|
||||||
emit requestSent(friendPk, message);
|
emit requestSent(friendPk, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(sudden6): emit save request
|
emit saveRequest();
|
||||||
// profile.saveToxSave();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Core::sendMessage(uint32_t friendId, const QString& message)
|
int Core::sendMessage(uint32_t friendId, const QString& message)
|
||||||
|
@ -772,8 +769,8 @@ void Core::removeFriend(uint32_t friendId, bool fake)
|
||||||
emit failedToRemoveFriend(friendId);
|
emit failedToRemoveFriend(friendId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO(sudden6): emit save request
|
|
||||||
// profile.saveToxSave();
|
emit saveRequest();
|
||||||
emit friendRemoved(friendId);
|
emit friendRemoved(friendId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,8 +829,7 @@ void Core::setUsername(const QString& username)
|
||||||
}
|
}
|
||||||
|
|
||||||
emit usernameSet(username);
|
emit usernameSet(username);
|
||||||
|
emit saveRequest();
|
||||||
// TODO(sudden6): request saving
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -914,8 +910,7 @@ void Core::setStatusMessage(const QString& message)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(sudden6): request saving
|
emit saveRequest();
|
||||||
|
|
||||||
emit statusMessageSet(message);
|
emit statusMessageSet(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -941,8 +936,7 @@ void Core::setStatus(Status status)
|
||||||
}
|
}
|
||||||
|
|
||||||
tox_self_set_status(tox, userstatus);
|
tox_self_set_status(tox, userstatus);
|
||||||
// TODO(sudden6): emit save request
|
emit saveRequest();
|
||||||
// profile.saveToxSave();
|
|
||||||
emit statusSet(status);
|
emit statusSet(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,6 +199,8 @@ signals:
|
||||||
|
|
||||||
void fileSendFailed(uint32_t friendId, const QString& fname);
|
void fileSendFailed(uint32_t friendId, const QString& fname);
|
||||||
|
|
||||||
|
void saveRequest();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core(QThread* coreThread);
|
Core(QThread* coreThread);
|
||||||
|
|
||||||
|
|
|
@ -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";
|
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
|
// TODO(sudden6): check if needed
|
||||||
//setAvatar(data, selfPk);
|
//setAvatar(data, selfPk);
|
||||||
}
|
}
|
||||||
|
@ -224,7 +227,7 @@ Profile* Profile::createProfile(QString name, QString password)
|
||||||
Profile::~Profile()
|
Profile::~Profile()
|
||||||
{
|
{
|
||||||
if (!isRemoved && core->isReady()) {
|
if (!isRemoved && core->isReady()) {
|
||||||
saveToxSave();
|
onSaveToxSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRemoved) {
|
if (!isRemoved) {
|
||||||
|
@ -306,7 +309,7 @@ bool Profile::isNewProfile()
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
void Profile::saveToxSave()
|
void Profile::onSaveToxSave()
|
||||||
{
|
{
|
||||||
assert(core->isReady());
|
assert(core->isReady());
|
||||||
QByteArray data = core->getToxSaveData();
|
QByteArray data = core->getToxSaveData();
|
||||||
|
@ -756,7 +759,7 @@ QString Profile::setPassword(const QString& newPassword)
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply new encryption
|
// apply new encryption
|
||||||
saveToxSave();
|
onSaveToxSave();
|
||||||
|
|
||||||
bool dbSuccess = false;
|
bool dbSuccess = false;
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,6 @@ public:
|
||||||
QString setPassword(const QString& newPassword);
|
QString setPassword(const QString& newPassword);
|
||||||
const ToxEncrypt* getPasskey() const;
|
const ToxEncrypt* getPasskey() const;
|
||||||
|
|
||||||
void saveToxSave();
|
|
||||||
void saveToxSave(QByteArray data);
|
|
||||||
|
|
||||||
QPixmap loadAvatar();
|
QPixmap loadAvatar();
|
||||||
QPixmap loadAvatar(const ToxPk& owner);
|
QPixmap loadAvatar(const ToxPk& owner);
|
||||||
QByteArray loadAvatarData(const ToxPk& owner);
|
QByteArray loadAvatarData(const ToxPk& owner);
|
||||||
|
@ -91,11 +88,13 @@ public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void loadDatabase(const ToxId& id, QString password);
|
void loadDatabase(const ToxId& id, QString password);
|
||||||
|
void onSaveToxSave();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Profile(QString name, const QString& password, bool newProfile, const QByteArray& toxsave);
|
Profile(QString name, const QString& password, bool newProfile, const QByteArray& toxsave);
|
||||||
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);
|
||||||
|
void saveToxSave(QByteArray data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Core> core = nullptr;
|
std::unique_ptr<Core> core = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user