Having a KTp::Contact

Daniele E. Domenichelli daniele.domenichelli at gmail.com
Thu Jan 3 14:05:22 UTC 2013


On 03/01/13 13:57, David Edmundson wrote:
>> Just one more idea: in several places we need the Tp::Account together
>> with the Tp::Contact, (for example all the "actions" require both, and
>> the contact grid widget requires 2 methods to get the contact and the
>> account).
>> Does it make sense to have a method
>>
>>   Tp::Account KTp::Contact::account() const
>>
> That would solve so many problems.
> 
> Problem is it's not easy to do. I can't find a hook I could use
> outside Tp. I really don't want some sort of "setAccount" method on
> the connection that client side code calls because that's horrendous.
> 
> I think the only way to fix that is inside TpQt, but even there I
> can't find a neat way to do it. Account::onConnectionBuilt maybe...
> but it's still not great.

Can we use GlobalContactManager::accountForContact(this) the first time
the account() method is called, and since it is not going to change,
store a pointer internally so that we do not need to call it again later?

Or if we cannot use the GlobalContactManager directly we can do it in
the same way it is done in there:


Tp::AccountPtr GlobalContactManager::accountForContact(const
Tp::ContactPtr &contact) const
{
    return accountForConnection(contact->manager()->connection());
}

Tp::AccountPtr GlobalContactManager::accountForConnection(const
Tp::ConnectionPtr &connection) const
{
    //loop through all accounts looking for a matching connection.
    //arguably inneficient, but no. of accounts is normally very low,
and it's not called very often.
    Q_FOREACH(const Tp::AccountPtr &account,
d->accountManager->allAccounts()) {
        if (account->connection() == connection) {
            return account;
        }
    }

    return Tp::AccountPtr();
}



More information about the KDE-Telepathy mailing list