MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9
   Home · All Classes · All Namespaces · Modules · Functions · Files

roster/roster-item.cpp

#include "roster-item.h"
#include "_gen/roster-item.moc.hpp"

#include <TelepathyQt4/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();
}

Copyright © 2008-2011 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.6.5