mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(profile): Move core connect from form to model
This commit is contained in:
parent
36adfc89e9
commit
ae7b47342d
|
@ -57,4 +57,9 @@ public:
|
||||||
|
|
||||||
virtual SetAvatarResult setAvatar(const QString& path) = 0;
|
virtual SetAvatarResult setAvatar(const QString& path) = 0;
|
||||||
virtual void removeAvatar() = 0;
|
virtual void removeAvatar() = 0;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void idChanged(const ToxId& id);
|
||||||
|
void usernameChanged(const QString& username);
|
||||||
|
void statusMessageChanged(const QString& message);
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,13 +37,17 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ProfileInfo constructor.
|
* @brief ProfileInfo constructor.
|
||||||
|
* @param core Pointer to Tox Core.
|
||||||
* @param profile Pointer to Profile.
|
* @param profile Pointer to Profile.
|
||||||
* @note All pointers parameters shouldn't be null.
|
* @note All pointers parameters shouldn't be null.
|
||||||
*/
|
*/
|
||||||
|
ProfileInfo::ProfileInfo(Core* core, Profile *profile)
|
||||||
ProfileInfo::ProfileInfo(Profile *profile)
|
|
||||||
: profile{profile}
|
: profile{profile}
|
||||||
|
, core{core}
|
||||||
{
|
{
|
||||||
|
connect(core, &Core::idSet, this, &ProfileInfo::idChanged);
|
||||||
|
connect(core, &Core::usernameSet, this, &ProfileInfo::usernameChanged);
|
||||||
|
connect(core, &Core::statusMessageSet, this, &ProfileInfo::usernameChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -324,7 +328,6 @@ IProfileInfo::SetAvatarResult ProfileInfo::setAvatar(const QString &path)
|
||||||
return SetAvatarResult::TooLarge;
|
return SetAvatarResult::TooLarge;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core* core = Core::getInstance();
|
|
||||||
profile->setAvatar(bytes, core->getSelfPublicKey());
|
profile->setAvatar(bytes, core->getSelfPublicKey());
|
||||||
return SetAvatarResult::OK;
|
return SetAvatarResult::OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
|
|
||||||
#include "iprofileinfo.h"
|
#include "iprofileinfo.h"
|
||||||
|
|
||||||
class ToxId;
|
class Core;
|
||||||
class QPoint;
|
class QPoint;
|
||||||
class Profile;
|
class Profile;
|
||||||
|
|
||||||
class ProfileInfo : public IProfileInfo
|
class ProfileInfo : public IProfileInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProfileInfo(Profile* profile);
|
ProfileInfo(Core* core, Profile* profile);
|
||||||
|
|
||||||
bool setPassword(const QString& password) override;
|
bool setPassword(const QString& password) override;
|
||||||
bool deletePassword() override;
|
bool deletePassword() override;
|
||||||
|
@ -51,4 +51,5 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Profile* const profile;
|
Profile* const profile;
|
||||||
|
Core* const core;
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,7 +105,6 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo, QWidget* parent)
|
||||||
{
|
{
|
||||||
bodyUI = new Ui::IdentitySettings;
|
bodyUI = new Ui::IdentitySettings;
|
||||||
bodyUI->setupUi(this);
|
bodyUI->setupUi(this);
|
||||||
core = Core::getInstance();
|
|
||||||
|
|
||||||
const uint32_t maxNameLength = tox_max_name_length();
|
const uint32_t maxNameLength = tox_max_name_length();
|
||||||
const QString toolTip = tr("Tox user names cannot exceed %1 characters.").arg(maxNameLength);
|
const QString toolTip = tr("Tox user names cannot exceed %1 characters.").arg(maxNameLength);
|
||||||
|
@ -161,8 +160,7 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo, QWidget* parent)
|
||||||
|
|
||||||
connect(bodyUI->toxIdLabel, &CroppingLabel::clicked, this, &ProfileForm::copyIdClicked);
|
connect(bodyUI->toxIdLabel, &CroppingLabel::clicked, this, &ProfileForm::copyIdClicked);
|
||||||
connect(toxId, &ClickableTE::clicked, this, &ProfileForm::copyIdClicked);
|
connect(toxId, &ClickableTE::clicked, this, &ProfileForm::copyIdClicked);
|
||||||
// TODO: Move to model
|
connect(profileInfo, &IProfileInfo::idChanged, this, &ProfileForm::setToxId);
|
||||||
connect(core, &Core::idSet, this, &ProfileForm::setToxId);
|
|
||||||
connect(bodyUI->userName, &QLineEdit::editingFinished, this, &ProfileForm::onUserNameEdited);
|
connect(bodyUI->userName, &QLineEdit::editingFinished, this, &ProfileForm::onUserNameEdited);
|
||||||
connect(bodyUI->statusMessage, &QLineEdit::editingFinished,
|
connect(bodyUI->statusMessage, &QLineEdit::editingFinished,
|
||||||
this, &ProfileForm::onStatusMessageEdited);
|
this, &ProfileForm::onStatusMessageEdited);
|
||||||
|
@ -185,10 +183,9 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo, QWidget* parent)
|
||||||
connect(bodyUI->toxmeUpdateButton, &QPushButton::clicked,
|
connect(bodyUI->toxmeUpdateButton, &QPushButton::clicked,
|
||||||
this, &ProfileForm::onRegisterButtonClicked);
|
this, &ProfileForm::onRegisterButtonClicked);
|
||||||
|
|
||||||
// TODO: Move to model
|
connect(profileInfo, &IProfileInfo::usernameChanged, this,
|
||||||
connect(core, &Core::usernameSet, this,
|
|
||||||
[=](const QString& val) { bodyUI->userName->setText(val); });
|
[=](const QString& val) { bodyUI->userName->setText(val); });
|
||||||
connect(core, &Core::statusMessageSet, this,
|
connect(profileInfo, &IProfileInfo::statusMessageChanged, this,
|
||||||
[=](const QString& val) { bodyUI->statusMessage->setText(val); });
|
[=](const QString& val) { bodyUI->statusMessage->setText(val); });
|
||||||
|
|
||||||
for (QComboBox* cb : findChildren<QComboBox*>()) {
|
for (QComboBox* cb : findChildren<QComboBox*>()) {
|
||||||
|
@ -296,8 +293,10 @@ void ProfileForm::onSelfAvatarLoaded(const QPixmap& pic)
|
||||||
|
|
||||||
void ProfileForm::setToxId(const ToxId& id)
|
void ProfileForm::setToxId(const ToxId& id)
|
||||||
{
|
{
|
||||||
auto idString = id.toString();
|
QString idString = id.toString();
|
||||||
static const QString ToxIdColor = QStringLiteral("%1<span style='color:blue'>%2</span><span style='color:gray'>%3</span>");
|
static const QString ToxIdColor = QStringLiteral("%1"
|
||||||
|
"<span style='color:blue'>%2</span>"
|
||||||
|
"<span style='color:gray'>%3</span>");
|
||||||
toxId->setText(ToxIdColor
|
toxId->setText(ToxIdColor
|
||||||
.arg(idString.mid(0, 64))
|
.arg(idString.mid(0, 64))
|
||||||
.arg(idString.mid(64, 8))
|
.arg(idString.mid(64, 8))
|
||||||
|
@ -305,7 +304,7 @@ void ProfileForm::setToxId(const ToxId& id)
|
||||||
|
|
||||||
delete qr;
|
delete qr;
|
||||||
qr = new QRWidget();
|
qr = new QRWidget();
|
||||||
qr->setQRData("tox:" + id.toString());
|
qr->setQRData("tox:" + idString);
|
||||||
bodyUI->qrCode->setPixmap(QPixmap::fromImage(qr->getImage()->scaledToWidth(150)));
|
bodyUI->qrCode->setPixmap(QPixmap::fromImage(qr->getImage()->scaledToWidth(150)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,6 @@ private:
|
||||||
void refreshProfiles();
|
void refreshProfiles();
|
||||||
Ui::IdentitySettings* bodyUI;
|
Ui::IdentitySettings* bodyUI;
|
||||||
MaskablePixmapWidget* profilePicture;
|
MaskablePixmapWidget* profilePicture;
|
||||||
Core* core;
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
bool hasCheck = false;
|
bool hasCheck = false;
|
||||||
QRWidget* qr;
|
QRWidget* qr;
|
||||||
|
|
|
@ -231,8 +231,9 @@ void Widget::init()
|
||||||
addFriendForm = new AddFriendForm;
|
addFriendForm = new AddFriendForm;
|
||||||
groupInviteForm = new GroupInviteForm;
|
groupInviteForm = new GroupInviteForm;
|
||||||
|
|
||||||
|
Core* core = Nexus::getCore();
|
||||||
Profile* profile = Nexus::getProfile();
|
Profile* profile = Nexus::getProfile();
|
||||||
profileInfo = new ProfileInfo(profile);
|
profileInfo = new ProfileInfo(core, profile);
|
||||||
profileForm = new ProfileForm(profileInfo);
|
profileForm = new ProfileForm(profileInfo);
|
||||||
|
|
||||||
// connect logout tray menu action
|
// connect logout tray menu action
|
||||||
|
@ -241,7 +242,6 @@ void Widget::init()
|
||||||
connect(profile, &Profile::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded);
|
connect(profile, &Profile::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded);
|
||||||
|
|
||||||
const Settings& s = Settings::getInstance();
|
const Settings& s = Settings::getInstance();
|
||||||
Core* core = Nexus::getCore();
|
|
||||||
CoreAV* av = core->getAv();
|
CoreAV* av = core->getAv();
|
||||||
connect(av, &CoreAV::avEnd, this, &Widget::onCallEnd);
|
connect(av, &CoreAV::avEnd, this, &Widget::onCallEnd);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user