mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(core): Move setAvatar to profile from core
This commit is contained in:
parent
4664c6249a
commit
65b1463933
|
@ -22,7 +22,6 @@
|
|||
#include "corefile.h"
|
||||
#include "src/core/coreav.h"
|
||||
#include "src/core/toxstring.h"
|
||||
#include "src/net/avatarbroadcaster.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/persistence/profile.h"
|
||||
#include "src/persistence/settings.h"
|
||||
|
@ -315,13 +314,6 @@ void Core::start(const QByteArray& savedata)
|
|||
tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback);
|
||||
tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback);
|
||||
|
||||
QByteArray data = profile.loadAvatarData(getSelfPublicKey().toString());
|
||||
if (data.isEmpty()) {
|
||||
qDebug() << "Self avatar not found, will broadcast empty avatar to friends";
|
||||
}
|
||||
|
||||
setAvatar(data);
|
||||
|
||||
ready = true;
|
||||
|
||||
if (isNewProfile) {
|
||||
|
@ -838,21 +830,6 @@ void Core::setUsername(const QString& username)
|
|||
}
|
||||
}
|
||||
|
||||
void Core::setAvatar(const QByteArray& data)
|
||||
{
|
||||
if (!data.isEmpty()) {
|
||||
QPixmap pic;
|
||||
pic.loadFromData(data);
|
||||
profile.saveAvatar(data, getSelfPublicKey().toString());
|
||||
emit selfAvatarChanged(pic);
|
||||
} else {
|
||||
emit selfAvatarChanged(QPixmap(":/img/contact_dark.svg"));
|
||||
}
|
||||
|
||||
AvatarBroadcaster::setAvatar(data);
|
||||
AvatarBroadcaster::enableAutoBroadcast();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns our Tox ID
|
||||
*/
|
||||
|
|
|
@ -94,7 +94,6 @@ public slots:
|
|||
void setStatus(Status status);
|
||||
void setUsername(const QString& username);
|
||||
void setStatusMessage(const QString& message);
|
||||
void setAvatar(const QByteArray& data);
|
||||
|
||||
int sendMessage(uint32_t friendId, const QString& message);
|
||||
void sendGroupMessage(int groupId, const QString& message);
|
||||
|
@ -145,7 +144,6 @@ signals:
|
|||
void statusMessageSet(const QString& message);
|
||||
void statusSet(Status status);
|
||||
void idSet(const ToxId& id);
|
||||
void selfAvatarChanged(const QPixmap& pic);
|
||||
|
||||
void messageSentResult(uint32_t friendId, const QString& message, int messageId);
|
||||
void groupSentResult(int groupId, const QString& message, int result);
|
||||
|
|
|
@ -198,6 +198,8 @@ void Nexus::showMainGUI()
|
|||
GUI::setEnabled(false);
|
||||
|
||||
// Connections
|
||||
connect(profile, &Profile::selfAvatarChanged, widget, &Widget::onSelfAvatarLoaded);
|
||||
|
||||
Core* core = profile->getCore();
|
||||
connect(core, &Core::requestSent, profile, &Profile::onRequestSent);
|
||||
|
||||
|
@ -209,7 +211,6 @@ void Nexus::showMainGUI()
|
|||
connect(core, &Core::statusSet, widget, &Widget::onStatusSet);
|
||||
connect(core, &Core::usernameSet, widget, &Widget::setUsername);
|
||||
connect(core, &Core::statusMessageSet, widget, &Widget::setStatusMessage);
|
||||
connect(core, &Core::selfAvatarChanged, widget, &Widget::onSelfAvatarLoaded);
|
||||
connect(core, &Core::friendAdded, widget, &Widget::addFriend);
|
||||
connect(core, &Core::failedToAddFriend, widget, &Widget::addFriendFailed);
|
||||
connect(core, &Core::friendUsernameChanged, widget, &Widget::onFriendUsernameChanged);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "profilelocker.h"
|
||||
#include "settings.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/net/avatarbroadcaster.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/widget/gui.h"
|
||||
#include "src/widget/widget.h"
|
||||
|
@ -65,7 +66,17 @@ Profile::Profile(QString name, const QString& password, bool isNewProfile, const
|
|||
[this, password](const ToxId& id) { loadDatabase(id, password); },
|
||||
Qt::QueuedConnection);
|
||||
core->moveToThread(coreThread);
|
||||
QObject::connect(coreThread, &QThread::started, core, [=]() { core->start(toxsave); });
|
||||
QObject::connect(coreThread, &QThread::started, core, [=]() {
|
||||
core->start(toxsave);
|
||||
|
||||
QString selfPk = core->getSelfPublicKey().toString();
|
||||
QByteArray data = loadAvatarData(selfPk);
|
||||
if (data.isEmpty()) {
|
||||
qDebug() << "Self avatar not found, will broadcast empty avatar to friends";
|
||||
}
|
||||
|
||||
setAvatar(data, core->getSelfPublicKey().toString());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -439,6 +450,22 @@ void Profile::loadDatabase(const ToxId& id, QString password)
|
|||
}
|
||||
}
|
||||
|
||||
void Profile::setAvatar(QByteArray pic, const QString& ownerId)
|
||||
{
|
||||
QPixmap pixmap;
|
||||
if (!pic.isEmpty()) {
|
||||
pixmap.loadFromData(pic);
|
||||
} else {
|
||||
pixmap.load(":/img/contact_dark.svg");
|
||||
}
|
||||
|
||||
saveAvatar(pic, ownerId);
|
||||
|
||||
emit selfAvatarChanged(pixmap);
|
||||
AvatarBroadcaster::setAvatar(pic);
|
||||
AvatarBroadcaster::enableAutoBroadcast();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds history message about friendship request attempt if history is enabled
|
||||
* @param friendPk Pk of a friend which request is destined to
|
||||
|
@ -530,8 +557,9 @@ History* Profile::getHistory()
|
|||
void Profile::removeAvatar(const QString& ownerId)
|
||||
{
|
||||
QFile::remove(avatarPath(ownerId));
|
||||
if (ownerId == core->getSelfId().getPublicKey().toString())
|
||||
core->setAvatar({});
|
||||
if (ownerId == core->getSelfId().getPublicKey().toString()) {
|
||||
setAvatar({}, core->getSelfPublicKey().toString());
|
||||
}
|
||||
}
|
||||
|
||||
bool Profile::exists(QString name)
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
QPixmap loadAvatar();
|
||||
QPixmap loadAvatar(const QString& ownerId);
|
||||
QByteArray loadAvatarData(const QString& ownerId);
|
||||
void setAvatar(QByteArray pic, const QString& ownerId);
|
||||
void saveAvatar(QByteArray pic, const QString& ownerId);
|
||||
QByteArray getAvatarHash(const QString& ownerId);
|
||||
void removeAvatar(const QString& ownerId);
|
||||
|
@ -80,6 +81,9 @@ public:
|
|||
static bool isEncrypted(QString name);
|
||||
static QString getDbPath(const QString& profileName);
|
||||
|
||||
signals:
|
||||
void selfAvatarChanged(const QPixmap& pixmap);
|
||||
|
||||
public slots:
|
||||
void onRequestSent(const ToxPk& friendPk, const QString& message);
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ GroupNetCamView::GroupNetCamView(int group, QWidget* parent)
|
|||
connect(timer, &QTimer::timeout, this, &GroupNetCamView::onUpdateActivePeer);
|
||||
timer->start();
|
||||
|
||||
connect(Core::getInstance(), &Core::selfAvatarChanged, [this](const QPixmap& pixmap) {
|
||||
connect(Nexus::getProfile(), &Profile::selfAvatarChanged, [this](const QPixmap& pixmap) {
|
||||
selfVideoSurface->getVideoSurface()->setAvatar(pixmap);
|
||||
setActive();
|
||||
});
|
||||
|
|
|
@ -73,7 +73,7 @@ NetCamView::NetCamView(int friendId, QWidget* parent)
|
|||
selfFrame->resetBoundary(boundingRect);
|
||||
});
|
||||
|
||||
connections += connect(Core::getInstance(), &Core::selfAvatarChanged,
|
||||
connections += connect(Nexus::getProfile(), &Profile::selfAvatarChanged,
|
||||
[this](const QPixmap& pixmap) { selfVideoSurface->setAvatar(pixmap); });
|
||||
|
||||
connections += connect(Core::getInstance(), &Core::friendAvatarChanged,
|
||||
|
|
|
@ -305,7 +305,7 @@ void ProfileForm::onAvatarClicked()
|
|||
return;
|
||||
}
|
||||
|
||||
Nexus::getCore()->setAvatar(bytes);
|
||||
Nexus::getProfile()->setAvatar(bytes, core->getSelfPublicKey().toString());
|
||||
}
|
||||
|
||||
void ProfileForm::onRenameClicked()
|
||||
|
|
|
@ -232,6 +232,9 @@ void Widget::init()
|
|||
// connect logout tray menu action
|
||||
connect(actionLogout, &QAction::triggered, profileForm, &ProfileForm::onLogoutClicked);
|
||||
|
||||
Profile* profile = Nexus::getProfile();
|
||||
connect(profile, &Profile::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded);
|
||||
|
||||
const Settings& s = Settings::getInstance();
|
||||
Core* core = Nexus::getCore();
|
||||
CoreAV* av = core->getAv();
|
||||
|
@ -239,7 +242,6 @@ void Widget::init()
|
|||
|
||||
connect(core, &Core::fileDownloadFinished, filesForm, &FilesForm::onFileDownloadComplete);
|
||||
connect(core, &Core::fileUploadFinished, filesForm, &FilesForm::onFileUploadComplete);
|
||||
connect(core, &Core::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded);
|
||||
connect(ui->addButton, &QPushButton::clicked, this, &Widget::onAddClicked);
|
||||
connect(ui->groupButton, &QPushButton::clicked, this, &Widget::onGroupClicked);
|
||||
connect(ui->transferButton, &QPushButton::clicked, this, &Widget::onTransferClicked);
|
||||
|
|
Loading…
Reference in New Issue
Block a user