From 61a6301cc4cb92595511952dbf6005a0e07024f4 Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Sun, 4 Jun 2017 16:05:57 -0600 Subject: [PATCH 4/4] Change the accounts QHash key from objectPath() to uniqueIdentifier(). Export accounts() as the resulting QHash instead of as a QList. --- TelepathyQt/account-set.cpp | 41 +++++++++++++++++++++-------------------- TelepathyQt/account-set.h | 8 +++++--- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git TelepathyQt/account-set.cpp TelepathyQt/account-set.cpp index 137a511b..f904926c 100644 --- TelepathyQt/account-set.cpp +++ TelepathyQt/account-set.cpp @@ -96,8 +96,8 @@ void AccountSet::Private::insertAccounts() void AccountSet::Private::insertAccount(const Tp::AccountPtr &account) { - QString accountPath = account->objectPath(); - Q_ASSERT(!wrappers.contains(accountPath)); + QString uniqueIdentifier = account->uniqueIdentifier(); + Q_ASSERT(!wrappers.contains(uniqueIdentifier)); wrapAccount(account); filterAccount(account); @@ -110,11 +110,11 @@ void AccountSet::Private::insertAccount(const Tp::AccountPtr &account) void AccountSet::Private::removeAccount(const Tp::AccountPtr &account) { - QString accountPath = account->objectPath(); - Q_ASSERT(wrappers.contains(accountPath)); - accounts.remove(accountPath); + QString uniqueIdentifier = account->uniqueIdentifier(); + Q_ASSERT(wrappers.contains(uniqueIdentifier)); + accounts.remove(uniqueIdentifier); - AccountWrapper *wrapper = wrappers.take(accountPath); + AccountWrapper *wrapper = wrappers.take(uniqueIdentifier); Q_ASSERT(wrapper->disconnect(parent)); wrapper->deleteLater(); @@ -224,26 +224,26 @@ void AccountSet::Private::wrapAccount(const AccountPtr &account) parent->connect(wrapper, SIGNAL(accountCapabilitiesChanged(Tp::AccountPtr,Tp::ConnectionCapabilities)), SLOT(onAccountChanged(Tp::AccountPtr))); - wrappers.insert(account->objectPath(), wrapper); + wrappers.insert(account->uniqueIdentifier(), wrapper); } void AccountSet::Private::filterAccount(const AccountPtr &account) { - QString accountPath = account->objectPath(); - Q_ASSERT(wrappers.contains(accountPath)); - AccountWrapper *wrapper = wrappers[accountPath]; + QString uniqueIdentifier = account->uniqueIdentifier(); + Q_ASSERT(wrappers.contains(uniqueIdentifier)); + AccountWrapper *wrapper = wrappers[uniqueIdentifier]; /* account changed, let's check if it matches filter */ if (accountMatchFilter(wrapper)) { - if (!accounts.contains(account->objectPath())) { - accounts.insert(account->objectPath(), account); + if (!accounts.contains(uniqueIdentifier)) { + accounts.insert(uniqueIdentifier, account); if (ready) { emit parent->accountAdded(account); } } } else { - if (accounts.contains(account->objectPath())) { - accounts.remove(account->objectPath()); + if (accounts.contains(uniqueIdentifier)) { + accounts.remove(uniqueIdentifier); if (ready) { emit parent->accountRemoved(account); } @@ -364,7 +364,7 @@ void AccountSet::Private::AccountWrapper::onAccountCapalitiesChanged( * SIGNAL(accountRemoved(const Tp::AccountPtr &)), * SLOT(onValidAccountRemoved(const Tp::AccountPtr &))); * - * QList accounts = validAccountsSet->accounts(); + * QList accounts = validAccountsSet->accounts().values(); * // do something with accounts * } * @@ -394,7 +394,7 @@ void AccountSet::Private::AccountWrapper::onAccountCapalitiesChanged( * * AccountSetPtr filteredAccountSet = am->filterAccounts(filter); * // connect to AccountSet::accountAdded/accountRemoved signals - * QList accounts = filteredAccountSet->accounts(); + * QList accounts = filteredAccountSet->accounts().values(); * // do something with accounts * * .... @@ -472,16 +472,17 @@ AccountFilterConstPtr AccountSet::filter() const } /** - * Return a list of account objects that match filter. + * Return a hash of account object unique identifiers with account objects that + * match filter. * * Change notification is via the accountAdded() and accountRemoved() signals. * - * \return A list of pointers to Account objects. + * \return A hash of account unique identifiers and account object pointers. * \sa accountAdded(), accountRemoved() */ -QList AccountSet::accounts() const +Accounts AccountSet::accounts() const { - return mPriv->accounts.values(); + return mPriv->accounts; } /** diff --git TelepathyQt/account-set.h TelepathyQt/account-set.h index c0681c32..6518b7ca 100644 --- TelepathyQt/account-set.h +++ TelepathyQt/account-set.h @@ -32,20 +32,22 @@ #include #include -#include +#include #include #include namespace Tp { +typedef QHash Accounts; + class TP_QT_EXPORT AccountSet : public Object { Q_OBJECT Q_DISABLE_COPY(AccountSet) Q_PROPERTY(AccountManagerPtr accountManager READ accountManager) Q_PROPERTY(AccountFilterConstPtr filter READ filter) - Q_PROPERTY(QList accounts READ accounts) + Q_PROPERTY(Accounts accounts READ accounts) Q_PROPERTY(Tp::Presence requestedPresence READ requestedPresence WRITE setPresence NOTIFY requestedPresenceChanged) Q_PROPERTY(Tp::Presence currentPresence READ currentPresence NOTIFY currentPresenceChanged) Q_PROPERTY(Tp::ConnectionStatus connectionStatus READ connectionStatus NOTIFY connectionStatusChanged) @@ -63,7 +65,7 @@ public: AccountFilterConstPtr filter() const; - QList accounts() const; + Accounts accounts() const; void setPresence(const Tp::Presence &presence); -- 2.12.3