basic conversation window binding

This commit is contained in:
Blue 2019-04-09 18:04:08 +03:00
parent 1cbcad44af
commit 4775c7b700
16 changed files with 333 additions and 80 deletions

View file

@ -63,7 +63,7 @@ void Models::Accounts::addAccount(Account* account)
{
beginInsertRows(QModelIndex(), accs.size(), accs.size());
accs.push_back(account);
connect(account, SIGNAL(childChanged(Item*, int, int)), this, SLOT(onAccountChanged(Item*, int, int)));
connect(account, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onAccountChanged(Models::Item*, int, int)));
endInsertRows();
}

View file

@ -29,7 +29,7 @@ private:
static std::deque<QString> columns;
private slots:
void onAccountChanged(Item* item, int row, int col);
void onAccountChanged(Models::Item* item, int row, int col);
};
}

View file

@ -81,9 +81,9 @@ QVariant Models::Contact::data(int column) const
case 1:
return jid;
case 2:
return availability;
case 3:
return state;
case 3:
return availability;
default:
return QVariant();
}
@ -124,6 +124,7 @@ void Models::Contact::removePresence(const QString& name)
QMap<QString, Presence*>::iterator itr = presences.find(name);
if (itr == presences.end()) {
qDebug() << "an attempt to remove non existing presence " << name << " from the contact " << jid << " of account " << getAccountName() << ", skipping";
} else {
Presence* pr = itr.value();
presences.erase(itr);
@ -154,6 +155,8 @@ void Models::Contact::refresh()
void Models::Contact::_removeChild(int index)
{
Item* child = childItems[index];
disconnect(child, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(refresh()));
Item::_removeChild(index);
refresh();
}
@ -161,12 +164,7 @@ void Models::Contact::_removeChild(int index)
void Models::Contact::appendChild(Models::Item* child)
{
Item::appendChild(child);
refresh();
}
void Models::Contact::changed(int col)
{
Item::changed(col);
connect(child, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(refresh()));
refresh();
}
@ -191,3 +189,18 @@ QIcon Models::Contact::getStatusIcon() const
return QIcon::fromTheme(Shared::subscriptionStateThemeIcons[state]);
}
}
QString Models::Contact::getAccountName() const
{
const Item* p = this;
do {
p = p->parentItemConst();
} while (p != 0 && p->type != Item::account);
if (p == 0) {
qDebug() << "An attempt to request account name of the contact " << jid << " but the parent account wasn't found, returning empty string";
return "";
}
return p->getName();
}

View file

@ -30,12 +30,14 @@ public:
void removePresence(const QString& name);
void appendChild(Models::Item * child) override;
QString getAccountName() const;
protected:
void refresh();
void changed(int col) override;
void _removeChild(int index) override;
protected slots:
void refresh();
protected:
void setAvailability(Shared::Availability p_state);
void setAvailability(unsigned int p_state);

View file

@ -41,7 +41,7 @@ void Models::Item::appendChild(Models::Item* child)
childItems.push_back(child);
child->parent = this;
QObject::connect(child, SIGNAL(childChanged(Item*, int, int)), this, SIGNAL(childChanged(Item*, int, int)));
QObject::connect(child, SIGNAL(childChanged(Models::Item*, int, int)), this, SIGNAL(childChanged(Models::Item*, int, int)));
QObject::connect(child, SIGNAL(childIsAboutToBeInserted(Item*, int, int)), this, SIGNAL(childIsAboutToBeInserted(Item*, int, int)));
QObject::connect(child, SIGNAL(childInserted()), this, SIGNAL(childInserted()));
QObject::connect(child, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)), this, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)));
@ -87,6 +87,11 @@ Models::Item * Models::Item::parentItem()
return parent;
}
const Models::Item * Models::Item::parentItemConst() const
{
return parent;
}
int Models::Item::columnCount() const
{
return 1;
@ -116,7 +121,7 @@ void Models::Item::_removeChild(int index)
{
Item* child = childItems[index];
QObject::connect(child, SIGNAL(childChanged(Item*, int, int)), this, SIGNAL(childChanged(Item*, int, int)));
QObject::connect(child, SIGNAL(childChanged(Models::Item*, int, int)), this, SIGNAL(childChanged(Models::Item*, int, int)));
QObject::connect(child, SIGNAL(childIsAboutToBeInserted(Item*, int, int)), this, SIGNAL(childIsAboutToBeInserted(Item*, int, int)));
QObject::connect(child, SIGNAL(childInserted()), this, SIGNAL(childInserted()));
QObject::connect(child, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)), this, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)));

View file

@ -25,7 +25,7 @@ class Item : public QObject{
~Item();
signals:
void childChanged(Item* item, int row, int col);
void childChanged(Models::Item* item, int row, int col);
void childIsAboutToBeInserted(Item* parent, int first, int last);
void childInserted();
void childIsAboutToBeRemoved(Item* parent, int first, int last);
@ -45,6 +45,7 @@ class Item : public QObject{
virtual QVariant data(int column) const;
int row() const;
Item *parentItem();
const Item *parentItemConst() const;
const Type type;

View file

@ -17,7 +17,7 @@ Models::Roster::Roster(QObject* parent):
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)),
this,
SLOT(onAccountDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
connect(root, SIGNAL(childChanged(Item*, int, int)), this, SLOT(onChildChanged(Item*, int, int)));
connect(root, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onChildChanged(Models::Item*, int, int)));
connect(root, SIGNAL(childIsAboutToBeInserted(Item*, int, int)), this, SLOT(onChildIsAboutToBeInserted(Item*, int, int)));
connect(root, SIGNAL(childInserted()), this, SLOT(onChildInserted()));
connect(root, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)), this, SLOT(onChildIsAboutToBeRemoved(Item*, int, int)));

View file

@ -16,9 +16,9 @@ namespace Models
class Roster : public QAbstractItemModel
{
class ElId;
Q_OBJECT
public:
class ElId;
Roster(QObject* parent = 0);
~Roster();
@ -51,7 +51,7 @@ private:
private slots:
void onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector<int>& roles);
void onChildChanged(Item* item, int row, int col);
void onChildChanged(Models::Item* item, int row, int col);
void onChildIsAboutToBeInserted(Item* parent, int first, int last);
void onChildInserted();
void onChildIsAboutToBeRemoved(Item* parent, int first, int last);
@ -59,7 +59,7 @@ private slots:
void onChildIsAboutToBeMoved(Item* source, int first, int last, Item* destination, int newIndex);
void onChildMoved();
private:
public:
class ElId {
public:
ElId (const QString& p_account, const QString& p_name);