Home · Modules · All Classes · All Namespaces
roster/roster-window.cpp
#include "roster-window.h"
#include "_gen/roster-window.moc.hpp"
#include "roster-widget.h"
#include <TelepathyQt/Types>
#include <TelepathyQt/ChannelFactory>
#include <TelepathyQt/Connection>
#include <TelepathyQt/ConnectionFactory>
#include <TelepathyQt/ContactFactory>
#include <TelepathyQt/PendingOperation>
#include <TelepathyQt/PendingReady>
#include <QDebug>
using namespace Tp;
RosterWindow::RosterWindow(const QString &accountName, QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle(QLatin1String("Roster"));
setupGui();
ChannelFactoryPtr channelFactory = ChannelFactory::create(
QDBusConnection::sessionBus());
ConnectionFactoryPtr connectionFactory = ConnectionFactory::create(
QDBusConnection::sessionBus(), Connection::FeatureConnected |
ContactFactoryPtr contactFactory = ContactFactory::create(
TP_QT_ACCOUNT_OBJECT_PATH_BASE + QLatin1Char('/') + accountName,
connectionFactory, channelFactory, contactFactory);
connect(mAccount->becomeReady(Account::FeatureCore),
SIGNAL(finished(Tp::PendingOperation *)),
SLOT(onAccountReady(Tp::PendingOperation *)));
resize(240, 320);
}
RosterWindow::~RosterWindow()
{
}
void RosterWindow::setupGui()
{
mRoster = new RosterWidget();
setCentralWidget(mRoster);
}
void RosterWindow::onAccountReady(Tp::PendingOperation *op)
{
if (op->isError()) {
qWarning() << "Account cannot become ready - " <<
op->errorName() << '-' << op->errorMessage();
QCoreApplication::exit(1);
return;
}
qDebug() << "Account ready";
connect(mAccount.data(),
SIGNAL(connectionChanged(Tp::ConnectionPtr)),
SLOT(onAccountConnectionChanged(Tp::ConnectionPtr)));
if (mAccount->connection().isNull()) {
qDebug() << "The account given has no Connection. Please set it online to continue.";
}
onAccountConnectionChanged(mAccount->connection());
}
void RosterWindow::onAccountConnectionChanged(const ConnectionPtr &conn)
{
if (conn) {
mRoster->setConnection(conn);
} else {
mRoster->unsetConnection();
}
}