mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Initial avatars support
This commit is contained in:
parent
7ad6ad2731
commit
8de71c19ed
|
@ -14,6 +14,7 @@ However, it is not a fork.
|
|||
- Video calls
|
||||
- Tox DNS
|
||||
- Translations in various languages
|
||||
- Avatars
|
||||
|
||||
<h2>Downloads</h2>
|
||||
|
||||
|
|
30
core.cpp
30
core.cpp
|
@ -216,9 +216,10 @@ void Core::start()
|
|||
QByteArray data;
|
||||
QBuffer buffer(&data);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
pic.save(&buffer);
|
||||
pic.save(&buffer, "PNG");
|
||||
buffer.close();
|
||||
tox_set_avatar(tox, TOX_AVATARFORMAT_PNG, (uint8_t*)data.constData(), data.size());
|
||||
if (tox_set_avatar(tox, TOX_AVATARFORMAT_PNG, (uint8_t*)data.constData(), data.size()) != 0)
|
||||
qWarning() << "Core:start: Error setting avatar, size:"<<data.size();
|
||||
emit selfAvatarChanged(pic);
|
||||
}
|
||||
else
|
||||
|
@ -279,6 +280,10 @@ void Core::onUserStatusChanged(Tox*/* tox*/, int friendId, uint8_t userstatus, v
|
|||
status = Status::Online;
|
||||
break;
|
||||
}
|
||||
|
||||
if (status == Status::Online || status == Status::Away)
|
||||
tox_request_avatar_data(static_cast<Core*>(core)->tox, friendId);
|
||||
|
||||
emit static_cast<Core*>(core)->friendStatusChanged(friendId, status);
|
||||
}
|
||||
|
||||
|
@ -449,16 +454,25 @@ void Core::onFileDataCallback(Tox*, int32_t friendnumber, uint8_t filenumber, co
|
|||
file->filesize, file->bytesSent, ToxFile::RECEIVING);
|
||||
}
|
||||
|
||||
void Core::onAvatarInfoCallback(Tox* tox, int32_t friendnumber, uint8_t format,
|
||||
uint8_t *hash, void *userdata)
|
||||
void Core::onAvatarInfoCallback(Tox*, int32_t friendnumber, uint8_t format,
|
||||
uint8_t *, void *)
|
||||
{
|
||||
qDebug() << "Core: Got avatar info from "<<friendnumber;
|
||||
qDebug() << "Core: Got avatar info from "<<friendnumber
|
||||
<<": format "<<format;
|
||||
}
|
||||
|
||||
void Core::onAvatarDataCallback(Tox* tox, int32_t friendnumber, uint8_t format,
|
||||
uint8_t *hash, uint8_t *data, uint32_t datalen, void *userdata)
|
||||
void Core::onAvatarDataCallback(Tox*, int32_t friendnumber, uint8_t,
|
||||
uint8_t *, uint8_t *data, uint32_t datalen, void *core)
|
||||
{
|
||||
qDebug() << "Core: Got avatar data from "<<friendnumber;
|
||||
QPixmap pic;
|
||||
pic.loadFromData((uchar*)data, datalen);
|
||||
if (pic.isNull())
|
||||
qDebug() << "Core: Got invalid avatar data from "<<friendnumber;
|
||||
else
|
||||
{
|
||||
qDebug() << "Core: Got avatar data from "<<friendnumber<<", size:"<<pic.size();
|
||||
emit static_cast<Core*>(core)->friendAvatarChanged(friendnumber, pic);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::acceptFriendRequest(const QString& userId)
|
||||
|
|
1
core.h
1
core.h
|
@ -106,6 +106,7 @@ signals:
|
|||
void friendStatusMessageChanged(int friendId, const QString& message);
|
||||
void friendUsernameChanged(int friendId, const QString& username);
|
||||
void friendTypingChanged(int friendId, bool isTyping);
|
||||
void friendAvatarChanged(int friendId, const QPixmap& pic);
|
||||
|
||||
void friendStatusMessageLoaded(int friendId, const QString& message);
|
||||
void friendUsernameLoaded(int friendId, const QString& username);
|
||||
|
|
|
@ -464,3 +464,11 @@ void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
|
|||
|
||||
addSystemInfoMessage("File: \"" + fname + "\" failed to send.", "red");
|
||||
}
|
||||
|
||||
void ChatForm::onAvatarChange(int FriendId, const QPixmap &pic)
|
||||
{
|
||||
if (FriendId != f->friendId)
|
||||
return;
|
||||
|
||||
avatarLabel->setPixmap(pic);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
struct Friend;
|
||||
class FileTransferInstance;
|
||||
class NetCamView;
|
||||
class QPixmap;
|
||||
|
||||
class ChatForm : public GenericChatForm
|
||||
{
|
||||
|
@ -55,6 +56,7 @@ public slots:
|
|||
void onAvPeerTimeout(int FriendId, int CallId);
|
||||
void onAvMediaChange(int FriendId, int CallId, bool video);
|
||||
void onMicMuteToggle();
|
||||
void onAvatarChange(int FriendId, const QPixmap& pic);
|
||||
|
||||
private slots:
|
||||
void onSendTriggered();
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
class QLayout;
|
||||
class QGridLayout;
|
||||
class QPixmap;
|
||||
|
||||
class FriendListWidget : public QWidget
|
||||
{
|
||||
|
|
|
@ -190,3 +190,11 @@ void FriendWidget::resetEventFlags()
|
|||
Friend* f = FriendList::findFriend(friendId);
|
||||
f->hasNewEvents = 0;
|
||||
}
|
||||
|
||||
void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)
|
||||
{
|
||||
if (FriendId != friendId)
|
||||
return;
|
||||
|
||||
avatar.setPixmap(pic);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "genericchatroomwidget.h"
|
||||
#include "croppinglabel.h"
|
||||
|
||||
class QPixmap;
|
||||
|
||||
struct FriendWidget : public GenericChatroomWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -39,6 +41,9 @@ signals:
|
|||
void removeFriend(int friendId);
|
||||
void copyFriendIdToClipboard(int friendId);
|
||||
|
||||
public slots:
|
||||
void onAvatarChange(int FriendId, const QPixmap& pic);
|
||||
|
||||
public:
|
||||
int friendId;
|
||||
QLabel avatar, statusPic;
|
||||
|
|
|
@ -168,6 +168,7 @@ Widget::Widget(QWidget *parent)
|
|||
qRegisterMetaType<uint8_t>("uint8_t");
|
||||
qRegisterMetaType<int32_t>("int32_t");
|
||||
qRegisterMetaType<int64_t>("int64_t");
|
||||
qRegisterMetaType<QPixmap>("QPixmap");
|
||||
qRegisterMetaType<ToxFile>("ToxFile");
|
||||
qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
|
||||
|
||||
|
@ -435,7 +436,6 @@ void Widget::setStatusMessage(const QString &statusMessage)
|
|||
|
||||
void Widget::addFriend(int friendId, const QString &userId)
|
||||
{
|
||||
|
||||
qDebug() << "Widget: Adding friend with id "+userId;
|
||||
Friend* newfriend = FriendList::addFriend(friendId, userId);
|
||||
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline);
|
||||
|
@ -463,6 +463,8 @@ void Widget::addFriend(int friendId, const QString &userId)
|
|||
connect(core, &Core::avRequestTimeout, newfriend->chatForm, &ChatForm::onAvRequestTimeout);
|
||||
connect(core, &Core::avPeerTimeout, newfriend->chatForm, &ChatForm::onAvPeerTimeout);
|
||||
connect(core, &Core::avMediaChange, newfriend->chatForm, &ChatForm::onAvMediaChange);
|
||||
connect(core, &Core::friendAvatarChanged, newfriend->chatForm, &ChatForm::onAvatarChange);
|
||||
connect(core, &Core::friendAvatarChanged, newfriend->widget, &FriendWidget::onAvatarChange);
|
||||
}
|
||||
|
||||
void Widget::addFriendFailed(const QString&)
|
||||
|
|
Loading…
Reference in New Issue
Block a user