1
0
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:
Tux3 / Mlkj / !Lev.uXFMLA 2014-09-24 17:28:38 +02:00
parent 7ad6ad2731
commit 8de71c19ed
9 changed files with 51 additions and 9 deletions

View File

@ -14,6 +14,7 @@ However, it is not a fork.
- Video calls - Video calls
- Tox DNS - Tox DNS
- Translations in various languages - Translations in various languages
- Avatars
<h2>Downloads</h2> <h2>Downloads</h2>

View File

@ -216,9 +216,10 @@ void Core::start()
QByteArray data; QByteArray data;
QBuffer buffer(&data); QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
pic.save(&buffer); pic.save(&buffer, "PNG");
buffer.close(); 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); emit selfAvatarChanged(pic);
} }
else else
@ -279,6 +280,10 @@ void Core::onUserStatusChanged(Tox*/* tox*/, int friendId, uint8_t userstatus, v
status = Status::Online; status = Status::Online;
break; 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); 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); file->filesize, file->bytesSent, ToxFile::RECEIVING);
} }
void Core::onAvatarInfoCallback(Tox* tox, int32_t friendnumber, uint8_t format, void Core::onAvatarInfoCallback(Tox*, int32_t friendnumber, uint8_t format,
uint8_t *hash, void *userdata) 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, void Core::onAvatarDataCallback(Tox*, int32_t friendnumber, uint8_t,
uint8_t *hash, uint8_t *data, uint32_t datalen, void *userdata) 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) void Core::acceptFriendRequest(const QString& userId)

1
core.h
View File

@ -106,6 +106,7 @@ signals:
void friendStatusMessageChanged(int friendId, const QString& message); void friendStatusMessageChanged(int friendId, const QString& message);
void friendUsernameChanged(int friendId, const QString& username); void friendUsernameChanged(int friendId, const QString& username);
void friendTypingChanged(int friendId, bool isTyping); void friendTypingChanged(int friendId, bool isTyping);
void friendAvatarChanged(int friendId, const QPixmap& pic);
void friendStatusMessageLoaded(int friendId, const QString& message); void friendStatusMessageLoaded(int friendId, const QString& message);
void friendUsernameLoaded(int friendId, const QString& username); void friendUsernameLoaded(int friendId, const QString& username);

View File

@ -464,3 +464,11 @@ void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
addSystemInfoMessage("File: \"" + fname + "\" failed to send.", "red"); addSystemInfoMessage("File: \"" + fname + "\" failed to send.", "red");
} }
void ChatForm::onAvatarChange(int FriendId, const QPixmap &pic)
{
if (FriendId != f->friendId)
return;
avatarLabel->setPixmap(pic);
}

View File

@ -23,6 +23,7 @@
struct Friend; struct Friend;
class FileTransferInstance; class FileTransferInstance;
class NetCamView; class NetCamView;
class QPixmap;
class ChatForm : public GenericChatForm class ChatForm : public GenericChatForm
{ {
@ -55,6 +56,7 @@ public slots:
void onAvPeerTimeout(int FriendId, int CallId); void onAvPeerTimeout(int FriendId, int CallId);
void onAvMediaChange(int FriendId, int CallId, bool video); void onAvMediaChange(int FriendId, int CallId, bool video);
void onMicMuteToggle(); void onMicMuteToggle();
void onAvatarChange(int FriendId, const QPixmap& pic);
private slots: private slots:
void onSendTriggered(); void onSendTriggered();

View File

@ -23,6 +23,7 @@
class QLayout; class QLayout;
class QGridLayout; class QGridLayout;
class QPixmap;
class FriendListWidget : public QWidget class FriendListWidget : public QWidget
{ {

View File

@ -190,3 +190,11 @@ void FriendWidget::resetEventFlags()
Friend* f = FriendList::findFriend(friendId); Friend* f = FriendList::findFriend(friendId);
f->hasNewEvents = 0; f->hasNewEvents = 0;
} }
void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)
{
if (FriendId != friendId)
return;
avatar.setPixmap(pic);
}

View File

@ -22,6 +22,8 @@
#include "genericchatroomwidget.h" #include "genericchatroomwidget.h"
#include "croppinglabel.h" #include "croppinglabel.h"
class QPixmap;
struct FriendWidget : public GenericChatroomWidget struct FriendWidget : public GenericChatroomWidget
{ {
Q_OBJECT Q_OBJECT
@ -39,6 +41,9 @@ signals:
void removeFriend(int friendId); void removeFriend(int friendId);
void copyFriendIdToClipboard(int friendId); void copyFriendIdToClipboard(int friendId);
public slots:
void onAvatarChange(int FriendId, const QPixmap& pic);
public: public:
int friendId; int friendId;
QLabel avatar, statusPic; QLabel avatar, statusPic;

View File

@ -168,6 +168,7 @@ Widget::Widget(QWidget *parent)
qRegisterMetaType<uint8_t>("uint8_t"); qRegisterMetaType<uint8_t>("uint8_t");
qRegisterMetaType<int32_t>("int32_t"); qRegisterMetaType<int32_t>("int32_t");
qRegisterMetaType<int64_t>("int64_t"); qRegisterMetaType<int64_t>("int64_t");
qRegisterMetaType<QPixmap>("QPixmap");
qRegisterMetaType<ToxFile>("ToxFile"); qRegisterMetaType<ToxFile>("ToxFile");
qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection"); qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
@ -435,7 +436,6 @@ void Widget::setStatusMessage(const QString &statusMessage)
void Widget::addFriend(int friendId, const QString &userId) void Widget::addFriend(int friendId, const QString &userId)
{ {
qDebug() << "Widget: Adding friend with id "+userId; qDebug() << "Widget: Adding friend with id "+userId;
Friend* newfriend = FriendList::addFriend(friendId, userId); Friend* newfriend = FriendList::addFriend(friendId, userId);
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline); 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::avRequestTimeout, newfriend->chatForm, &ChatForm::onAvRequestTimeout);
connect(core, &Core::avPeerTimeout, newfriend->chatForm, &ChatForm::onAvPeerTimeout); connect(core, &Core::avPeerTimeout, newfriend->chatForm, &ChatForm::onAvPeerTimeout);
connect(core, &Core::avMediaChange, newfriend->chatForm, &ChatForm::onAvMediaChange); 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&) void Widget::addFriendFailed(const QString&)