forked from blue/squawk
trust summary gui delivery
This commit is contained in:
parent
fffef9876a
commit
4f295fee3c
@ -21,9 +21,15 @@
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
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,15 +801,13 @@ 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() {
|
||||
notReadyPassword = true;}
|
||||
|
@ -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
|
||||
|
@ -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<Shared::KeyInfo> 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();
|
||||
for (Shared::KeyInfo& key : keys) {
|
||||
@ -200,7 +198,7 @@ void Core::OmemoHandler::onOwnBundlesReceived() {
|
||||
QString jid = acc->getBareJid();
|
||||
std::list<Shared::KeyInfo> 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();
|
||||
for (Shared::KeyInfo& key : keys) {
|
||||
|
@ -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<QDateTime, QByteArray> SignedPreKeyPair;
|
||||
|
@ -96,6 +96,9 @@ void Core::RosterHandler::addedAccount(const QString& jid) {
|
||||
|
||||
if (newContact) {
|
||||
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;
|
||||
for (QSet<QString>::const_iterator itr = gr.begin(), end = gr.end(); itr != end; ++itr) {
|
||||
const QString& groupName = *itr;
|
||||
|
@ -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<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
||||
return Core::makeReadyTask(std::move(modifiedKeys));
|
||||
}
|
||||
|
||||
QXmppTask<bool> TrustHandler::hasKey(const QString& encryption,
|
||||
QXmppTask<bool> Core::TrustHandler::hasKey(const QString& encryption,
|
||||
const QString& keyOwnerJid,
|
||||
QXmpp::TrustLevels trustLevels)
|
||||
{
|
||||
@ -179,7 +179,7 @@ QXmppTask<bool> TrustHandler::hasKey(const QString& encryption,
|
||||
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 QList<QString>& keyOwnerJids,
|
||||
QXmpp::TrustLevels trustLevels)
|
||||
@ -202,7 +202,7 @@ QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> TrustHandler::ke
|
||||
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,
|
||||
QXmpp::TrustLevels trustLevels)
|
||||
{
|
||||
@ -219,17 +219,17 @@ QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> TrustHandle
|
||||
return Core::makeReadyTask(std::move(res));
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::removeKeys(const QString& encryption) {
|
||||
QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption) {
|
||||
getCache(encryption)->drop();
|
||||
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);
|
||||
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;
|
||||
for (const QByteArray& keyId : keyIds)
|
||||
set.insert(keyId);
|
||||
@ -258,7 +258,7 @@ QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QList<
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::addKeys(
|
||||
QXmppTask<void> Core::TrustHandler::addKeys(
|
||||
const QString& encryption,
|
||||
const QString& keyOwnerJid,
|
||||
const QList<QByteArray>& keyIds,
|
||||
@ -287,7 +287,7 @@ QXmppTask<void> TrustHandler::addKeys(
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<QByteArray> TrustHandler::ownKey(const QString& encryption) {
|
||||
QXmppTask<QByteArray> Core::TrustHandler::ownKey(const QString& encryption) {
|
||||
QByteArray res;
|
||||
try {
|
||||
res = ownKeys->getRecord(encryption);
|
||||
@ -295,7 +295,7 @@ QXmppTask<QByteArray> TrustHandler::ownKey(const QString& encryption) {
|
||||
return Core::makeReadyTask(std::move(res));
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::resetOwnKey(const QString& encryption) {
|
||||
QXmppTask<void> Core::TrustHandler::resetOwnKey(const QString& encryption) {
|
||||
try {
|
||||
ownKeys->removeRecord(encryption);
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
@ -303,12 +303,12 @@ QXmppTask<void> TrustHandler::resetOwnKey(const QString& encryption) {
|
||||
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);
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<QXmpp::TrustSecurityPolicy> TrustHandler::securityPolicy(const QString& encryption) {
|
||||
QXmppTask<QXmpp::TrustSecurityPolicy> Core::TrustHandler::securityPolicy(const QString& encryption) {
|
||||
QXmpp::TrustSecurityPolicy res;
|
||||
try {
|
||||
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));
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::resetSecurityPolicy(const QString& encryption) {
|
||||
QXmppTask<void> Core::TrustHandler::resetSecurityPolicy(const QString& encryption) {
|
||||
try {
|
||||
securityPolicies->removeRecord(encryption);
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<void> TrustHandler::setSecurityPolicy(
|
||||
QXmppTask<void> Core::TrustHandler::setSecurityPolicy(
|
||||
const QString& encryption,
|
||||
QXmpp::TrustSecurityPolicy securityPolicy)
|
||||
{
|
||||
@ -333,8 +333,9 @@ QXmppTask<void> TrustHandler::setSecurityPolicy(
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
Core::TrustHandler::Keys Core::TrustHandler::getKeys(const QString& protocol, const QString& jid) const {
|
||||
std::map<QString, KeyCache*>::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<QString, KeyCache*>::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<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) {
|
||||
switch (level) {
|
||||
case QXmpp::TrustLevel::Undecided: return Shared::TrustLevel::undecided;
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define CORE_TRUSTHANDLER_H
|
||||
|
||||
#include <shared/enums.h>
|
||||
#include <shared/trustsummary.h>
|
||||
|
||||
#include <QXmppTrustStorage.h>
|
||||
#include <cache.h>
|
||||
@ -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<void> setOwnKey(CSR encryption, const QByteArray& keyId) override;
|
||||
virtual QXmppTask<QXmpp::TrustSecurityPolicy> securityPolicy(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 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);
|
||||
|
@ -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<int>(rl)];
|
||||
}
|
||||
|
||||
QString Shared::Global::getName(Shared::Affiliation af)
|
||||
{
|
||||
QString Shared::Global::getName(Shared::Affiliation 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)];
|
||||
}
|
||||
|
||||
QString Shared::Global::getName(Shared::ConnectionState cs)
|
||||
{
|
||||
QString Shared::Global::getName(Shared::ConnectionState 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)];
|
||||
}
|
||||
|
||||
QString Shared::Global::getName(Shared::SubscriptionState ss)
|
||||
{
|
||||
QString Shared::Global::getName(Shared::SubscriptionState 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)];
|
||||
}
|
||||
|
||||
QString Shared::Global::getName(Shared::TrustLevel tl)
|
||||
{
|
||||
QString Shared::Global::getName(Shared::TrustLevel 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);
|
||||
if (itr != instance->pluginSupport.end()) {
|
||||
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);
|
||||
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<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")) {
|
||||
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<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); \
|
||||
} \
|
||||
return static_cast<Enum>(src); \
|
||||
|
@ -121,9 +121,7 @@ namespace Shared {
|
||||
template<typename T>
|
||||
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) {}
|
||||
|
||||
|
@ -27,6 +27,17 @@ const std::set<Shared::TrustLevel> Shared::TrustSummary::untrustedLevels({
|
||||
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():
|
||||
data()
|
||||
{}
|
||||
|
@ -17,6 +17,8 @@
|
||||
#ifndef SHARED_TRUSTSUMMARY_H
|
||||
#define SHARED_TRUSTSUMMARY_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
@ -42,10 +44,18 @@ private:
|
||||
typedef std::map<EncryptionProtocol, Amounts> 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> untrustedLevels;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(Shared::TrustSummary)
|
||||
|
||||
#endif // SHARED_TRUSTSUMMARY_H
|
||||
|
@ -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),
|
||||
availability(Shared::Availability::offline),
|
||||
state(Shared::SubscriptionState::none),
|
||||
trust(),
|
||||
presences(),
|
||||
status()
|
||||
{
|
||||
QMap<QString, QVariant>::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<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));
|
||||
}
|
||||
|
||||
void Models::Contact::setState(unsigned int p_state)
|
||||
{
|
||||
void Models::Contact::setState(unsigned int p_state) {
|
||||
setState(Shared::Global::fromInt<Shared::SubscriptionState>(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<Shared::TrustSummary>());
|
||||
} else {
|
||||
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);
|
||||
|
||||
if (itr == presences.end()) {
|
||||
@ -135,14 +129,12 @@ void Models::Contact::addPresence(const QString& p_name, const QMap<QString, QVa
|
||||
appendChild(pr);
|
||||
} else {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Contact::removePresence(const QString& name)
|
||||
{
|
||||
void Models::Contact::removePresence(const QString& name) {
|
||||
QMap<QString, Presence*>::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<QString, Presence*>::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<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];
|
||||
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<Item*>::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();
|
||||
}
|
||||
|
@ -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 <QMap>
|
||||
#include <QIcon>
|
||||
|
||||
#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 {
|
||||
|
||||
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<QString, Presence*> presences;
|
||||
QString status;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user