avatars for mucs, some tooltip tweaks

This commit is contained in:
Blue 2019-12-17 19:54:53 +03:00
parent f367502b8e
commit 867c3a18e9
6 changed files with 111 additions and 18 deletions

View File

@ -440,25 +440,34 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence)
}
} else {
if (pendingVCardRequests.find(jid) == pendingVCardRequests.end()) {
RosterItem* item = 0;
std::map<QString, Contact*>::const_iterator itr = contacts.find(jid);
if (itr != contacts.end()) {
Contact* cnt = itr->second;
item = itr->second;
} else {
std::map<QString, Conference*>::const_iterator citr = conferences.find(jid);
if (citr != conferences.end()) {
item = citr->second;
}
}
if (item != 0) {
switch (p_presence.vCardUpdateType()) {
case QXmppPresence::VCardUpdateNone: //this presence has nothing to do with photo
break;
case QXmppPresence::VCardUpdateNotReady: //let's say the photo didn't change here
break;
case QXmppPresence::VCardUpdateNoPhoto: //there is no photo, need to drop if any
if (!cnt->hasAvatar() || (cnt->hasAvatar() && !cnt->isAvatarAutoGenerated())) {
cnt->setAutoGeneratedAvatar();
if (!item->hasAvatar() || (item->hasAvatar() && !item->isAvatarAutoGenerated())) {
item->setAutoGeneratedAvatar();
}
break;
break;
case QXmppPresence::VCardUpdateValidPhoto: //there is a photo, need to load
if (cnt->hasAvatar()) {
if (cnt->isAvatarAutoGenerated()) {
if (item->hasAvatar()) {
if (item->isAvatarAutoGenerated()) {
requestVCard(jid);
} else {
if (cnt->avatarHash() != p_presence.photoHash()) {
if (item->avatarHash() != p_presence.photoHash()) {
requestVCard(jid);
}
}
@ -1317,12 +1326,27 @@ void Core::Account::addNewRoom(const QString& jid, const QString& nick, const QS
handleNewConference(conf);
emit addRoom(jid, {
QMap<QString, QVariant> cData = {
{"autoJoin", conf->getAutoJoin()},
{"joined", conf->getJoined()},
{"nick", conf->getNick()},
{"name", conf->getName()}
});
};
if (conf->hasAvatar()) {
if (!conf->isAvatarAutoGenerated()) {
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::valid));
} else {
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::autocreated));
}
cData.insert("avatarPath", conf->avatarPath());
} else {
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::empty));
cData.insert("avatarPath", "");
requestVCard(jid);
}
emit addRoom(jid, cData);
}
void Core::Account::addContactToGroupRequest(const QString& jid, const QString& groupName)

View File

@ -258,7 +258,7 @@ QIcon Models::Contact::getStatusIcon(bool big) const
{
if (getMessagesCount() > 0) {
return Shared::icon("mail-message", big);
} else if (state == Shared::both) {
} else if (state == Shared::both || state == Shared::to) {
return Shared::availabilityIcon(availability, big);;
} else {
return Shared::subscriptionStateIcon(state, big);

View File

@ -21,7 +21,7 @@
#include "item.h"
#include "presence.h"
#include "../../global.h"
#include "global.h"
#include <QMap>
#include <QIcon>
#include <deque>

View File

@ -27,6 +27,8 @@ Models::Room::Room(const QString& p_jid, const QMap<QString, QVariant>& data, Mo
jid(p_jid),
nick(""),
subject(""),
avatarState(Shared::Avatar::empty),
avatarPath(""),
messages(),
participants()
{
@ -49,6 +51,15 @@ Models::Room::Room(const QString& p_jid, const QMap<QString, QVariant>& data, Mo
if (itr != data.end()) {
setSubject(itr.value().toString());
}
itr = data.find("avatarState");
if (itr != data.end()) {
setAvatarState(itr.value().toUInt());
}
itr = data.find("avatarPath");
if (itr != data.end()) {
setAvatarPath(itr.value().toString());
}
}
Models::Room::~Room()
@ -111,6 +122,10 @@ QVariant Models::Room::data(int column) const
return getMessagesCount();
case 6:
return getSubject();
case 7:
return static_cast<quint8>(getAvatarState());
case 8:
return getAvatarPath();
default:
return QVariant();
}
@ -165,6 +180,10 @@ void Models::Room::update(const QString& field, const QVariant& value)
setNick(value.toString());
} else if (field == "subject") {
setSubject(value.toString());
} else if (field == "avatarState") {
setAvatarState(value.toUInt());
} else if (field == "avatarPath") {
setAvatarPath(value.toString());
}
}
@ -318,3 +337,39 @@ bool Models::Room::columnInvolvedInDisplay(int col)
{
return Item::columnInvolvedInDisplay(col) && col == 1;
}
QString Models::Room::getAvatarPath() const
{
return avatarPath;
}
Shared::Avatar Models::Room::getAvatarState() const
{
return avatarState;
}
void Models::Room::setAvatarPath(const QString& path)
{
if (avatarPath != path) {
avatarPath = path;
changed(8);
}
}
void Models::Room::setAvatarState(Shared::Avatar p_state)
{
if (avatarState != p_state) {
avatarState = p_state;
changed(7);
}
}
void Models::Room::setAvatarState(unsigned int p_state)
{
if (p_state <= static_cast<quint8>(Shared::Avatar::valid)) {
Shared::Avatar state = static_cast<Shared::Avatar>(p_state);
setAvatarState(state);
} else {
qDebug() << "An attempt to set invalid avatar state" << p_state << "to the room" << jid << ", skipping";
}
}

View File

@ -21,7 +21,7 @@
#include "item.h"
#include "participant.h"
#include "../../global.h"
#include "global.h"
namespace Models {
@ -69,12 +69,17 @@ public:
void toOfflineState() override;
QString getDisplayedName() const override;
Shared::Avatar getAvatarState() const;
QString getAvatarPath() const;
private:
void handleParticipantUpdate(std::map<QString, Participant*>::const_iterator itr, const QMap<QString, QVariant>& data);
protected:
bool columnInvolvedInDisplay(int col) override;
void setAvatarState(Shared::Avatar p_state);
void setAvatarState(unsigned int p_state);
void setAvatarPath(const QString& path);
private:
bool autoJoin;
@ -82,6 +87,8 @@ private:
QString jid;
QString nick;
QString subject;
Shared::Avatar avatarState;
QString avatarPath;
Messages messages;
std::map<QString, Participant*> participants;

View File

@ -66,7 +66,6 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
case Qt::DisplayRole:
{
if (index.column() != 0) {
result = "";
break;
}
switch (item->type) {
@ -126,11 +125,17 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
}
break;
case Item::room: {
if (index.column() != 0) {
break;
}
quint8 col = index.column();
Room* room = static_cast<Room*>(item);
result = room->getStatusIcon(false);
if (col == 0) {
result = room->getStatusIcon(false);
} else if (col == 1) {
QString path = room->getAvatarPath();
if (path.size() > 0) {
result = QIcon(path);
}
}
}
break;
case Item::participant: {
@ -179,7 +184,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
}
str += tr("Jabber ID: ") + contact->getJid() + "\n";
Shared::SubscriptionState ss = contact->getState();
if (ss == Shared::both) {
if (ss == Shared::both || ss == Shared::to) {
Shared::Availability av = contact->getAvailability();
str += tr("Availability: ") + QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1());
if (av != Shared::offline) {
@ -252,6 +257,8 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
if (count > 0) {
str += tr("New messages: ") + std::to_string(count).c_str() + "\n";
}
str += tr("Jabber ID: ") + rm->getJid() + "\n";
str += tr("Subscription: ") + rm->getStatusText();
if (rm->getJoined()) {
str += QString("\n") + tr("Members: ") + std::to_string(rm->childCount()).c_str();