Qt Development‎ > ‎

Telepathy

Sample Code

// create account manager and get accounts
void
MyClass::start() {
        m_accountMngr = Tp::AccountManager::create();
    connect(m_accountMngr->becomeReady(),
            SIGNAL(finished(Tp::PendingOperation *)),
            SLOT(onAMReady(Tp::PendingOperation *)));
    connect(m_accountMngr.data(),
            SIGNAL(accountCreated(const QString &)),
            SLOT(onAccountCreated(const QString &)));
}

// account manager is ready: create accounts and get them ready
void MyClass::onAMReady(Tp::PendingOperation *op)
{
foreach (const QString &path, m_accountMngr->allAccountPaths()) {
qDebug() << "Account: " << path;
Tp::AccountPtr ptr = Tp::Account::create(m_accountMngr->dbusConnection(), m_accountMngr->busName(), path);
m_accounts << ptr;

connect(
ptr->becomeReady(), SIGNAL(finished(Tp::PendingOperation *)),
this, SLOT(accountReady(Tp::PendingOperation *))
);
}
}

// account is ready: now you can call/text
void MyClass::accountReady(Tp::PendingOperation *pOp) {
Tp::PendingReady *pReady = dynamic_cast<Tp::PendingReady *>(pOp);
Tp::Account *pAccount = dynamic_cast<Tp::Account *>(pReady->object());

    if ( !pAccount->haveConnection() ) return;

if ( pAccount->protocol()=="skype" ) {
        // start call
QVariantMap request;
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"), TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"), (uint) Tp::HandleTypeContact);
request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetID"), "12341111");
Tp::PendingChannelRequest *pReq = pAccount->ensureChannel(request);
        connect(pReq, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(channelRequestFinished(Tp::PendingOperation*)));

        // start sms
        *pReq = pAccount->ensureTextChat("12341111");
connect(pReq, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(channelRequestFinished(Tp::PendingOperation*)));
}
}

// chance for you to make sure the request worked
void MyClass::channelRequestFinished(Tp::PendingOperation *pOp) {
if ( !pOp->isValid() ) {
qDebug() << "Invalid channel request: " << pOp->errorMessage();
return;
}

qDebug() << "Channel request finished.";
}


Comments