Esempio n. 1
0
Tp::ContactPtr ToTpContactPtr(TpContact * tpContact)
{
    if (!tpContact) {
        return Tp::ContactPtr();
    }

    TpConnection * tpConnection = tp_contact_get_connection(tpContact);
    if (!tpConnection) {
        return Tp::ContactPtr();
    }

    const gchar *busName = tp_proxy_get_bus_name(TP_PROXY(tpConnection));
    if (!busName) {
        return Tp::ContactPtr();
    }

    const gchar *objectPath = tp_proxy_get_object_path(TP_PROXY(tpConnection));
    if (!objectPath) {
        return Tp::ContactPtr();
    }

    Tp::ConnectionPtr connection = Tp::Connection::create(busName, objectPath);
    if (connection.isNull()) {
        return Tp::ContactPtr();
    }

    if (connection->contactManager().isNull()) {
        return Tp::ContactPtr();
    }

    TpHandle handle = tp_contact_get_handle(contact);
    // TODO use async version
    return connection->contactManager()->lookupContactByHandle(handle);
}
bool TelepathyAddContactPage::apply(Kopete::Account *account, Kopete::MetaContact *parentMetaContact)
{
    if (!account->isConnected()) {
        KMessageBox::error(this, i18n("You must be connected to add a contact."), i18n("Telepathy plugin"));
        return false;
    }
    TelepathyAccount *tAccount = static_cast<TelepathyAccount*>(account);

    Tp::ConnectionPtr connection = tAccount->account()->connection();

    if (!connection) {
        KMessageBox::error(this, i18n("You must be connected to add a contact."), i18n("Telepathy plugin"));
        kWarning() << "TelepathyAccount->account()->connection() is null.";
        return false;
    }

    if (connection->status() != Tp::ConnectionStatusConnected) {
        KMessageBox::error(this, i18n("You must be connected to add a contact."), i18n("Telepathy plugin"));
        kWarning() << "connection.status() is not Connected.";
        return false;
    }

    // Get new id.
    QString newId = d->mainUi.textUserId->text();

    kDebug() << "Starting to apply adding contact" << newId;

    QObject::connect(connection->contactManager()->contactsForIdentifiers(QStringList() << newId),
            SIGNAL(finished(Tp::PendingOperation*)),
            new TelepathyAddContactAsyncContext(tAccount, parentMetaContact),
            SLOT(normalizedContactFetched(Tp::PendingOperation*)));

    return true;
}
void ContactWrapper::onConnectionChanged(const Tp::ConnectionPtr& newConn)
{
    // connection needs to be valid
    if (newConn) {
        connect(newConn->contactManager().data(), SIGNAL(stateChanged(Tp::ContactListState)), this, SLOT(onContactManagerStateChanged(Tp::ContactListState)));
    }
}