diff --git a/core/account.cpp b/core/account.cpp index 6fb26a0..89ce95c 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -440,25 +440,34 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence) } } else { if (pendingVCardRequests.find(jid) == pendingVCardRequests.end()) { + RosterItem* item = 0; std::map::const_iterator itr = contacts.find(jid); if (itr != contacts.end()) { - Contact* cnt = itr->second; + item = itr->second; + } else { + std::map::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 cData = { {"autoJoin", conf->getAutoJoin()}, {"joined", conf->getJoined()}, {"nick", conf->getNick()}, {"name", conf->getName()} - }); + }; + + if (conf->hasAvatar()) { + if (!conf->isAvatarAutoGenerated()) { + cData.insert("avatarState", static_cast(Shared::Avatar::valid)); + } else { + cData.insert("avatarState", static_cast(Shared::Avatar::autocreated)); + } + cData.insert("avatarPath", conf->avatarPath()); + } else { + cData.insert("avatarState", static_cast(Shared::Avatar::empty)); + cData.insert("avatarPath", ""); + requestVCard(jid); + } + + emit addRoom(jid, cData); } void Core::Account::addContactToGroupRequest(const QString& jid, const QString& groupName) diff --git a/ui/models/contact.cpp b/ui/models/contact.cpp index cde8941..a5390fb 100644 --- a/ui/models/contact.cpp +++ b/ui/models/contact.cpp @@ -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); diff --git a/ui/models/contact.h b/ui/models/contact.h index fda893f..f8ac346 100644 --- a/ui/models/contact.h +++ b/ui/models/contact.h @@ -21,7 +21,7 @@ #include "item.h" #include "presence.h" -#include "../../global.h" +#include "global.h" #include #include #include diff --git a/ui/models/room.cpp b/ui/models/room.cpp index a251f4d..72eafd2 100644 --- a/ui/models/room.cpp +++ b/ui/models/room.cpp @@ -27,6 +27,8 @@ Models::Room::Room(const QString& p_jid, const QMap& 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& 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(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(Shared::Avatar::valid)) { + Shared::Avatar state = static_cast(p_state); + setAvatarState(state); + } else { + qDebug() << "An attempt to set invalid avatar state" << p_state << "to the room" << jid << ", skipping"; + } +} diff --git a/ui/models/room.h b/ui/models/room.h index 71ac221..3a6ebee 100644 --- a/ui/models/room.h +++ b/ui/models/room.h @@ -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::const_iterator itr, const QMap& 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 participants; diff --git a/ui/models/roster.cpp b/ui/models/roster.cpp index 2f226f2..8e006a9 100644 --- a/ui/models/roster.cpp +++ b/ui/models/roster.cpp @@ -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(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();