forked from blue/squawk
mucs initial, just display; archive fixes
This commit is contained in:
parent
30c59fbb91
commit
eda96e138d
19 changed files with 626 additions and 43 deletions
|
@ -21,6 +21,7 @@ set(squawkUI_SRC
|
|||
models/contact.cpp
|
||||
models/presence.cpp
|
||||
models/group.cpp
|
||||
models/room.cpp
|
||||
conversation.cpp
|
||||
messageline.cpp
|
||||
newcontact.cpp
|
||||
|
|
|
@ -51,6 +51,7 @@ Conversation::Conversation(Models::Contact* p_contact, QWidget* parent):
|
|||
//connect(m_ui->attachButton, SIGNAL(clicked(bool)), this, SLOT(onAttach()));
|
||||
|
||||
m_ui->messageEditor->installEventFilter(&ker);
|
||||
line->setMyName(p_contact->getAccountName());
|
||||
|
||||
Models::Contact::Messages deque;
|
||||
contact->getMessages(deque);
|
||||
|
@ -59,7 +60,6 @@ Conversation::Conversation(Models::Contact* p_contact, QWidget* parent):
|
|||
addMessage(*itr);
|
||||
}
|
||||
|
||||
line->setMyName(p_contact->getAccountName());
|
||||
connect(line, SIGNAL(resize(int)), this, SLOT(onMessagesResize(int)));
|
||||
|
||||
QScrollBar* vs = m_ui->scrollArea->verticalScrollBar();
|
||||
|
|
|
@ -152,8 +152,8 @@ void Models::Contact::removePresence(const QString& name)
|
|||
qDebug() << "an attempt to remove non existing presence " << name << " from the contact " << jid << " of account " << getAccountName() << ", skipping";
|
||||
} else {
|
||||
Presence* pr = itr.value();
|
||||
removeChild(pr->row());
|
||||
presences.erase(itr);
|
||||
removeChild(pr->row());
|
||||
pr->deleteLater();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class Contact : public Item
|
|||
Q_OBJECT
|
||||
public:
|
||||
typedef std::deque<Shared::Message> Messages;
|
||||
Contact(const QString& p_jid ,const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||
Contact(const QString& p_jid, const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||
~Contact();
|
||||
|
||||
QString getJid() const;
|
||||
|
|
|
@ -3,10 +3,15 @@
|
|||
Models::Item::Item(Type p_type, const QMap<QString, QVariant> &p_data, Item *p_parent):
|
||||
QObject(),
|
||||
type(p_type),
|
||||
name(p_data.value("name").toString()),
|
||||
name(""),
|
||||
childItems(),
|
||||
parent(p_parent)
|
||||
{}
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator itr = p_data.find("name");
|
||||
if (itr != p_data.end()) {
|
||||
setName(itr.value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
Models::Item::~Item()
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@ class Item : public QObject{
|
|||
account,
|
||||
group,
|
||||
contact,
|
||||
conversation,
|
||||
room,
|
||||
presence,
|
||||
root
|
||||
};
|
||||
|
|
186
ui/models/room.cpp
Normal file
186
ui/models/room.cpp
Normal file
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
* <one line to give the program's name and a brief idea of what it does.>
|
||||
* Copyright (C) 2019 Юрий Губич <y.gubich@initi.ru>
|
||||
*
|
||||
* 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 "room.h"
|
||||
#include <QIcon>
|
||||
|
||||
Models::Room::Room(const QString& p_jid, const QMap<QString, QVariant>& data, Models::Item* parentItem):
|
||||
Item(room, data, parentItem),
|
||||
autoJoin(false),
|
||||
joined(false),
|
||||
jid(p_jid),
|
||||
nick(""),
|
||||
messages()
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("autoJoin");
|
||||
if (itr != data.end()) {
|
||||
setAutoJoin(itr.value().toBool());
|
||||
}
|
||||
|
||||
itr = data.find("joined");
|
||||
if (itr != data.end()) {
|
||||
setJoined(itr.value().toBool());
|
||||
}
|
||||
|
||||
itr = data.find("nick");
|
||||
if (itr != data.end()) {
|
||||
setNick(itr.value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
Models::Room::~Room()
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int Models::Room::getUnreadMessagesCount() const
|
||||
{
|
||||
return messages.size();
|
||||
}
|
||||
|
||||
int Models::Room::columnCount() const
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
QString Models::Room::getJid() const
|
||||
{
|
||||
return jid;
|
||||
}
|
||||
|
||||
bool Models::Room::getAutoJoin() const
|
||||
{
|
||||
return autoJoin;
|
||||
}
|
||||
|
||||
bool Models::Room::getJoined() const
|
||||
{
|
||||
return joined;
|
||||
}
|
||||
|
||||
QString Models::Room::getNick() const
|
||||
{
|
||||
return nick;
|
||||
}
|
||||
|
||||
QString Models::Room::getRoomName() const
|
||||
{
|
||||
if (name.size() == 0) {
|
||||
return jid;
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant Models::Room::data(int column) const
|
||||
{
|
||||
switch (column) {
|
||||
case 0:
|
||||
return getRoomName();
|
||||
case 1:
|
||||
return jid;
|
||||
case 2:
|
||||
return getJoined();
|
||||
case 3:
|
||||
return getAutoJoin();
|
||||
case 4:
|
||||
return getNick();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Room::setAutoJoin(bool p_autoJoin)
|
||||
{
|
||||
if (autoJoin != p_autoJoin) {
|
||||
autoJoin = p_autoJoin;
|
||||
changed(3);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Room::setJid(const QString& p_jid)
|
||||
{
|
||||
if (jid != p_jid) {
|
||||
jid = p_jid;
|
||||
changed(1);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Room::setJoined(bool p_joined)
|
||||
{
|
||||
if (joined != p_joined) {
|
||||
joined = p_joined;
|
||||
changed(2);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Room::setNick(const QString& p_nick)
|
||||
{
|
||||
if (nick != p_nick) {
|
||||
nick = p_nick;
|
||||
changed(4);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Room::update(const QString& field, const QVariant& value)
|
||||
{
|
||||
if (field == "name") {
|
||||
setName(value.toString());
|
||||
} else if (field == "jid") {
|
||||
setJid(value.toString());
|
||||
} else if (field == "joined") {
|
||||
setJoined(value.toBool());
|
||||
} else if (field == "autoJoin") {
|
||||
setAutoJoin(value.toBool());
|
||||
} else if (field == "nick") {
|
||||
setNick(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
QIcon Models::Room::getStatusIcon(bool big) const
|
||||
{
|
||||
if (autoJoin) {
|
||||
if (joined) {
|
||||
return Shared::connectionStateIcon(Shared::connected, big);
|
||||
} else {
|
||||
return Shared::connectionStateIcon(Shared::disconnected, big);
|
||||
}
|
||||
} else {
|
||||
if (joined) {
|
||||
return Shared::connectionStateIcon(Shared::connecting, big);
|
||||
} else {
|
||||
return Shared::connectionStateIcon(Shared::error, big);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString Models::Room::getStatusText() const
|
||||
{
|
||||
if (autoJoin) {
|
||||
if (joined) {
|
||||
return "Subscribed";
|
||||
} else {
|
||||
return "Temporarily unsubscribed";
|
||||
}
|
||||
} else {
|
||||
if (joined) {
|
||||
return "Temporarily subscribed";
|
||||
} else {
|
||||
return "Unsubscribed";
|
||||
}
|
||||
}
|
||||
}
|
70
ui/models/room.h
Normal file
70
ui/models/room.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* <one line to give the program's name and a brief idea of what it does.>
|
||||
* Copyright (C) 2019 Юрий Губич <y.gubich@initi.ru>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef MODELS_ROOM_H
|
||||
#define MODELS_ROOM_H
|
||||
|
||||
#include "item.h"
|
||||
#include "../global.h"
|
||||
|
||||
namespace Models {
|
||||
|
||||
/**
|
||||
* @todo write docs
|
||||
*/
|
||||
class Room : public Models::Item
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Room(const QString& p_jid, const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||
~Room();
|
||||
|
||||
int columnCount() const override;
|
||||
QVariant data(int column) const override;
|
||||
|
||||
unsigned int getUnreadMessagesCount() const;
|
||||
bool getJoined() const;
|
||||
bool getAutoJoin() const;
|
||||
QString getJid() const;
|
||||
QString getNick() const;
|
||||
QString getRoomName() const;
|
||||
|
||||
QIcon getStatusIcon(bool big = false) const;
|
||||
QString getStatusText() const;
|
||||
|
||||
void setJoined(bool p_joined);
|
||||
void setAutoJoin(bool p_autoJoin);
|
||||
void setJid(const QString& p_jid);
|
||||
void setNick(const QString& p_nick);
|
||||
|
||||
void update(const QString& field, const QVariant& value);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
bool autoJoin;
|
||||
bool joined;
|
||||
QString jid;
|
||||
QString nick;
|
||||
std::deque<Shared::Message> messages;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // MODELS_ROOM_H
|
|
@ -74,21 +74,26 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
break;
|
||||
case Qt::DecorationRole:
|
||||
switch (item->type) {
|
||||
case Item::account:{
|
||||
case Item::account: {
|
||||
Account* acc = static_cast<Account*>(item);
|
||||
result = acc->getStatusIcon(false);
|
||||
}
|
||||
break;
|
||||
case Item::contact:{
|
||||
case Item::contact: {
|
||||
Contact* contact = static_cast<Contact*>(item);
|
||||
result = contact->getStatusIcon(false);
|
||||
}
|
||||
break;
|
||||
case Item::presence:{
|
||||
case Item::presence: {
|
||||
Presence* presence = static_cast<Presence*>(item);
|
||||
result = presence->getStatusIcon(false);
|
||||
}
|
||||
break;
|
||||
case Item::room: {
|
||||
Room* room = static_cast<Room*>(item);
|
||||
result = room->getStatusIcon(false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -172,6 +177,17 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
result = str;
|
||||
}
|
||||
break;
|
||||
case Item::room: {
|
||||
Room* rm = static_cast<Room*>(item);
|
||||
unsigned int count = rm->getUnreadMessagesCount();
|
||||
QString str("");
|
||||
if (count > 0) {
|
||||
str += QString("New messages: ") + std::to_string(count).c_str() + "\n";
|
||||
}
|
||||
str += QString("Subscription: ") + rm->getStatusText() + "\n";
|
||||
result = str;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result = "";
|
||||
break;
|
||||
|
@ -313,8 +329,8 @@ void Models::Roster::addGroup(const QString& account, const QString& name)
|
|||
if (itr != accounts.end()) {
|
||||
Account* acc = itr->second;
|
||||
Group* group = new Group({{"name", name}});
|
||||
acc->appendChild(group);
|
||||
groups.insert(std::make_pair(id, group));
|
||||
acc->appendChild(group);
|
||||
} else {
|
||||
qDebug() << "An attempt to add group " << name << " to non existing account " << account << ", skipping";
|
||||
}
|
||||
|
@ -382,8 +398,8 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
|
||||
}
|
||||
contact = new Contact(jid, data);
|
||||
parent->appendChild(contact);
|
||||
contacts.insert(std::make_pair(id, contact));
|
||||
parent->appendChild(contact);
|
||||
}
|
||||
|
||||
void Models::Roster::removeGroup(const QString& account, const QString& name)
|
||||
|
@ -638,6 +654,17 @@ void Models::Roster::removeAccount(const QString& account)
|
|||
}
|
||||
}
|
||||
|
||||
std::map<ElId, Room*>::const_iterator rItr = rooms.begin();
|
||||
while (rItr != rooms.end()) {
|
||||
if (rItr->first.account == account) {
|
||||
std::map<ElId, Room*>::const_iterator lItr = rItr;
|
||||
++rItr;
|
||||
rooms.erase(lItr);
|
||||
} else {
|
||||
++rItr;
|
||||
}
|
||||
}
|
||||
|
||||
acc->deleteLater();
|
||||
}
|
||||
|
||||
|
@ -650,3 +677,66 @@ QString Models::Roster::getContactName(const QString& account, const QString& ji
|
|||
}
|
||||
return cItr->second->getContactName();
|
||||
}
|
||||
|
||||
void Models::Roster::addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
Account* acc;
|
||||
{
|
||||
std::map<QString, Account*>::iterator itr = accounts.find(account);
|
||||
if (itr == accounts.end()) {
|
||||
qDebug() << "An attempt to add a room " << jid << " to non existing account " << account << ", skipping";
|
||||
return;
|
||||
}
|
||||
acc = itr->second;
|
||||
}
|
||||
|
||||
ElId id = {account, jid};
|
||||
std::map<ElId, Room*>::const_iterator itr = rooms.find(id);
|
||||
if (itr != rooms.end()) {
|
||||
qDebug() << "An attempt to add already existing room" << jid << ", skipping";
|
||||
return;
|
||||
}
|
||||
|
||||
Room* room = new Room(jid, data);
|
||||
rooms.insert(std::make_pair(id, room));
|
||||
acc->appendChild(room);
|
||||
}
|
||||
|
||||
void Models::Roster::changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
ElId id = {account, jid};
|
||||
std::map<ElId, Room*>::const_iterator itr = rooms.find(id);
|
||||
if (itr == rooms.end()) {
|
||||
qDebug() << "An attempt to change non existing room" << jid << ", skipping";
|
||||
return;
|
||||
}
|
||||
Room* room = itr->second;
|
||||
for (QMap<QString, QVariant>::const_iterator dItr = data.begin(), dEnd = data.end(); dItr != dEnd; ++dItr) {
|
||||
room->update(dItr.key(), dItr.value());
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::removeRoom(const QString& account, const QString jid)
|
||||
{
|
||||
Account* acc;
|
||||
{
|
||||
std::map<QString, Account*>::iterator itr = accounts.find(account);
|
||||
if (itr == accounts.end()) {
|
||||
qDebug() << "An attempt to remove a room " << jid << " from non existing account " << account << ", skipping";
|
||||
return;
|
||||
}
|
||||
acc = itr->second;
|
||||
}
|
||||
|
||||
ElId id = {account, jid};
|
||||
std::map<ElId, Room*>::const_iterator itr = rooms.find(id);
|
||||
if (itr == rooms.end()) {
|
||||
qDebug() << "An attempt to remove non existing room" << jid << ", skipping";
|
||||
return;
|
||||
}
|
||||
|
||||
Room* room = itr->second;
|
||||
acc->removeChild(room->row());
|
||||
room->deleteLater();
|
||||
rooms.erase(itr);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "account.h"
|
||||
#include "contact.h"
|
||||
#include "group.h"
|
||||
#include "room.h"
|
||||
|
||||
namespace Models
|
||||
{
|
||||
|
@ -36,6 +37,9 @@ public:
|
|||
void removePresence(const QString& account, const QString& jid, const QString& name);
|
||||
void addMessage(const QString& account, const Shared::Message& data);
|
||||
void dropMessages(const QString& account, const QString& jid);
|
||||
void addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||
void changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||
void removeRoom(const QString& account, const QString jid);
|
||||
QString getContactName(const QString& account, const QString& jid);
|
||||
|
||||
QVariant data ( const QModelIndex& index, int role ) const override;
|
||||
|
@ -53,6 +57,7 @@ private:
|
|||
std::map<QString, Account*> accounts;
|
||||
std::map<ElId, Group*> groups;
|
||||
std::multimap<ElId, Contact*> contacts;
|
||||
std::map<ElId, Room*> rooms;
|
||||
|
||||
private slots:
|
||||
void onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector<int>& roles);
|
||||
|
|
|
@ -418,3 +418,18 @@ void Squawk::onRosterContextMenu(const QPoint& point)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Squawk::addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
rosterModel.addRoom(account, jid, data);
|
||||
}
|
||||
|
||||
void Squawk::changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
rosterModel.changeRoom(account, jid, data);
|
||||
}
|
||||
|
||||
void Squawk::removeRoom(const QString& account, const QString jid)
|
||||
{
|
||||
rosterModel.removeRoom(account, jid);
|
||||
}
|
||||
|
|
|
@ -57,6 +57,9 @@ public slots:
|
|||
void stateChanged(int state);
|
||||
void accountMessage(const QString& account, const Shared::Message& data);
|
||||
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list);
|
||||
void addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||
void changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||
void removeRoom(const QString& account, const QString jid);
|
||||
|
||||
private:
|
||||
typedef std::map<Models::Roster::ElId, Conversation*> Conversations;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue