From 1735ebeb55d917f9b5eda507ce7aa370107ce554 Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Sun, 4 Jun 2017 15:45:07 -0600 Subject: [PATCH 3/3] Add cumulative account connection information to AccountSet. Allow setting the requested and automatic presence of an entire account set. --- TelepathyQt/account-set-internal.h | 14 ++ TelepathyQt/account-set.cpp | 317 ++++++++++++++++++++++++++++++++++++- TelepathyQt/account-set.h | 24 +++ 3 files changed, 354 insertions(+), 1 deletion(-) diff --git TelepathyQt/account-set-internal.h TelepathyQt/account-set-internal.h index f7dbf9e0..66e2b511 100644 --- TelepathyQt/account-set-internal.h +++ TelepathyQt/account-set-internal.h @@ -43,6 +43,13 @@ struct TP_QT_NO_EXPORT AccountSet::Private void removeAccount(const AccountPtr &account); void wrapAccount(const AccountPtr &account); void filterAccount(const AccountPtr &account); + void accountPropertiesChanged(); + void requestedPresenceChanged(); + void currentPresenceChanged(); + void automaticPresenceChanged(); + void connectionStatusChanged(); + void changingPresence(); + void onlinenessChanged(); bool accountMatchFilter(AccountWrapper *account); AccountSet *parent; @@ -50,6 +57,13 @@ struct TP_QT_NO_EXPORT AccountSet::Private AccountFilterConstPtr filter; QHash wrappers; QHash accounts; + + Tp::Presence requestedPresence; + Tp::Presence currentPresence; + Tp::Presence automaticPresence; + Tp::ConnectionStatus connectionStatus; + bool isChangingPresence; + bool isOnline; bool ready; }; diff --git TelepathyQt/account-set.cpp TelepathyQt/account-set.cpp index fce92a39..bb8ab5c8 100644 --- TelepathyQt/account-set.cpp +++ TelepathyQt/account-set.cpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace Tp { @@ -69,6 +70,7 @@ void AccountSet::Private::init() if (filter->isValid()) { connectSignals(); insertAccounts(); + accountPropertiesChanged(); ready = true; } } @@ -93,6 +95,10 @@ void AccountSet::Private::insertAccount(const Tp::AccountPtr &account) Q_ASSERT(!wrappers.contains(accountPath)); wrapAccount(account); filterAccount(account); + + if (ready) { + accountPropertiesChanged(); + } } void AccountSet::Private::removeAccount(const Tp::AccountPtr &account) @@ -106,6 +112,125 @@ void AccountSet::Private::removeAccount(const Tp::AccountPtr &account) wrapper->deleteLater(); emit parent->accountRemoved(account); + + if (ready) { + accountPropertiesChanged(); + } +} + +void AccountSet::Private::accountPropertiesChanged() +{ + requestedPresenceChanged(); + currentPresenceChanged(); + automaticPresenceChanged(); + connectionStatusChanged(); + changingPresence(); + onlinenessChanged(); +} + +void AccountSet::Private::requestedPresenceChanged() +{ + Tp::Presence highestRequestedPresence = Tp::PresenceSpec::offline().presence(); + + foreach (const Tp::AccountPtr &account, accounts.values()) { + if (account->requestedPresence() > highestRequestedPresence) { + highestRequestedPresence = account->requestedPresence(); + } + } + + if (requestedPresence != highestRequestedPresence) { + requestedPresence = highestRequestedPresence; + emit parent->requestedPresenceChanged(requestedPresence); + } +} + +void AccountSet::Private::currentPresenceChanged() +{ + Tp::Presence highestCurrentPresence = Tp::PresenceSpec::offline().presence(); + + foreach (const Tp::AccountPtr &account, accounts.values()) { + if (account->currentPresence() > highestCurrentPresence) { + highestCurrentPresence = account->currentPresence(); + } + } + + if (currentPresence != highestCurrentPresence) { + currentPresence = highestCurrentPresence; + emit parent->currentPresenceChanged(currentPresence); + } +} + +void AccountSet::Private::automaticPresenceChanged() +{ + Tp::Presence highestAutomaticPresence = Tp::PresenceSpec::offline().presence(); + + foreach (const Tp::AccountPtr &account, accounts.values()) { + if (account->automaticPresence() > highestAutomaticPresence) { + highestAutomaticPresence = account->automaticPresence(); + } + } + + if (automaticPresence != highestAutomaticPresence) { + automaticPresence = highestAutomaticPresence; + emit parent->automaticPresenceChanged(automaticPresence); + } +} + +void AccountSet::Private::connectionStatusChanged() +{ + Tp::ConnectionStatus status = Tp::ConnectionStatusDisconnected; + QList allConnectionStatuses; + + foreach (const Tp::AccountPtr &account, accounts.values()) { + allConnectionStatuses << account->connectionStatus(); + } + + if (allConnectionStatuses.contains(Tp::ConnectionStatusConnecting)) { + status = Tp::ConnectionStatusConnecting; + } else if (allConnectionStatuses.contains(Tp::ConnectionStatusConnected)) { + status = Tp::ConnectionStatusConnected; + } + + if (connectionStatus != status) { + connectionStatus = status; + emit parent->connectionStatusChanged(connectionStatus); + } +} + +void AccountSet::Private::changingPresence() +{ + bool changing = false; + + foreach (const Tp::AccountPtr &account, accounts.values()) { + changing = account->isChangingPresence(); + + if (account->isChangingPresence()) { + break; + } + } + + if (isChangingPresence != changing) { + isChangingPresence = changing; + emit parent->isChangingPresence(isChangingPresence); + } +} + +void AccountSet::Private::onlinenessChanged() +{ + bool online = false; + + foreach (const Tp::AccountPtr &account, accounts.values()) { + online = account->isOnline(); + + if (!account->isOnline()) { + break; + } + } + + if (isOnline != online) { + isOnline = online; + emit parent->onlinenessChanged(isOnline); + } } void AccountSet::Private::wrapAccount(const AccountPtr &account) @@ -116,7 +241,7 @@ void AccountSet::Private::wrapAccount(const AccountPtr &account) SLOT(onAccountRemoved(Tp::AccountPtr))); parent->connect(wrapper, SIGNAL(accountPropertyChanged(Tp::AccountPtr,QString)), - SLOT(onAccountChanged(Tp::AccountPtr))); + SLOT(onAccountPropertyChanged(Tp::AccountPtr,QString))); parent->connect(wrapper, SIGNAL(accountCapabilitiesChanged(Tp::AccountPtr,Tp::ConnectionCapabilities)), SLOT(onAccountChanged(Tp::AccountPtr))); @@ -381,6 +506,111 @@ QList AccountSet::accounts() const } /** + * Set the requested presence of all accounts that match filter. + * + * \param presence The requested presence. + */ +void AccountSet::setPresence(const Tp::Presence &presence) +{ + foreach (const Tp::AccountPtr &account, mPriv->accounts.values()) { + account->setRequestedPresence(presence); + } +} + +/** + * Set the automatic presence of all accounts that match filter. The presence + * type determines if the account connects automatically. + * + * \param presence The automatic presence. + */ +void AccountSet::setAutomaticPresence(const Tp::Presence &presence) +{ + foreach (const Tp::AccountPtr &account, mPriv->accounts.values()) { + account->setConnectsAutomatically(presence.type() > Tp::PresenceSpec::offline().presence().type()); + account->setAutomaticPresence(presence); + } +} + +/** + * The requested presence of all accounts that match filter. + * + * Change notification is via the requestedPresenceChanged() signal. + * + * \return The highest requested presence of the accounts that match filter. + * \sa requestedPresenceChanged() + */ +Tp::Presence AccountSet::requestedPresence() const +{ + return mPriv->requestedPresence; +} + +/** + * The current presence of all accounts that match filter. + * + * Change notification is via the currentPresenceChanged() signal. + * + * \return The highest current presence of the accounts that match filter. + * \sa currentPresenceChanged() + */ +Tp::Presence AccountSet::currentPresence() const +{ + return mPriv->currentPresence; +} + +/** + * The automatic presence of all accounts that match filter. + * + * Change notification is via the automaticPresenceChanged() signal. + * + * \return The highest automatic presence of the accounts that match filter. + * \sa automaticPresenceChanged() + */ +Tp::Presence AccountSet::automaticPresence() const +{ + return mPriv->automaticPresence; +} + +/** + * The connection status of all accounts that match filter. + * + * Change notification is via the connectionStatusChanged() signal. + * + * \return connecting if any account is connecting, connected if at + * least one account is connected, or disconnected. + * \sa connectionStatusChanged() +*/ +Tp::ConnectionStatus AccountSet::connectionStatus() const +{ + return mPriv->connectionStatus; +} + +/** + * Of all accounts that match filter, if any are changing presence. + * + * Change notification is via the isChangingPresence() signal. + * + * \return true if any accounts that match filter are changing presence. + * \sa isChangingPresence() + */ +bool AccountSet::changingPresence() const +{ + return mPriv->isChangingPresence; +} + +/** + * Of all accounts that match filter, if all are online. + * + * Change notification is via the onlinenessChanged() signal. + * + * \return false if all accounts that match filter are not online. + * \sa onlinenessChanged() + */ +bool AccountSet::online() const +{ + return mPriv->isOnline; +} + +/** * \fn void AccountSet::accountAdded(const Tp::AccountPtr &account) * * Emitted whenever an account that matches filter is added to @@ -400,6 +630,60 @@ QList AccountSet::accounts() const * \sa accounts() */ +/** + * \fn void AccountSet::requestedPresenceChanged(const Tp::Presence &requestedPresence) + * + * Emitted whenever the highest requested presence of this set of accounts changes. + * + * \param requestedPresence The highest requested presence. + * \sa requestedPresence() + */ + +/** + * \fn void AccountSet::currentPresenceChanged(const Tp::Presence ¤tPresence) + * + * Emitted whenever the highest current presence of this set of accounts changes. + * + * \param currentPresence The highest current presence. + * \sa currentPresence() + */ + +/** + * \fn void AccountSet::automaticPresenceChanged(const Tp::Presence &automaticPresence) + * + * Emitted whenever the highest automatic presence of this set of accounts changes. + * + * \param automaticPresence The highest automatic presence. + * \sa automaticPresence() + */ + +/** + * \fn void AccountSet::connectionStatusChanged(Tp::ConnectionStatus connectionStatus) + * + * Emitted whenever the connection status of this set of accounts changes. + * + * \param connectionStatus The connection status. + * \sa connectionStatus() + */ + +/** + * \fn void AccountSet::isChangingPresence(bool changingPresence) + * + * Emitted whenever any of this set of accounts are changing presence. + * + * \param changingPresence If any account is changing presence. + * \sa changingPresence() + */ + +/** + * \fn void AccountSet::onlinenessChanged(bool online) + * + * Emitted whenever any of this set of accounts onlineness changes. + * + * \param online If all accounts are online. + * \sa online() + */ + void AccountSet::onNewAccount(const AccountPtr &account) { mPriv->insertAccount(account); @@ -415,4 +699,35 @@ void AccountSet::onAccountChanged(const AccountPtr &account) mPriv->filterAccount(account); } +void AccountSet::onAccountPropertyChanged(const Tp::AccountPtr &account, const QString &propertyName) +{ + mPriv->filterAccount(account); + + if (propertyName == QLatin1String("requestedPresence")) { + if (mPriv->requestedPresence != account->requestedPresence()) { + mPriv->requestedPresenceChanged(); + } + } else if (propertyName == QLatin1String("currentPresence")) { + if (mPriv->currentPresence != account->currentPresence()) { + mPriv->currentPresenceChanged(); + } + } else if (propertyName == QLatin1String("automaticPresence")) { + if (mPriv->automaticPresence != account->automaticPresence()) { + mPriv->automaticPresenceChanged(); + } + } else if (propertyName == QLatin1String("connectionStatus")) { + if (mPriv->connectionStatus != account->connectionStatus()) { + mPriv->connectionStatusChanged(); + } + } else if (propertyName == QLatin1String("changingPresence")) { + if (mPriv->isChangingPresence != account->isChangingPresence()) { + mPriv->changingPresence(); + } + } else if (propertyName == QLatin1String("online")) { + if (mPriv->isOnline != account->isOnline()) { + mPriv->onlinenessChanged(); + } + } +} + } // Tp diff --git TelepathyQt/account-set.h TelepathyQt/account-set.h index 40dd79af..8bc15d09 100644 --- TelepathyQt/account-set.h +++ TelepathyQt/account-set.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,12 @@ class TP_QT_EXPORT AccountSet : public Object Q_PROPERTY(AccountManagerPtr accountManager READ accountManager) Q_PROPERTY(AccountFilterConstPtr filter READ filter) Q_PROPERTY(QList 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::Presence automaticPresence READ automaticPresence WRITE setAutomaticPresence NOTIFY automaticPresenceChanged) + Q_PROPERTY(Tp::ConnectionStatus connectionStatus READ connectionStatus NOTIFY connectionStatusChanged) + Q_PROPERTY(bool changingPresence READ changingPresence NOTIFY isChangingPresence) + Q_PROPERTY(bool online READ online NOTIFY onlinenessChanged) public: AccountSet(const AccountManagerPtr &accountManager, @@ -59,14 +66,31 @@ public: QList accounts() const; + void setPresence(const Tp::Presence &presence); + void setAutomaticPresence(const Tp::Presence &presence); + + Tp::Presence requestedPresence() const; + Tp::Presence currentPresence() const; + Tp::Presence automaticPresence() const; + Tp::ConnectionStatus connectionStatus() const; + bool changingPresence() const; + bool online() const; + Q_SIGNALS: void accountAdded(const Tp::AccountPtr &account); void accountRemoved(const Tp::AccountPtr &account); + void requestedPresenceChanged(const Tp::Presence &requestedPresence); + void currentPresenceChanged(const Tp::Presence ¤tPresence); + void automaticPresenceChanged(const Tp::Presence &automaticPresence); + void connectionStatusChanged(Tp::ConnectionStatus connectionStatus); + void isChangingPresence(bool changingPresence); + void onlinenessChanged(bool online); private Q_SLOTS: TP_QT_NO_EXPORT void onNewAccount(const Tp::AccountPtr &account); TP_QT_NO_EXPORT void onAccountRemoved(const Tp::AccountPtr &account); TP_QT_NO_EXPORT void onAccountChanged(const Tp::AccountPtr &account); + TP_QT_NO_EXPORT void onAccountPropertyChanged(const Tp::AccountPtr &account, const QString &propertyName); private: struct Private; -- 2.13.6