roster/roster-item.cpp

| Home · All Classes · All Namespaces · Modules · Functions · Files

roster/roster-item.cpp
#include "roster-item.h"
#include "_gen/roster-item.moc.hpp"
#include <TelepathyQt/Presence>
using namespace Tp;
RosterItem::RosterItem(const ContactPtr &contact, QListWidget *parent)
: QObject(parent),
QListWidgetItem(parent),
mContact(contact)
{
onContactChanged();
connect(contact.data(),
SIGNAL(aliasChanged(QString)),
SLOT(onContactChanged()));
connect(contact.data(),
SIGNAL(presenceChanged(Tp::Presence)),
SLOT(onContactChanged()));
connect(contact.data(),
SIGNAL(subscriptionStateChanged(Tp::Contact::PresenceState)),
SLOT(onContactChanged()));
connect(contact.data(),
SIGNAL(publishStateChanged(Tp::Contact::PresenceState,QString)),
SLOT(onContactChanged()));
connect(contact.data(),
SIGNAL(blockStatusChanged(bool)),
SLOT(onContactChanged()));
}
RosterItem::~RosterItem()
{
}
void RosterItem::onContactChanged()
{
QString status = mContact->presence().status();
// I've asked to see the contact presence
if (mContact->subscriptionState() == Contact::PresenceStateAsk) {
setText(QString(QLatin1String("%1 (%2) (awaiting approval)")).arg(mContact->id()).arg(status));
// The contact asked to see my presence
} else if (mContact->publishState() == Contact::PresenceStateAsk) {
setText(QString(QLatin1String("%1 (%2) (pending approval)")).arg(mContact->id()).arg(status));
} else if (mContact->subscriptionState() == Contact::PresenceStateNo &&
mContact->publishState() == Contact::PresenceStateNo) {
setText(QString(QLatin1String("%1 (unknown)")).arg(mContact->id()));
} else {
setText(QString(QLatin1String("%1 (%2)")).arg(mContact->id()).arg(status));
}
if (mContact->isBlocked()) {
setText(QString(QLatin1String("%1 (blocked)")).arg(text()));
}
emit changed();
}