mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Cache avatars
This commit is contained in:
parent
ab3f2e2950
commit
ff2994a0fd
5
core.cpp
5
core.cpp
@ -210,7 +210,7 @@ void Core::start()
|
||||
tox_get_address(tox, friendAddress);
|
||||
emit friendAddressGenerated(CFriendAddress::toString(friendAddress));
|
||||
|
||||
QPixmap pic = Settings::getInstance().getSavedAvatar();
|
||||
QPixmap pic = Settings::getInstance().getSavedAvatar(getSelfId().toString());
|
||||
if (!pic.isNull() && !pic.size().isEmpty())
|
||||
{
|
||||
QByteArray data;
|
||||
@ -471,6 +471,7 @@ void Core::onAvatarDataCallback(Tox*, int32_t friendnumber, uint8_t,
|
||||
else
|
||||
{
|
||||
qDebug() << "Core: Got avatar data from "<<friendnumber<<", size:"<<pic.size();
|
||||
Settings::getInstance().saveAvatar(pic, static_cast<Core*>(core)->getFriendAddress(friendnumber));
|
||||
emit static_cast<Core*>(core)->friendAvatarChanged(friendnumber, pic);
|
||||
}
|
||||
}
|
||||
@ -783,7 +784,7 @@ void Core::setAvatar(uint8_t format, const QByteArray& data)
|
||||
|
||||
QPixmap pic;
|
||||
pic.loadFromData(data);
|
||||
Settings::getInstance().saveAvatar(pic);
|
||||
Settings::getInstance().saveAvatar(pic, getSelfId().toString());
|
||||
emit selfAvatarChanged(pic);
|
||||
}
|
||||
|
||||
|
@ -258,17 +258,17 @@ QString Settings::getSettingsDirPath()
|
||||
#endif
|
||||
}
|
||||
|
||||
QPixmap Settings::getSavedAvatar()
|
||||
QPixmap Settings::getSavedAvatar(const QString &ownerId)
|
||||
{
|
||||
QString filePath = QDir(getSettingsDirPath()).filePath(AVATAR_FILENAME);
|
||||
QString filePath = QDir(getSettingsDirPath()).filePath("avatar_"+ownerId);
|
||||
QPixmap pic;
|
||||
pic.load(filePath);
|
||||
return pic;
|
||||
}
|
||||
|
||||
void Settings::saveAvatar(QPixmap& pic)
|
||||
void Settings::saveAvatar(QPixmap& pic, const QString& ownerId)
|
||||
{
|
||||
QString filePath = QDir(getSettingsDirPath()).filePath(AVATAR_FILENAME);
|
||||
QString filePath = QDir(getSettingsDirPath()).filePath("avatar_"+ownerId);
|
||||
pic.save(filePath, "png");
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,8 @@ public:
|
||||
bool getEncryptLogs() const;
|
||||
void setEncryptLogs(bool newValue);
|
||||
|
||||
QPixmap getSavedAvatar();
|
||||
void saveAvatar(QPixmap& pic);
|
||||
QPixmap getSavedAvatar(const QString& ownerId);
|
||||
void saveAvatar(QPixmap& pic, const QString& ownerId);
|
||||
|
||||
// Assume all widgets have unique names
|
||||
// Don't use it to save every single thing you want to save, use it
|
||||
|
@ -465,6 +465,14 @@ void Widget::addFriend(int friendId, const QString &userId)
|
||||
connect(core, &Core::avMediaChange, newfriend->chatForm, &ChatForm::onAvMediaChange);
|
||||
connect(core, &Core::friendAvatarChanged, newfriend->chatForm, &ChatForm::onAvatarChange);
|
||||
connect(core, &Core::friendAvatarChanged, newfriend->widget, &FriendWidget::onAvatarChange);
|
||||
|
||||
// Try to get the avatar from the cache
|
||||
QPixmap avatar = Settings::getInstance().getSavedAvatar(userId);
|
||||
if (!avatar.isNull())
|
||||
{
|
||||
newfriend->chatForm->onAvatarChange(friendId, avatar);
|
||||
newfriend->widget->onAvatarChange(friendId, avatar);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::addFriendFailed(const QString&)
|
||||
|
Loading…
x
Reference in New Issue
Block a user