From d050cd82dde47e1b74c6bcd4b34cd87fbb4afb35 Mon Sep 17 00:00:00 2001 From: blue Date: Sat, 19 Oct 2019 22:34:25 +0300 Subject: [PATCH] some lines to vCard object --- core/account.cpp | 38 +++++++++++++++++++ core/account.h | 2 + global.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ global.h | 17 +++++++++ 4 files changed, 153 insertions(+) diff --git a/core/account.cpp b/core/account.cpp index a14e60f..1da14a3 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -1341,6 +1341,7 @@ void Core::Account::onVCardReceived(const QXmppVCardIq& card) if (confItr == conferences.end()) { if (jid == getLogin() + "@" + getServer()) { onOwnVCardReceived(card); + } else { qDebug() << "received vCard" << jid << "doesn't belong to any of known contacts or conferences, skipping"; } @@ -1353,11 +1354,32 @@ void Core::Account::onVCardReceived(const QXmppVCardIq& card) } QByteArray ava = card.photo(); + if (ava.size() > 0) { item->setAvatar(ava); } else { item->setAutoGeneratedAvatar(); } + + Shared::VCard vCard; + vCard.setFirstName(card.firstName()); + vCard.setMiddleName(card.middleName()); + vCard.setLastName(card.lastName()); + vCard.setBirthday(card.birthday()); + vCard.setNickName(card.nickName()); + vCard.setDescription(card.description()); + if (item->hasAvatar()) { + if (item->isAvatarAutoGenerated()) { + vCard.setAvatarType(Shared::Avatar::valid); + } else { + vCard.setAvatarType(Shared::Avatar::autocreated); + } + vCard.setAvatarPath(item->avatarPath()); + } else { + vCard.setAvatarType(Shared::Avatar::empty); + } + + emit receivedVCard(jid, vCard); } void Core::Account::onOwnVCardReceived(const QXmppVCardIq& card) @@ -1438,6 +1460,22 @@ void Core::Account::onOwnVCardReceived(const QXmppVCardIq& card) } ownVCardRequestInProgress = false; + + Shared::VCard vCard; + vCard.setFirstName(card.firstName()); + vCard.setMiddleName(card.middleName()); + vCard.setLastName(card.lastName()); + vCard.setBirthday(card.birthday()); + vCard.setNickName(card.nickName()); + vCard.setDescription(card.description()); + if (avatarType.size() > 0) { + vCard.setAvatarType(Shared::Avatar::valid); + vCard.setAvatarPath(path + "avatar." + avatarType); + } else { + vCard.setAvatarType(Shared::Avatar::empty); + } + + emit receivedVCard(getLogin() + "@" + getServer(), vCard); } QString Core::Account::getAvatarPath() const diff --git a/core/account.h b/core/account.h index f9d8469..b5b8c46 100644 --- a/core/account.h +++ b/core/account.h @@ -87,6 +87,7 @@ public: void setRoomAutoJoin(const QString& jid, bool joined); void removeRoomRequest(const QString& jid); void addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin); + void requestVCard(const QString& jid); signals: void changed(const QMap& data); @@ -109,6 +110,7 @@ signals: void addRoomParticipant(const QString& jid, const QString& nickName, const QMap& data); void changeRoomParticipant(const QString& jid, const QString& nickName, const QMap& data); void removeRoomParticipant(const QString& jid, const QString& nickName); + void receivedVCard(const QString& jid, const Shared::VCard& card); private: QString name; diff --git a/global.cpp b/global.cpp index e9156fd..fa63539 100644 --- a/global.cpp +++ b/global.cpp @@ -353,6 +353,102 @@ Shared::VCard::VCard(const QDateTime& creationTime): { } +QString Shared::VCard::getAvatarPath() const +{ + return photoPath; +} + +Shared::Avatar Shared::VCard::getAvatarType() const +{ + return photoType; +} + +QDate Shared::VCard::getBirthday() const +{ + return birthday; +} + +QString Shared::VCard::getDescription() const +{ + return description; +} + +QString Shared::VCard::getFirstName() const +{ + return firstName; +} + +QString Shared::VCard::getLastName() const +{ + return lastName; +} + +QString Shared::VCard::getMiddleName() const +{ + return middleName; +} + +QString Shared::VCard::getNickName() const +{ + return nickName; +} + +void Shared::VCard::setAvatarPath(const QString& path) +{ + if (path != photoPath) { + photoPath = path; + } +} + +void Shared::VCard::setAvatarType(Shared::Avatar type) +{ + if (photoType != type) { + photoType = type; + } +} + +void Shared::VCard::setBirthday(const QDate& date) +{ + if (date.isValid() && birthday != date) { + birthday = date; + } +} + +void Shared::VCard::setDescription(const QString& descr) +{ + if (description != descr) { + description = descr; + } +} + +void Shared::VCard::setFirstName(const QString& first) +{ + if (firstName != first) { + firstName = first; + } +} + +void Shared::VCard::setLastName(const QString& last) +{ + if (lastName != last) { + lastName = last; + } +} + +void Shared::VCard::setMiddleName(const QString& middle) +{ + if (middleName != middle) { + middleName = middle; + } +} + +void Shared::VCard::setNickName(const QString& nick) +{ + if (nickName != nick) { + nickName = nick; + } +} + QIcon Shared::availabilityIcon(Shared::Availability av, bool big) { const std::deque& fallback = QApplication::palette().window().color().lightnessF() > 0.5 ? diff --git a/global.h b/global.h index e0acd91..b20e616 100644 --- a/global.h +++ b/global.h @@ -272,6 +272,23 @@ public: VCard(); VCard(const QDateTime& creationTime); + QString getFirstName() const; + void setFirstName(const QString& first); + QString getMiddleName() const; + void setMiddleName(const QString& middle); + QString getLastName() const; + void setLastName(const QString& last); + QString getNickName() const; + void setNickName(const QString& nick); + QString getDescription() const; + void setDescription(const QString& descr); + QDate getBirthday() const; + void setBirthday(const QDate& date); + Avatar getAvatarType() const; + void setAvatarType(Avatar type); + QString getAvatarPath() const; + void setAvatarPath(const QString& path); + private: QString firstName; QString middleName;