1
0
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:
Diadlo 2017-10-08 00:11:46 +03:00
parent 36adfc89e9
commit ae7b47342d
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
6 changed files with 24 additions and 17 deletions

View File

@ -57,4 +57,9 @@ public:
virtual SetAvatarResult setAvatar(const QString& path) = 0;
virtual void removeAvatar() = 0;
signals:
void idChanged(const ToxId& id);
void usernameChanged(const QString& username);
void statusMessageChanged(const QString& message);
};

View File

@ -37,13 +37,17 @@
/**
* @brief ProfileInfo constructor.
* @param core Pointer to Tox Core.
* @param profile Pointer to Profile.
* @note All pointers parameters shouldn't be null.
*/
ProfileInfo::ProfileInfo(Profile *profile)
ProfileInfo::ProfileInfo(Core* core, 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;
}
Core* core = Core::getInstance();
profile->setAvatar(bytes, core->getSelfPublicKey());
return SetAvatarResult::OK;
}

View File

@ -19,14 +19,14 @@
#include "iprofileinfo.h"
class ToxId;
class Core;
class QPoint;
class Profile;
class ProfileInfo : public IProfileInfo
{
public:
ProfileInfo(Profile* profile);
ProfileInfo(Core* core, Profile* profile);
bool setPassword(const QString& password) override;
bool deletePassword() override;
@ -51,4 +51,5 @@ public:
private:
Profile* const profile;
Core* const core;
};

View File

@ -105,7 +105,6 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo, QWidget* parent)
{
bodyUI = new Ui::IdentitySettings;
bodyUI->setupUi(this);
core = Core::getInstance();
const uint32_t maxNameLength = tox_max_name_length();
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(toxId, &ClickableTE::clicked, this, &ProfileForm::copyIdClicked);
// TODO: Move to model
connect(core, &Core::idSet, this, &ProfileForm::setToxId);
connect(profileInfo, &IProfileInfo::idChanged, this, &ProfileForm::setToxId);
connect(bodyUI->userName, &QLineEdit::editingFinished, this, &ProfileForm::onUserNameEdited);
connect(bodyUI->statusMessage, &QLineEdit::editingFinished,
this, &ProfileForm::onStatusMessageEdited);
@ -185,10 +183,9 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo, QWidget* parent)
connect(bodyUI->toxmeUpdateButton, &QPushButton::clicked,
this, &ProfileForm::onRegisterButtonClicked);
// TODO: Move to model
connect(core, &Core::usernameSet, this,
connect(profileInfo, &IProfileInfo::usernameChanged, this,
[=](const QString& val) { bodyUI->userName->setText(val); });
connect(core, &Core::statusMessageSet, this,
connect(profileInfo, &IProfileInfo::statusMessageChanged, this,
[=](const QString& val) { bodyUI->statusMessage->setText(val); });
for (QComboBox* cb : findChildren<QComboBox*>()) {
@ -296,8 +293,10 @@ void ProfileForm::onSelfAvatarLoaded(const QPixmap& pic)
void ProfileForm::setToxId(const ToxId& id)
{
auto idString = id.toString();
static const QString ToxIdColor = QStringLiteral("%1<span style='color:blue'>%2</span><span style='color:gray'>%3</span>");
QString idString = id.toString();
static const QString ToxIdColor = QStringLiteral("%1"
"<span style='color:blue'>%2</span>"
"<span style='color:gray'>%3</span>");
toxId->setText(ToxIdColor
.arg(idString.mid(0, 64))
.arg(idString.mid(64, 8))
@ -305,7 +304,7 @@ void ProfileForm::setToxId(const ToxId& id)
delete qr;
qr = new QRWidget();
qr->setQRData("tox:" + id.toString());
qr->setQRData("tox:" + idString);
bodyUI->qrCode->setPixmap(QPixmap::fromImage(qr->getImage()->scaledToWidth(150)));
}

View File

@ -93,7 +93,6 @@ private:
void refreshProfiles();
Ui::IdentitySettings* bodyUI;
MaskablePixmapWidget* profilePicture;
Core* core;
QTimer timer;
bool hasCheck = false;
QRWidget* qr;

View File

@ -231,8 +231,9 @@ void Widget::init()
addFriendForm = new AddFriendForm;
groupInviteForm = new GroupInviteForm;
Core* core = Nexus::getCore();
Profile* profile = Nexus::getProfile();
profileInfo = new ProfileInfo(profile);
profileInfo = new ProfileInfo(core, profile);
profileForm = new ProfileForm(profileInfo);
// connect logout tray menu action
@ -241,7 +242,6 @@ void Widget::init()
connect(profile, &Profile::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded);
const Settings& s = Settings::getInstance();
Core* core = Nexus::getCore();
CoreAV* av = core->getAv();
connect(av, &CoreAV::avEnd, this, &Widget::onCallEnd);