diff --git a/core.cpp b/core.cpp index 11a27b612..9b7f7913c 100644 --- a/core.cpp +++ b/core.cpp @@ -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/.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 "<(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)->getFriendAddress(friendnumber)); emit static_cast(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; iwidget, &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;