forked from blue/squawk
Client node now displays in all participants and presences, some additional checkups before querying empty clients, refactoring
This commit is contained in:
parent
76a9c5da0c
commit
21b40a9ccb
19 changed files with 407 additions and 317 deletions
|
@ -1,28 +1,36 @@
|
|||
set(SOURCE_FILES
|
||||
abstractparticipant.cpp
|
||||
account.cpp
|
||||
accounts.cpp
|
||||
contact.cpp
|
||||
element.cpp
|
||||
group.cpp
|
||||
item.cpp
|
||||
participant.cpp
|
||||
presence.cpp
|
||||
reference.cpp
|
||||
room.cpp
|
||||
roster.cpp
|
||||
)
|
||||
|
||||
set(HEADER_FILES
|
||||
abstractparticipant.h
|
||||
account.h
|
||||
accounts.h
|
||||
contact.h
|
||||
element.h
|
||||
group.h
|
||||
item.h
|
||||
participant.h
|
||||
presence.h
|
||||
reference.h
|
||||
room.h
|
||||
roster.h
|
||||
)
|
||||
|
||||
target_sources(squawk PRIVATE
|
||||
abstractparticipant.cpp
|
||||
abstractparticipant.h
|
||||
account.cpp
|
||||
account.h
|
||||
accounts.cpp
|
||||
accounts.h
|
||||
contact.cpp
|
||||
contact.h
|
||||
element.cpp
|
||||
element.h
|
||||
group.cpp
|
||||
group.h
|
||||
item.cpp
|
||||
item.h
|
||||
participant.cpp
|
||||
participant.h
|
||||
presence.cpp
|
||||
presence.h
|
||||
reference.cpp
|
||||
reference.h
|
||||
room.cpp
|
||||
room.h
|
||||
roster.cpp
|
||||
roster.h
|
||||
)
|
||||
${SOURCE_FILES}
|
||||
${HEADER_FILES}
|
||||
)
|
||||
|
||||
add_subdirectory(info)
|
||||
|
|
|
@ -18,40 +18,38 @@
|
|||
|
||||
#include "abstractparticipant.h"
|
||||
|
||||
using namespace Models;
|
||||
|
||||
Models::AbstractParticipant::AbstractParticipant(Models::Item::Type p_type, const QMap<QString, QVariant>& data, Models::Item* parentItem):
|
||||
Item(p_type, data, parentItem),
|
||||
availability(Shared::Availability::offline),
|
||||
lastActivity(data.value("lastActivity").toDateTime()),
|
||||
status(data.value("status").toString())
|
||||
status(data.value("status").toString()),
|
||||
client()
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("availability");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end())
|
||||
setAvailability(itr.value().toUInt());
|
||||
}
|
||||
|
||||
itr = data.find("client");
|
||||
if (itr != data.end())
|
||||
setClient(itr.value().value<Shared::ClientId>());
|
||||
}
|
||||
|
||||
Models::AbstractParticipant::AbstractParticipant(const Models::AbstractParticipant& other):
|
||||
Item(other),
|
||||
availability(other.availability),
|
||||
lastActivity(other.lastActivity),
|
||||
status(other.status)
|
||||
{
|
||||
status(other.status),
|
||||
client(other.client)
|
||||
{}
|
||||
|
||||
|
||||
Models::AbstractParticipant::~AbstractParticipant() {}
|
||||
|
||||
int Models::AbstractParticipant::columnCount() const {
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
||||
Models::AbstractParticipant::~AbstractParticipant()
|
||||
{
|
||||
}
|
||||
|
||||
int Models::AbstractParticipant::columnCount() const
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
QVariant Models::AbstractParticipant::data(int column) const
|
||||
{
|
||||
QVariant Models::AbstractParticipant::data(int column) const {
|
||||
switch (column) {
|
||||
case 0:
|
||||
return Item::data(column);
|
||||
|
@ -61,62 +59,71 @@ QVariant Models::AbstractParticipant::data(int column) const
|
|||
return QVariant::fromValue(availability);
|
||||
case 3:
|
||||
return status;
|
||||
case 4:
|
||||
return QVariant::fromValue(client);
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
Shared::Availability Models::AbstractParticipant::getAvailability() const
|
||||
{
|
||||
Shared::Availability Models::AbstractParticipant::getAvailability() const {
|
||||
return availability;
|
||||
}
|
||||
|
||||
QDateTime Models::AbstractParticipant::getLastActivity() const
|
||||
{
|
||||
QDateTime Models::AbstractParticipant::getLastActivity() const {
|
||||
return lastActivity;
|
||||
}
|
||||
|
||||
QString Models::AbstractParticipant::getStatus() const
|
||||
{
|
||||
QString Models::AbstractParticipant::getStatus() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
void Models::AbstractParticipant::setAvailability(Shared::Availability p_avail)
|
||||
{
|
||||
void Models::AbstractParticipant::setAvailability(Shared::Availability p_avail) {
|
||||
if (availability != p_avail) {
|
||||
availability = p_avail;
|
||||
changed(2);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::AbstractParticipant::setAvailability(unsigned int avail)
|
||||
{
|
||||
void Models::AbstractParticipant::setAvailability(unsigned int avail) {
|
||||
setAvailability(Shared::Global::fromInt<Shared::Availability>(avail));
|
||||
}
|
||||
|
||||
void Models::AbstractParticipant::setLastActivity(const QDateTime& p_time)
|
||||
{
|
||||
void Models::AbstractParticipant::setLastActivity(const QDateTime& p_time) {
|
||||
if (lastActivity != p_time) {
|
||||
lastActivity = p_time;
|
||||
changed(1);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::AbstractParticipant::setStatus(const QString& p_state)
|
||||
{
|
||||
void Models::AbstractParticipant::setStatus(const QString& p_state) {
|
||||
if (status != p_state) {
|
||||
status = p_state;
|
||||
changed(3);
|
||||
}
|
||||
}
|
||||
|
||||
QIcon Models::AbstractParticipant::getStatusIcon(bool big) const
|
||||
{
|
||||
Shared::ClientId Models::AbstractParticipant::getClient() const {
|
||||
return client;
|
||||
}
|
||||
|
||||
QString Models::AbstractParticipant::getClientNode() const {
|
||||
return client.node;
|
||||
}
|
||||
|
||||
void Models::AbstractParticipant::setClient(const Shared::ClientId& id) {
|
||||
if (client != id) {
|
||||
client = id;
|
||||
changed(4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QIcon Models::AbstractParticipant::getStatusIcon(bool big) const {
|
||||
return Shared::availabilityIcon(availability, big);
|
||||
}
|
||||
|
||||
void Models::AbstractParticipant::update(const QString& key, const QVariant& value)
|
||||
{
|
||||
void Models::AbstractParticipant::update(const QString& key, const QVariant& value) {
|
||||
if (key == "name") {
|
||||
setName(value.toString());
|
||||
} else if (key == "status") {
|
||||
|
@ -125,5 +132,7 @@ void Models::AbstractParticipant::update(const QString& key, const QVariant& val
|
|||
setAvailability(value.toUInt());
|
||||
} else if (key == "lastActivity") {
|
||||
setLastActivity(value.toDateTime());
|
||||
} else if (key == "client") {
|
||||
setClient(value.value<Shared::ClientId>());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,10 @@
|
|||
|
||||
|
||||
#include "item.h"
|
||||
#include "shared/enums.h"
|
||||
#include "shared/icons.h"
|
||||
#include "shared/global.h"
|
||||
#include <shared/enums.h>
|
||||
#include <shared/icons.h>
|
||||
#include <shared/global.h>
|
||||
#include <shared/clientid.h>
|
||||
|
||||
#include <QIcon>
|
||||
#include <QDateTime>
|
||||
|
@ -51,6 +52,10 @@ public:
|
|||
QString getStatus() const;
|
||||
void setStatus(const QString& p_state);
|
||||
virtual QIcon getStatusIcon(bool big = false) const;
|
||||
|
||||
Shared::ClientId getClient() const;
|
||||
void setClient(const Shared::ClientId& id);
|
||||
QString getClientNode() const;
|
||||
|
||||
virtual void update(const QString& key, const QVariant& value);
|
||||
|
||||
|
@ -58,6 +63,7 @@ protected:
|
|||
Shared::Availability availability;
|
||||
QDateTime lastActivity;
|
||||
QString status;
|
||||
Shared::ClientId client;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,52 +26,46 @@ Models::Participant::Participant(const QMap<QString, QVariant>& data, Models::It
|
|||
role(Shared::Role::unspecified)
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("affiliation");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end())
|
||||
setAffiliation(itr.value().toUInt());
|
||||
}
|
||||
|
||||
|
||||
itr = data.find("role");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end())
|
||||
setRole(itr.value().toUInt());
|
||||
}
|
||||
|
||||
|
||||
itr = data.find("avatarState");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end())
|
||||
setAvatarState(itr.value().toUInt());
|
||||
}
|
||||
|
||||
itr = data.find("avatarPath");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end())
|
||||
setAvatarPath(itr.value().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Models::Participant::~Participant()
|
||||
{
|
||||
{}
|
||||
|
||||
int Models::Participant::columnCount() const {
|
||||
return 9;
|
||||
}
|
||||
|
||||
int Models::Participant::columnCount() const
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
QVariant Models::Participant::data(int column) const
|
||||
{
|
||||
QVariant Models::Participant::data(int column) const {
|
||||
switch (column) {
|
||||
case 4:
|
||||
return QVariant::fromValue(affiliation);
|
||||
case 5:
|
||||
return QVariant::fromValue(role);
|
||||
return QVariant::fromValue(affiliation);
|
||||
case 6:
|
||||
return QVariant::fromValue(getAvatarState());
|
||||
return QVariant::fromValue(role);
|
||||
case 7:
|
||||
return QVariant::fromValue(getAvatarState());
|
||||
case 8:
|
||||
return getAvatarPath();
|
||||
default:
|
||||
return AbstractParticipant::data(column);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Participant::update(const QString& key, const QVariant& value)
|
||||
{
|
||||
void Models::Participant::update(const QString& key, const QVariant& value) {
|
||||
if (key == "affiliation") {
|
||||
setAffiliation(value.toUInt());
|
||||
} else if (key == "role") {
|
||||
|
@ -85,67 +79,58 @@ void Models::Participant::update(const QString& key, const QVariant& value)
|
|||
}
|
||||
}
|
||||
|
||||
Shared::Affiliation Models::Participant::getAffiliation() const
|
||||
{
|
||||
Shared::Affiliation Models::Participant::getAffiliation() const {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
void Models::Participant::setAffiliation(Shared::Affiliation p_aff)
|
||||
{
|
||||
void Models::Participant::setAffiliation(Shared::Affiliation p_aff) {
|
||||
if (p_aff != affiliation) {
|
||||
affiliation = p_aff;
|
||||
changed(4);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Participant::setAffiliation(unsigned int aff)
|
||||
{
|
||||
setAffiliation(Shared::Global::fromInt<Shared::Affiliation>(aff));
|
||||
}
|
||||
|
||||
Shared::Role Models::Participant::getRole() const
|
||||
{
|
||||
return role;
|
||||
}
|
||||
|
||||
void Models::Participant::setRole(Shared::Role p_role)
|
||||
{
|
||||
if (p_role != role) {
|
||||
role = p_role;
|
||||
changed(5);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Participant::setRole(unsigned int p_role)
|
||||
{
|
||||
setRole(Shared::Global::fromInt<Shared::Role>(p_role));
|
||||
void Models::Participant::setAffiliation(unsigned int aff) {
|
||||
setAffiliation(Shared::Global::fromInt<Shared::Affiliation>(aff));
|
||||
}
|
||||
|
||||
QString Models::Participant::getAvatarPath() const
|
||||
{
|
||||
return avatarPath;
|
||||
Shared::Role Models::Participant::getRole() const {
|
||||
return role;
|
||||
}
|
||||
|
||||
Shared::Avatar Models::Participant::getAvatarState() const
|
||||
{
|
||||
return avatarState;
|
||||
}
|
||||
|
||||
void Models::Participant::setAvatarPath(const QString& path)
|
||||
{
|
||||
if (avatarPath != path) {
|
||||
avatarPath = path;
|
||||
changed(7);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Participant::setAvatarState(Shared::Avatar p_state)
|
||||
{
|
||||
if (avatarState != p_state) {
|
||||
avatarState = p_state;
|
||||
void Models::Participant::setRole(Shared::Role p_role) {
|
||||
if (p_role != role) {
|
||||
role = p_role;
|
||||
changed(6);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Participant::setAvatarState(unsigned int p_state)
|
||||
{setAvatarState(Shared::Global::fromInt<Shared::Avatar>(p_state));}
|
||||
void Models::Participant::setRole(unsigned int p_role) {
|
||||
setRole(Shared::Global::fromInt<Shared::Role>(p_role));
|
||||
}
|
||||
|
||||
QString Models::Participant::getAvatarPath() const {
|
||||
return avatarPath;
|
||||
}
|
||||
|
||||
Shared::Avatar Models::Participant::getAvatarState() const {
|
||||
return avatarState;
|
||||
}
|
||||
|
||||
void Models::Participant::setAvatarPath(const QString& path) {
|
||||
if (avatarPath != path) {
|
||||
avatarPath = path;
|
||||
changed(8);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Participant::setAvatarState(Shared::Avatar p_state) {
|
||||
if (avatarState != p_state) {
|
||||
avatarState = p_state;
|
||||
changed(7);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Participant::setAvatarState(unsigned int p_state) {
|
||||
setAvatarState(Shared::Global::fromInt<Shared::Avatar>(p_state));
|
||||
}
|
||||
|
|
|
@ -21,14 +21,8 @@
|
|||
|
||||
Models::Presence::Presence(const QMap<QString, QVariant>& data, Item* parentItem):
|
||||
AbstractParticipant(Item::presence, data, parentItem)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
Models::Presence::~Presence()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
int Models::Presence::columnCount() const
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
|
|
@ -34,8 +34,6 @@ class Presence : public Models::AbstractParticipant
|
|||
public:
|
||||
explicit Presence(const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||
~Presence();
|
||||
|
||||
int columnCount() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -225,6 +225,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
if (s.size() > 0) {
|
||||
str += "\n" + tr("Status: ") + s;
|
||||
}
|
||||
str += "\n" + tr("Client: ") + contact->getClientNode();
|
||||
|
||||
result = str;
|
||||
}
|
||||
|
@ -240,7 +241,8 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
}
|
||||
|
||||
str += tr("Affiliation: ") + Shared::Global::getName(p->getAffiliation()) + "\n";
|
||||
str += tr("Role: ") + Shared::Global::getName(p->getRole());
|
||||
str += tr("Role: ") + Shared::Global::getName(p->getRole()) + "\n";
|
||||
str += tr("Client: ") + p->getClientNode();
|
||||
|
||||
result = str;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue