Home · All Classes · All Namespaces · Modules · Functions · Files |
The AccountSet class represents a set of Telepathy accounts filtered by a given criteria. More...
#include <TelepathyQt4/AccountSet>
Inherits Tp::Object.
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.
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.
Tp::AccountSet::AccountSet | ( | const AccountManagerPtr & | accountManager, |
const AccountFilterConstPtr & | filter | ||
) |
Construct a new AccountSet object.
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.
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.
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.
account | The account that was added to this set. |
void Tp::AccountSet::accountRemoved | ( | const Tp::AccountPtr & | account | ) | [signal] |
Emitted whenever an account that matches filter is removed from this set.
account | The account that was removed from this set. |
AccountManagerPtr Tp::AccountSet::accountManager [read] |
Return the account manager object used to filter accounts.
AccountFilterConstPtr Tp::AccountSet::filter [read] |
Return the filter used to filter accounts.
QList< AccountPtr > Tp::AccountSet::accounts [read] |
Return a list of account objects that match filter.
Change notification is via the accountAdded() and accountRemoved() signals.
Copyright © 2008-2011 Collabora Ltd. and Nokia Corporation | Telepathy-Qt4 0.8.0 |