1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

revert special self avatar

This commit is contained in:
dubslow 2014-09-27 17:19:30 -05:00
parent b1b89ac1f4
commit eb67f9b3dd
3 changed files with 17 additions and 27 deletions

View File

@ -210,8 +210,7 @@ void Core::start()
tox_get_address(tox, friendAddress);
emit friendAddressGenerated(CFriendAddress::toString(friendAddress));
QPixmap pic;
pic.load(QDir(Settings::getInstance().getSettingsDirPath()).filePath("avatar.png"));
QPixmap pic = Settings::getInstance().getSavedAvatar(getSelfId().toString());
if (!pic.isNull() && !pic.size().isEmpty())
{
QByteArray data;
@ -222,22 +221,7 @@ void Core::start()
setAvatar(TOX_AVATAR_FORMAT_PNG, data);
}
else
{
qDebug() << "Core: self avatar missing, trying by id";
// this will leave a avatars/<selfid>.png duplicate of avatar.png, but whatever
QPixmap pic = Settings::getInstance().getSavedAvatar(getSelfId().toString());
if (!pic.isNull() && !pic.size().isEmpty())
{
QByteArray data;
QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly);
pic.save(&buffer, "PNG");
buffer.close();
setAvatar(TOX_AVATAR_FORMAT_PNG, data);
}
else
qDebug() << "Core: Error loading self avatar";
}
qDebug() << "Core: Error loading self avatar";
bootstrapDht();
@ -490,8 +474,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).left(64));
// ignore nospam (good idea, and also the addFriend funcs which call getAvatar don't have it)
Settings::getInstance().saveAvatar(pic, static_cast<Core*>(core)->getFriendAddress(friendnumber));
emit static_cast<Core*>(core)->friendAvatarChanged(friendnumber, pic);
}
}
@ -804,10 +787,14 @@ void Core::setAvatar(uint8_t format, const QByteArray& data)
QPixmap pic;
pic.loadFromData(data);
QString path = QDir(Settings::getInstance().getSettingsDirPath()).filePath("avatar.png");
pic.save(path, "png");
Settings::getInstance().saveAvatar(pic, getSelfId().toString());
emit selfAvatarChanged(pic);
// according to tox.h, we need not broadcast ourselves, that's done in tox_set_avatar
// Broadcast our new avatar!
// according to tox.h, we need not broadcast this ourselves, but initial testing indicated elsewise
const uint32_t friendCount = tox_count_friendlist(tox);;
for (unsigned i=0; i<friendCount; i++)
tox_send_avatar_info(tox, i);
}
ToxID Core::getSelfId()

View File

@ -260,12 +260,14 @@ QString Settings::getSettingsDirPath()
QPixmap Settings::getSavedAvatar(const QString &ownerId)
{
QDir dir(getSettingsDirPath());
QString filePath = dir.filePath("avatars/"+ownerId+".png");
QString filePath = dir.filePath("avatars/"+ownerId.left(64)+".png");
QFileInfo info(filePath);
QPixmap pic;
if (!info.exists())
{
QString filePath = dir.filePath("avatar_"+ownerId);
QString filePath = dir.filePath("avatar_"+ownerId.left(64));
if (!QFileInfo(filePath).exists()) // try without truncation, for old self avatars
QString filePath = dir.filePath("avatar_"+ownerId);
pic.load(filePath);
saveAvatar(pic, ownerId);
QFile::remove(filePath);
@ -279,7 +281,8 @@ void Settings::saveAvatar(QPixmap& pic, const QString& ownerId)
{
QDir dir(getSettingsDirPath());
dir.mkdir("avatars/"); // remove this in a week or two hopefully
QString filePath = dir.filePath("avatars/"+ownerId+".png");
// ignore nospam (good idea, and also the addFriend funcs which call getAvatar don't have it)
QString filePath = dir.filePath("avatars/"+ownerId.left(64)+".png");
pic.save(filePath, "png");
}

View File

@ -477,7 +477,7 @@ void Widget::addFriend(int friendId, const QString &userId)
connect(core, &Core::friendAvatarRemoved, newfriend->widget, &FriendWidget::onAvatarRemoved);
// Try to get the avatar from the cache
QPixmap avatar = Settings::getInstance().getSavedAvatar(userId.left(64)); // just to be safe
QPixmap avatar = Settings::getInstance().getSavedAvatar(userId);
if (!avatar.isNull())
{
qWarning() << "Widget: loadded avatar for id" << userId;