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 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(),
}
{
qWarning() << "Account manager cannot become ready:" <<
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();
}
void MyClass::onValidAccountAdded(const Tp::AccountPtr &account)
{
}
void MyClass::onValidAccountRemoved(const Tp::AccountPtr &account)
{
}
You can also define your own filter using AccountManager::filterAccounts:
{
...
filter->addProperty(QLatin1String("protocolName"), QLatin1String("jabber"));
filter->addProperty(QLatin1String("enabled"), true);
AccountSetPtr filteredAccountSet = am->filterAccounts(filter);
QList<AccountPtr> accounts = filteredAccountSet->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.