diff --git a/core/account.cpp b/core/account.cpp index 422a7eb..0f000d9 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -224,7 +224,6 @@ void Core::Account::onRosterItemChanged(const QString& bareJid) QXmppRosterManager& rm = client.rosterManager(); QXmppRosterIq::Item re = rm.getRosterEntry(bareJid); - QStringList res = rm.getResources(bareJid); Shared::SubscriptionState state = castSubscriptionState(re.subscriptionType()); contact->setGroups(re.groups()); @@ -315,6 +314,11 @@ void Core::Account::handleNewConference(Core::Conference* contact) QObject::connect(contact, SIGNAL(nickChanged(const QString&)), this, SLOT(onMucNickNameChanged(const QString&))); QObject::connect(contact, SIGNAL(joinedChanged(bool)), this, SLOT(onMucJoinedChanged(bool))); QObject::connect(contact, SIGNAL(autoJoinChanged(bool)), this, SLOT(onMucAutoJoinChanged(bool))); + QObject::connect(contact, SIGNAL(addParticipant(const QString&, const QMap&)), + this, SLOT(onMucAddParticipant(const QString&, const QMap&))); + QObject::connect(contact, SIGNAL(changeParticipant(const QString&, const QMap&)), + this, SLOT(onMucChangeParticipant(const QString&, const QMap&))); + QObject::connect(contact, SIGNAL(removeParticipant(const QString&)), this, SLOT(onMucRemoveParticipant(const QString&))); } @@ -1058,3 +1062,21 @@ void Core::Account::setRoomJoined(const QString& jid, bool joined) cItr->second->setJoined(joined); } + +void Core::Account::onMucAddParticipant(const QString& nickName, const QMap& data) +{ + Conference* room = static_cast(sender()); + emit addRoomParticipant(room->jid, nickName, data); +} + +void Core::Account::onMucChangeParticipant(const QString& nickName, const QMap& data) +{ + Conference* room = static_cast(sender()); + emit changeRoomParticipant(room->jid, nickName, data); +} + +void Core::Account::onMucRemoveParticipant(const QString& nickName) +{ + Conference* room = static_cast(sender()); + emit removeRoomParticipant(room->jid, nickName); +} diff --git a/core/account.h b/core/account.h index b8973ba..ea604f9 100644 --- a/core/account.h +++ b/core/account.h @@ -91,6 +91,9 @@ signals: void message(const Shared::Message& data); void responseArchive(const QString& jid, const std::list& list); void error(const QString& text); + void addRoomParticipant(const QString& jid, const QString& nickName, const QMap& data); + void changeRoomParticipant(const QString& jid, const QString& nickName, const QMap& data); + void removeRoomParticipant(const QString& jid, const QString& nickName); private: QString name; @@ -136,6 +139,9 @@ private slots: void onMucJoinedChanged(bool joined); void onMucAutoJoinChanged(bool autoJoin); void onMucNickNameChanged(const QString& nickName); + void onMucAddParticipant(const QString& nickName, const QMap& data); + void onMucChangeParticipant(const QString& nickName, const QMap& data); + void onMucRemoveParticipant(const QString& nickName); void bookmarksReceived(const QXmppBookmarkSet& bookmarks); diff --git a/core/conference.cpp b/core/conference.cpp index 18e46da..3124da5 100644 --- a/core/conference.cpp +++ b/core/conference.cpp @@ -33,6 +33,9 @@ Core::Conference::Conference(const QString& p_jid, const QString& p_account, boo connect(room, SIGNAL(joined()), this, SLOT(onRoomJoined())); connect(room, SIGNAL(left()), this, SLOT(onRoomLeft())); connect(room, SIGNAL(nameChanged(const QString&)), this, SLOT(onRoomNameChanged(const QString&))); + connect(room, SIGNAL(participantAdded(const QString&)), this, SLOT(onRoomParticipantAdded(const QString&))); + connect(room, SIGNAL(participantChanged(const QString&)), this, SLOT(onRoomParticipantChanged(const QString&))); + connect(room, SIGNAL(participantRemoved(const QString&)), this, SLOT(onRoomParticipantRemoved(const QString&))); connect(room, SIGNAL(nickNameChanged(const QString&)), this, SLOT(onRoomNickNameChanged(const QString&))); connect(room, SIGNAL(error(const QXmppStanza::Error&)), this, SLOT(onRoomError(const QXmppStanza::Error&))); @@ -119,5 +122,65 @@ void Core::Conference::onRoomNickNameChanged(const QString& p_nick) void Core::Conference::onRoomError(const QXmppStanza::Error& err) { - qDebug() << "MUC error"; + qDebug() << "MUC" << jid << "error:" << err.text(); +} + +void Core::Conference::onRoomParticipantAdded(const QString& p_name) +{ + QStringList comps = p_name.split("/"); + QString resource = comps.back(); + if (resource == jid) { + qDebug() << "Room" << jid << "is reporting of adding itself to the list participants. Not sure what to do with that yet, skipping"; + } else { + qDebug() << "Participant" << resource << "had entered room" << jid; + QXmppPresence pres = room->participantPresence(jid); + QDateTime lastInteraction = pres.lastUserInteraction(); + if (!lastInteraction.isValid()) { + lastInteraction = QDateTime::currentDateTime(); + } + QXmppMucItem mi = pres.mucItem(); + + emit addParticipant(resource, { + {"lastActivity", lastInteraction}, + {"availability", pres.availableStatusType()}, + {"status", pres.statusText()}, + {"affiliation", mi.affiliation()}, + {"role", mi.role()} + }); + } +} + +void Core::Conference::onRoomParticipantChanged(const QString& p_name) +{ + QStringList comps = p_name.split("/"); + QString resource = comps.back(); + if (resource == jid) { + qDebug() << "Room" << jid << "is reporting of changing his own presence. Not sure what to do with that yet, skipping"; + } else { + QXmppPresence pres = room->participantPresence(jid); + QDateTime lastInteraction = pres.lastUserInteraction(); + if (!lastInteraction.isValid()) { + lastInteraction = QDateTime::currentDateTime(); + } + QXmppMucItem mi = pres.mucItem(); + + emit changeParticipant(resource, { + {"lastActivity", lastInteraction}, + {"availability", pres.availableStatusType()}, + {"status", pres.statusText()}, + {"affiliation", mi.affiliation()}, + {"role", mi.role()} + }); + } +} + +void Core::Conference::onRoomParticipantRemoved(const QString& p_name) +{ + QStringList comps = p_name.split("/"); + QString resource = comps.back(); + if (resource == jid) { + qDebug() << "Room" << jid << "is reporting of removing his own presence from the list of participants. Not sure what to do with that yet, skipping"; + } else { + emit removeParticipant(resource); + } } diff --git a/core/conference.h b/core/conference.h index 739faa2..c589fdf 100644 --- a/core/conference.h +++ b/core/conference.h @@ -48,6 +48,9 @@ signals: void nickChanged(const QString& nick); void joinedChanged(bool joined); void autoJoinChanged(bool autoJoin); + void addParticipant(const QString& name, const QMap& data); + void changeParticipant(const QString& name, const QMap& data); + void removeParticipant(const QString& name); private: QString nick; @@ -61,6 +64,9 @@ private slots: void onRoomNameChanged(const QString& p_name); void onRoomNickNameChanged(const QString& p_nick); void onRoomError(const QXmppStanza::Error& err); + void onRoomParticipantAdded(const QString& p_name); + void onRoomParticipantChanged(const QString& p_name); + void onRoomParticipantRemoved(const QString& p_name); }; diff --git a/core/squawk.cpp b/core/squawk.cpp index 08eb31b..fa8be41 100644 --- a/core/squawk.cpp +++ b/core/squawk.cpp @@ -440,3 +440,20 @@ void Core::Squawk::setRoomAutoJoin(const QString& account, const QString& jid, b itr->second->setRoomAutoJoin(jid, joined); } +void Core::Squawk::onAccountAddRoomPresence(const QString& jid, const QString& nick, const QMap& data) +{ + Account* acc = static_cast(sender()); + emit addRoomParticipant(acc->getName(), jid, nick, data); +} + +void Core::Squawk::onAccountChangeRoomPresence(const QString& jid, const QString& nick, const QMap& data) +{ + Account* acc = static_cast(sender()); + emit changeRoomParticipant(acc->getName(), jid, nick, data); +} + +void Core::Squawk::onAccountRemoveRoomPresence(const QString& jid, const QString& nick) +{ + Account* acc = static_cast(sender()); + emit removeRoomParticipant(acc->getName(), jid, nick); +} diff --git a/core/squawk.h b/core/squawk.h index 8accae4..81706f4 100644 --- a/core/squawk.h +++ b/core/squawk.h @@ -58,6 +58,9 @@ signals: void addRoom(const QString& account, const QString jid, const QMap& data); void changeRoom(const QString& account, const QString jid, const QMap& data); void removeRoom(const QString& account, const QString jid); + void addRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap& data); + void changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap& data); + void removeRoomParticipant(const QString& account, const QString& jid, const QString& name); public slots: void start(); @@ -105,6 +108,9 @@ private slots: void onAccountAddRoom(const QString jid, const QMap& data); void onAccountChangeRoom(const QString jid, const QMap& data); void onAccountRemoveRoom(const QString jid); + void onAccountAddRoomPresence(const QString& jid, const QString& nick, const QMap& data); + void onAccountChangeRoomPresence(const QString& jid, const QString& nick, const QMap& data); + void onAccountRemoveRoomPresence(const QString& jid, const QString& nick); }; } diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 511f985..e56d8fd 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -22,6 +22,7 @@ set(squawkUI_SRC models/presence.cpp models/group.cpp models/room.cpp + models/abstractparticipant.cpp widgets/conversation.cpp widgets/chat.cpp widgets/room.cpp diff --git a/ui/models/abstractparticipant.cpp b/ui/models/abstractparticipant.cpp new file mode 100644 index 0000000..6563807 --- /dev/null +++ b/ui/models/abstractparticipant.cpp @@ -0,0 +1,126 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#include "abstractparticipant.h" + +using namespace Models; + +Models::AbstractParticipant::AbstractParticipant(Models::Item::Type p_type, const QMap& data, Models::Item* parentItem): + Item(p_type, data, parentItem), + availability(Shared::offline), + lastActivity(data.value("lastActivity").toDateTime()), + status(data.value("status").toString()) +{ + QMap::const_iterator itr = data.find("availability"); + if (itr != data.end()) { + setAvailability(itr.value().toUInt()); + } +} + +Models::AbstractParticipant::~AbstractParticipant() +{ +} + +int Models::AbstractParticipant::columnCount() const +{ + return 5; +} + +QVariant Models::AbstractParticipant::data(int column) const +{ + switch (column) { + case 0: + return Item::data(column); + case 1: + return lastActivity; + case 2: + return availability; + case 3: + return status; + default: + return QVariant(); + } +} + +Shared::Availability Models::AbstractParticipant::getAvailability() const +{ + return availability; +} + +QDateTime Models::AbstractParticipant::getLastActivity() const +{ + return lastActivity; +} + +QString Models::AbstractParticipant::getStatus() const +{ + return status; +} + +void Models::AbstractParticipant::setAvailability(Shared::Availability p_avail) +{ + if (availability != p_avail) { + availability = p_avail; + changed(2); + } +} + +void Models::AbstractParticipant::setAvailability(unsigned int avail) +{ + if (avail <= Shared::availabilityHighest) { + Shared::Availability state = static_cast(avail); + setAvailability(state); + } else { + qDebug("An attempt to set wrong state to the contact"); + } +} + + +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) +{ + if (status != p_state) { + status = p_state; + changed(3); + } +} + +QIcon Models::AbstractParticipant::getStatusIcon(bool big) const +{ + return Shared::availabilityIcon(availability, big); +} + +void Models::AbstractParticipant::update(const QString& key, const QVariant& value) +{ + 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()); + } +} diff --git a/ui/models/abstractparticipant.h b/ui/models/abstractparticipant.h new file mode 100644 index 0000000..44cbcb9 --- /dev/null +++ b/ui/models/abstractparticipant.h @@ -0,0 +1,60 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + +#ifndef MODELS_ABSTRACTPARTICIPANT_H +#define MODELS_ABSTRACTPARTICIPANT_H + + +#include "item.h" +#include "../../global.h" +#include + +namespace Models { + +class AbstractParticipant : public Models::Item +{ + Q_OBJECT +public: + explicit AbstractParticipant(Type p_type, const QMap &data, Item *parentItem = 0); + ~AbstractParticipant(); + + virtual int columnCount() const override; + virtual QVariant data(int column) const override; + + Shared::Availability getAvailability() const; + void setAvailability(Shared::Availability p_avail); + void setAvailability(unsigned int avail); + + QDateTime getLastActivity() const; + void setLastActivity(const QDateTime& p_time); + + QString getStatus() const; + void setStatus(const QString& p_state); + virtual QIcon getStatusIcon(bool big = false) const; + + virtual void update(const QString& key, const QVariant& value); + +protected: + Shared::Availability availability; + QDateTime lastActivity; + QString status; +}; + +} + +#endif // MODELS_ABSTRACTPARTICIPANT_H diff --git a/ui/models/account.cpp b/ui/models/account.cpp index 196206a..56a7806 100644 --- a/ui/models/account.cpp +++ b/ui/models/account.cpp @@ -1,3 +1,21 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + #include "account.h" #include diff --git a/ui/models/account.h b/ui/models/account.h index 8474fab..fbdf204 100644 --- a/ui/models/account.h +++ b/ui/models/account.h @@ -1,3 +1,21 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + #ifndef MODELS_ACCOUNT_H #define MODELS_ACCOUNT_H diff --git a/ui/models/accounts.cpp b/ui/models/accounts.cpp index c8b7129..75626c4 100644 --- a/ui/models/accounts.cpp +++ b/ui/models/accounts.cpp @@ -1,3 +1,21 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + #include "accounts.h" #include "../../global.h" diff --git a/ui/models/accounts.h b/ui/models/accounts.h index dd88ab9..e8be07c 100644 --- a/ui/models/accounts.h +++ b/ui/models/accounts.h @@ -1,3 +1,21 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + #ifndef MODELS_ACCOUNTS_H #define MODELS_ACCOUNTS_H diff --git a/ui/models/contact.cpp b/ui/models/contact.cpp index 6f79662..4c7b440 100644 --- a/ui/models/contact.cpp +++ b/ui/models/contact.cpp @@ -1,3 +1,21 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + #include "contact.h" #include diff --git a/ui/models/contact.h b/ui/models/contact.h index ea8c469..d390aec 100644 --- a/ui/models/contact.h +++ b/ui/models/contact.h @@ -1,3 +1,21 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + #ifndef MODELS_CONTACT_H #define MODELS_CONTACT_H diff --git a/ui/models/group.cpp b/ui/models/group.cpp index 61098f1..1880714 100644 --- a/ui/models/group.cpp +++ b/ui/models/group.cpp @@ -1,6 +1,6 @@ /* - * - * Copyright (C) 2019 Юрий Губич + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich * * 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 diff --git a/ui/models/group.h b/ui/models/group.h index fe1bb0d..8301dc8 100644 --- a/ui/models/group.h +++ b/ui/models/group.h @@ -1,6 +1,6 @@ /* - * - * Copyright (C) 2019 Юрий Губич + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich * * 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 diff --git a/ui/models/item.cpp b/ui/models/item.cpp index 5251cfb..59457c3 100644 --- a/ui/models/item.cpp +++ b/ui/models/item.cpp @@ -1,3 +1,21 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + #include "item.h" #include "account.h" diff --git a/ui/models/item.h b/ui/models/item.h index 2f6fc5e..4728e54 100644 --- a/ui/models/item.h +++ b/ui/models/item.h @@ -1,3 +1,21 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + #ifndef MODELS_ITEM_H #define MODELS_ITEM_H @@ -18,6 +36,7 @@ class Item : public QObject{ contact, room, presence, + participant, root }; diff --git a/ui/models/presence.cpp b/ui/models/presence.cpp index be2f8c9..20ddb06 100644 --- a/ui/models/presence.cpp +++ b/ui/models/presence.cpp @@ -1,5 +1,5 @@ /* - * + * Squawk messenger. * Copyright (C) 2019 Yury Gubich * * This program is free software: you can redistribute it and/or modify @@ -19,105 +19,22 @@ #include "presence.h" Models::Presence::Presence(const QMap& data, Item* parentItem): - Item(Item::presence, data, parentItem), - availability(Shared::offline), - lastActivity(data.value("lastActivity").toDateTime()), - status(data.value("status").toString()), + AbstractParticipant(Item::presence, data, parentItem), messages() { - QMap::const_iterator itr = data.find("availability"); - if (itr != data.end()) { - setAvailability(itr.value().toUInt()); - } } Models::Presence::~Presence() { } -int Models::Presence::columnCount() const -{ - return 5; -} - QVariant Models::Presence::data(int column) const { switch (column) { - case 0: - return Item::data(column); - case 1: - return lastActivity; - case 2: - return availability; - case 3: - return status; case 4: return getMessagesCount(); default: - return QVariant(); - } -} - -Shared::Availability Models::Presence::getAvailability() const -{ - return availability; -} - -QDateTime Models::Presence::getLastActivity() const -{ - return lastActivity; -} - -QString Models::Presence::getStatus() const -{ - return status; -} - -void Models::Presence::setAvailability(Shared::Availability p_avail) -{ - if (availability != p_avail) { - availability = p_avail; - changed(2); - } -} - -void Models::Presence::setAvailability(unsigned int avail) -{ - if (avail <= Shared::availabilityHighest) { - Shared::Availability state = static_cast(avail); - setAvailability(state); - } else { - qDebug("An attempt to set wrong state to the contact"); - } -} - - -void Models::Presence::setLastActivity(const QDateTime& p_time) -{ - if (lastActivity != p_time) { - lastActivity = p_time; - changed(1); - } -} - -void Models::Presence::setStatus(const QString& p_state) -{ - if (status != p_state) { - status = p_state; - changed(3); - } -} - -void Models::Presence::update(const QString& key, const QVariant& value) -{ - 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()); + return AbstractParticipant::data(column); } } @@ -143,9 +60,9 @@ void Models::Presence::dropMessages() QIcon Models::Presence::getStatusIcon(bool big) const { if (getMessagesCount() > 0) { - return Shared::icon("mail-message"); + return Shared::icon("mail-message", big); } else { - return Shared::availabilityIcon(availability, big); + return AbstractParticipant::getStatusIcon(); } } diff --git a/ui/models/presence.h b/ui/models/presence.h index b44f066..b6b9df9 100644 --- a/ui/models/presence.h +++ b/ui/models/presence.h @@ -1,5 +1,5 @@ /* - * + * Squawk messenger. * Copyright (C) 2019 Yury Gubich * * This program is free software: you can redistribute it and/or modify @@ -19,14 +19,14 @@ #ifndef MODELS_PRESENCE_H #define MODELS_PRESENCE_H -#include "item.h" +#include "abstractparticipant.h" #include "../../global.h" #include #include namespace Models { -class Presence : public Models::Item +class Presence : public Models::AbstractParticipant { Q_OBJECT public: @@ -34,21 +34,10 @@ public: explicit Presence(const QMap &data, Item *parentItem = 0); ~Presence(); - virtual int columnCount() const override; - virtual QVariant data(int column) const override; + QVariant data(int column) const override; - Shared::Availability getAvailability() const; - void setAvailability(Shared::Availability p_avail); - void setAvailability(unsigned int avail); + QIcon getStatusIcon(bool big = false) const override; - QDateTime getLastActivity() const; - void setLastActivity(const QDateTime& p_time); - - QString getStatus() const; - void setStatus(const QString& p_state); - QIcon getStatusIcon(bool big = false) const; - - void update(const QString& key, const QVariant& value); unsigned int getMessagesCount() const; void dropMessages(); void addMessage(const Shared::Message& data); @@ -56,9 +45,6 @@ public: void getMessages(Messages& container) const; private: - Shared::Availability availability; - QDateTime lastActivity; - QString status; Messages messages; }; diff --git a/ui/models/room.cpp b/ui/models/room.cpp index 62b47fb..ab56b11 100644 --- a/ui/models/room.cpp +++ b/ui/models/room.cpp @@ -1,6 +1,6 @@ /* - * - * Copyright (C) 2019 Юрий Губич + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich * * 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 diff --git a/ui/models/room.h b/ui/models/room.h index 456c13e..2cf8fe5 100644 --- a/ui/models/room.h +++ b/ui/models/room.h @@ -1,6 +1,6 @@ /* - * - * Copyright (C) 2019 Юрий Губич + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich * * 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 diff --git a/ui/models/roster.cpp b/ui/models/roster.cpp index c91d909..7e3ea4e 100644 --- a/ui/models/roster.cpp +++ b/ui/models/roster.cpp @@ -1,3 +1,21 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + #include "roster.h" #include #include diff --git a/ui/models/roster.h b/ui/models/roster.h index 862c5b4..ad697e8 100644 --- a/ui/models/roster.h +++ b/ui/models/roster.h @@ -1,3 +1,21 @@ +/* + * Squawk messenger. + * Copyright (C) 2019 Yury Gubich + * + * 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 . + */ + #ifndef MODELS_ROSTER_H #define MODELS_ROSTER_H