Home · All Classes · All Namespaces · Modules · Functions · Files
Signals | Public Member Functions | Properties

Tp::AccountSet Class Reference
[Account proxies]

The AccountSet class provides an object representing a set of Telepathy accounts filtered by a given criteria. More...

#include <TelepathyQt4/AccountSet>

Inherits Tp::RefCounted.

List of all members.

Signals

Public Member Functions

Properties


Detailed Description

The AccountSet class provides an object representing a set of Telepathy accounts filtered by a given criteria.

AccountSet is automatically updated whenever accounts that match the given criteria are added, removed or updated.

Usage

Creating an AccountSet object

The easiest way to create AccountSet objects is through AccountManager. One can just use the AccountManager convenience methods such as AccountManager::validAccountsSet() to get a set of account objects representing valid accounts.

For example:

 class MyClass : public QObject
 {
     QOBJECT

 public:
     MyClass(QObject *parent = 0);
     ~MyClass() { }

 private Q_SLOTS:
     void onAccountManagerReady(Tp::PendingOperation *);
     void onValidAccountAdded(const Tp::AccountPtr &);
     void onValidAccountRemoved(const Tp::AccountPtr &);

 private:
     AccountManagerPtr am;
     AccountSetPtr validAccountsSet;
 };

 MyClass::MyClass(QObject *parent)
     : QObject(parent)
       am(AccountManager::create())
 {
     connect(am->becomeReady(),
             SIGNAL(finished(Tp::PendingOperation*)),
             SLOT(onAccountManagerReady(Tp::PendingOperation*)));
 }

 void MyClass::onAccountManagerReady(Tp::PendingOperation *op)
 {
     if (op->isError()) {
         qWarning() << "Account manager cannot become ready:" <<
             op->errorName() << "-" << op->errorMessage();
         return;
     }

     validAccountsSet = am->validAccountsSet();
     connect(validAccountsSet.data(),
             SIGNAL(accountAdded(const Tp::AccountPtr &)),
             SLOT(onValidAccountAdded(const Tp::AccountPtr &)));
     connect(validAccountsSet.data(),
             SIGNAL(accountRemoved(const Tp::AccountPtr &)),
             SLOT(onValidAccountRemoved(const Tp::AccountPtr &)));

     QList<AccountPtr> accounts = validAccountsSet->accounts();
     // do something with accounts
 }

 void MyClass::onValidAccountAdded(const Tp::AccountPtr &account)
 {
     // do something with account
 }

 void MyClass::onValidAccountRemoved(const Tp::AccountPtr &account)
 {
     // do something with account
 }

You can also define your own filter using AccountManager::filterAccounts:

 void MyClass::onAccountManagerReady(Tp::PendingOperation *op)
 {
     ...

     QList<AccountFilterConstPtr> filters;
     AccountPropertyFilterPtr filter = AccountPropertyFilter::create();
     filter->addProperty(QLatin1String("protocolName"), QLatin1String("jabber"));
     filter->addProperty(QLatin1String("enabled"), true);
     filters.append(filter);

     AccountSetPtr filteredAccountSet = am->filterAccounts(filter);
     // connect to AccountSet::accountAdded/accountRemoved signals
     QList<AccountPtr> accounts = filteredAccountSet->accounts();
     // do something with accounts

     ....
 }

Note that for AccountSet to property work with AccountCapabilityFilter objects, the feature Account::FeatureCapabilities need to be enabled in all accounts return by the AccountManager passed as param in the constructor. The easiest way to do this is to enable AccountManager feature AccountManager::FeatureFilterByCapabilities.

AccountSet can also be instantiated directly, but when doing it, the AccountManager object passed as param in the constructor must be ready for AccountSet properly work.


Constructor & Destructor Documentation

Tp::AccountSet::AccountSet ( const AccountManagerPtr accountManager,
const QList< AccountFilterConstPtr > &  filters 
)

Construct a new AccountSet object.

Parameters:
accountManager An account manager object used to filter accounts. The account manager object must be ready.
filters The desired filter.
Tp::AccountSet::AccountSet ( const AccountManagerPtr accountManager,
const QVariantMap &  filter 
)

Construct a new AccountSet object.

The filter must contain Account property names and values as map items.

Parameters:
accountManager An account manager object used to filter accounts. The account manager object must be ready.
filter The desired filter.
Tp::AccountSet::~AccountSet (  )  [virtual]

Class destructor.


Member Function Documentation

AccountManagerPtr Tp::AccountSet::accountManager (  )  const
bool Tp::AccountSet::isFilterValid (  )  const

Return whether the filter returned by filter()/filters() is valid.

If the filter is invalid accounts() will always return an empty list.

This method is deprecated and should not be used in newly written code. Use Filter::isValid() instead.

Deprecated:
Use Filter::isValid() instead.
Returns:
true if the filter returned by filter()/filters() is valid, otherwise false.
TELEPATHY_QT4_DEPRECATED QVariantMap Tp::AccountSet::filter (  )  const
TELEPATHY_QT4_DEPRECATED QList<AccountFilterConstPtr> Tp::AccountSet::filters (  )  const
QList<AccountPtr> Tp::AccountSet::accounts (  )  const
void Tp::AccountSet::accountAdded ( const Tp::AccountPtr account  )  [signal]

This signal is emitted whenever an account that matches filters is added to this set.

Parameters:
account The account that was added to this set.
void Tp::AccountSet::accountRemoved ( const Tp::AccountPtr account  )  [signal]

This signal is emitted whenever an account that matches filters is removed from this set.

Parameters:
account The account that was removed from this set.

Property Documentation

AccountManagerPtr Tp::AccountSet::accountManager [read]

Return the account manager object used to filter accounts.

Returns:
The AccountManager object used to filter accounts.
bool Tp::AccountSet::filterValid [read]
QVariantMap Tp::AccountSet::filter [read]

Return the filter used to filter accounts.

The filter is composed by Account property names and values as map items.

Deprecated:
Returns:
A QVariantMap representing the filter used to filter accounts.
QList< AccountFilterConstPtr > Tp::AccountSet::filters [read]

Return the filters used to filter accounts.

Deprecated:
Returns:
A list of filter objects used to filter accounts.
QList< AccountPtr > Tp::AccountSet::accounts [read]

Return a list of account objects that match filters.

Returns:
A list of account objects that match filters.


Copyright © 2008-2010 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.4.4