[Telepathy-commits] [telepathy-qt4/master] Expose group members, local pending and remote pending
Olli Salli
olli.salli at collabora.co.uk
Mon Oct 20 09:13:36 PDT 2008
---
TelepathyQt4/cli-channel.cpp | 75 ++++++++++++++++++++++----
TelepathyQt4/cli-channel.h | 124 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 182 insertions(+), 17 deletions(-)
diff --git a/TelepathyQt4/cli-channel.cpp b/TelepathyQt4/cli-channel.cpp
index 571386a..40cdf7a 100644
--- a/TelepathyQt4/cli-channel.cpp
+++ b/TelepathyQt4/cli-channel.cpp
@@ -63,7 +63,7 @@ struct Channel::Private
// Group members
bool groupHaveMembers;
QSet<uint> groupMembers;
- QMap<uint, GroupLocalPendingInfo> groupLocalPending;
+ GroupLocalPendingInfoMap groupLocalPending;
QSet<uint> groupRemotePending;
// Group handle owners
@@ -362,6 +362,21 @@ uint Channel::groupFlags() const
return mPriv->groupFlags;
}
+QSet<uint> Channel::groupMembers() const
+{
+ return mPriv->groupMembers;
+}
+
+Channel::GroupLocalPendingInfoMap Channel::groupLocalPending() const
+{
+ return mPriv->groupLocalPending;
+}
+
+QSet<uint> Channel::groupRemotePending() const
+{
+ return mPriv->groupRemotePending;
+}
+
void Channel::gotMainProperties(QDBusPendingCallWatcher* watcher)
{
QDBusPendingReply<QVariantMap> reply = *watcher;
@@ -609,14 +624,22 @@ void Channel::onMembersChanged(const QString& message, const Telepathy::UIntList
return;
}
+ UIntList currentAdded;
+ UIntList currentRemoved;
+ UIntList localAdded;
+ UIntList localRemoved;
+ UIntList remoteAdded;
+ UIntList remoteRemoved;
+
foreach (uint handle, added) {
- debug() << " +++" << handle;
- mPriv->groupMembers.insert(handle);
+ if (!mPriv->groupMembers.contains(handle)) {
+ debug() << " +++" << handle;
+ mPriv->groupMembers.insert(handle);
+ currentAdded.append(handle);
+ }
}
foreach (uint handle, localPending) {
- debug() << " LP" << handle;
-
GroupLocalPendingInfo info(actor, reason, message);
// Special-case renaming a local-pending contact, if the signal is
@@ -631,21 +654,35 @@ void Channel::onMembersChanged(const QString& message, const Telepathy::UIntList
info = mPriv->groupLocalPending[removed[0]];
}
- mPriv->groupLocalPending[handle] = info;
+ if (!mPriv->groupLocalPending.contains(handle)) {
+ debug() << " LP" << handle;
+ mPriv->groupLocalPending[handle] = info;
+ localAdded.append(handle);
+ }
}
foreach (uint handle, remotePending) {
- debug() << " RP" << handle;
- mPriv->groupRemotePending.insert(handle);
+ if (!mPriv->groupRemotePending.contains(handle)) {
+ debug() << " RP" << handle;
+ mPriv->groupRemotePending.insert(handle);
+ remoteAdded.append(handle);
+ }
}
foreach (uint handle, removed) {
debug() << " ---" << handle;
- mPriv->groupMembers.remove(handle);
- mPriv->groupLocalPending.remove(handle);
- mPriv->groupRemotePending.remove(handle);
+ if (mPriv->groupMembers.remove(handle))
+ currentRemoved.append(handle);
+ if (mPriv->groupLocalPending.remove(handle))
+ localRemoved.append(handle);
+
+ if (mPriv->groupRemotePending.remove(handle))
+ remoteRemoved.append(handle);
+
+#if 0
+ // TODO self rename before enabling again!
if (handle == mPriv->groupSelfHandle) {
debug() << " Self handle removed, saving info...";
@@ -654,6 +691,22 @@ void Channel::onMembersChanged(const QString& message, const Telepathy::UIntList
mPriv->groupRemoveReason = reason;
mPriv->groupRemoveMessage = message;
}
+#endif
+ }
+
+ if (currentAdded.size() || currentRemoved.size()) {
+ debug() << " Emitting groupMembersChanged with" << currentAdded.size() << "contacts added and" << currentRemoved.size() << "contacts removed";
+ emit groupMembersChanged(mPriv->groupMembers, currentAdded, currentRemoved, actor, reason, message);
+ }
+
+ if (localAdded.size() || localRemoved.size()) {
+ debug() << " Emitting groupLocalPendingChanged with" << localAdded.size() << "contacts added and" << localRemoved.size() << "contacts removed";
+ emit groupLocalPendingChanged(mPriv->groupLocalPending, localAdded, localRemoved, actor, reason, message);
+ }
+
+ if (remoteAdded.size() || remoteRemoved.size()) {
+ debug() << " Emitting groupRemotePendingChanged with" << remoteAdded.size() << "contacts added and" << remoteRemoved.size() << "contacts removed";
+ emit groupMembersChanged(mPriv->groupRemotePending, remoteAdded, remoteRemoved, actor, reason, message);
}
}
diff --git a/TelepathyQt4/cli-channel.h b/TelepathyQt4/cli-channel.h
index a9c8509..b0a152a 100644
--- a/TelepathyQt4/cli-channel.h
+++ b/TelepathyQt4/cli-channel.h
@@ -236,6 +236,20 @@ public:
*/
uint groupFlags() const;
+ /**
+ * Returns the current members of the group.
+ *
+ * \return Set of handles representing the members.
+ */
+ QSet<uint> groupMembers() const;
+
+ /**
+ * Class opaquely storing information on a contact whose attempt to join the
+ * group is to be confirmed by the local user using AddMembers().
+ *
+ * Extended information is not always available; this will be reflected by
+ * the return value of isValid().
+ */
class GroupLocalPendingInfo
{
public:
@@ -246,10 +260,38 @@ public:
GroupLocalPendingInfo(uint actor, uint reason, const QString& message)
: mActor(actor), mReason(reason), mMessage(message), mIsValid(true) {}
+ /**
+ * Returns whether or not this object actually contains valid
+ * information received from the service. For some, particularly older
+ * services, extended information will not always be available. If the
+ * returned value is false, the values returned by the other methods for
+ * this object are undefined.
+ *
+ * \return Whether the information stored in this object is valid.
+ */
bool isValid() const { return mIsValid; }
+ /**
+ * Returns the contact requesting or causing the change.
+ *
+ * \return The handle of the contact.
+ */
uint actor() const { return mActor; }
+
+ /**
+ * Returns the reason for the change.
+ *
+ * \return The reason, as specified in #ChannelGroupChangeReason.
+ */
uint reason() const { return mReason; }
+
+ /**
+ * Returns a human-readable message from the contact represented by
+ * actor() pertaining to the change, or an empty string if there is no
+ * message.
+ *
+ * \return The message as a string.
+ */
const QString& message() const { return mMessage; }
private:
@@ -259,25 +301,92 @@ public:
bool mIsValid;
};
-Q_SIGNALS:
+ /**
+ * Mapping from contact handles to local pending contact information.
+ */
+ typedef QMap<uint, GroupLocalPendingInfo> GroupLocalPendingInfoMap;
/**
- * Emitted when the value returned by groupFlags() changes.
+ * Returns the members currently waiting for local approval to join the
+ * group.
+ *
+ * The returned value is a mapping from contact handles to
+ * GroupLocalPendingInfo objects. See the documentation for that class for
+ * more information.
*
- * \param flags The new set of flags.
+ * \returns A mapping from handles to info for the members waiting for local
+ * approval.
*/
- void groupFlagsHasNewValue(uint flags);
+ GroupLocalPendingInfoMap groupLocalPending() const;
+
+ /**
+ * Returns the contacts currently waiting for remote approval to join the
+ * group.
+ *
+ * \returns Set of handles representing the contacts.
+ */
+ QSet<uint> groupRemotePending() const;
+
+Q_SIGNALS:
/**
* Emitted when the value returned by groupFlags() changes.
*
- * \param flags New value of the set of flags.
+ * \param flags The value which would now be returned by groupFlags().
* \param added Flags added compared to the previous value.
* \param removed Flags removed compared to the previous value.
*/
void groupFlagsChanged(uint flags, uint added, uint removed);
- //@}
+ /**
+ * Emitted when the value returned by groupMembers() changes.
+ *
+ * \param members The value which would now be returned by groupMembers().
+ * \param added Handles of the contacts which were added to the value.
+ * \param remove Handles of the contacts which were removed from the value.
+ * \param actor Handle of the contact requesting or causing the change.
+ * \param reason Reason of the change, as specified in
+ * #ChannelGroupChangeReason.
+ * \param message Message specified by the actor related to the change, such
+ * as the part message in IRC.
+ */
+ void groupMembersChanged(const QSet<uint>& members, const Telepathy::UIntList& added, const Telepathy::UIntList& removed, uint actor, uint reason, const QString& message);
+
+ /**
+ * Emitted when the value returned by groupLocalPending() changes.
+ *
+ * The added and remove lists only specify the handles of the contacts added
+ * to or removed from the mapping, not the extended information pertaining
+ * to them. Local pending info never changes for a particular contact after
+ * the contact first appears in the mapping, so no change notification is
+ * necessary for the extended information itself.
+ *
+ * \param localPending The value which would now be returned by
+ * groupLocalPending().
+ * \param added Handles of the contacts which were added to the value.
+ * \param remove Handles of the contacts which were removed from the value.
+ * \param actor Handle of the contact requesting or causing the change.
+ * \param reason Reason of the change, as specified in
+ * #ChannelGroupChangeReason.
+ * \param message Message specified by the actor related to the change, such
+ * as the part message in IRC.
+ */
+ void groupLocalPendingChanged(const GroupLocalPendingInfoMap& localPending, const Telepathy::UIntList& added, const Telepathy::UIntList& removed, uint actor, uint reason, const QString& message);
+
+ /**
+ * Emitted when the value returned by groupRemotePending() changes.
+ *
+ * \param members The value which would now be returned by
+ * groupRemotePending().
+ * \param added Handles of the contacts which were added to the value.
+ * \param remove Handles of the contacts which were removed from the value.
+ * \param actor Handle of the contact requesting or causing the change.
+ * \param reason Reason of the change, as specified in
+ * #ChannelGroupChangeReason.
+ * \param message Message specified by the actor related to the change, such
+ * as the part message in IRC.
+ */
+ void groupRemotePendingChanged(const QSet<uint>& remotePending, const Telepathy::UIntList& added, const Telepathy::UIntList& removed, uint actor, uint reason, const QString& message);
/**
* \name Optional interface proxy factory
@@ -552,4 +661,7 @@ private:
}
}
+Q_DECLARE_METATYPE(Telepathy::Client::Channel::GroupLocalPendingInfo);
+Q_DECLARE_METATYPE(Telepathy::Client::Channel::GroupLocalPendingInfoMap);
+
#endif
--
1.5.6.5
More information about the Telepathy-commits
mailing list