From 6d3864d2d555271d98730edc877e6018a1528f54 Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Sat, 4 Mar 2017 13:47:33 -0700 Subject: [PATCH 1/2] Implement presence < and > operators. --- TelepathyQt/presence.cpp | 23 +++++++++++++++++++++++ TelepathyQt/presence.h | 2 ++ 2 files changed, 25 insertions(+) diff --git TelepathyQt/presence.cpp TelepathyQt/presence.cpp index 823067d..d5a9c6b 100644 --- TelepathyQt/presence.cpp +++ TelepathyQt/presence.cpp @@ -150,6 +150,29 @@ bool Presence::operator!=(const Presence &other) const return mPriv->sp != other.mPriv->sp; } +bool Presence::operator <(const Presence &other) const +{ + if (!isValid() || !other.isValid()) { + if (!isValid() && !other.isValid()) { + return false; + } + return true; + } + + if (type() > other.type()) { + return true; + } else if (type() == other.type()) { + return (statusMessage() < other.statusMessage()); + } else { + return false; + } +} + +bool Presence::operator >(const Presence &other) const +{ + return (other < *this); +} + ConnectionPresenceType Presence::type() const { if (!isValid()) { diff --git TelepathyQt/presence.h TelepathyQt/presence.h index 31fd056..ef4e848 100644 --- TelepathyQt/presence.h +++ TelepathyQt/presence.h @@ -57,6 +57,8 @@ public: Presence &operator=(const Presence &other); bool operator==(const Presence &other) const; bool operator!=(const Presence &other) const; + bool operator <(const Presence &other) const; + bool operator >(const Presence &other) const; ConnectionPresenceType type() const; QString status() const; -- 2.10.2 From b3a2daceb11fcadb0e2d9dc3be2fe5b4b9b23302 Mon Sep 17 00:00:00 2001 From: "James D. Smith" Date: Thu, 23 Mar 2017 14:56:04 -0600 Subject: [PATCH 2/2] AccountSet account connection properties averages and setPresence capability. --- TelepathyQt/account-set-internal.h | 11 +++ TelepathyQt/account-set.cpp | 165 ++++++++++++++++++++++++++++++++++++- TelepathyQt/account-set.h | 20 +++++ 3 files changed, 195 insertions(+), 1 deletion(-) diff --git TelepathyQt/account-set-internal.h TelepathyQt/account-set-internal.h index f7dbf9e..290d093 100644 --- TelepathyQt/account-set-internal.h +++ TelepathyQt/account-set-internal.h @@ -43,6 +43,11 @@ struct TP_QT_NO_EXPORT AccountSet::Private void removeAccount(const AccountPtr &account); void wrapAccount(const AccountPtr &account); void filterAccount(const AccountPtr &account); + void requestedPresenceChanged(); + void currentPresenceChanged(); + void connectionStatusChanged(); + void changingPresence(); + void onlinenessChanged(); bool accountMatchFilter(AccountWrapper *account); AccountSet *parent; @@ -50,6 +55,12 @@ struct TP_QT_NO_EXPORT AccountSet::Private AccountFilterConstPtr filter; QHash wrappers; QHash accounts; + + Tp::Presence requestedPresence; + Tp::Presence currentPresence; + Tp::ConnectionStatus connectionStatus; + bool isChangingPresence; + bool isOnline; bool ready; }; diff --git TelepathyQt/account-set.cpp TelepathyQt/account-set.cpp index fce92a3..67cbdd6 100644 --- TelepathyQt/account-set.cpp +++ TelepathyQt/account-set.cpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace Tp { @@ -66,6 +67,12 @@ AccountSet::Private::Private(AccountSet *parent, void AccountSet::Private::init() { + requestedPresence = Tp::Presence::offline(); + currentPresence = Tp::Presence::offline(); + connectionStatus = Tp::ConnectionStatusDisconnected; + isChangingPresence = false; + isOnline = false; + if (filter->isValid()) { connectSignals(); insertAccounts(); @@ -93,6 +100,12 @@ void AccountSet::Private::insertAccount(const Tp::AccountPtr &account) Q_ASSERT(!wrappers.contains(accountPath)); wrapAccount(account); filterAccount(account); + + requestedPresenceChanged(); + currentPresenceChanged(); + connectionStatusChanged(); + changingPresence(); + onlinenessChanged(); } void AccountSet::Private::removeAccount(const Tp::AccountPtr &account) @@ -106,6 +119,97 @@ void AccountSet::Private::removeAccount(const Tp::AccountPtr &account) wrapper->deleteLater(); emit parent->accountRemoved(account); + + requestedPresenceChanged(); + currentPresenceChanged(); + connectionStatusChanged(); + changingPresence(); + onlinenessChanged(); +} + +void AccountSet::Private::requestedPresenceChanged() +{ + Tp::Presence highestRequestedPresence = Tp::PresenceSpec::unknown().presence(); + + foreach (const Tp::AccountPtr &account, accounts) { + 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::unknown().presence(); + + foreach (const Tp::AccountPtr &account, accounts) { + if (account->currentPresence() > highestCurrentPresence) { + highestCurrentPresence = account->currentPresence(); + } + } + + if (currentPresence != highestCurrentPresence) { + currentPresence = highestCurrentPresence; + emit parent->currentPresenceChanged(currentPresence); + } +} + +void AccountSet::Private::connectionStatusChanged() +{ + Tp::ConnectionStatus status = Tp::ConnectionStatusDisconnected; + QList allConnectionStatuses; + + foreach (const Tp::AccountPtr &account, accounts) { + 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) { + 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) { + 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 +220,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))); @@ -380,6 +484,38 @@ QList AccountSet::accounts() const return mPriv->accounts.values(); } +void AccountSet::setPresence(const Tp::Presence &presence) +{ + foreach (const Tp::AccountPtr &account, mPriv->accounts.values()) { + account->setRequestedPresence(presence); + } +} + +Tp::Presence AccountSet::requestedPresence() const +{ + return mPriv->requestedPresence; +} + +Tp::Presence AccountSet::currentPresence() const +{ + return mPriv->currentPresence; +} + +Tp::ConnectionStatus AccountSet::connectionStatus() const +{ + return mPriv->connectionStatus; +} + +bool AccountSet::changingPresence() const +{ + return mPriv->isChangingPresence; +} + +bool AccountSet::online() const +{ + return mPriv->isOnline; +} + /** * \fn void AccountSet::accountAdded(const Tp::AccountPtr &account) * @@ -415,4 +551,31 @@ 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("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 40dd79a..c0681c3 100644 --- TelepathyQt/account-set.h +++ TelepathyQt/account-set.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,11 @@ 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::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 +65,28 @@ public: QList accounts() const; + void setPresence(const Tp::Presence &presence); + + Tp::Presence requestedPresence() const; + Tp::Presence currentPresence() 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 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.10.2