2019-09-01 19:46:12 +00:00
|
|
|
/*
|
|
|
|
* Squawk messenger.
|
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "abstractparticipant.h"
|
|
|
|
|
|
|
|
Models::AbstractParticipant::AbstractParticipant(Models::Item::Type p_type, const QMap<QString, QVariant>& data, Models::Item* parentItem):
|
|
|
|
Item(p_type, data, parentItem),
|
2020-04-03 22:28:15 +00:00
|
|
|
availability(Shared::Availability::offline),
|
2019-09-01 19:46:12 +00:00
|
|
|
lastActivity(data.value("lastActivity").toDateTime()),
|
2023-03-14 19:49:58 +00:00
|
|
|
status(data.value("status").toString()),
|
|
|
|
client()
|
2019-09-01 19:46:12 +00:00
|
|
|
{
|
|
|
|
QMap<QString, QVariant>::const_iterator itr = data.find("availability");
|
2023-03-14 19:49:58 +00:00
|
|
|
if (itr != data.end())
|
2019-09-01 19:46:12 +00:00
|
|
|
setAvailability(itr.value().toUInt());
|
2023-03-14 19:49:58 +00:00
|
|
|
|
|
|
|
itr = data.find("client");
|
|
|
|
if (itr != data.end())
|
|
|
|
setClient(itr.value().value<Shared::ClientId>());
|
2019-09-01 19:46:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 14:30:16 +00:00
|
|
|
Models::AbstractParticipant::AbstractParticipant(const Models::AbstractParticipant& other):
|
|
|
|
Item(other),
|
|
|
|
availability(other.availability),
|
|
|
|
lastActivity(other.lastActivity),
|
2023-03-14 19:49:58 +00:00
|
|
|
status(other.status),
|
|
|
|
client(other.client)
|
|
|
|
{}
|
2019-09-28 14:30:16 +00:00
|
|
|
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
Models::AbstractParticipant::~AbstractParticipant() {}
|
2019-09-01 19:46:12 +00:00
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
int Models::AbstractParticipant::columnCount() const {
|
|
|
|
return 5;
|
2019-09-01 19:46:12 +00:00
|
|
|
}
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
QVariant Models::AbstractParticipant::data(int column) const {
|
2019-09-01 19:46:12 +00:00
|
|
|
switch (column) {
|
|
|
|
case 0:
|
|
|
|
return Item::data(column);
|
|
|
|
case 1:
|
|
|
|
return lastActivity;
|
|
|
|
case 2:
|
2020-04-03 22:28:15 +00:00
|
|
|
return QVariant::fromValue(availability);
|
2019-09-01 19:46:12 +00:00
|
|
|
case 3:
|
|
|
|
return status;
|
2023-03-14 19:49:58 +00:00
|
|
|
case 4:
|
|
|
|
return QVariant::fromValue(client);
|
2019-09-01 19:46:12 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
Shared::Availability Models::AbstractParticipant::getAvailability() const {
|
2019-09-01 19:46:12 +00:00
|
|
|
return availability;
|
|
|
|
}
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
QDateTime Models::AbstractParticipant::getLastActivity() const {
|
2019-09-01 19:46:12 +00:00
|
|
|
return lastActivity;
|
|
|
|
}
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
QString Models::AbstractParticipant::getStatus() const {
|
2019-09-01 19:46:12 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
void Models::AbstractParticipant::setAvailability(Shared::Availability p_avail) {
|
2019-09-01 19:46:12 +00:00
|
|
|
if (availability != p_avail) {
|
|
|
|
availability = p_avail;
|
|
|
|
changed(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
void Models::AbstractParticipant::setAvailability(unsigned int avail) {
|
2020-04-03 22:28:15 +00:00
|
|
|
setAvailability(Shared::Global::fromInt<Shared::Availability>(avail));
|
2019-09-01 19:46:12 +00:00
|
|
|
}
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
void Models::AbstractParticipant::setLastActivity(const QDateTime& p_time) {
|
2019-09-01 19:46:12 +00:00
|
|
|
if (lastActivity != p_time) {
|
|
|
|
lastActivity = p_time;
|
|
|
|
changed(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
void Models::AbstractParticipant::setStatus(const QString& p_state) {
|
2019-09-01 19:46:12 +00:00
|
|
|
if (status != p_state) {
|
|
|
|
status = p_state;
|
|
|
|
changed(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
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 {
|
2019-09-01 19:46:12 +00:00
|
|
|
return Shared::availabilityIcon(availability, big);
|
|
|
|
}
|
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
void Models::AbstractParticipant::update(const QString& key, const QVariant& value) {
|
2019-09-01 19:46:12 +00:00
|
|
|
if (key == "name") {
|
|
|
|
setName(value.toString());
|
|
|
|
} else if (key == "status") {
|
|
|
|
setStatus(value.toString());
|
|
|
|
} else if (key == "availability") {
|
|
|
|
setAvailability(value.toUInt());
|
|
|
|
} else if (key == "lastActivity") {
|
|
|
|
setLastActivity(value.toDateTime());
|
2023-03-14 19:49:58 +00:00
|
|
|
} else if (key == "client") {
|
|
|
|
setClient(value.value<Shared::ClientId>());
|
2019-09-01 19:46:12 +00:00
|
|
|
}
|
|
|
|
}
|