[Telepathy-commits] [telepathy-qt4/master] Expose handle owners

Olli Salli olli.salli at collabora.co.uk
Mon Oct 20 09:13:37 PDT 2008


---
 TelepathyQt4/cli-channel.cpp |   40 ++++++++++++++++++++++++++++++---
 TelepathyQt4/cli-channel.h   |   50 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 4 deletions(-)

diff --git a/TelepathyQt4/cli-channel.cpp b/TelepathyQt4/cli-channel.cpp
index 40cdf7a..47c9d56 100644
--- a/TelepathyQt4/cli-channel.cpp
+++ b/TelepathyQt4/cli-channel.cpp
@@ -377,6 +377,16 @@ QSet<uint> Channel::groupRemotePending() const
     return mPriv->groupRemotePending;
 }
 
+bool Channel::groupAreHandleOwnersAvailable() const
+{
+    return mPriv->groupAreHandleOwnersAvailable;
+}
+
+HandleOwnerMap Channel::groupHandleOwners() const
+{
+    return mPriv->groupHandleOwners;
+}
+
 void Channel::gotMainProperties(QDBusPendingCallWatcher* watcher)
 {
     QDBusPendingReply<QVariantMap> reply = *watcher;
@@ -719,13 +729,35 @@ void Channel::onHandleOwnersChanged(const Telepathy::HandleOwnerMap& added, cons
         return;
     }
 
+    UIntList emitAdded;
+    UIntList emitRemoved;
+
     for (HandleOwnerMap::const_iterator i = added.begin();
                                         i != added.end();
-                                        ++i)
-        mPriv->groupHandleOwners[i.key()] = i.value();
+                                        ++i) {
+        uint handle = i.key();
+        uint global = i.value();
+
+        if (!mPriv->groupHandleOwners.contains(handle)
+                || mPriv->groupHandleOwners[handle]) {
+            debug() << " +++/changed" << handle << "->" << global;
+            mPriv->groupHandleOwners[global] = global;
+            emitAdded.append(handle);
+        }
+    }
 
-    foreach (uint handle, removed)
-        mPriv->groupHandleOwners.remove(handle);
+    foreach (uint handle, removed) {
+        if (mPriv->groupHandleOwners.contains(handle)) {
+            debug() << " ---" << handle;
+            mPriv->groupHandleOwners.remove(handle);
+            emitRemoved.append(handle);
+        }
+    }
+
+    if (emitAdded.size() || emitRemoved.size()) {
+        debug() << "Emitting groupHandleOwnersChanged with" << emitAdded.size() << "added" << emitRemoved.size() << "removed";
+        emit groupHandleOwnersChanged(mPriv->groupHandleOwners, emitAdded, emitRemoved);
+    }
 }
 
 void Channel::onSelfHandleChanged(uint newSelfHandle)
diff --git a/TelepathyQt4/cli-channel.h b/TelepathyQt4/cli-channel.h
index b0a152a..cad6333 100644
--- a/TelepathyQt4/cli-channel.h
+++ b/TelepathyQt4/cli-channel.h
@@ -327,6 +327,45 @@ public:
      */
     QSet<uint> groupRemotePending() const;
 
+    /**
+     * Returns whether globally valid handles can be looked up using the
+     * channel-specific handle on this channel using this object.
+     *
+     * Handle owner lookup is only available if:
+     * <ul>
+     *  <li>The object has readiness #ReadinessFull
+     *  <li>The list returned by interfaces() contains
+     *        #TELEPATHY_INTERFACE_CHANNEL_INTERFACE_GROUP</li>
+     *  <li>The set of flags returned by groupFlags() contains
+     *        GroupFlagProperties and GroupFlagChannelSpecificHandles</li>
+     * </ul>
+     *
+     * If this function returns <code>false</code>, the return value of
+     * groupHandleOwners() is undefined and groupHandleOwnersChanged() will
+     * never be emitted.
+     *
+     * The value returned by this function will stay fixed for the entire time
+     * the object spends having readiness #ReadinessFull, so no change
+     * notification is provided.
+     *
+     * \return If handle owner lookup functionality is available.
+     */
+    bool groupAreHandleOwnersAvailable() const;
+
+    /**
+     * Returns a mapping of handles specific to this channel to globally valid
+     * handles.
+     *
+     * The mapping includes at least all of the channel-specific handles in this
+     * channel's members, local-pending and remote-pending sets as keys. Any
+     * handle not in the keys of this mapping is not channel-specific in this
+     * channel. Handles which are channel-specific, but for which the owner is
+     * unknown, appear in this mapping with 0 as owner.
+     *
+     * \return A mapping from group-specific handles to globally valid handles.
+     */
+    HandleOwnerMap groupHandleOwners() const;
+
 Q_SIGNALS:
 
     /**
@@ -389,6 +428,17 @@ Q_SIGNALS:
     void groupRemotePendingChanged(const QSet<uint>& remotePending, const Telepathy::UIntList& added, const Telepathy::UIntList& removed, uint actor, uint reason, const QString& message);
 
     /**
+     * Emitted when the value returned by groupHandleOwners() changes.
+     *
+     * \param owners The value which would now be returned by
+     *               groupHandleOwners().
+     * \param added Handles which have been added to the mapping as keys, or
+     *              existing handle keys for which the value has changed.
+     * \param removed Handles which have been removed from the mapping.
+     */
+    void groupHandleOwnersChanged(const HandleOwnerMap& owners, const Telepathy::UIntList& added, const Telepathy::UIntList& removed);
+
+    /**
      * \name Optional interface proxy factory
      *
      * Factory functions fabricating proxies for optional %Channel interfaces and
-- 
1.5.6.5




More information about the Telepathy-commits mailing list