forked from blue/squawk
cleanup some warnings suppression
This commit is contained in:
parent
5fbb03fc46
commit
23ec80ccba
26 changed files with 630 additions and 924 deletions
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "accounts.h"
|
||||
#include "shared/icons.h"
|
||||
#include "shared/defines.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QDebug>
|
||||
|
@ -26,32 +27,24 @@ std::deque<QString> Models::Accounts::columns = {"Name", "Server", "State", "Err
|
|||
|
||||
Models::Accounts::Accounts(QObject* parent):
|
||||
QAbstractTableModel(parent),
|
||||
accs()
|
||||
{
|
||||
accs() {}
|
||||
|
||||
}
|
||||
Models::Accounts::~Accounts() {}
|
||||
|
||||
Models::Accounts::~Accounts()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant Models::Accounts::data (const QModelIndex& index, int role) const
|
||||
{
|
||||
QVariant Models::Accounts::data (const QModelIndex& index, int role) const {
|
||||
QVariant answer;
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
answer = accs[index.row()]->data(index.column());
|
||||
break;
|
||||
case Qt::DecorationRole:
|
||||
if (index.column() == 2) {
|
||||
if (index.column() == 2)
|
||||
answer = Shared::connectionStateIcon(accs[index.row()]->getState());
|
||||
}
|
||||
break;
|
||||
case Qt::ForegroundRole:
|
||||
if (!accs[index.row()]->getActive()) {
|
||||
if (!accs[index.row()]->getActive())
|
||||
answer = qApp->palette().brush(QPalette::Disabled, QPalette::Text);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -59,53 +52,46 @@ QVariant Models::Accounts::data (const QModelIndex& index, int role) const
|
|||
return answer;
|
||||
}
|
||||
|
||||
int Models::Accounts::columnCount ( const QModelIndex& parent ) const
|
||||
{
|
||||
int Models::Accounts::columnCount (const QModelIndex& parent) const {
|
||||
SHARED_UNUSED(parent);
|
||||
return columns.size();
|
||||
}
|
||||
|
||||
int Models::Accounts::rowCount ( const QModelIndex& parent ) const
|
||||
{
|
||||
int Models::Accounts::rowCount (const QModelIndex& parent) const {
|
||||
SHARED_UNUSED(parent);
|
||||
return accs.size();
|
||||
}
|
||||
|
||||
unsigned int Models::Accounts::size() const
|
||||
{
|
||||
unsigned int Models::Accounts::size() const {
|
||||
return rowCount(QModelIndex());
|
||||
}
|
||||
|
||||
unsigned int Models::Accounts::activeSize() const
|
||||
{
|
||||
unsigned int Models::Accounts::activeSize() const {
|
||||
unsigned int size = 0;
|
||||
for (const Models::Account* acc : accs) {
|
||||
if (acc->getActive()) {
|
||||
if (acc->getActive())
|
||||
++size;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
QVariant Models::Accounts::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
QVariant Models::Accounts::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
|
||||
return tr(columns[section].toLatin1());
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
void Models::Accounts::addAccount(Account* account)
|
||||
{
|
||||
void Models::Accounts::addAccount(Account* account) {
|
||||
beginInsertRows(QModelIndex(), accs.size(), accs.size());
|
||||
int index = 0;
|
||||
std::deque<Account*>::const_iterator before = accs.begin();
|
||||
while (before != accs.end()) {
|
||||
Account* bfr = *before;
|
||||
if (bfr->getDisplayedName() > account->getDisplayedName()) {
|
||||
if (bfr->getDisplayedName() > account->getDisplayedName())
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
|
||||
before++;
|
||||
}
|
||||
|
||||
|
@ -117,25 +103,23 @@ void Models::Accounts::addAccount(Account* account)
|
|||
emit changed();
|
||||
}
|
||||
|
||||
void Models::Accounts::onAccountChanged(Item* item, int row, int col)
|
||||
{
|
||||
if (row < 0) {
|
||||
void Models::Accounts::onAccountChanged(Item* item, int row, int col) {
|
||||
if (row < 0)
|
||||
return;
|
||||
}
|
||||
|
||||
if (static_cast<std::deque<Models::Account*>::size_type>(row) < accs.size()) {
|
||||
Account* acc = getAccount(row);
|
||||
if (item != acc) {
|
||||
if (item != acc)
|
||||
return; //it means the signal is emitted by one of accounts' children, not exactly him, this model has no interest in that
|
||||
}
|
||||
|
||||
if (col == 0) {
|
||||
int newRow = 0;
|
||||
std::deque<Account*>::const_iterator before = accs.begin();
|
||||
while (before != accs.end()) {
|
||||
Item* bfr = *before;
|
||||
if (bfr->getDisplayedName() > item->getDisplayedName()) {
|
||||
if (bfr->getDisplayedName() > item->getDisplayedName())
|
||||
break;
|
||||
}
|
||||
|
||||
newRow++;
|
||||
before++;
|
||||
}
|
||||
|
@ -152,20 +136,18 @@ void Models::Accounts::onAccountChanged(Item* item, int row, int col)
|
|||
}
|
||||
}
|
||||
|
||||
if (col < columnCount(QModelIndex())) {
|
||||
if (col < columnCount(QModelIndex()))
|
||||
emit dataChanged(createIndex(row, col), createIndex(row, col));
|
||||
}
|
||||
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
Models::Account * Models::Accounts::getAccount(int index)
|
||||
{
|
||||
Models::Account * Models::Accounts::getAccount(int index) {
|
||||
return accs[index];
|
||||
}
|
||||
|
||||
void Models::Accounts::removeAccount(int index)
|
||||
{
|
||||
void Models::Accounts::removeAccount(int index) {
|
||||
Account* account = accs[index];
|
||||
beginRemoveRows(QModelIndex(), index, index);
|
||||
disconnect(account, &Account::childChanged, this, &Accounts::onAccountChanged);
|
||||
|
@ -175,14 +157,13 @@ void Models::Accounts::removeAccount(int index)
|
|||
emit sizeChanged(accs.size());
|
||||
}
|
||||
|
||||
std::deque<QString> Models::Accounts::getActiveNames() const
|
||||
{
|
||||
std::deque<QString> Models::Accounts::getActiveNames() const {
|
||||
std::deque<QString> res;
|
||||
|
||||
for (const Models::Account* acc : accs) {
|
||||
if (acc->getActive()) {
|
||||
if (acc->getActive())
|
||||
res.push_back(acc->getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "emails.h"
|
||||
|
||||
#include "shared/icons.h"
|
||||
#include "shared/defines.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
Models::EMails::EMails(bool p_edit, QObject* parent):
|
||||
|
@ -27,10 +28,15 @@ Models::EMails::EMails(bool p_edit, QObject* parent):
|
|||
deque() {}
|
||||
|
||||
int Models::EMails::columnCount(const QModelIndex& parent) const {
|
||||
return 3;}
|
||||
SHARED_UNUSED(parent);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int Models::EMails::rowCount(const QModelIndex& parent) const {
|
||||
return deque.size();}
|
||||
SHARED_UNUSED(parent);
|
||||
return deque.size();
|
||||
|
||||
}
|
||||
|
||||
void Models::EMails::revertPreferred(quint32 row) {
|
||||
setData(createIndex(row, 2), !isPreferred(row));}
|
||||
|
@ -83,9 +89,9 @@ QVariant Models::EMails::data(const QModelIndex& index, int role) const {
|
|||
|
||||
Qt::ItemFlags Models::EMails::flags(const QModelIndex& index) const {
|
||||
Qt::ItemFlags f = QAbstractTableModel::flags(index);
|
||||
if (edit && index.column() != 2) {
|
||||
if (edit && index.column() != 2)
|
||||
f = Qt::ItemIsEditable | f;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
@ -114,9 +120,9 @@ bool Models::EMails::setData(const QModelIndex& index, const QVariant& value, in
|
|||
return true;
|
||||
case 1: {
|
||||
quint8 newRole = value.toUInt();
|
||||
if (newRole > Shared::VCard::Email::work) {
|
||||
if (newRole > Shared::VCard::Email::work)
|
||||
return false;
|
||||
}
|
||||
|
||||
item.role = static_cast<Shared::VCard::Email::Role>(newRole);
|
||||
return true;
|
||||
}
|
||||
|
@ -160,19 +166,17 @@ QModelIndex Models::EMails::addNewEmptyLine() {
|
|||
}
|
||||
|
||||
bool Models::EMails::isPreferred(quint32 row) const {
|
||||
if (row < deque.size()) {
|
||||
if (row < deque.size())
|
||||
return deque[row].prefered;
|
||||
} else {
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Models::EMails::removeLines(quint32 index, quint32 count) {
|
||||
if (index < deque.size()) {
|
||||
quint32 maxCount = deque.size() - index;
|
||||
if (count > maxCount) {
|
||||
if (count > maxCount)
|
||||
count = maxCount;
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
beginRemoveRows(QModelIndex(), index, index + count - 1);
|
||||
|
@ -185,21 +189,19 @@ void Models::EMails::removeLines(quint32 index, quint32 count) {
|
|||
}
|
||||
|
||||
void Models::EMails::getEmails(std::deque<Shared::VCard::Email>& emails) const {
|
||||
for (const Shared::VCard::Email& my : deque) {
|
||||
for (const Shared::VCard::Email& my : deque)
|
||||
emails.emplace_back(my);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::EMails::setEmails(const std::deque<Shared::VCard::Email>& emails) {
|
||||
if (deque.size() > 0) {
|
||||
if (deque.size() > 0)
|
||||
removeLines(0, deque.size());
|
||||
}
|
||||
|
||||
if (emails.size() > 0) {
|
||||
beginInsertRows(QModelIndex(), 0, emails.size() - 1);
|
||||
for (const Shared::VCard::Email& comming : emails) {
|
||||
for (const Shared::VCard::Email& comming : emails)
|
||||
deque.emplace_back(comming);
|
||||
}
|
||||
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
#include "keys.h"
|
||||
|
||||
#include "shared/defines.h"
|
||||
|
||||
const QHash<int, QByteArray> Models::Keys::roles = {
|
||||
{Label, "label"},
|
||||
{FingerPrint, "fingerPrint"},
|
||||
|
@ -28,13 +30,11 @@ Models::Keys::Keys(QObject* parent):
|
|||
modified() {}
|
||||
|
||||
Models::Keys::~Keys() {
|
||||
for (Shared::KeyInfo* key : keys) {
|
||||
for (Shared::KeyInfo* key : keys)
|
||||
delete key;
|
||||
}
|
||||
|
||||
for (std::pair<const int, Shared::KeyInfo*>& pair: modified) {
|
||||
for (std::pair<const int, Shared::KeyInfo*>& pair: modified)
|
||||
delete pair.second;
|
||||
}
|
||||
}
|
||||
|
||||
std::deque<Shared::KeyInfo> Models::Keys::modifiedKeys() const {
|
||||
|
@ -92,15 +92,15 @@ QVariant Models::Keys::data(const QModelIndex& index, int role) const {
|
|||
}
|
||||
|
||||
int Models::Keys::rowCount(const QModelIndex& parent) const {
|
||||
SHARED_UNUSED(parent);
|
||||
return keys.size();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> Models::Keys::roleNames() const {return roles;}
|
||||
|
||||
QModelIndex Models::Keys::index(int row, int column, const QModelIndex& parent) const {
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
return createIndex(row, column, keys[row]);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "phones.h"
|
||||
|
||||
#include "shared/icons.h"
|
||||
#include "shared/defines.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
Models::Phones::Phones(bool p_edit, QObject* parent):
|
||||
|
@ -27,10 +28,14 @@ Models::Phones::Phones(bool p_edit, QObject* parent):
|
|||
deque() {}
|
||||
|
||||
int Models::Phones::columnCount(const QModelIndex& parent) const {
|
||||
return 4;}
|
||||
SHARED_UNUSED(parent);
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Models::Phones::rowCount(const QModelIndex& parent) const {
|
||||
return deque.size();}
|
||||
SHARED_UNUSED(parent);
|
||||
return deque.size();
|
||||
}
|
||||
|
||||
void Models::Phones::revertPreferred(quint32 row) {
|
||||
setData(createIndex(row, 3), !isPreferred(row));
|
||||
|
@ -77,9 +82,9 @@ QVariant Models::Phones::data(const QModelIndex& index, int role) const {
|
|||
case Qt::DisplayRole:
|
||||
return QVariant();
|
||||
case Qt::DecorationRole:
|
||||
if (deque[index.row()].prefered) {
|
||||
if (deque[index.row()].prefered)
|
||||
return Shared::icon("favorite", false);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
default:
|
||||
return QVariant();
|
||||
|
@ -101,9 +106,9 @@ QModelIndex Models::Phones::addNewEmptyLine() {
|
|||
|
||||
Qt::ItemFlags Models::Phones::flags(const QModelIndex& index) const {
|
||||
Qt::ItemFlags f = QAbstractTableModel::flags(index);
|
||||
if (edit && index.column() != 3) {
|
||||
if (edit && index.column() != 3)
|
||||
f = Qt::ItemIsEditable | f;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
@ -139,25 +144,22 @@ bool Models::Phones::dropPrefered() {
|
|||
}
|
||||
|
||||
void Models::Phones::getPhones(std::deque<Shared::VCard::Phone>& phones) const {
|
||||
for (const Shared::VCard::Phone& my : deque) {
|
||||
for (const Shared::VCard::Phone& my : deque)
|
||||
phones.emplace_back(my);
|
||||
}
|
||||
}
|
||||
|
||||
bool Models::Phones::isPreferred(quint32 row) const {
|
||||
if (row < deque.size()) {
|
||||
if (row < deque.size())
|
||||
return deque[row].prefered;
|
||||
} else {
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Phones::removeLines(quint32 index, quint32 count) {
|
||||
if (index < deque.size()) {
|
||||
quint32 maxCount = deque.size() - index;
|
||||
if (count > maxCount) {
|
||||
if (count > maxCount)
|
||||
count = maxCount;
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
beginRemoveRows(QModelIndex(), index, index + count - 1);
|
||||
|
@ -178,17 +180,17 @@ bool Models::Phones::setData(const QModelIndex& index, const QVariant& value, in
|
|||
return true;
|
||||
case 1: {
|
||||
quint8 newRole = value.toUInt();
|
||||
if (newRole > Shared::VCard::Phone::work) {
|
||||
if (newRole > Shared::VCard::Phone::work)
|
||||
return false;
|
||||
}
|
||||
|
||||
item.role = static_cast<Shared::VCard::Phone::Role>(newRole);
|
||||
return true;
|
||||
}
|
||||
case 2: {
|
||||
quint8 newType = value.toUInt();
|
||||
if (newType > Shared::VCard::Phone::other) {
|
||||
if (newType > Shared::VCard::Phone::other)
|
||||
return false;
|
||||
}
|
||||
|
||||
item.type = static_cast<Shared::VCard::Phone::Type>(newType);
|
||||
return true;
|
||||
}
|
||||
|
@ -209,15 +211,15 @@ bool Models::Phones::setData(const QModelIndex& index, const QVariant& value, in
|
|||
}
|
||||
|
||||
void Models::Phones::setPhones(const std::deque<Shared::VCard::Phone>& phones) {
|
||||
if (deque.size() > 0) {
|
||||
if (deque.size() > 0)
|
||||
removeLines(0, deque.size());
|
||||
}
|
||||
|
||||
|
||||
if (phones.size() > 0) {
|
||||
beginInsertRows(QModelIndex(), 0, phones.size() - 1);
|
||||
for (const Shared::VCard::Phone& comming : phones) {
|
||||
for (const Shared::VCard::Phone& comming : phones)
|
||||
deque.emplace_back(comming);
|
||||
}
|
||||
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <QIcon>
|
||||
#include <QFont>
|
||||
|
||||
#include "shared/defines.h"
|
||||
|
||||
Models::Roster::Roster(QObject* parent):
|
||||
QAbstractItemModel(parent),
|
||||
accountsModel(new Accounts()),
|
||||
|
@ -39,14 +41,12 @@ Models::Roster::Roster(QObject* parent):
|
|||
connect(root, &Item::childMoved, this, &Roster::onChildMoved);
|
||||
}
|
||||
|
||||
Models::Roster::~Roster()
|
||||
{
|
||||
Models::Roster::~Roster() {
|
||||
delete accountsModel;
|
||||
delete root;
|
||||
}
|
||||
|
||||
void Models::Roster::addAccount(const QMap<QString, QVariant>& data)
|
||||
{
|
||||
void Models::Roster::addAccount(const QMap<QString, QVariant>& data) {
|
||||
Account* acc = new Account(data);
|
||||
connect(acc, &Account::reconnected, this, &Roster::onAccountReconnected);
|
||||
root->appendChild(acc);
|
||||
|
@ -56,24 +56,21 @@ void Models::Roster::addAccount(const QMap<QString, QVariant>& data)
|
|||
emit addedElement({acc->getId()});
|
||||
}
|
||||
|
||||
QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
QVariant Models::Roster::data (const QModelIndex& index, int role) const {
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant result;
|
||||
|
||||
Item *item = static_cast<Item*>(index.internalPointer());
|
||||
if (item->type == Item::reference) {
|
||||
if (item->type == Item::reference)
|
||||
item = static_cast<Reference*>(item)->dereference();
|
||||
}
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
{
|
||||
if (index.column() != 0) {
|
||||
case Qt::DisplayRole: {
|
||||
if (index.column() != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
switch (item->type) {
|
||||
case Item::group: {
|
||||
Group* gr = static_cast<Group*>(item);
|
||||
|
@ -81,9 +78,9 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
|
||||
str += gr->getName();
|
||||
unsigned int amount = gr->getUnreadMessages();
|
||||
if (amount > 0) {
|
||||
if (amount > 0)
|
||||
str += QString(" (") + tr("New messages") + ")";
|
||||
}
|
||||
|
||||
|
||||
result = str;
|
||||
}
|
||||
|
@ -104,9 +101,8 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
} else if (col == 1) {
|
||||
QString path = acc->getAvatarPath();
|
||||
|
||||
if (path.size() > 0) {
|
||||
if (path.size() > 0)
|
||||
result = QIcon(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -116,16 +112,15 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
if (col == 0) {
|
||||
result = contact->getStatusIcon(false);
|
||||
} else if (col == 1) {
|
||||
if (contact->getAvatarState() != Shared::Avatar::empty) {
|
||||
if (contact->getAvatarState() != Shared::Avatar::empty)
|
||||
result = QIcon(contact->getAvatarPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Item::presence: {
|
||||
if (index.column() != 0) {
|
||||
if (index.column() != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
Presence* presence = static_cast<Presence*>(item);
|
||||
result = presence->getStatusIcon(false);
|
||||
}
|
||||
|
@ -138,9 +133,8 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
} else if (col == 1) {
|
||||
QString path = room->getAvatarPath();
|
||||
|
||||
if (path.size() > 0) {
|
||||
if (path.size() > 0)
|
||||
result = QIcon(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -151,14 +145,11 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
result = p->getStatusIcon(false);
|
||||
} else if (col == 1) {
|
||||
QString path = p->getAvatarPath();
|
||||
if (path.size() > 0) {
|
||||
if (path.size() > 0)
|
||||
result = QIcon(path);
|
||||
}
|
||||
}
|
||||
if (index.column() != 0) {
|
||||
if (index.column() != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -194,9 +185,9 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
Contact* contact = static_cast<Contact*>(item);
|
||||
QString str("");
|
||||
int mc = contact->getMessagesCount();
|
||||
if (mc > 0) {
|
||||
if (mc > 0)
|
||||
str += QString(tr("New messages: ")) + std::to_string(mc).c_str() + "\n";
|
||||
}
|
||||
|
||||
str += tr("Jabber ID: ") + contact->getJid() + "\n";
|
||||
Shared::SubscriptionState ss = contact->getState();
|
||||
if (ss == Shared::SubscriptionState::both || ss == Shared::SubscriptionState::to) {
|
||||
|
@ -204,9 +195,8 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
str += tr("Availability: ") + Shared::Global::getName(av);
|
||||
if (av != Shared::Availability::offline) {
|
||||
QString s = contact->getStatus();
|
||||
if (s.size() > 0) {
|
||||
if (s.size() > 0)
|
||||
str += "\n" + tr("Status: ") + s;
|
||||
}
|
||||
}
|
||||
str += "\n" + tr("Subscription: ") + Shared::Global::getName(ss);
|
||||
} else {
|
||||
|
@ -222,9 +212,9 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
Shared::Availability av = contact->getAvailability();
|
||||
str += tr("Availability: ") + Shared::Global::getName(av);
|
||||
QString s = contact->getStatus();
|
||||
if (s.size() > 0) {
|
||||
if (s.size() > 0)
|
||||
str += "\n" + tr("Status: ") + s;
|
||||
}
|
||||
|
||||
str += "\n" + tr("Client: ") + contact->getClientNode();
|
||||
|
||||
result = str;
|
||||
|
@ -236,9 +226,8 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
Shared::Availability av = p->getAvailability();
|
||||
str += tr("Availability: ") + Shared::Global::getName(av) + "\n";
|
||||
QString s = p->getStatus();
|
||||
if (s.size() > 0) {
|
||||
if (s.size() > 0)
|
||||
str += tr("Status: ") + s + "\n";
|
||||
}
|
||||
|
||||
str += tr("Affiliation: ") + Shared::Global::getName(p->getAffiliation()) + "\n";
|
||||
str += tr("Role: ") + Shared::Global::getName(p->getRole()) + "\n";
|
||||
|
@ -251,9 +240,9 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
Group* gr = static_cast<Group*>(item);
|
||||
unsigned int count = gr->getUnreadMessages();
|
||||
QString str("");
|
||||
if (count > 0) {
|
||||
if (count > 0)
|
||||
str += tr("New messages: ") + std::to_string(count).c_str() + "\n";
|
||||
}
|
||||
|
||||
str += tr("Online contacts: ") + std::to_string(gr->getOnlineContacts()).c_str() + "\n";
|
||||
str += tr("Total contacts: ") + std::to_string(gr->childCount()).c_str();
|
||||
result = str;
|
||||
|
@ -263,15 +252,14 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
Room* rm = static_cast<Room*>(item);
|
||||
unsigned int count = rm->getMessagesCount();
|
||||
QString str("");
|
||||
if (count > 0) {
|
||||
if (count > 0)
|
||||
str += tr("New messages: ") + std::to_string(count).c_str() + "\n";
|
||||
}
|
||||
|
||||
str += tr("Jabber ID: ") + rm->getJid() + "\n";
|
||||
str += tr("Subscription: ") + rm->getStatusText();
|
||||
if (rm->getJoined()) {
|
||||
if (rm->getJoined())
|
||||
str += QString("\n") + tr("Members: ") + std::to_string(rm->childCount()).c_str();
|
||||
}
|
||||
|
||||
result = str;
|
||||
}
|
||||
break;
|
||||
|
@ -284,9 +272,8 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
switch (item->type) {
|
||||
case Item::account: {
|
||||
Account* acc = static_cast<Account*>(item);
|
||||
if (!acc->getActive()) {
|
||||
if (!acc->getActive())
|
||||
result = qApp->palette().brush(QPalette::Disabled, QPalette::Text);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -299,17 +286,14 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||
return result;
|
||||
}
|
||||
|
||||
int Models::Roster::columnCount (const QModelIndex& parent) const
|
||||
{
|
||||
if (parent.isValid()) {
|
||||
int Models::Roster::columnCount (const QModelIndex& parent) const {
|
||||
if (parent.isValid())
|
||||
return static_cast<Item*>(parent.internalPointer())->columnCount();
|
||||
} else {
|
||||
else
|
||||
return root->columnCount();
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::updateAccount(const QString& account, const QString& field, const QVariant& value)
|
||||
{
|
||||
void Models::Roster::updateAccount(const QString& account, const QString& field, const QVariant& value) {
|
||||
std::map<QString, Account*>::iterator itr = accounts.find(account);
|
||||
if (itr != accounts.end()) {
|
||||
Account* acc = itr->second;
|
||||
|
@ -317,75 +301,63 @@ void Models::Roster::updateAccount(const QString& account, const QString& field,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
Qt::ItemFlags Models::Roster::flags(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
Qt::ItemFlags Models::Roster::flags(const QModelIndex& index) const {
|
||||
if (!index.isValid())
|
||||
return Qt::ItemFlags();
|
||||
}
|
||||
|
||||
return QAbstractItemModel::flags(index);
|
||||
}
|
||||
|
||||
|
||||
int Models::Roster::rowCount (const QModelIndex& parent) const
|
||||
{
|
||||
int Models::Roster::rowCount (const QModelIndex& parent) const{
|
||||
Item *parentItem;
|
||||
|
||||
if (!parent.isValid()) {
|
||||
if (!parent.isValid())
|
||||
parentItem = root;
|
||||
} else {
|
||||
else
|
||||
parentItem = static_cast<Item*>(parent.internalPointer());
|
||||
}
|
||||
|
||||
return parentItem->childCount();
|
||||
}
|
||||
|
||||
QVariant Models::Roster::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
QVariant Models::Roster::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
SHARED_UNUSED(section);
|
||||
SHARED_UNUSED(orientation);
|
||||
SHARED_UNUSED(role);
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::parent (const QModelIndex& child) const
|
||||
{
|
||||
if (!child.isValid()) {
|
||||
QModelIndex Models::Roster::parent (const QModelIndex& child) const {
|
||||
if (!child.isValid())
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
Item *childItem = static_cast<Item*>(child.internalPointer());
|
||||
if (childItem == root) {
|
||||
if (childItem == root)
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
Item *parentItem = childItem->parentItem();
|
||||
|
||||
if (parentItem == root) {
|
||||
if (parentItem == root)
|
||||
return createIndex(0, 0, parentItem);
|
||||
}
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::index (int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
QModelIndex Models::Roster::index (int row, int column, const QModelIndex& parent) const {
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
Item *parentItem;
|
||||
|
||||
if (!parent.isValid()) {
|
||||
if (!parent.isValid())
|
||||
parentItem = root;
|
||||
} else {
|
||||
else
|
||||
parentItem = static_cast<Item*>(parent.internalPointer());
|
||||
}
|
||||
|
||||
Item *childItem = parentItem->child(row);
|
||||
if (childItem) {
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
} else {
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
}
|
||||
|
||||
Models::Roster::ElId::ElId(const QString& p_account, const QString& p_name):
|
||||
|
@ -393,27 +365,22 @@ Models::Roster::ElId::ElId(const QString& p_account, const QString& p_name):
|
|||
name(p_name)
|
||||
{}
|
||||
|
||||
bool Models::Roster::ElId::operator <(const Models::Roster::ElId& other) const
|
||||
{
|
||||
if (account == other.account) {
|
||||
bool Models::Roster::ElId::operator <(const Models::Roster::ElId& other) const {
|
||||
if (account == other.account)
|
||||
return name < other.name;
|
||||
} else {
|
||||
else
|
||||
return account < other.account;
|
||||
}
|
||||
}
|
||||
|
||||
bool Models::Roster::ElId::operator!=(const Models::Roster::ElId& other) const
|
||||
{
|
||||
bool Models::Roster::ElId::operator!=(const Models::Roster::ElId& other) const {
|
||||
return !(operator == (other));
|
||||
}
|
||||
|
||||
bool Models::Roster::ElId::operator==(const Models::Roster::ElId& other) const
|
||||
{
|
||||
bool Models::Roster::ElId::operator==(const Models::Roster::ElId& other) const {
|
||||
return (account == other.account) && (name == other.name);
|
||||
}
|
||||
|
||||
void Models::Roster::onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector<int>& roles)
|
||||
{
|
||||
void Models::Roster::onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector<int>& roles) {
|
||||
if (tl.column() == 0) {
|
||||
emit dataChanged(tl, br, roles);
|
||||
} else if (tl.column() == 2) {
|
||||
|
@ -423,8 +390,7 @@ void Models::Roster::onAccountDataChanged(const QModelIndex& tl, const QModelInd
|
|||
}
|
||||
}
|
||||
|
||||
void Models::Roster::addGroup(const QString& account, const QString& name)
|
||||
{
|
||||
void Models::Roster::addGroup(const QString& account, const QString& name) {
|
||||
ElId id(account, name);
|
||||
std::map<ElId, Group*>::const_iterator gItr = groups.find(id);
|
||||
if (gItr != groups.end()) {
|
||||
|
@ -438,15 +404,13 @@ void Models::Roster::addGroup(const QString& account, const QString& name)
|
|||
groups.insert(std::make_pair(id, group));
|
||||
acc->appendChild(group);
|
||||
|
||||
|
||||
emit addedElement({acc->getId(), group->getId()});
|
||||
} else {
|
||||
qDebug() << "An attempt to add group " << name << " to non existing account " << account << ", skipping";
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::addContact(const QString& account, const QString& jid, const QString& group, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
void Models::Roster::addContact(const QString& account, const QString& jid, const QString& group, const QMap<QString, QVariant>& data) {
|
||||
Item* parent;
|
||||
Account* acc;
|
||||
Contact* contact;
|
||||
|
@ -513,16 +477,15 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
}
|
||||
path.push_back(contact->getId());
|
||||
|
||||
if (ref == 0) {
|
||||
if (ref == 0)
|
||||
ref = new Reference(contact);
|
||||
}
|
||||
|
||||
parent->appendChild(ref);
|
||||
|
||||
emit addedElement(path);
|
||||
}
|
||||
|
||||
void Models::Roster::removeGroup(const QString& account, const QString& name)
|
||||
{
|
||||
void Models::Roster::removeGroup(const QString& account, const QString& name) {
|
||||
ElId id(account, name);
|
||||
std::map<ElId, Group*>::const_iterator gItr = groups.find(id);
|
||||
if (gItr == groups.end()) {
|
||||
|
@ -541,11 +504,10 @@ void Models::Roster::removeGroup(const QString& account, const QString& name)
|
|||
item->removeChild(0);
|
||||
|
||||
Contact* cont = static_cast<Contact*>(ref->dereference());
|
||||
if (cont->referencesCount() == 1) {
|
||||
if (cont->referencesCount() == 1)
|
||||
toInsert.push_back(ref);
|
||||
} else {
|
||||
else
|
||||
delete ref;
|
||||
}
|
||||
}
|
||||
|
||||
if (toInsert.size() > 0) {
|
||||
|
@ -559,8 +521,7 @@ void Models::Roster::removeGroup(const QString& account, const QString& name)
|
|||
groups.erase(gItr);
|
||||
}
|
||||
|
||||
void Models::Roster::changeContact(const QString& account, const QString& jid, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
void Models::Roster::changeContact(const QString& account, const QString& jid, const QMap<QString, QVariant>& data) {
|
||||
Element* el = getElement(ElId(account, jid));
|
||||
if (el != nullptr) {
|
||||
for (QMap<QString, QVariant>::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) {
|
||||
|
@ -569,18 +530,15 @@ void Models::Roster::changeContact(const QString& account, const QString& jid, c
|
|||
}
|
||||
}
|
||||
|
||||
void Models::Roster::changeMessage(const QString& account, const QString& jid, const QString& id, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
void Models::Roster::changeMessage(const QString& account, const QString& jid, const QString& id, const QMap<QString, QVariant>& data) {
|
||||
Element* el = getElement(ElId(account, jid));
|
||||
if (el != nullptr) {
|
||||
if (el != nullptr)
|
||||
el->changeMessage(id, data);
|
||||
} else {
|
||||
else
|
||||
qDebug() << "A request to change a message of the contact " << jid << " in the account " << account << " but it wasn't found";
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::removeContact(const QString& account, const QString& jid)
|
||||
{
|
||||
void Models::Roster::removeContact(const QString& account, const QString& jid) {
|
||||
ElId id(account, jid);
|
||||
std::map<ElId, Contact*>::iterator itr = contacts.find(id);
|
||||
|
||||
|
@ -592,21 +550,18 @@ void Models::Roster::removeContact(const QString& account, const QString& jid)
|
|||
|
||||
std::set<ElId> toRemove;
|
||||
for (std::pair<ElId, Group*> pair : groups) {
|
||||
if (pair.second->childCount() == 0) {
|
||||
if (pair.second->childCount() == 0)
|
||||
toRemove.insert(pair.first);
|
||||
}
|
||||
}
|
||||
|
||||
for (const ElId& elId : toRemove) {
|
||||
for (const ElId& elId : toRemove)
|
||||
removeGroup(elId.account, elId.name);
|
||||
}
|
||||
} else {
|
||||
qDebug() << "An attempt to remove contact " << jid << " from account " << account <<" which doesn't exist there, skipping";
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::removeContact(const QString& account, const QString& jid, const QString& group)
|
||||
{
|
||||
void Models::Roster::removeContact(const QString& account, const QString& jid, const QString& group) {
|
||||
ElId contactId(account, jid);
|
||||
ElId groupId(account, group);
|
||||
|
||||
|
@ -639,20 +594,18 @@ void Models::Roster::removeContact(const QString& account, const QString& jid, c
|
|||
} else {
|
||||
delete ref;
|
||||
}
|
||||
if (gr->childCount() == 0) {
|
||||
if (gr->childCount() == 0)
|
||||
removeGroup(account, group);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::onChildChanged(Models::Item* item, int row, int col)
|
||||
{
|
||||
void Models::Roster::onChildChanged(Models::Item* item, int row, int col) {
|
||||
SHARED_UNUSED(col);
|
||||
QModelIndex index = createIndex(row, 0, item);
|
||||
QModelIndex index2 = createIndex(row, 1, item);
|
||||
emit dataChanged(index, index2);
|
||||
}
|
||||
|
||||
void Models::Roster::onChildIsAboutToBeInserted(Models::Item* parent, int first, int last)
|
||||
{
|
||||
void Models::Roster::onChildIsAboutToBeInserted(Models::Item* parent, int first, int last) {
|
||||
int row = 0;
|
||||
if (parent != root) {
|
||||
row = parent->row();
|
||||
|
@ -662,45 +615,39 @@ void Models::Roster::onChildIsAboutToBeInserted(Models::Item* parent, int first,
|
|||
}
|
||||
}
|
||||
|
||||
void Models::Roster::onChildIsAboutToBeMoved(Models::Item* source, int first, int last, Models::Item* destination, int newIndex)
|
||||
{
|
||||
void Models::Roster::onChildIsAboutToBeMoved(Models::Item* source, int first, int last, Models::Item* destination, int newIndex) {
|
||||
int oldRow = 0;
|
||||
if (source != root) {
|
||||
if (source != root)
|
||||
oldRow = source->row();
|
||||
}
|
||||
|
||||
int newRow = 0;
|
||||
if (destination != root) {
|
||||
if (destination != root)
|
||||
newRow = destination->row();
|
||||
}
|
||||
|
||||
beginMoveRows(createIndex(oldRow, 0, source), first, last, createIndex(newRow, 0, destination), newIndex);
|
||||
}
|
||||
|
||||
void Models::Roster::onChildIsAboutToBeRemoved(Models::Item* parent, int first, int last)
|
||||
{
|
||||
void Models::Roster::onChildIsAboutToBeRemoved(Models::Item* parent, int first, int last) {
|
||||
int row = 0;
|
||||
if (parent != root) {
|
||||
if (parent != root)
|
||||
row = parent->row();
|
||||
}
|
||||
|
||||
beginRemoveRows(createIndex(row, 0, parent), first, last);
|
||||
}
|
||||
|
||||
void Models::Roster::onChildInserted()
|
||||
{
|
||||
void Models::Roster::onChildInserted() {
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void Models::Roster::onChildMoved()
|
||||
{
|
||||
void Models::Roster::onChildMoved() {
|
||||
endMoveRows();
|
||||
}
|
||||
|
||||
void Models::Roster::onChildRemoved()
|
||||
{
|
||||
void Models::Roster::onChildRemoved() {
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void Models::Roster::addPresence(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
void Models::Roster::addPresence(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data) {
|
||||
ElId contactId(account, jid);
|
||||
std::map<ElId, Contact*>::iterator itr = contacts.find(contactId);
|
||||
if (itr != contacts.end()) {
|
||||
|
@ -709,8 +656,7 @@ void Models::Roster::addPresence(const QString& account, const QString& jid, con
|
|||
|
||||
}
|
||||
|
||||
void Models::Roster::removePresence(const QString& account, const QString& jid, const QString& name)
|
||||
{
|
||||
void Models::Roster::removePresence(const QString& account, const QString& jid, const QString& name) {
|
||||
ElId contactId(account, jid);
|
||||
std::map<ElId, Contact*>::iterator itr = contacts.find(contactId);
|
||||
if (itr != contacts.end()) {
|
||||
|
@ -718,16 +664,13 @@ void Models::Roster::removePresence(const QString& account, const QString& jid,
|
|||
}
|
||||
}
|
||||
|
||||
void Models::Roster::addMessage(const QString& account, const Shared::Message& data)
|
||||
{
|
||||
void Models::Roster::addMessage(const QString& account, const Shared::Message& data) {
|
||||
Element* el = getElement(ElId(account, data.getPenPalJid()));
|
||||
if (el != nullptr) {
|
||||
if (el != nullptr)
|
||||
el->addMessage(data);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::removeAccount(const QString& account)
|
||||
{
|
||||
void Models::Roster::removeAccount(const QString& account) {
|
||||
std::map<QString, Account*>::const_iterator itr = accounts.find(account);
|
||||
if (itr == accounts.end()) {
|
||||
qDebug() << "An attempt to remove non existing account " << account << ", skipping";
|
||||
|
@ -777,26 +720,23 @@ void Models::Roster::removeAccount(const QString& account)
|
|||
acc->deleteLater();
|
||||
}
|
||||
|
||||
QString Models::Roster::getContactName(const QString& account, const QString& jid) const
|
||||
{
|
||||
QString Models::Roster::getContactName(const QString& account, const QString& jid) const {
|
||||
ElId id(account, jid);
|
||||
std::map<ElId, Contact*>::const_iterator cItr = contacts.find(id);
|
||||
QString name = "";
|
||||
if (cItr == contacts.end()) {
|
||||
std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
|
||||
if (rItr == rooms.end()) {
|
||||
if (rItr == rooms.end())
|
||||
qDebug() << "An attempt to get a name of non existing contact/room " << account << ":" << jid << ", skipping";
|
||||
} else {
|
||||
else
|
||||
name = rItr->second->getRoomName();
|
||||
}
|
||||
} else {
|
||||
name = cItr->second->getContactName();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
void Models::Roster::addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
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);
|
||||
|
@ -826,8 +766,7 @@ void Models::Roster::addRoom(const QString& account, const QString jid, const QM
|
|||
emit addedElement({acc->getId(), room->getId()});
|
||||
}
|
||||
|
||||
void Models::Roster::changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
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()) {
|
||||
|
@ -840,8 +779,7 @@ void Models::Roster::changeRoom(const QString& account, const QString jid, const
|
|||
}
|
||||
}
|
||||
|
||||
void Models::Roster::removeRoom(const QString& account, const QString jid)
|
||||
{
|
||||
void Models::Roster::removeRoom(const QString& account, const QString jid) {
|
||||
Account* acc;
|
||||
{
|
||||
std::map<QString, Account*>::iterator itr = accounts.find(account);
|
||||
|
@ -865,8 +803,7 @@ void Models::Roster::removeRoom(const QString& account, const QString jid)
|
|||
rooms.erase(itr);
|
||||
}
|
||||
|
||||
void Models::Roster::addRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
void Models::Roster::addRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data) {
|
||||
ElId id = {account, jid};
|
||||
std::map<ElId, Room*>::const_iterator itr = rooms.find(id);
|
||||
if (itr == rooms.end()) {
|
||||
|
@ -877,8 +814,7 @@ void Models::Roster::addRoomParticipant(const QString& account, const QString& j
|
|||
}
|
||||
}
|
||||
|
||||
void Models::Roster::changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
void Models::Roster::changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data) {
|
||||
ElId id = {account, jid};
|
||||
std::map<ElId, Room*>::const_iterator itr = rooms.find(id);
|
||||
if (itr == rooms.end()) {
|
||||
|
@ -889,8 +825,7 @@ void Models::Roster::changeRoomParticipant(const QString& account, const QString
|
|||
}
|
||||
}
|
||||
|
||||
void Models::Roster::removeRoomParticipant(const QString& account, const QString& jid, const QString& name)
|
||||
{
|
||||
void Models::Roster::removeRoomParticipant(const QString& account, const QString& jid, const QString& name) {
|
||||
ElId id = {account, jid};
|
||||
std::map<ElId, Room*>::const_iterator itr = rooms.find(id);
|
||||
if (itr == rooms.end()) {
|
||||
|
@ -901,20 +836,17 @@ void Models::Roster::removeRoomParticipant(const QString& account, const QString
|
|||
}
|
||||
}
|
||||
|
||||
std::deque<QString> Models::Roster::groupList(const QString& account) const
|
||||
{
|
||||
std::deque<QString> Models::Roster::groupList(const QString& account) const {
|
||||
std::deque<QString> answer;
|
||||
for (std::pair<ElId, Group*> pair : groups) {
|
||||
if (pair.first.account == account) {
|
||||
if (pair.first.account == account)
|
||||
answer.push_back(pair.first.name);
|
||||
}
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
bool Models::Roster::groupHasContact(const QString& account, const QString& group, const QString& contact) const
|
||||
{
|
||||
bool Models::Roster::groupHasContact(const QString& account, const QString& group, const QString& contact) const {
|
||||
ElId grId({account, group});
|
||||
std::map<ElId, Group*>::const_iterator gItr = groups.find(grId);
|
||||
if (gItr == groups.end()) {
|
||||
|
@ -924,22 +856,19 @@ bool Models::Roster::groupHasContact(const QString& account, const QString& grou
|
|||
}
|
||||
}
|
||||
|
||||
QString Models::Roster::getContactIconPath(const QString& account, const QString& jid, const QString& resource) const
|
||||
{
|
||||
QString Models::Roster::getContactIconPath(const QString& account, const QString& jid, const QString& resource) const {
|
||||
ElId id(account, jid);
|
||||
std::map<ElId, Contact*>::const_iterator cItr = contacts.find(id);
|
||||
QString path = "";
|
||||
if (cItr == contacts.end()) {
|
||||
std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
|
||||
if (rItr == rooms.end()) {
|
||||
if (rItr == rooms.end())
|
||||
qDebug() << "An attempt to get an icon path of non existing contact" << account << ":" << jid << ", returning empty value";
|
||||
} else {
|
||||
else
|
||||
path = rItr->second->getParticipantIconPath(resource);
|
||||
}
|
||||
} else {
|
||||
if (cItr->second->getAvatarState() != Shared::Avatar::empty) {
|
||||
if (cItr->second->getAvatarState() != Shared::Avatar::empty)
|
||||
path = cItr->second->getAvatarPath();
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
@ -950,34 +879,29 @@ Models::Account * Models::Roster::getAccount(const QString& name) {
|
|||
const Models::Account * Models::Roster::getAccountConst(const QString& name) const {
|
||||
return accounts.at(name);}
|
||||
|
||||
const Models::Element * Models::Roster::getElementConst(const Models::Roster::ElId& id) const
|
||||
{
|
||||
const Models::Element * Models::Roster::getElementConst(const Models::Roster::ElId& id) const {
|
||||
std::map<ElId, Contact*>::const_iterator cItr = contacts.find(id);
|
||||
|
||||
if (cItr != contacts.end()) {
|
||||
return cItr->second;
|
||||
} else {
|
||||
std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
|
||||
if (rItr != rooms.end()) {
|
||||
if (rItr != rooms.end())
|
||||
return rItr->second;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Models::Roster::markMessageAsRead(const Models::Roster::ElId& elementId, const QString& messageId)
|
||||
{
|
||||
bool Models::Roster::markMessageAsRead(const Models::Roster::ElId& elementId, const QString& messageId) {
|
||||
const Element* el = getElementConst(elementId);
|
||||
if (el != nullptr) {
|
||||
if (el != nullptr)
|
||||
return el->markMessageAsRead(messageId);
|
||||
} else {
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::getAccountIndex(const QString& name) const
|
||||
{
|
||||
QModelIndex Models::Roster::getAccountIndex(const QString& name) const {
|
||||
std::map<QString, Account*>::const_iterator itr = accounts.find(name);
|
||||
if (itr == accounts.end()) {
|
||||
return QModelIndex();
|
||||
|
@ -986,8 +910,7 @@ QModelIndex Models::Roster::getAccountIndex(const QString& name) const
|
|||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::getGroupIndex(const QString& account, const QString& name) const
|
||||
{
|
||||
QModelIndex Models::Roster::getGroupIndex(const QString& account, const QString& name) const {
|
||||
std::map<QString, Account*>::const_iterator itr = accounts.find(account);
|
||||
if (itr == accounts.end()) {
|
||||
return QModelIndex();
|
||||
|
@ -1002,8 +925,7 @@ QModelIndex Models::Roster::getGroupIndex(const QString& account, const QString&
|
|||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::getContactIndex(const QString& account, const QString& jid, const QString& resource) const
|
||||
{
|
||||
QModelIndex Models::Roster::getContactIndex(const QString& account, const QString& jid, const QString& resource) const {
|
||||
std::map<QString, Account*>::const_iterator itr = accounts.find(account);
|
||||
if (itr == accounts.end()) {
|
||||
return QModelIndex();
|
||||
|
@ -1017,11 +939,10 @@ QModelIndex Models::Roster::getContactIndex(const QString& account, const QStrin
|
|||
return contactIndex;
|
||||
} else {
|
||||
Presence* pres = cItr->second->getPresence(resource);
|
||||
if (pres != nullptr) {
|
||||
if (pres != nullptr)
|
||||
return index(pres->row(), 0, contactIndex);
|
||||
} else {
|
||||
else
|
||||
return contactIndex;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::map<ElId, Room*>::const_iterator rItr = rooms.find(ElId(account, jid));
|
||||
|
@ -1031,11 +952,10 @@ QModelIndex Models::Roster::getContactIndex(const QString& account, const QStrin
|
|||
return roomIndex;
|
||||
} else {
|
||||
Participant* part = rItr->second->getParticipant(resource);
|
||||
if (part != nullptr) {
|
||||
if (part != nullptr)
|
||||
return index(part->row(), 0, roomIndex);
|
||||
} else {
|
||||
else
|
||||
return roomIndex;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return QModelIndex();
|
||||
|
@ -1044,93 +964,78 @@ QModelIndex Models::Roster::getContactIndex(const QString& account, const QStrin
|
|||
}
|
||||
}
|
||||
|
||||
void Models::Roster::onElementRequestArchive(const QString& before)
|
||||
{
|
||||
void Models::Roster::onElementRequestArchive(const QString& before) {
|
||||
Element* el = static_cast<Element*>(sender());
|
||||
emit requestArchive(el->getAccountName(), el->getJid(), before);
|
||||
}
|
||||
|
||||
void Models::Roster::responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last)
|
||||
{
|
||||
void Models::Roster::responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last) {
|
||||
ElId id(account, jid);
|
||||
Element* el = getElement(id);
|
||||
if (el != nullptr) {
|
||||
if (el != nullptr)
|
||||
el->responseArchive(list, last);
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::fileProgress(const std::list<Shared::MessageInfo>& msgs, qreal value, bool up)
|
||||
{
|
||||
void Models::Roster::fileProgress(const std::list<Shared::MessageInfo>& msgs, qreal value, bool up) {
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
Element* el = getElement(ElId(info.account, info.jid));
|
||||
if (el != nullptr) {
|
||||
if (el != nullptr)
|
||||
el->fileProgress(info.messageId, value, up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::fileComplete(const std::list<Shared::MessageInfo>& msgs, bool up)
|
||||
{
|
||||
void Models::Roster::fileComplete(const std::list<Shared::MessageInfo>& msgs, bool up) {
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
Element* el = getElement(ElId(info.account, info.jid));
|
||||
if (el != nullptr) {
|
||||
if (el != nullptr)
|
||||
el->fileComplete(info.messageId, up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::fileError(const std::list<Shared::MessageInfo>& msgs, const QString& err, bool up)
|
||||
{
|
||||
void Models::Roster::fileError(const std::list<Shared::MessageInfo>& msgs, const QString& err, bool up) {
|
||||
for (const Shared::MessageInfo& info : msgs) {
|
||||
Element* el = getElement(ElId(info.account, info.jid));
|
||||
if (el != nullptr) {
|
||||
if (el != nullptr)
|
||||
el->fileError(info.messageId, err, up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Models::Element * Models::Roster::getElement(const Models::Roster::ElId& id)
|
||||
{
|
||||
Models::Element * Models::Roster::getElement(const Models::Roster::ElId& id) {
|
||||
return const_cast<Models::Element*>(getElementConst(id));
|
||||
}
|
||||
|
||||
Models::Item::Type Models::Roster::getContactType(const Models::Roster::ElId& id) const
|
||||
{
|
||||
Models::Item::Type Models::Roster::getContactType(const Models::Roster::ElId& id) const {
|
||||
const Models::Element* el = getElementConst(id);
|
||||
if (el == nullptr) {
|
||||
if (el == nullptr)
|
||||
return Item::root;
|
||||
}
|
||||
|
||||
|
||||
return el->type;
|
||||
}
|
||||
|
||||
|
||||
void Models::Roster::onAccountReconnected()
|
||||
{
|
||||
void Models::Roster::onAccountReconnected() {
|
||||
Account* acc = static_cast<Account*>(sender());
|
||||
|
||||
QString accName = acc->getName();
|
||||
for (const std::pair<const ElId, Contact*>& pair : contacts) {
|
||||
if (pair.first.account == accName) {
|
||||
if (pair.first.account == accName)
|
||||
pair.second->handleRecconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Models::Roster::recalculateUnreadMessages()
|
||||
{
|
||||
void Models::Roster::recalculateUnreadMessages() {
|
||||
int count(0);
|
||||
for (const std::pair<const ElId, Contact*>& pair : contacts) {
|
||||
for (const std::pair<const ElId, Contact*>& pair : contacts)
|
||||
count += pair.second->getMessagesCount();
|
||||
}
|
||||
for (const std::pair<const ElId, Room*>& pair : rooms) {
|
||||
|
||||
for (const std::pair<const ElId, Room*>& pair : rooms)
|
||||
count += pair.second->getMessagesCount();
|
||||
}
|
||||
|
||||
emit unreadMessagesCountChanged(count);
|
||||
}
|
||||
|
||||
std::list<QString> Models::Roster::getItemPath(const QModelIndex& index) const
|
||||
{
|
||||
std::list<QString> Models::Roster::getItemPath(const QModelIndex& index) const {
|
||||
std::list<QString> result;
|
||||
if (index.isValid() && index.model() == this) {
|
||||
Item* item = static_cast<Item*>(index.internalPointer());
|
||||
|
@ -1143,8 +1048,7 @@ std::list<QString> Models::Roster::getItemPath(const QModelIndex& index) const
|
|||
return result;
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::getIndexByPath(const std::list<QString>& path) const
|
||||
{
|
||||
QModelIndex Models::Roster::getIndexByPath(const std::list<QString>& path) const {
|
||||
if (path.empty())
|
||||
return QModelIndex();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue