initial functionality of mucs

This commit is contained in:
Blue 2019-08-28 14:40:55 +03:00
parent e2cc1bae2e
commit 023494de0b
23 changed files with 347 additions and 119 deletions

View file

@ -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());

View file

@ -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();

View file

@ -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();
}

View file

@ -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;

View file

@ -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;

View file

@ -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;