forked from blue/squawk
offline avatars in mucs
This commit is contained in:
parent
29c7d31c89
commit
21c7d65027
16 changed files with 225 additions and 45 deletions
|
@ -410,28 +410,37 @@ bool Core::RosterItem::isMuc() const
|
|||
|
||||
QString Core::RosterItem::avatarPath(const QString& resource) const
|
||||
{
|
||||
QString path(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
||||
path += "/" + account + "/" + jid + "/" + (resource.size() == 0 ? jid : resource);
|
||||
QString path = folderPath() + "/" + (resource.size() == 0 ? jid : resource);
|
||||
return path;
|
||||
}
|
||||
|
||||
bool Core::RosterItem::setAvatar(const QByteArray& data, const QString& resource)
|
||||
QString Core::RosterItem::folderPath() const
|
||||
{
|
||||
bool result = archive->setAvatar(data, false, resource);
|
||||
QString path(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
||||
path += "/" + account + "/" + jid;
|
||||
return path;
|
||||
}
|
||||
|
||||
bool Core::RosterItem::setAvatar(const QByteArray& data, Archive::AvatarInfo& info, const QString& resource)
|
||||
{
|
||||
bool result = archive->setAvatar(data, info, false, resource);
|
||||
if (resource.size() == 0 && result) {
|
||||
if (data.size() == 0) {
|
||||
emit avatarChanged(Shared::Avatar::empty, "");
|
||||
} else {
|
||||
QMimeDatabase db;
|
||||
QMimeType type = db.mimeTypeForData(data);
|
||||
QString ext = type.preferredSuffix();
|
||||
emit avatarChanged(Shared::Avatar::valid, avatarPath(resource) + "." + ext);
|
||||
emit avatarChanged(Shared::Avatar::valid, avatarPath(resource) + "." + info.type);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Core::RosterItem::setAutoGeneratedAvatar(const QString& resource)
|
||||
{
|
||||
Archive::AvatarInfo info;
|
||||
return setAutoGeneratedAvatar(info, resource);
|
||||
}
|
||||
|
||||
bool Core::RosterItem::setAutoGeneratedAvatar(Archive::AvatarInfo& info, const QString& resource)
|
||||
{
|
||||
QImage image(96, 96, QImage::Format_ARGB32_Premultiplied);
|
||||
QPainter painter(&image);
|
||||
|
@ -453,7 +462,7 @@ bool Core::RosterItem::setAutoGeneratedAvatar(const QString& resource)
|
|||
stream.open(QBuffer::WriteOnly);
|
||||
image.save(&stream, "PNG");
|
||||
stream.close();
|
||||
bool result = archive->setAvatar(arr, true, resource);
|
||||
bool result = archive->setAvatar(arr, info, true, resource);
|
||||
if (resource.size() == 0 && result) {
|
||||
emit avatarChanged(Shared::Avatar::autocreated, avatarPath(resource) + ".png");
|
||||
}
|
||||
|
@ -468,6 +477,7 @@ bool Core::RosterItem::readAvatarInfo(Archive::AvatarInfo& target, const QString
|
|||
Shared::VCard Core::RosterItem::handleResponseVCard(const QXmppVCardIq& card, const QString& resource)
|
||||
{
|
||||
Archive::AvatarInfo info;
|
||||
Archive::AvatarInfo newInfo;
|
||||
bool hasAvatar = readAvatarInfo(info, resource);
|
||||
|
||||
QByteArray ava = card.photo();
|
||||
|
@ -477,13 +487,10 @@ Shared::VCard Core::RosterItem::handleResponseVCard(const QXmppVCardIq& card, co
|
|||
QString path = "";
|
||||
|
||||
if (ava.size() > 0) {
|
||||
bool changed = setAvatar(ava, resource);
|
||||
bool changed = setAvatar(ava, newInfo, resource);
|
||||
if (changed) {
|
||||
type = Shared::Avatar::valid;
|
||||
QMimeDatabase db;
|
||||
QMimeType type = db.mimeTypeForData(ava);
|
||||
QString ext = type.preferredSuffix();
|
||||
path = avatarPath(resource) + "." + ext;
|
||||
path = avatarPath(resource) + "." + newInfo.type;
|
||||
} else if (hasAvatar) {
|
||||
if (info.autogenerated) {
|
||||
type = Shared::Avatar::autocreated;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue