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 { } else {
if (pendingVCardRequests.find(jid) == pendingVCardRequests.end()) { if (pendingVCardRequests.find(jid) == pendingVCardRequests.end()) {
RosterItem* item = 0;
std::map<QString, Contact*>::const_iterator itr = contacts.find(jid); std::map<QString, Contact*>::const_iterator itr = contacts.find(jid);
if (itr != contacts.end()) { 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()) { switch (p_presence.vCardUpdateType()) {
case QXmppPresence::VCardUpdateNone: //this presence has nothing to do with photo case QXmppPresence::VCardUpdateNone: //this presence has nothing to do with photo
break; break;
case QXmppPresence::VCardUpdateNotReady: //let's say the photo didn't change here case QXmppPresence::VCardUpdateNotReady: //let's say the photo didn't change here
break; break;
case QXmppPresence::VCardUpdateNoPhoto: //there is no photo, need to drop if any case QXmppPresence::VCardUpdateNoPhoto: //there is no photo, need to drop if any
if (!cnt->hasAvatar() || (cnt->hasAvatar() && !cnt->isAvatarAutoGenerated())) { if (!item->hasAvatar() || (item->hasAvatar() && !item->isAvatarAutoGenerated())) {
cnt->setAutoGeneratedAvatar(); item->setAutoGeneratedAvatar();
} }
break; break;
case QXmppPresence::VCardUpdateValidPhoto: //there is a photo, need to load case QXmppPresence::VCardUpdateValidPhoto: //there is a photo, need to load
if (cnt->hasAvatar()) { if (item->hasAvatar()) {
if (cnt->isAvatarAutoGenerated()) { if (item->isAvatarAutoGenerated()) {
requestVCard(jid); requestVCard(jid);
} else { } else {
if (cnt->avatarHash() != p_presence.photoHash()) { if (item->avatarHash() != p_presence.photoHash()) {
requestVCard(jid); requestVCard(jid);
} }
} }
@ -1317,12 +1326,27 @@ void Core::Account::addNewRoom(const QString& jid, const QString& nick, const QS
handleNewConference(conf); handleNewConference(conf);
emit addRoom(jid, { QMap<QString, QVariant> cData = {
{"autoJoin", conf->getAutoJoin()}, {"autoJoin", conf->getAutoJoin()},
{"joined", conf->getJoined()}, {"joined", conf->getJoined()},
{"nick", conf->getNick()}, {"nick", conf->getNick()},
{"name", conf->getName()} {"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) 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) { if (getMessagesCount() > 0) {
return Shared::icon("mail-message", big); return Shared::icon("mail-message", big);
} else if (state == Shared::both) { } else if (state == Shared::both || state == Shared::to) {
return Shared::availabilityIcon(availability, big);; return Shared::availabilityIcon(availability, big);;
} else { } else {
return Shared::subscriptionStateIcon(state, big); return Shared::subscriptionStateIcon(state, big);

View File

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

View File

@ -27,6 +27,8 @@ Models::Room::Room(const QString& p_jid, const QMap<QString, QVariant>& data, Mo
jid(p_jid), jid(p_jid),
nick(""), nick(""),
subject(""), subject(""),
avatarState(Shared::Avatar::empty),
avatarPath(""),
messages(), messages(),
participants() participants()
{ {
@ -49,6 +51,15 @@ Models::Room::Room(const QString& p_jid, const QMap<QString, QVariant>& data, Mo
if (itr != data.end()) { if (itr != data.end()) {
setSubject(itr.value().toString()); 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() Models::Room::~Room()
@ -111,6 +122,10 @@ QVariant Models::Room::data(int column) const
return getMessagesCount(); return getMessagesCount();
case 6: case 6:
return getSubject(); return getSubject();
case 7:
return static_cast<quint8>(getAvatarState());
case 8:
return getAvatarPath();
default: default:
return QVariant(); return QVariant();
} }
@ -165,6 +180,10 @@ void Models::Room::update(const QString& field, const QVariant& value)
setNick(value.toString()); setNick(value.toString());
} else if (field == "subject") { } else if (field == "subject") {
setSubject(value.toString()); 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; 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 "item.h"
#include "participant.h" #include "participant.h"
#include "../../global.h" #include "global.h"
namespace Models { namespace Models {
@ -69,12 +69,17 @@ public:
void toOfflineState() override; void toOfflineState() override;
QString getDisplayedName() const override; QString getDisplayedName() const override;
Shared::Avatar getAvatarState() const;
QString getAvatarPath() const;
private: private:
void handleParticipantUpdate(std::map<QString, Participant*>::const_iterator itr, const QMap<QString, QVariant>& data); void handleParticipantUpdate(std::map<QString, Participant*>::const_iterator itr, const QMap<QString, QVariant>& data);
protected: protected:
bool columnInvolvedInDisplay(int col) override; bool columnInvolvedInDisplay(int col) override;
void setAvatarState(Shared::Avatar p_state);
void setAvatarState(unsigned int p_state);
void setAvatarPath(const QString& path);
private: private:
bool autoJoin; bool autoJoin;
@ -82,6 +87,8 @@ private:
QString jid; QString jid;
QString nick; QString nick;
QString subject; QString subject;
Shared::Avatar avatarState;
QString avatarPath;
Messages messages; Messages messages;
std::map<QString, Participant*> participants; std::map<QString, Participant*> participants;

View File

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