1
0
Fork 0
forked from blue/squawk

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

@ -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();
}

View file

@ -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;
};