From 4f295fee3ca6695178b8f8a1095a48c2bbfaae16 Mon Sep 17 00:00:00 2001 From: blue Date: Fri, 17 Mar 2023 23:59:51 +0300 Subject: [PATCH] trust summary gui delivery --- core/account.cpp | 32 ++++++---- core/account.h | 6 +- core/handlers/omemohandler.cpp | 6 +- core/handlers/omemohandler.h | 3 +- core/handlers/rosterhandler.cpp | 3 + core/handlers/trusthandler.cpp | 50 ++++++++++----- core/handlers/trusthandler.h | 9 ++- shared/global.cpp | 50 +++++---------- shared/global.h | 4 +- shared/trustsummary.cpp | 11 ++++ shared/trustsummary.h | 10 +++ ui/models/contact.cpp | 109 +++++++++++++++----------------- ui/models/contact.h | 19 ++++-- 13 files changed, 169 insertions(+), 143 deletions(-) diff --git a/core/account.cpp b/core/account.cpp index 3e713c4..736d5ae 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -21,9 +21,15 @@ #include -using namespace Core; - -Account::Account(const QString& p_login, const QString& p_server, const QString& p_password, const QString& p_name, bool p_active, NetworkAccess* p_net, QObject* parent): +Core::Account::Account( + const QString& p_login, + const QString& p_server, + const QString& p_password, + const QString& p_name, + bool p_active, + NetworkAccess* p_net, + QObject* parent +): QObject(parent), name(p_name), archiveQueries(), @@ -36,13 +42,15 @@ Account::Account(const QString& p_login, const QString& p_server, const QString& rh(new RosterHandler(this)), vh(new VCardHandler(this)), dh(new DiscoveryHandler(this)), -#ifdef WITH_OMEMO +#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0) th(new TrustHandler(this)), +#endif +#ifdef WITH_OMEMO oh(new OmemoHandler(this)), - tm(new QXmppTrustManager(th)), om(new QXmppOmemoManager(oh)), #endif #if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0) + tm(new QXmppTrustManager(th)), cm(new QXmppCarbonManagerV2()), psm(new QXmppPubSubManager()), #else @@ -157,7 +165,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString& } } -Account::~Account() { +Core::Account::~Account() { if (reconnectScheduled) { reconnectScheduled = false; reconnectTimer->stop(); @@ -701,9 +709,7 @@ void Core::Account::setActive(bool p_active) { if (active != p_active) { active = p_active; - emit changed({ - {"active", active} - }); + emit changed({{"active", active}}); } } @@ -795,14 +801,12 @@ void Core::Account::addContactToGroupRequest(const QString& jid, const QString& void Core::Account::removeContactFromGroupRequest(const QString& jid, const QString& groupName) { rh->removeContactFromGroupRequest(jid, groupName);} -void Core::Account::renameContactRequest(const QString& jid, const QString& newName) -{ +void Core::Account::renameContactRequest(const QString& jid, const QString& newName) { Contact* cnt = rh->getContact(jid); - if (cnt == 0) { + if (cnt == 0) qDebug() << "An attempt to rename non existing contact" << jid << "of account" << name << ", skipping"; - } else { + else rm->renameItem(jid, newName); - } } void Core::Account::invalidatePassword() { diff --git a/core/account.h b/core/account.h index 26365c1..fe3988c 100644 --- a/core/account.h +++ b/core/account.h @@ -191,14 +191,16 @@ private: RosterHandler* rh; VCardHandler* vh; DiscoveryHandler* dh; -#ifdef WITH_OMEMO +#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0) TrustHandler* th; +#endif +#ifdef WITH_OMEMO OmemoHandler* oh; - QXmppTrustManager* tm; QXmppOmemoManager* om; #endif #if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0) + QXmppTrustManager* tm; QXmppCarbonManagerV2* cm; QXmppPubSubManager* psm; #else diff --git a/core/handlers/omemohandler.cpp b/core/handlers/omemohandler.cpp index 4bccc4b..c8bcb17 100644 --- a/core/handlers/omemohandler.cpp +++ b/core/handlers/omemohandler.cpp @@ -19,8 +19,6 @@ #include "core/account.h" #include "core/adapterfunctions.h" -constexpr const char* ns_omemo_2 = "urn:xmpp:omemo:2"; - Core::OmemoHandler::OmemoHandler(Account* account) : QObject(), QXmppOmemoStorage(), @@ -182,7 +180,7 @@ void Core::OmemoHandler::requestOwnBundles() { void Core::OmemoHandler::onBundlesReceived(const QString& jid) { std::list keys; acc->oh->getDevices(jid, keys); - std::map trustLevels = acc->th->getKeys(ns_omemo_2, jid); + std::map trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid); qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size(); for (Shared::KeyInfo& key : keys) { @@ -200,7 +198,7 @@ void Core::OmemoHandler::onOwnBundlesReceived() { QString jid = acc->getBareJid(); std::list keys; acc->oh->getDevices(jid, keys); - std::map trustLevels = acc->th->getKeys(ns_omemo_2, jid); + std::map trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid); qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size(); for (Shared::KeyInfo& key : keys) { diff --git a/core/handlers/omemohandler.h b/core/handlers/omemohandler.h index b0db613..7053450 100644 --- a/core/handlers/omemohandler.h +++ b/core/handlers/omemohandler.h @@ -33,8 +33,7 @@ Q_DECLARE_METATYPE(QXmppOmemoStorage::Device); namespace Core { class Account; -class OmemoHandler :public QObject, public QXmppOmemoStorage -{ +class OmemoHandler : public QObject, public QXmppOmemoStorage { Q_OBJECT public: typedef std::pair SignedPreKeyPair; diff --git a/core/handlers/rosterhandler.cpp b/core/handlers/rosterhandler.cpp index 3738d2c..ceaab2d 100644 --- a/core/handlers/rosterhandler.cpp +++ b/core/handlers/rosterhandler.cpp @@ -96,6 +96,9 @@ void Core::RosterHandler::addedAccount(const QString& jid) { if (newContact) { QMap cData = contact->getInfo(); +#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0) + cData.insert("trust", QVariant::fromValue(acc->th->getSummary(jid))); +#endif int grCount = 0; for (QSet::const_iterator itr = gr.begin(), end = gr.end(); itr != end; ++itr) { const QString& groupName = *itr; diff --git a/core/handlers/trusthandler.cpp b/core/handlers/trusthandler.cpp index cc97e57..35e1bc6 100644 --- a/core/handlers/trusthandler.cpp +++ b/core/handlers/trusthandler.cpp @@ -18,9 +18,9 @@ #include "core/account.h" #include "core/adapterfunctions.h" -using namespace Core; - Core::TrustHandler::TrustHandler(Account* account): + QObject(), + QXmppTrustStorage(), acc(account), db(acc->getName() + "/trust"), protocols(db.createDirectory() + "/protocols"), @@ -161,7 +161,7 @@ QXmppTask>> Core::TrustHandler::s return Core::makeReadyTask(std::move(modifiedKeys)); } -QXmppTask TrustHandler::hasKey(const QString& encryption, +QXmppTask Core::TrustHandler::hasKey(const QString& encryption, const QString& keyOwnerJid, QXmpp::TrustLevels trustLevels) { @@ -179,7 +179,7 @@ QXmppTask TrustHandler::hasKey(const QString& encryption, return Core::makeReadyTask(std::move(found)); } -QXmppTask>> TrustHandler::keys( +QXmppTask>> Core::TrustHandler::keys( const QString& encryption, const QList& keyOwnerJids, QXmpp::TrustLevels trustLevels) @@ -202,7 +202,7 @@ QXmppTask>> TrustHandler::ke return Core::makeReadyTask(std::move(res)); } -QXmppTask>> TrustHandler::keys( +QXmppTask>> Core::TrustHandler::keys( const QString& encryption, QXmpp::TrustLevels trustLevels) { @@ -219,17 +219,17 @@ QXmppTask>> TrustHandle return Core::makeReadyTask(std::move(res)); } -QXmppTask TrustHandler::removeKeys(const QString& encryption) { +QXmppTask Core::TrustHandler::removeKeys(const QString& encryption) { getCache(encryption)->drop(); return Core::makeReadyTask(); } -QXmppTask TrustHandler::removeKeys(const QString& encryption, const QString& keyOwnerJid) { +QXmppTask Core::TrustHandler::removeKeys(const QString& encryption, const QString& keyOwnerJid) { getCache(encryption)->removeRecord(keyOwnerJid); return Core::makeReadyTask(); } -QXmppTask TrustHandler::removeKeys(const QString& encryption, const QList& keyIds) { +QXmppTask Core::TrustHandler::removeKeys(const QString& encryption, const QList& keyIds) { std::set set; for (const QByteArray& keyId : keyIds) set.insert(keyId); @@ -258,7 +258,7 @@ QXmppTask TrustHandler::removeKeys(const QString& encryption, const QList< return Core::makeReadyTask(); } -QXmppTask TrustHandler::addKeys( +QXmppTask Core::TrustHandler::addKeys( const QString& encryption, const QString& keyOwnerJid, const QList& keyIds, @@ -287,7 +287,7 @@ QXmppTask TrustHandler::addKeys( return Core::makeReadyTask(); } -QXmppTask TrustHandler::ownKey(const QString& encryption) { +QXmppTask Core::TrustHandler::ownKey(const QString& encryption) { QByteArray res; try { res = ownKeys->getRecord(encryption); @@ -295,7 +295,7 @@ QXmppTask TrustHandler::ownKey(const QString& encryption) { return Core::makeReadyTask(std::move(res)); } -QXmppTask TrustHandler::resetOwnKey(const QString& encryption) { +QXmppTask Core::TrustHandler::resetOwnKey(const QString& encryption) { try { ownKeys->removeRecord(encryption); } catch (const DataBase::NotFound& e) {} @@ -303,12 +303,12 @@ QXmppTask TrustHandler::resetOwnKey(const QString& encryption) { return Core::makeReadyTask(); } -QXmppTask TrustHandler::setOwnKey(const QString& encryption, const QByteArray& keyId) { +QXmppTask Core::TrustHandler::setOwnKey(const QString& encryption, const QByteArray& keyId) { ownKeys->forceRecord(encryption, keyId); return Core::makeReadyTask(); } -QXmppTask TrustHandler::securityPolicy(const QString& encryption) { +QXmppTask Core::TrustHandler::securityPolicy(const QString& encryption) { QXmpp::TrustSecurityPolicy res; try { res = static_cast(securityPolicies->getRecord(encryption)); @@ -316,14 +316,14 @@ QXmppTask TrustHandler::securityPolicy(const QString return Core::makeReadyTask(std::move(res)); } -QXmppTask TrustHandler::resetSecurityPolicy(const QString& encryption) { +QXmppTask Core::TrustHandler::resetSecurityPolicy(const QString& encryption) { try { securityPolicies->removeRecord(encryption); } catch (const DataBase::NotFound& e) {} return Core::makeReadyTask(); } -QXmppTask TrustHandler::setSecurityPolicy( +QXmppTask Core::TrustHandler::setSecurityPolicy( const QString& encryption, QXmpp::TrustSecurityPolicy securityPolicy) { @@ -333,8 +333,9 @@ QXmppTask TrustHandler::setSecurityPolicy( return Core::makeReadyTask(); } -Core::TrustHandler::Keys Core::TrustHandler::getKeys(const QString& protocol, const QString& jid) const { - std::map::const_iterator itr = keysByProtocol.find(protocol); +Core::TrustHandler::Keys Core::TrustHandler::getKeys(Shared::EncryptionProtocol protocol, const QString& jid) const { + const QString& prt = Shared::TrustSummary::protocolKeys.at(protocol); + std::map::const_iterator itr = keysByProtocol.find(prt); if (itr != keysByProtocol.end()) { try { Keys map = itr->second->getRecord(jid); @@ -347,6 +348,21 @@ Core::TrustHandler::Keys Core::TrustHandler::getKeys(const QString& protocol, co } } +Shared::TrustSummary Core::TrustHandler::getSummary(const QString& jid) const { + Shared::TrustSummary result; + for (const std::pair& pair : keysByProtocol) { + try { + Keys keys = pair.second->getRecord(jid); + Shared::EncryptionProtocol protocol = Shared::TrustSummary::protocolValues.at(pair.first); + for (const std::pair& trust : keys) { + result.increment(protocol, trust.second); + } + } catch (const DataBase::NotFound& e) {} + } + + return result; +} + Shared::TrustLevel Core::TrustHandler::convert(Core::TrustHandler::TL level) { switch (level) { case QXmpp::TrustLevel::Undecided: return Shared::TrustLevel::undecided; diff --git a/core/handlers/trusthandler.h b/core/handlers/trusthandler.h index 677a4f7..d21e0c3 100644 --- a/core/handlers/trusthandler.h +++ b/core/handlers/trusthandler.h @@ -18,6 +18,7 @@ #define CORE_TRUSTHANDLER_H #include +#include #include #include @@ -25,7 +26,8 @@ namespace Core { class Account; -class TrustHandler : public QXmppTrustStorage { +class TrustHandler : public QObject, public QXmppTrustStorage { + Q_OBJECT public: TrustHandler(Account* account); ~TrustHandler(); @@ -57,12 +59,13 @@ public: virtual QXmppTask setOwnKey(CSR encryption, const QByteArray& keyId) override; virtual QXmppTask securityPolicy(CSR encryption) override; virtual QXmppTask resetSecurityPolicy(CSR encryption) override; - virtual QXmppTask setSecurityPolicy(CSR encryption, QXmpp::TrustSecurityPolicy securityPolicy) override; + virtual QXmppTask setSecurityPolicy(const QString& encryption, QXmpp::TrustSecurityPolicy securityPolicy) override; static TL convert(Shared::TrustLevel level); static Shared::TrustLevel convert(TL level); - Keys getKeys(const QString& protocol, const QString& jid) const; + Keys getKeys(Shared::EncryptionProtocol protocol, const QString& jid) const; + Shared::TrustSummary getSummary(const QString& jid) const; private: KeyCache* createNewCache(const QString& encryption); diff --git a/shared/global.cpp b/shared/global.cpp index 7a1b494..1b5763b 100644 --- a/shared/global.cpp +++ b/shared/global.cpp @@ -226,61 +226,50 @@ Shared::Global::FileInfo Shared::Global::getFileInfo(const QString& path) } -Shared::Global * Shared::Global::getInstance() -{ +Shared::Global * Shared::Global::getInstance() { return instance; } -QString Shared::Global::getName(Message::State rl) -{ +QString Shared::Global::getName(Message::State rl) { return instance->messageState[static_cast(rl)]; } -QString Shared::Global::getName(Shared::Affiliation af) -{ +QString Shared::Global::getName(Shared::Affiliation af) { return instance->affiliation[static_cast(af)]; } -QString Shared::Global::getName(Shared::Availability av) -{ +QString Shared::Global::getName(Shared::Availability av) { return instance->availability[static_cast(av)]; } -QString Shared::Global::getName(Shared::ConnectionState cs) -{ +QString Shared::Global::getName(Shared::ConnectionState cs) { return instance->connectionState[static_cast(cs)]; } -QString Shared::Global::getName(Shared::Role rl) -{ +QString Shared::Global::getName(Shared::Role rl) { return instance->role[static_cast(rl)]; } -QString Shared::Global::getName(Shared::SubscriptionState ss) -{ +QString Shared::Global::getName(Shared::SubscriptionState ss) { return instance->subscriptionState[static_cast(ss)]; } -QString Shared::Global::getName(Shared::AccountPassword ap) -{ +QString Shared::Global::getName(Shared::AccountPassword ap) { return instance->accountPassword[static_cast(ap)]; } -QString Shared::Global::getName(Shared::TrustLevel tl) -{ +QString Shared::Global::getName(Shared::TrustLevel tl) { return instance->trustLevel[static_cast(tl)]; } -void Shared::Global::setSupported(const QString& pluginName, bool support) -{ +void Shared::Global::setSupported(const QString& pluginName, bool support) { std::map::iterator itr = instance->pluginSupport.find(pluginName); if (itr != instance->pluginSupport.end()) { itr->second = support; } } -bool Shared::Global::supported(const QString& pluginName) -{ +bool Shared::Global::supported(const QString& pluginName) { std::map::iterator itr = instance->pluginSupport.find(pluginName); if (itr != instance->pluginSupport.end()) { return itr->second; @@ -288,8 +277,7 @@ bool Shared::Global::supported(const QString& pluginName) return false; } -QString Shared::Global::getDescription(Shared::AccountPassword ap) -{ +QString Shared::Global::getDescription(Shared::AccountPassword ap) { return instance->accountPasswordDescription[static_cast(ap)]; } @@ -355,8 +343,7 @@ void Shared::Global::highlightInFileManager(const QString& path) } } -QIcon Shared::Global::createThemePreview(const QString& path) -{ +QIcon Shared::Global::createThemePreview(const QString& path) { if (supported("colorSchemeTools")) { QIcon* icon = createPreview(path); QIcon localIcon = *icon; @@ -367,8 +354,7 @@ QIcon Shared::Global::createThemePreview(const QString& path) } } -QString Shared::Global::getColorSchemeName(const QString& path) -{ +QString Shared::Global::getColorSchemeName(const QString& path) { if (supported("colorSchemeTools")) { QString res; colorSchemeName(path, res); @@ -378,8 +364,7 @@ QString Shared::Global::getColorSchemeName(const QString& path) } } -void Shared::Global::setTheme(const QString& path) -{ +void Shared::Global::setTheme(const QString& path) { if (supported("colorSchemeTools")) { if (path.toLower() == "system") { QApplication::setPalette(getInstance()->defaultSystemPalette); @@ -391,8 +376,7 @@ void Shared::Global::setTheme(const QString& path) } } -void Shared::Global::setStyle(const QString& style) -{ +void Shared::Global::setStyle(const QString& style) { if (style.toLower() == "system") { QApplication::setStyle(getInstance()->defaultSystemStyle); } else { @@ -404,7 +388,7 @@ void Shared::Global::setStyle(const QString& style) template<> \ Enum Shared::Global::fromInt(int src) \ { \ - if (src < static_cast(Enum##Lowest) && src > static_cast(Enum##Highest)) { \ + if (src < static_cast(Enum##Lowest) || src > static_cast(Enum##Highest)) { \ throw EnumOutOfRange(#Enum); \ } \ return static_cast(src); \ diff --git a/shared/global.h b/shared/global.h index b311f9f..578fc42 100644 --- a/shared/global.h +++ b/shared/global.h @@ -121,9 +121,7 @@ namespace Shared { template static T fromInt(unsigned int src); - class EnumOutOfRange: - public Utils::Exception - { + class EnumOutOfRange: public Utils::Exception { public: EnumOutOfRange(const std::string& p_name):Exception(), name(p_name) {} diff --git a/shared/trustsummary.cpp b/shared/trustsummary.cpp index 658538c..33a3873 100644 --- a/shared/trustsummary.cpp +++ b/shared/trustsummary.cpp @@ -27,6 +27,17 @@ const std::set Shared::TrustSummary::untrustedLevels({ Shared::TrustLevel::manuallyDistrusted }); +const std::map Shared::TrustSummary::protocolKeys({ + {Shared::EncryptionProtocol::omemo, "eu.siacs.conversations.axolotl"}, + {Shared::EncryptionProtocol::omemo1, "urn:xmpp:omemo:1"}, + {Shared::EncryptionProtocol::omemo2, "urn:xmpp:omemo:2"} +}); +const std::map Shared::TrustSummary::protocolValues({ + {"eu.siacs.conversations.axolotl", Shared::EncryptionProtocol::omemo}, + {"urn:xmpp:omemo:1", Shared::EncryptionProtocol::omemo1}, + {"urn:xmpp:omemo:2", Shared::EncryptionProtocol::omemo2} +}); + Shared::TrustSummary::TrustSummary(): data() {} diff --git a/shared/trustsummary.h b/shared/trustsummary.h index 3283c10..7c79978 100644 --- a/shared/trustsummary.h +++ b/shared/trustsummary.h @@ -17,6 +17,8 @@ #ifndef SHARED_TRUSTSUMMARY_H #define SHARED_TRUSTSUMMARY_H +#include + #include #include @@ -42,10 +44,18 @@ private: typedef std::map Data; Data data; + +public: + static const std::map protocolKeys; + static const std::map protocolValues; + +private: static const std::set trustedLevels; static const std::set untrustedLevels; }; } +Q_DECLARE_METATYPE(Shared::TrustSummary) + #endif // SHARED_TRUSTSUMMARY_H diff --git a/ui/models/contact.cpp b/ui/models/contact.cpp index d5c7dc4..b963421 100644 --- a/ui/models/contact.cpp +++ b/ui/models/contact.cpp @@ -24,62 +24,56 @@ Models::Contact::Contact(const Account* acc, const QString& p_jid ,const QMap::const_iterator itr = data.find("state"); - if (itr != data.end()) { + if (itr != data.end()) setState(itr.value().toUInt()); - } + + itr = data.find("trust"); + if (itr != data.end()) + setTrust(itr.value().value()); } -Models::Contact::~Contact() -{ -} +Models::Contact::~Contact() {} -void Models::Contact::setAvailability(unsigned int p_state) -{ +void Models::Contact::setAvailability(unsigned int p_state) { setAvailability(Shared::Global::fromInt(p_state)); } -void Models::Contact::setState(unsigned int p_state) -{ +void Models::Contact::setState(unsigned int p_state) { setState(Shared::Global::fromInt(p_state)); } -Shared::Availability Models::Contact::getAvailability() const -{ +Shared::Availability Models::Contact::getAvailability() const { return availability; } -void Models::Contact::setAvailability(Shared::Availability p_state) -{ +void Models::Contact::setAvailability(Shared::Availability p_state) { if (availability != p_state) { availability = p_state; changed(3); } } -QString Models::Contact::getStatus() const -{ +QString Models::Contact::getStatus() const { return status; } -void Models::Contact::setStatus(const QString& p_state) -{ +void Models::Contact::setStatus(const QString& p_state) { if (status != p_state) { status = p_state; changed(5); } } -int Models::Contact::columnCount() const -{ - return 8; +int Models::Contact::columnCount() const { + return 9; } -QVariant Models::Contact::data(int column) const -{ +QVariant Models::Contact::data(int column) const { switch (column) { case 0: return getContactName(); @@ -97,35 +91,35 @@ QVariant Models::Contact::data(int column) const return QVariant::fromValue(getAvatarState()); case 7: return getAvatarPath(); + case 8: + return QVariant::fromValue(getTrust()); default: return QVariant(); } } -QString Models::Contact::getContactName() const -{ - if (name == "") { +QString Models::Contact::getContactName() const { + if (name == "") return jid; - } else { + else return name; - } } -void Models::Contact::update(const QString& field, const QVariant& value) -{ +void Models::Contact::update(const QString& field, const QVariant& value) { if (field == "name") { setName(value.toString()); } else if (field == "availability") { setAvailability(value.toUInt()); } else if (field == "state") { setState(value.toUInt()); + } else if (field == "trust") { + setTrust(value.value()); } else { Element::update(field, value); } } -void Models::Contact::addPresence(const QString& p_name, const QMap& data) -{ +void Models::Contact::addPresence(const QString& p_name, const QMap& data) { QMap::iterator itr = presences.find(p_name); if (itr == presences.end()) { @@ -135,14 +129,12 @@ void Models::Contact::addPresence(const QString& p_name, const QMap::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) { + for (QMap::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) pr->update(itr.key(), itr.value()); - } } } -void Models::Contact::removePresence(const QString& name) -{ +void Models::Contact::removePresence(const QString& name) { QMap::iterator itr = presences.find(name); if (itr == presences.end()) { @@ -155,18 +147,15 @@ void Models::Contact::removePresence(const QString& name) } } -Models::Presence * Models::Contact::getPresence(const QString& name) -{ +Models::Presence * Models::Contact::getPresence(const QString& name) { QMap::iterator itr = presences.find(name); - if (itr == presences.end()) { + if (itr == presences.end()) return nullptr; - } else { + else return itr.value(); - } } -void Models::Contact::refresh() -{ +void Models::Contact::refresh() { QDateTime lastActivity; Presence* presence = 0; for (QMap::iterator itr = presences.begin(), end = presences.end(); itr != end; ++itr) { @@ -188,36 +177,43 @@ void Models::Contact::refresh() } } -void Models::Contact::_removeChild(int index) -{ +void Models::Contact::_removeChild(int index) { Item* child = childItems[index]; disconnect(child, &Item::childChanged, this, &Contact::refresh); Item::_removeChild(index); refresh(); } -void Models::Contact::_appendChild(Models::Item* child) -{ +void Models::Contact::_appendChild(Models::Item* child) { Item::_appendChild(child); connect(child, &Item::childChanged, this, &Contact::refresh); refresh(); } -Shared::SubscriptionState Models::Contact::getState() const -{ +Shared::SubscriptionState Models::Contact::getState() const { return state; } -void Models::Contact::setState(Shared::SubscriptionState p_state) -{ +void Models::Contact::setState(Shared::SubscriptionState p_state) { if (state != p_state) { state = p_state; changed(2); } } -QIcon Models::Contact::getStatusIcon(bool big) const -{ +Shared::TrustSummary Models::Contact::getTrust() const { + return trust; +} + +void Models::Contact::setTrust(const Shared::TrustSummary& p_trust) { + //if (trust != p_trust) { + trust = p_trust; + changed(8); + //} +} + + +QIcon Models::Contact::getStatusIcon(bool big) const { if (getMessagesCount() > 0) { return Shared::icon("mail-message", big); } else if (state == Shared::SubscriptionState::both || state == Shared::SubscriptionState::to) { @@ -227,8 +223,7 @@ QIcon Models::Contact::getStatusIcon(bool big) const } } -void Models::Contact::toOfflineState() -{ +void Models::Contact::toOfflineState() { std::deque::size_type size = childItems.size(); if (size > 0) { emit childIsAboutToBeRemoved(this, 0, size - 1); @@ -245,13 +240,11 @@ void Models::Contact::toOfflineState() } } -QString Models::Contact::getDisplayedName() const -{ +QString Models::Contact::getDisplayedName() const { return getContactName(); } -void Models::Contact::handleRecconnect() -{ +void Models::Contact::handleRecconnect() { if (getMessagesCount() > 0) { feed->requestLatestMessages(); } diff --git a/ui/models/contact.h b/ui/models/contact.h index c4fc131..36802cb 100644 --- a/ui/models/contact.h +++ b/ui/models/contact.h @@ -19,17 +19,19 @@ #ifndef MODELS_CONTACT_H #define MODELS_CONTACT_H -#include "element.h" -#include "presence.h" -#include "shared/enums.h" -#include "shared/message.h" -#include "shared/icons.h" -#include "shared/global.h" - #include #include + #include +#include "element.h" +#include "presence.h" +#include +#include +#include +#include +#include + namespace Models { class Contact : public Element @@ -56,6 +58,7 @@ public: QString getContactName() const; QString getStatus() const; QString getDisplayedName() const override; + Shared::TrustSummary getTrust() const; void handleRecconnect(); //this is a special method Models::Roster calls when reconnect happens @@ -73,10 +76,12 @@ protected: void setState(Shared::SubscriptionState p_state); void setState(unsigned int p_state); void setStatus(const QString& p_state); + void setTrust(const Shared::TrustSummary& p_trust); private: Shared::Availability availability; Shared::SubscriptionState state; + Shared::TrustSummary trust; QMap presences; QString status; };