trust summary gui delivery

This commit is contained in:
Blue 2023-03-17 23:59:51 +03:00
parent fffef9876a
commit 4f295fee3c
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
13 changed files with 169 additions and 143 deletions

View File

@ -21,9 +21,15 @@
#include <QDateTime> #include <QDateTime>
using namespace Core; Core::Account::Account(
const QString& p_login,
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): const QString& p_server,
const QString& p_password,
const QString& p_name,
bool p_active,
NetworkAccess* p_net,
QObject* parent
):
QObject(parent), QObject(parent),
name(p_name), name(p_name),
archiveQueries(), archiveQueries(),
@ -36,13 +42,15 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
rh(new RosterHandler(this)), rh(new RosterHandler(this)),
vh(new VCardHandler(this)), vh(new VCardHandler(this)),
dh(new DiscoveryHandler(this)), dh(new DiscoveryHandler(this)),
#ifdef WITH_OMEMO #if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
th(new TrustHandler(this)), th(new TrustHandler(this)),
#endif
#ifdef WITH_OMEMO
oh(new OmemoHandler(this)), oh(new OmemoHandler(this)),
tm(new QXmppTrustManager(th)),
om(new QXmppOmemoManager(oh)), om(new QXmppOmemoManager(oh)),
#endif #endif
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0) #if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
tm(new QXmppTrustManager(th)),
cm(new QXmppCarbonManagerV2()), cm(new QXmppCarbonManagerV2()),
psm(new QXmppPubSubManager()), psm(new QXmppPubSubManager()),
#else #else
@ -157,7 +165,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
} }
} }
Account::~Account() { Core::Account::~Account() {
if (reconnectScheduled) { if (reconnectScheduled) {
reconnectScheduled = false; reconnectScheduled = false;
reconnectTimer->stop(); reconnectTimer->stop();
@ -701,9 +709,7 @@ void Core::Account::setActive(bool p_active) {
if (active != p_active) { if (active != p_active) {
active = p_active; active = p_active;
emit changed({ emit changed({{"active", active}});
{"active", active}
});
} }
} }
@ -795,15 +801,13 @@ void Core::Account::addContactToGroupRequest(const QString& jid, const QString&
void Core::Account::removeContactFromGroupRequest(const QString& jid, const QString& groupName) { void Core::Account::removeContactFromGroupRequest(const QString& jid, const QString& groupName) {
rh->removeContactFromGroupRequest(jid, 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); Contact* cnt = rh->getContact(jid);
if (cnt == 0) { if (cnt == 0)
qDebug() << "An attempt to rename non existing contact" << jid << "of account" << name << ", skipping"; qDebug() << "An attempt to rename non existing contact" << jid << "of account" << name << ", skipping";
} else { else
rm->renameItem(jid, newName); rm->renameItem(jid, newName);
} }
}
void Core::Account::invalidatePassword() { void Core::Account::invalidatePassword() {
notReadyPassword = true;} notReadyPassword = true;}

View File

@ -191,14 +191,16 @@ private:
RosterHandler* rh; RosterHandler* rh;
VCardHandler* vh; VCardHandler* vh;
DiscoveryHandler* dh; DiscoveryHandler* dh;
#ifdef WITH_OMEMO #if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
TrustHandler* th; TrustHandler* th;
#endif
#ifdef WITH_OMEMO
OmemoHandler* oh; OmemoHandler* oh;
QXmppTrustManager* tm;
QXmppOmemoManager* om; QXmppOmemoManager* om;
#endif #endif
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0) #if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
QXmppTrustManager* tm;
QXmppCarbonManagerV2* cm; QXmppCarbonManagerV2* cm;
QXmppPubSubManager* psm; QXmppPubSubManager* psm;
#else #else

View File

@ -19,8 +19,6 @@
#include "core/account.h" #include "core/account.h"
#include "core/adapterfunctions.h" #include "core/adapterfunctions.h"
constexpr const char* ns_omemo_2 = "urn:xmpp:omemo:2";
Core::OmemoHandler::OmemoHandler(Account* account) : Core::OmemoHandler::OmemoHandler(Account* account) :
QObject(), QObject(),
QXmppOmemoStorage(), QXmppOmemoStorage(),
@ -182,7 +180,7 @@ void Core::OmemoHandler::requestOwnBundles() {
void Core::OmemoHandler::onBundlesReceived(const QString& jid) { void Core::OmemoHandler::onBundlesReceived(const QString& jid) {
std::list<Shared::KeyInfo> keys; std::list<Shared::KeyInfo> keys;
acc->oh->getDevices(jid, keys); acc->oh->getDevices(jid, keys);
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(ns_omemo_2, jid); std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid);
qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size(); qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size();
for (Shared::KeyInfo& key : keys) { for (Shared::KeyInfo& key : keys) {
@ -200,7 +198,7 @@ void Core::OmemoHandler::onOwnBundlesReceived() {
QString jid = acc->getBareJid(); QString jid = acc->getBareJid();
std::list<Shared::KeyInfo> keys; std::list<Shared::KeyInfo> keys;
acc->oh->getDevices(jid, keys); acc->oh->getDevices(jid, keys);
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(ns_omemo_2, jid); std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(Shared::EncryptionProtocol::omemo2, jid);
qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size(); qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size();
for (Shared::KeyInfo& key : keys) { for (Shared::KeyInfo& key : keys) {

View File

@ -33,8 +33,7 @@ Q_DECLARE_METATYPE(QXmppOmemoStorage::Device);
namespace Core { namespace Core {
class Account; class Account;
class OmemoHandler :public QObject, public QXmppOmemoStorage class OmemoHandler : public QObject, public QXmppOmemoStorage {
{
Q_OBJECT Q_OBJECT
public: public:
typedef std::pair<QDateTime, QByteArray> SignedPreKeyPair; typedef std::pair<QDateTime, QByteArray> SignedPreKeyPair;

View File

@ -96,6 +96,9 @@ void Core::RosterHandler::addedAccount(const QString& jid) {
if (newContact) { if (newContact) {
QMap<QString, QVariant> cData = contact->getInfo(); QMap<QString, QVariant> 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; int grCount = 0;
for (QSet<QString>::const_iterator itr = gr.begin(), end = gr.end(); itr != end; ++itr) { for (QSet<QString>::const_iterator itr = gr.begin(), end = gr.end(); itr != end; ++itr) {
const QString& groupName = *itr; const QString& groupName = *itr;

View File

@ -18,9 +18,9 @@
#include "core/account.h" #include "core/account.h"
#include "core/adapterfunctions.h" #include "core/adapterfunctions.h"
using namespace Core;
Core::TrustHandler::TrustHandler(Account* account): Core::TrustHandler::TrustHandler(Account* account):
QObject(),
QXmppTrustStorage(),
acc(account), acc(account),
db(acc->getName() + "/trust"), db(acc->getName() + "/trust"),
protocols(db.createDirectory() + "/protocols"), protocols(db.createDirectory() + "/protocols"),
@ -161,7 +161,7 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
return Core::makeReadyTask(std::move(modifiedKeys)); return Core::makeReadyTask(std::move(modifiedKeys));
} }
QXmppTask<bool> TrustHandler::hasKey(const QString& encryption, QXmppTask<bool> Core::TrustHandler::hasKey(const QString& encryption,
const QString& keyOwnerJid, const QString& keyOwnerJid,
QXmpp::TrustLevels trustLevels) QXmpp::TrustLevels trustLevels)
{ {
@ -179,7 +179,7 @@ QXmppTask<bool> TrustHandler::hasKey(const QString& encryption,
return Core::makeReadyTask(std::move(found)); return Core::makeReadyTask(std::move(found));
} }
QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> TrustHandler::keys( QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> Core::TrustHandler::keys(
const QString& encryption, const QString& encryption,
const QList<QString>& keyOwnerJids, const QList<QString>& keyOwnerJids,
QXmpp::TrustLevels trustLevels) QXmpp::TrustLevels trustLevels)
@ -202,7 +202,7 @@ QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> TrustHandler::ke
return Core::makeReadyTask(std::move(res)); return Core::makeReadyTask(std::move(res));
} }
QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> TrustHandler::keys( QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> Core::TrustHandler::keys(
const QString& encryption, const QString& encryption,
QXmpp::TrustLevels trustLevels) QXmpp::TrustLevels trustLevels)
{ {
@ -219,17 +219,17 @@ QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> TrustHandle
return Core::makeReadyTask(std::move(res)); return Core::makeReadyTask(std::move(res));
} }
QXmppTask<void> TrustHandler::removeKeys(const QString& encryption) { QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption) {
getCache(encryption)->drop(); getCache(encryption)->drop();
return Core::makeReadyTask(); return Core::makeReadyTask();
} }
QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QString& keyOwnerJid) { QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const QString& keyOwnerJid) {
getCache(encryption)->removeRecord(keyOwnerJid); getCache(encryption)->removeRecord(keyOwnerJid);
return Core::makeReadyTask(); return Core::makeReadyTask();
} }
QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QList<QByteArray>& keyIds) { QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const QList<QByteArray>& keyIds) {
std::set<QByteArray> set; std::set<QByteArray> set;
for (const QByteArray& keyId : keyIds) for (const QByteArray& keyId : keyIds)
set.insert(keyId); set.insert(keyId);
@ -258,7 +258,7 @@ QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QList<
return Core::makeReadyTask(); return Core::makeReadyTask();
} }
QXmppTask<void> TrustHandler::addKeys( QXmppTask<void> Core::TrustHandler::addKeys(
const QString& encryption, const QString& encryption,
const QString& keyOwnerJid, const QString& keyOwnerJid,
const QList<QByteArray>& keyIds, const QList<QByteArray>& keyIds,
@ -287,7 +287,7 @@ QXmppTask<void> TrustHandler::addKeys(
return Core::makeReadyTask(); return Core::makeReadyTask();
} }
QXmppTask<QByteArray> TrustHandler::ownKey(const QString& encryption) { QXmppTask<QByteArray> Core::TrustHandler::ownKey(const QString& encryption) {
QByteArray res; QByteArray res;
try { try {
res = ownKeys->getRecord(encryption); res = ownKeys->getRecord(encryption);
@ -295,7 +295,7 @@ QXmppTask<QByteArray> TrustHandler::ownKey(const QString& encryption) {
return Core::makeReadyTask(std::move(res)); return Core::makeReadyTask(std::move(res));
} }
QXmppTask<void> TrustHandler::resetOwnKey(const QString& encryption) { QXmppTask<void> Core::TrustHandler::resetOwnKey(const QString& encryption) {
try { try {
ownKeys->removeRecord(encryption); ownKeys->removeRecord(encryption);
} catch (const DataBase::NotFound& e) {} } catch (const DataBase::NotFound& e) {}
@ -303,12 +303,12 @@ QXmppTask<void> TrustHandler::resetOwnKey(const QString& encryption) {
return Core::makeReadyTask(); return Core::makeReadyTask();
} }
QXmppTask<void> TrustHandler::setOwnKey(const QString& encryption, const QByteArray& keyId) { QXmppTask<void> Core::TrustHandler::setOwnKey(const QString& encryption, const QByteArray& keyId) {
ownKeys->forceRecord(encryption, keyId); ownKeys->forceRecord(encryption, keyId);
return Core::makeReadyTask(); return Core::makeReadyTask();
} }
QXmppTask<QXmpp::TrustSecurityPolicy> TrustHandler::securityPolicy(const QString& encryption) { QXmppTask<QXmpp::TrustSecurityPolicy> Core::TrustHandler::securityPolicy(const QString& encryption) {
QXmpp::TrustSecurityPolicy res; QXmpp::TrustSecurityPolicy res;
try { try {
res = static_cast<QXmpp::TrustSecurityPolicy>(securityPolicies->getRecord(encryption)); res = static_cast<QXmpp::TrustSecurityPolicy>(securityPolicies->getRecord(encryption));
@ -316,14 +316,14 @@ QXmppTask<QXmpp::TrustSecurityPolicy> TrustHandler::securityPolicy(const QString
return Core::makeReadyTask(std::move(res)); return Core::makeReadyTask(std::move(res));
} }
QXmppTask<void> TrustHandler::resetSecurityPolicy(const QString& encryption) { QXmppTask<void> Core::TrustHandler::resetSecurityPolicy(const QString& encryption) {
try { try {
securityPolicies->removeRecord(encryption); securityPolicies->removeRecord(encryption);
} catch (const DataBase::NotFound& e) {} } catch (const DataBase::NotFound& e) {}
return Core::makeReadyTask(); return Core::makeReadyTask();
} }
QXmppTask<void> TrustHandler::setSecurityPolicy( QXmppTask<void> Core::TrustHandler::setSecurityPolicy(
const QString& encryption, const QString& encryption,
QXmpp::TrustSecurityPolicy securityPolicy) QXmpp::TrustSecurityPolicy securityPolicy)
{ {
@ -333,8 +333,9 @@ QXmppTask<void> TrustHandler::setSecurityPolicy(
return Core::makeReadyTask(); return Core::makeReadyTask();
} }
Core::TrustHandler::Keys Core::TrustHandler::getKeys(const QString& protocol, const QString& jid) const { Core::TrustHandler::Keys Core::TrustHandler::getKeys(Shared::EncryptionProtocol protocol, const QString& jid) const {
std::map<QString, KeyCache*>::const_iterator itr = keysByProtocol.find(protocol); const QString& prt = Shared::TrustSummary::protocolKeys.at(protocol);
std::map<QString, KeyCache*>::const_iterator itr = keysByProtocol.find(prt);
if (itr != keysByProtocol.end()) { if (itr != keysByProtocol.end()) {
try { try {
Keys map = itr->second->getRecord(jid); 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<const QString, KeyCache*>& pair : keysByProtocol) {
try {
Keys keys = pair.second->getRecord(jid);
Shared::EncryptionProtocol protocol = Shared::TrustSummary::protocolValues.at(pair.first);
for (const std::pair<const QByteArray, Shared::TrustLevel>& trust : keys) {
result.increment(protocol, trust.second);
}
} catch (const DataBase::NotFound& e) {}
}
return result;
}
Shared::TrustLevel Core::TrustHandler::convert(Core::TrustHandler::TL level) { Shared::TrustLevel Core::TrustHandler::convert(Core::TrustHandler::TL level) {
switch (level) { switch (level) {
case QXmpp::TrustLevel::Undecided: return Shared::TrustLevel::undecided; case QXmpp::TrustLevel::Undecided: return Shared::TrustLevel::undecided;

View File

@ -18,6 +18,7 @@
#define CORE_TRUSTHANDLER_H #define CORE_TRUSTHANDLER_H
#include <shared/enums.h> #include <shared/enums.h>
#include <shared/trustsummary.h>
#include <QXmppTrustStorage.h> #include <QXmppTrustStorage.h>
#include <cache.h> #include <cache.h>
@ -25,7 +26,8 @@
namespace Core { namespace Core {
class Account; class Account;
class TrustHandler : public QXmppTrustStorage { class TrustHandler : public QObject, public QXmppTrustStorage {
Q_OBJECT
public: public:
TrustHandler(Account* account); TrustHandler(Account* account);
~TrustHandler(); ~TrustHandler();
@ -57,12 +59,13 @@ public:
virtual QXmppTask<void> setOwnKey(CSR encryption, const QByteArray& keyId) override; virtual QXmppTask<void> setOwnKey(CSR encryption, const QByteArray& keyId) override;
virtual QXmppTask<QXmpp::TrustSecurityPolicy> securityPolicy(CSR encryption) override; virtual QXmppTask<QXmpp::TrustSecurityPolicy> securityPolicy(CSR encryption) override;
virtual QXmppTask<void> resetSecurityPolicy(CSR encryption) override; virtual QXmppTask<void> resetSecurityPolicy(CSR encryption) override;
virtual QXmppTask<void> setSecurityPolicy(CSR encryption, QXmpp::TrustSecurityPolicy securityPolicy) override; virtual QXmppTask<void> setSecurityPolicy(const QString& encryption, QXmpp::TrustSecurityPolicy securityPolicy) override;
static TL convert(Shared::TrustLevel level); static TL convert(Shared::TrustLevel level);
static Shared::TrustLevel convert(TL 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: private:
KeyCache* createNewCache(const QString& encryption); KeyCache* createNewCache(const QString& encryption);

View File

@ -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; return instance;
} }
QString Shared::Global::getName(Message::State rl) QString Shared::Global::getName(Message::State rl) {
{
return instance->messageState[static_cast<int>(rl)]; return instance->messageState[static_cast<int>(rl)];
} }
QString Shared::Global::getName(Shared::Affiliation af) QString Shared::Global::getName(Shared::Affiliation af) {
{
return instance->affiliation[static_cast<int>(af)]; return instance->affiliation[static_cast<int>(af)];
} }
QString Shared::Global::getName(Shared::Availability av) QString Shared::Global::getName(Shared::Availability av) {
{
return instance->availability[static_cast<int>(av)]; return instance->availability[static_cast<int>(av)];
} }
QString Shared::Global::getName(Shared::ConnectionState cs) QString Shared::Global::getName(Shared::ConnectionState cs) {
{
return instance->connectionState[static_cast<int>(cs)]; return instance->connectionState[static_cast<int>(cs)];
} }
QString Shared::Global::getName(Shared::Role rl) QString Shared::Global::getName(Shared::Role rl) {
{
return instance->role[static_cast<int>(rl)]; return instance->role[static_cast<int>(rl)];
} }
QString Shared::Global::getName(Shared::SubscriptionState ss) QString Shared::Global::getName(Shared::SubscriptionState ss) {
{
return instance->subscriptionState[static_cast<int>(ss)]; return instance->subscriptionState[static_cast<int>(ss)];
} }
QString Shared::Global::getName(Shared::AccountPassword ap) QString Shared::Global::getName(Shared::AccountPassword ap) {
{
return instance->accountPassword[static_cast<int>(ap)]; return instance->accountPassword[static_cast<int>(ap)];
} }
QString Shared::Global::getName(Shared::TrustLevel tl) QString Shared::Global::getName(Shared::TrustLevel tl) {
{
return instance->trustLevel[static_cast<int>(tl)]; return instance->trustLevel[static_cast<int>(tl)];
} }
void Shared::Global::setSupported(const QString& pluginName, bool support) void Shared::Global::setSupported(const QString& pluginName, bool support) {
{
std::map<QString, bool>::iterator itr = instance->pluginSupport.find(pluginName); std::map<QString, bool>::iterator itr = instance->pluginSupport.find(pluginName);
if (itr != instance->pluginSupport.end()) { if (itr != instance->pluginSupport.end()) {
itr->second = support; itr->second = support;
} }
} }
bool Shared::Global::supported(const QString& pluginName) bool Shared::Global::supported(const QString& pluginName) {
{
std::map<QString, bool>::iterator itr = instance->pluginSupport.find(pluginName); std::map<QString, bool>::iterator itr = instance->pluginSupport.find(pluginName);
if (itr != instance->pluginSupport.end()) { if (itr != instance->pluginSupport.end()) {
return itr->second; return itr->second;
@ -288,8 +277,7 @@ bool Shared::Global::supported(const QString& pluginName)
return false; return false;
} }
QString Shared::Global::getDescription(Shared::AccountPassword ap) QString Shared::Global::getDescription(Shared::AccountPassword ap) {
{
return instance->accountPasswordDescription[static_cast<int>(ap)]; return instance->accountPasswordDescription[static_cast<int>(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")) { if (supported("colorSchemeTools")) {
QIcon* icon = createPreview(path); QIcon* icon = createPreview(path);
QIcon localIcon = *icon; 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")) { if (supported("colorSchemeTools")) {
QString res; QString res;
colorSchemeName(path, 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 (supported("colorSchemeTools")) {
if (path.toLower() == "system") { if (path.toLower() == "system") {
QApplication::setPalette(getInstance()->defaultSystemPalette); 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") { if (style.toLower() == "system") {
QApplication::setStyle(getInstance()->defaultSystemStyle); QApplication::setStyle(getInstance()->defaultSystemStyle);
} else { } else {
@ -404,7 +388,7 @@ void Shared::Global::setStyle(const QString& style)
template<> \ template<> \
Enum Shared::Global::fromInt(int src) \ Enum Shared::Global::fromInt(int src) \
{ \ { \
if (src < static_cast<int>(Enum##Lowest) && src > static_cast<int>(Enum##Highest)) { \ if (src < static_cast<int>(Enum##Lowest) || src > static_cast<int>(Enum##Highest)) { \
throw EnumOutOfRange(#Enum); \ throw EnumOutOfRange(#Enum); \
} \ } \
return static_cast<Enum>(src); \ return static_cast<Enum>(src); \

View File

@ -121,9 +121,7 @@ namespace Shared {
template<typename T> template<typename T>
static T fromInt(unsigned int src); static T fromInt(unsigned int src);
class EnumOutOfRange: class EnumOutOfRange: public Utils::Exception {
public Utils::Exception
{
public: public:
EnumOutOfRange(const std::string& p_name):Exception(), name(p_name) {} EnumOutOfRange(const std::string& p_name):Exception(), name(p_name) {}

View File

@ -27,6 +27,17 @@ const std::set<Shared::TrustLevel> Shared::TrustSummary::untrustedLevels({
Shared::TrustLevel::manuallyDistrusted Shared::TrustLevel::manuallyDistrusted
}); });
const std::map<Shared::EncryptionProtocol, QString> 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<QString, Shared::EncryptionProtocol> 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(): Shared::TrustSummary::TrustSummary():
data() data()
{} {}

View File

@ -17,6 +17,8 @@
#ifndef SHARED_TRUSTSUMMARY_H #ifndef SHARED_TRUSTSUMMARY_H
#define SHARED_TRUSTSUMMARY_H #define SHARED_TRUSTSUMMARY_H
#include <QObject>
#include <map> #include <map>
#include <set> #include <set>
@ -42,10 +44,18 @@ private:
typedef std::map<EncryptionProtocol, Amounts> Data; typedef std::map<EncryptionProtocol, Amounts> Data;
Data data; Data data;
public:
static const std::map<EncryptionProtocol, QString> protocolKeys;
static const std::map<QString, EncryptionProtocol> protocolValues;
private:
static const std::set<TrustLevel> trustedLevels; static const std::set<TrustLevel> trustedLevels;
static const std::set<TrustLevel> untrustedLevels; static const std::set<TrustLevel> untrustedLevels;
}; };
} }
Q_DECLARE_METATYPE(Shared::TrustSummary)
#endif // SHARED_TRUSTSUMMARY_H #endif // SHARED_TRUSTSUMMARY_H

View File

@ -24,62 +24,56 @@ Models::Contact::Contact(const Account* acc, const QString& p_jid ,const QMap<QS
Element(Item::contact, acc, p_jid, data, parentItem), Element(Item::contact, acc, p_jid, data, parentItem),
availability(Shared::Availability::offline), availability(Shared::Availability::offline),
state(Shared::SubscriptionState::none), state(Shared::SubscriptionState::none),
trust(),
presences(), presences(),
status() status()
{ {
QMap<QString, QVariant>::const_iterator itr = data.find("state"); QMap<QString, QVariant>::const_iterator itr = data.find("state");
if (itr != data.end()) { if (itr != data.end())
setState(itr.value().toUInt()); setState(itr.value().toUInt());
}
itr = data.find("trust");
if (itr != data.end())
setTrust(itr.value().value<Shared::TrustSummary>());
} }
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<Shared::Availability>(p_state)); setAvailability(Shared::Global::fromInt<Shared::Availability>(p_state));
} }
void Models::Contact::setState(unsigned int p_state) void Models::Contact::setState(unsigned int p_state) {
{
setState(Shared::Global::fromInt<Shared::SubscriptionState>(p_state)); setState(Shared::Global::fromInt<Shared::SubscriptionState>(p_state));
} }
Shared::Availability Models::Contact::getAvailability() const Shared::Availability Models::Contact::getAvailability() const {
{
return availability; return availability;
} }
void Models::Contact::setAvailability(Shared::Availability p_state) void Models::Contact::setAvailability(Shared::Availability p_state) {
{
if (availability != p_state) { if (availability != p_state) {
availability = p_state; availability = p_state;
changed(3); changed(3);
} }
} }
QString Models::Contact::getStatus() const QString Models::Contact::getStatus() const {
{
return status; return status;
} }
void Models::Contact::setStatus(const QString& p_state) void Models::Contact::setStatus(const QString& p_state) {
{
if (status != p_state) { if (status != p_state) {
status = p_state; status = p_state;
changed(5); changed(5);
} }
} }
int Models::Contact::columnCount() const int Models::Contact::columnCount() const {
{ return 9;
return 8;
} }
QVariant Models::Contact::data(int column) const QVariant Models::Contact::data(int column) const {
{
switch (column) { switch (column) {
case 0: case 0:
return getContactName(); return getContactName();
@ -97,35 +91,35 @@ QVariant Models::Contact::data(int column) const
return QVariant::fromValue(getAvatarState()); return QVariant::fromValue(getAvatarState());
case 7: case 7:
return getAvatarPath(); return getAvatarPath();
case 8:
return QVariant::fromValue(getTrust());
default: default:
return QVariant(); return QVariant();
} }
} }
QString Models::Contact::getContactName() const QString Models::Contact::getContactName() const {
{ if (name == "")
if (name == "") {
return jid; return jid;
} else { else
return name; 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") { if (field == "name") {
setName(value.toString()); setName(value.toString());
} else if (field == "availability") { } else if (field == "availability") {
setAvailability(value.toUInt()); setAvailability(value.toUInt());
} else if (field == "state") { } else if (field == "state") {
setState(value.toUInt()); setState(value.toUInt());
} else if (field == "trust") {
setTrust(value.value<Shared::TrustSummary>());
} else { } else {
Element::update(field, value); Element::update(field, value);
} }
} }
void Models::Contact::addPresence(const QString& p_name, const QMap<QString, QVariant>& data) void Models::Contact::addPresence(const QString& p_name, const QMap<QString, QVariant>& data) {
{
QMap<QString, Presence*>::iterator itr = presences.find(p_name); QMap<QString, Presence*>::iterator itr = presences.find(p_name);
if (itr == presences.end()) { if (itr == presences.end()) {
@ -135,14 +129,12 @@ void Models::Contact::addPresence(const QString& p_name, const QMap<QString, QVa
appendChild(pr); appendChild(pr);
} else { } else {
Presence* pr = itr.value(); Presence* pr = itr.value();
for (QMap<QString, QVariant>::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) { for (QMap<QString, QVariant>::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr)
pr->update(itr.key(), itr.value()); pr->update(itr.key(), itr.value());
} }
} }
}
void Models::Contact::removePresence(const QString& name) void Models::Contact::removePresence(const QString& name) {
{
QMap<QString, Presence*>::iterator itr = presences.find(name); QMap<QString, Presence*>::iterator itr = presences.find(name);
if (itr == presences.end()) { 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<QString, Presence*>::iterator itr = presences.find(name); QMap<QString, Presence*>::iterator itr = presences.find(name);
if (itr == presences.end()) { if (itr == presences.end())
return nullptr; return nullptr;
} else { else
return itr.value(); return itr.value();
} }
}
void Models::Contact::refresh() void Models::Contact::refresh() {
{
QDateTime lastActivity; QDateTime lastActivity;
Presence* presence = 0; Presence* presence = 0;
for (QMap<QString, Presence*>::iterator itr = presences.begin(), end = presences.end(); itr != end; ++itr) { for (QMap<QString, Presence*>::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]; Item* child = childItems[index];
disconnect(child, &Item::childChanged, this, &Contact::refresh); disconnect(child, &Item::childChanged, this, &Contact::refresh);
Item::_removeChild(index); Item::_removeChild(index);
refresh(); refresh();
} }
void Models::Contact::_appendChild(Models::Item* child) void Models::Contact::_appendChild(Models::Item* child) {
{
Item::_appendChild(child); Item::_appendChild(child);
connect(child, &Item::childChanged, this, &Contact::refresh); connect(child, &Item::childChanged, this, &Contact::refresh);
refresh(); refresh();
} }
Shared::SubscriptionState Models::Contact::getState() const Shared::SubscriptionState Models::Contact::getState() const {
{
return state; return state;
} }
void Models::Contact::setState(Shared::SubscriptionState p_state) void Models::Contact::setState(Shared::SubscriptionState p_state) {
{
if (state != p_state) { if (state != p_state) {
state = p_state; state = p_state;
changed(2); 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) { if (getMessagesCount() > 0) {
return Shared::icon("mail-message", big); return Shared::icon("mail-message", big);
} else if (state == Shared::SubscriptionState::both || state == Shared::SubscriptionState::to) { } 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<Item*>::size_type size = childItems.size(); std::deque<Item*>::size_type size = childItems.size();
if (size > 0) { if (size > 0) {
emit childIsAboutToBeRemoved(this, 0, size - 1); 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(); return getContactName();
} }
void Models::Contact::handleRecconnect() void Models::Contact::handleRecconnect() {
{
if (getMessagesCount() > 0) { if (getMessagesCount() > 0) {
feed->requestLatestMessages(); feed->requestLatestMessages();
} }

View File

@ -19,17 +19,19 @@
#ifndef MODELS_CONTACT_H #ifndef MODELS_CONTACT_H
#define 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 <QMap> #include <QMap>
#include <QIcon> #include <QIcon>
#include <deque> #include <deque>
#include "element.h"
#include "presence.h"
#include <shared/enums.h>
#include <shared/message.h>
#include <shared/icons.h>
#include <shared/global.h>
#include <shared/trustsummary.h>
namespace Models { namespace Models {
class Contact : public Element class Contact : public Element
@ -56,6 +58,7 @@ public:
QString getContactName() const; QString getContactName() const;
QString getStatus() const; QString getStatus() const;
QString getDisplayedName() const override; QString getDisplayedName() const override;
Shared::TrustSummary getTrust() const;
void handleRecconnect(); //this is a special method Models::Roster calls when reconnect happens 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(Shared::SubscriptionState p_state);
void setState(unsigned int p_state); void setState(unsigned int p_state);
void setStatus(const QString& p_state); void setStatus(const QString& p_state);
void setTrust(const Shared::TrustSummary& p_trust);
private: private:
Shared::Availability availability; Shared::Availability availability;
Shared::SubscriptionState state; Shared::SubscriptionState state;
Shared::TrustSummary trust;
QMap<QString, Presence*> presences; QMap<QString, Presence*> presences;
QString status; QString status;
}; };