| Home · All Classes · All Namespaces · Modules · Functions · Files

Signals | Public Member Functions | Properties
Tp::AccountSet Class Reference
Account proxies

The AccountSet class represents a set of Telepathy accounts filtered by a given criteria. More...

`#include <TelepathyQt/AccountSet>`

Inherits Tp::Object.

List of all members.

## Signals

- void accountAdded (const Tp::AccountPtr &account)
- void accountRemoved (const Tp::AccountPtr &account)

## Public Member Functions

- AccountSet (const AccountManagerPtr &accountManager, const AccountFilterConstPtr &filter)
- AccountSet (const AccountManagerPtr &accountManager, const QVariantMap &filter)
- virtual ~AccountSet ()
- AccountManagerPtr accountManager () const
- AccountFilterConstPtr filter () const
- QList< AccountPtr > accounts () const

## Properties

- AccountManagerPtr accountManager
- AccountFilterConstPtr filter
- QList< AccountPtr > accounts

## Detailed Description

The AccountSet class represents 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::validAccounts() 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->validAccounts();
         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)
     {
         ...

         AccountPropertyFilterPtr filter = AccountPropertyFilter::create();
         filter->addProperty(QLatin1String("protocolName"), QLatin1String("jabber"));
         filter->addProperty(QLatin1String("enabled"), true);

         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 AccountFilterConstPtr & | filter
| ) |  |

Construct a new AccountSet object.

Parameters:

  accountManager | An account manager object used to filter accounts. The account manager object must be ready.
  filter | 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

AccountFilterConstPtr Tp::AccountSet::filter | ( |  | ) | const

QList<AccountPtr> Tp::AccountSet::accounts | ( |  | ) | const

void Tp::AccountSet::accountAdded | ( | const Tp::AccountPtr & | account | ) | `[signal]`

Emitted whenever an account that matches filter is added to this set.

Parameters:

  account | The account that was added to this set.

See also:
  accounts()

void Tp::AccountSet::accountRemoved | ( | const Tp::AccountPtr & | account | ) | `[signal]`

Emitted whenever an account that matches filter is removed from this set.

Parameters:

  account | The account that was removed from this set.

See also:
  accounts()

## Property Documentation

AccountManagerPtr Tp::AccountSet::accountManager `[read]`

Return the account manager object used to filter accounts.

Returns:
  A pointer to the AccountManager object.

AccountFilterConstPtr Tp::AccountSet::filter `[read]`

Return the filter used to filter accounts.

Returns:
  A read-only pointer the AccountFilter object.

QList< AccountPtr > Tp::AccountSet::accounts `[read]`

Return a list of account objects that match filter.

Change notification is via the accountAdded() and accountRemoved() signals.

Returns:
  A list of pointers to Account objects.

See also:
  accountAdded(), accountRemoved()