forked from blue/squawk
initial functionality of mucs
This commit is contained in:
parent
e2cc1bae2e
commit
023494de0b
23 changed files with 347 additions and 119 deletions
|
@ -24,6 +24,7 @@ set(squawkUI_SRC
|
|||
models/room.cpp
|
||||
widgets/conversation.cpp
|
||||
widgets/chat.cpp
|
||||
widgets/room.cpp
|
||||
widgets/messageline.cpp
|
||||
newcontact.cpp
|
||||
)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "contact.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include "account.h"
|
||||
|
||||
Models::Contact::Contact(const QString& p_jid ,const QMap<QString, QVariant> &data, Item *parentItem):
|
||||
Item(Item::contact, data, parentItem),
|
||||
|
@ -227,16 +227,6 @@ QIcon Models::Contact::getStatusIcon(bool big) const
|
|||
}
|
||||
}
|
||||
|
||||
QString Models::Contact::getAccountName() const
|
||||
{
|
||||
const Account* acc = getParentAccount();
|
||||
if (acc == 0) {
|
||||
qDebug() << "An attempt to request account name of the contact " << jid << " but the parent account wasn't found, returning empty string";
|
||||
return "";
|
||||
}
|
||||
return acc->getName();
|
||||
}
|
||||
|
||||
void Models::Contact::addMessage(const Shared::Message& data)
|
||||
{
|
||||
const QString& res = data.getPenPalResource();
|
||||
|
@ -291,36 +281,6 @@ void Models::Contact::getMessages(Models::Contact::Messages& container) const
|
|||
}
|
||||
}
|
||||
|
||||
QString Models::Contact::getAccountJid() const
|
||||
{
|
||||
const Account* acc = getParentAccount();
|
||||
if (acc == 0) {
|
||||
qDebug() << "An attempt to request account jid of the contact " << jid << " but the parent account wasn't found, returning empty string";
|
||||
return "";
|
||||
}
|
||||
return acc->getLogin() + "@" + acc->getServer();
|
||||
}
|
||||
|
||||
QString Models::Contact::getAccountResource() const
|
||||
{
|
||||
const Account* acc = getParentAccount();
|
||||
if (acc == 0) {
|
||||
qDebug() << "An attempt to request account resource of the contact " << jid << " but the parent account wasn't found, returning empty string";
|
||||
return "";
|
||||
}
|
||||
return acc->getResource();
|
||||
}
|
||||
|
||||
const Models::Account * Models::Contact::getParentAccount() const
|
||||
{
|
||||
const Item* p = this;
|
||||
do {
|
||||
p = p->parentItemConst();
|
||||
} while (p != 0 && p->type != Item::account);
|
||||
|
||||
return static_cast<const Account*>(p);
|
||||
}
|
||||
|
||||
void Models::Contact::toOfflineState()
|
||||
{
|
||||
emit childIsAboutToBeRemoved(this, 0, childItems.size());
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
namespace Models {
|
||||
|
||||
class Account;
|
||||
class Contact : public Item
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -33,9 +32,6 @@ public:
|
|||
void removePresence(const QString& name);
|
||||
|
||||
void appendChild(Models::Item * child) override;
|
||||
QString getAccountName() const;
|
||||
QString getAccountJid() const;
|
||||
QString getAccountResource() const;
|
||||
QString getContactName() const;
|
||||
QString getStatus() const;
|
||||
|
||||
|
@ -46,7 +42,6 @@ public:
|
|||
|
||||
protected:
|
||||
void _removeChild(int index) override;
|
||||
const Account* getParentAccount() const;
|
||||
|
||||
protected slots:
|
||||
void refresh();
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#include "item.h"
|
||||
#include "account.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Models::Item::Item(Type p_type, const QMap<QString, QVariant> &p_data, Item *p_parent):
|
||||
QObject(),
|
||||
|
@ -153,3 +156,41 @@ void Models::Item::toOfflineState()
|
|||
it->toOfflineState();
|
||||
}
|
||||
}
|
||||
|
||||
const Models::Item * Models::Item::getParentAccount() const
|
||||
{
|
||||
const Item* p = this;
|
||||
|
||||
while (p != 0 && p->type != Item::account) {
|
||||
p = p->parentItemConst();
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
QString Models::Item::getAccountJid() const
|
||||
{
|
||||
const Account* acc = static_cast<const Account*>(getParentAccount());
|
||||
if (acc == 0) {
|
||||
return "";
|
||||
}
|
||||
return acc->getLogin() + "@" + acc->getServer();
|
||||
}
|
||||
|
||||
QString Models::Item::getAccountResource() const
|
||||
{
|
||||
const Account* acc = static_cast<const Account*>(getParentAccount());
|
||||
if (acc == 0) {
|
||||
return "";
|
||||
}
|
||||
return acc->getResource();
|
||||
}
|
||||
|
||||
QString Models::Item::getAccountName() const
|
||||
{
|
||||
const Account* acc = static_cast<const Account*>(getParentAccount());
|
||||
if (acc == 0) {
|
||||
return "";
|
||||
}
|
||||
return acc->getName();
|
||||
}
|
||||
|
|
|
@ -47,11 +47,17 @@ class Item : public QObject{
|
|||
Item *parentItem();
|
||||
const Item *parentItemConst() const;
|
||||
|
||||
|
||||
QString getAccountName() const;
|
||||
QString getAccountJid() const;
|
||||
QString getAccountResource() const;
|
||||
|
||||
const Type type;
|
||||
|
||||
protected:
|
||||
virtual void changed(int col);
|
||||
virtual void _removeChild(int index);
|
||||
const Item* getParentAccount() const;
|
||||
|
||||
protected:
|
||||
QString name;
|
||||
|
|
|
@ -184,7 +184,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
if (count > 0) {
|
||||
str += QString("New messages: ") + std::to_string(count).c_str() + "\n";
|
||||
}
|
||||
str += QString("Subscription: ") + rm->getStatusText() + "\n";
|
||||
str += QString("Subscription: ") + rm->getStatusText();
|
||||
result = str;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -72,7 +72,7 @@ private slots:
|
|||
public:
|
||||
class ElId {
|
||||
public:
|
||||
ElId (const QString& p_account, const QString& p_name);
|
||||
ElId (const QString& p_account = "", const QString& p_name = "");
|
||||
|
||||
const QString account;
|
||||
const QString name;
|
||||
|
|
|
@ -213,50 +213,63 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item)
|
|||
if (item.isValid()) {
|
||||
Models::Item* node = static_cast<Models::Item*>(item.internalPointer());
|
||||
Models::Contact* contact = 0;
|
||||
Models::Room* room = 0;
|
||||
QString res;
|
||||
Models::Roster::ElId* id = 0;
|
||||
switch (node->type) {
|
||||
case Models::Item::contact:
|
||||
contact = static_cast<Models::Contact*>(node);
|
||||
id = new Models::Roster::ElId(contact->getAccountName(), contact->getJid());
|
||||
break;
|
||||
case Models::Item::presence:
|
||||
contact = static_cast<Models::Contact*>(node->parentItem());
|
||||
id = new Models::Roster::ElId(contact->getAccountName(), contact->getJid());
|
||||
res = node->getName();
|
||||
break;
|
||||
case Models::Item::room:
|
||||
room = static_cast<Models::Room*>(node);
|
||||
id = new Models::Roster::ElId(room->getAccountName(), room->getJid());
|
||||
break;
|
||||
default:
|
||||
m_ui->roster->expand(item);
|
||||
break;
|
||||
}
|
||||
|
||||
if (contact != 0) {
|
||||
QString jid = contact->getJid();
|
||||
QString account = contact->getAccountName();
|
||||
Models::Roster::ElId id(account, jid);
|
||||
Conversations::const_iterator itr = conversations.find(id);
|
||||
if (id != 0) {
|
||||
Conversations::const_iterator itr = conversations.find(*id);
|
||||
Conversation* conv = 0;
|
||||
bool created = false;
|
||||
if (itr != conversations.end()) {
|
||||
itr->second->show();
|
||||
itr->second->raise();
|
||||
itr->second->activateWindow();
|
||||
conv = itr->second;
|
||||
} else if (contact != 0) {
|
||||
created = true;
|
||||
conv = new Chat(contact);
|
||||
} else if (room != 0) {
|
||||
created = true;
|
||||
conv = new Room(room);
|
||||
}
|
||||
|
||||
if (res.size() > 0) {
|
||||
itr->second->setPalResource(res);
|
||||
if (conv != 0) {
|
||||
if (created) {
|
||||
conv->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
connect(conv, SIGNAL(destroyed(QObject*)), this, SLOT(onConversationClosed(QObject*)));
|
||||
connect(conv, SIGNAL(sendMessage(const Shared::Message&)), this, SLOT(onConversationMessage(const Shared::Message&)));
|
||||
connect(conv, SIGNAL(requestArchive(const QString&)), this, SLOT(onConversationRequestArchive(const QString&)));
|
||||
connect(conv, SIGNAL(shown()), this, SLOT(onConversationShown()));
|
||||
|
||||
conversations.insert(std::make_pair(*id, conv));
|
||||
}
|
||||
} else {
|
||||
Chat* conv = new Chat(contact);
|
||||
|
||||
conv->setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(conv, SIGNAL(destroyed(QObject*)), this, SLOT(onConversationClosed(QObject*)));
|
||||
connect(conv, SIGNAL(sendMessage(const Shared::Message&)), this, SLOT(onConversationMessage(const Shared::Message&)));
|
||||
connect(conv, SIGNAL(requestArchive(const QString&)), this, SLOT(onConversationRequestArchive(const QString&)));
|
||||
connect(conv, SIGNAL(shown()), this, SLOT(onConversationShown()));
|
||||
|
||||
conversations.insert(std::make_pair(id, conv));
|
||||
|
||||
conv->show();
|
||||
conv->raise();
|
||||
conv->activateWindow();
|
||||
|
||||
if (res.size() > 0) {
|
||||
conv->setPalResource(res);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "accounts.h"
|
||||
#include "widgets/chat.h"
|
||||
#include "widgets/room.h"
|
||||
#include "models/roster.h"
|
||||
#include "newcontact.h"
|
||||
|
||||
|
|
|
@ -70,3 +70,37 @@ void Chat::setStatus(const QString& status)
|
|||
{
|
||||
statusLabel->setText(status);
|
||||
}
|
||||
|
||||
void Chat::handleSendMessage(const QString& text)
|
||||
{
|
||||
Shared::Message msg(Shared::Message::chat);
|
||||
msg.setFromJid(myJid);
|
||||
msg.setFromResource(myResource);
|
||||
msg.setToJid(palJid);
|
||||
msg.setToResource(activePalResource);
|
||||
msg.setBody(text);
|
||||
msg.setOutgoing(true);
|
||||
msg.generateRandomId();
|
||||
msg.setCurrentTime();
|
||||
addMessage(msg);
|
||||
emit sendMessage(msg);
|
||||
}
|
||||
|
||||
void Chat::addMessage(const Shared::Message& data)
|
||||
{
|
||||
Conversation::addMessage(data);
|
||||
|
||||
if (!data.getOutgoing()) { //TODO need to check if that was the last message
|
||||
const QString& res = data.getPenPalResource();
|
||||
if (res.size() > 0) {
|
||||
setPalResource(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Chat::setName(const QString& name)
|
||||
{
|
||||
Conversation::setName(name);
|
||||
line->setPalName(getJid(), name);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,9 +32,15 @@ class Chat : public Conversation
|
|||
public:
|
||||
Chat(Models::Contact* p_contact, QWidget* parent = 0);
|
||||
~Chat();
|
||||
|
||||
void addMessage(const Shared::Message & data) override;
|
||||
|
||||
protected slots:
|
||||
void onContactChanged(Models::Item* item, int row, int col);
|
||||
void handleSendMessage(const QString & text) override;
|
||||
|
||||
protected:
|
||||
void setName(const QString & name) override;
|
||||
|
||||
private:
|
||||
void updateState();
|
||||
|
|
|
@ -97,7 +97,6 @@ void Conversation::setName(const QString& name)
|
|||
{
|
||||
m_ui->nameLabel->setText(name);
|
||||
setWindowTitle(name);
|
||||
line->setPalName(getJid(), name);
|
||||
}
|
||||
|
||||
QString Conversation::getAccount() const
|
||||
|
@ -119,13 +118,6 @@ void Conversation::addMessage(const Shared::Message& data)
|
|||
if (place == MessageLine::invalid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.getOutgoing()) {
|
||||
const QString& res = data.getPenPalResource();
|
||||
if (res.size() > 0) {
|
||||
setPalResource(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KeyEnterReceiver::KeyEnterReceiver(QObject* parent): QObject(parent), ownEvent(false) {}
|
||||
|
@ -173,17 +165,7 @@ void Conversation::onEnterPressed()
|
|||
|
||||
if (body.size() > 0) {
|
||||
m_ui->messageEditor->clear();
|
||||
Shared::Message msg(Shared::Message::chat);
|
||||
msg.setFromJid(myJid);
|
||||
msg.setFromResource(myResource);
|
||||
msg.setToJid(palJid);
|
||||
msg.setToResource(activePalResource);
|
||||
msg.setBody(body);
|
||||
msg.setOutgoing(true);
|
||||
msg.generateRandomId();
|
||||
msg.setCurrentTime();
|
||||
addMessage(msg);
|
||||
emit sendMessage(msg);
|
||||
handleSendMessage(body);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
QString getJid() const;
|
||||
QString getAccount() const;
|
||||
QString getPalResource() const;
|
||||
void addMessage(const Shared::Message& data);
|
||||
virtual void addMessage(const Shared::Message& data);
|
||||
|
||||
void setPalResource(const QString& res);
|
||||
void responseArchive(const std::list<Shared::Message> list);
|
||||
|
@ -64,8 +64,9 @@ signals:
|
|||
void shown();
|
||||
|
||||
protected:
|
||||
void setName(const QString& name);
|
||||
virtual void setName(const QString& name);
|
||||
void applyVisualEffects();
|
||||
virtual void handleSendMessage(const QString& text) = 0;
|
||||
|
||||
protected slots:
|
||||
void onEnterPressed();
|
||||
|
|
|
@ -30,7 +30,8 @@ MessageLine::MessageLine(QWidget* parent):
|
|||
layout(new QVBoxLayout()),
|
||||
myName(),
|
||||
palNames(),
|
||||
views()
|
||||
views(),
|
||||
room(false)
|
||||
{
|
||||
setLayout(layout);
|
||||
setBackgroundRole(QPalette::Base);
|
||||
|
@ -44,6 +45,11 @@ MessageLine::~MessageLine()
|
|||
}
|
||||
}
|
||||
|
||||
void MessageLine::setRoom(bool p_room)
|
||||
{
|
||||
room = p_room;
|
||||
}
|
||||
|
||||
MessageLine::Position MessageLine::message(const Shared::Message& msg)
|
||||
{
|
||||
QString id = msg.getId();
|
||||
|
@ -110,25 +116,40 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg)
|
|||
|
||||
message->setGraphicsEffect(effect);
|
||||
|
||||
if (msg.getOutgoing()) {
|
||||
//body->setAlignment(Qt::AlignRight);
|
||||
sender->setAlignment(Qt::AlignRight);
|
||||
time->setAlignment(Qt::AlignRight);
|
||||
sender->setText(myName);
|
||||
hBox->addStretch();
|
||||
hBox->addWidget(message);
|
||||
} else {
|
||||
QString jid = msg.getFromJid();
|
||||
std::map<QString, QString>::iterator itr = palNames.find(jid);
|
||||
if (itr != palNames.end()) {
|
||||
sender->setText(itr->second);
|
||||
if (room) {
|
||||
if (msg.getFromResource() == myName) {
|
||||
//body->setAlignment(Qt::AlignRight);
|
||||
sender->setAlignment(Qt::AlignRight);
|
||||
time->setAlignment(Qt::AlignRight);
|
||||
sender->setText(myName);
|
||||
hBox->addStretch();
|
||||
hBox->addWidget(message);
|
||||
} else {
|
||||
sender->setText(jid);
|
||||
sender->setText(msg.getFromResource());
|
||||
hBox->addWidget(message);
|
||||
hBox->addStretch();
|
||||
}
|
||||
} else {
|
||||
if (msg.getOutgoing()) {
|
||||
//body->setAlignment(Qt::AlignRight);
|
||||
sender->setAlignment(Qt::AlignRight);
|
||||
time->setAlignment(Qt::AlignRight);
|
||||
sender->setText(myName);
|
||||
hBox->addStretch();
|
||||
hBox->addWidget(message);
|
||||
} else {
|
||||
QString jid = msg.getFromJid();
|
||||
std::map<QString, QString>::iterator itr = palNames.find(jid);
|
||||
if (itr != palNames.end()) {
|
||||
sender->setText(itr->second);
|
||||
} else {
|
||||
sender->setText(jid);
|
||||
}
|
||||
hBox->addWidget(message);
|
||||
hBox->addStretch();
|
||||
}
|
||||
hBox->addWidget(message);
|
||||
hBox->addStretch();
|
||||
}
|
||||
|
||||
|
||||
if (res == end) {
|
||||
layout->addLayout(hBox);
|
||||
} else {
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
QString firstMessageId() const;
|
||||
void showBusyIndicator();
|
||||
void hideBusyIndicator();
|
||||
void setRoom(bool p_room);
|
||||
|
||||
signals:
|
||||
void resize(int amount);
|
||||
|
@ -70,6 +71,7 @@ private:
|
|||
QString myName;
|
||||
std::map<QString, QString> palNames;
|
||||
std::deque<QHBoxLayout*> views;
|
||||
bool room;
|
||||
};
|
||||
|
||||
#endif // MESSAGELINE_H
|
||||
|
|
46
ui/widgets/room.cpp
Normal file
46
ui/widgets/room.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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 "room.h"
|
||||
|
||||
Room::Room(Models::Room* p_room, QWidget* parent):
|
||||
Conversation(p_room->getAccountJid(), p_room->getAccountResource(), p_room->getJid(), "", p_room->getAccountName(), parent),
|
||||
room(p_room)
|
||||
{
|
||||
setName(p_room->getName());
|
||||
line->setMyName(room->getNick());
|
||||
line->setRoom(true);
|
||||
}
|
||||
|
||||
Room::~Room()
|
||||
{
|
||||
}
|
||||
|
||||
void Room::handleSendMessage(const QString& text)
|
||||
{
|
||||
Shared::Message msg(Shared::Message::groupChat);
|
||||
msg.setFromJid(myJid);
|
||||
msg.setFromResource(myResource);
|
||||
msg.setToJid(palJid);
|
||||
//msg.setToResource(activePalResource);
|
||||
msg.setBody(text);
|
||||
msg.setOutgoing(true);
|
||||
msg.generateRandomId();
|
||||
msg.setCurrentTime();
|
||||
emit sendMessage(msg);
|
||||
}
|
43
ui/widgets/room.h
Normal file
43
ui/widgets/room.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef ROOM_H
|
||||
#define ROOM_H
|
||||
|
||||
#include "conversation.h"
|
||||
#include "../models/room.h"
|
||||
|
||||
/**
|
||||
* @todo write docs
|
||||
*/
|
||||
class Room : public Conversation
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Room(Models::Room* p_room, QWidget* parent = 0);
|
||||
~Room();
|
||||
|
||||
protected:
|
||||
void handleSendMessage(const QString & text) override;
|
||||
|
||||
private:
|
||||
Models::Room* room;
|
||||
|
||||
};
|
||||
|
||||
#endif // ROOM_H
|
Loading…
Add table
Add a link
Reference in a new issue