[Telepathy-commits] [telepathy-qt4/master] Channel: Added groupCanRescind and improved checks on groupAdd/RemoveContacts.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Tue Feb 10 12:36:05 PST 2009
---
TelepathyQt4/Client/channel.cpp | 62 ++++++++++++++++++++++++++++++++++-----
TelepathyQt4/Client/channel.h | 1 +
2 files changed, 55 insertions(+), 8 deletions(-)
diff --git a/TelepathyQt4/Client/channel.cpp b/TelepathyQt4/Client/channel.cpp
index ff6c11a..bc4f336 100644
--- a/TelepathyQt4/Client/channel.cpp
+++ b/TelepathyQt4/Client/channel.cpp
@@ -1162,16 +1162,27 @@ PendingOperation *Channel::groupAddContacts(const QList<QSharedPointer<Contact>
warning() << "Channel::groupAddContacts() used but adding contacts is not supported";
return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
"Channel does not support adding contacts");
- } else if (!mPriv->interfaces.contains(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_GROUP)) {
- warning() << "Channel::groupAddContacts() used with no group interface";
- return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
- "Channel does not support group interface");
} else if (contacts.isEmpty()) {
warning() << "Channel::groupAddContacts() used with empty contacts param";
return new PendingFailure(this, TELEPATHY_ERROR_INVALID_ARGUMENT,
"contacts cannot be an empty list");
}
+ foreach (const QSharedPointer<Contact> &contact, contacts) {
+ if (!contact) {
+ warning() << "Channel::groupAddContacts() used but contacts param contains "
+ "invalid contact";
+ return new PendingFailure(this, TELEPATHY_ERROR_INVALID_ARGUMENT,
+ "Unable to add invalid contacts");
+ }
+ }
+
+ if (!mPriv->interfaces.contains(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_GROUP)) {
+ warning() << "Channel::groupAddContacts() used with no group interface";
+ return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
+ "Channel does not support group interface");
+ }
+
UIntList handles;
foreach (const QSharedPointer<Contact> &contact, contacts) {
handles << contact->handle()[0];
@@ -1181,6 +1192,21 @@ PendingOperation *Channel::groupAddContacts(const QList<QSharedPointer<Contact>
}
/**
+ * Return if contacts on the remote pending list can be removed from this channel.
+ *
+ * \return \c true if contacts can be removed, \c false otherwise.
+ * \sa groupRemoveContacts()
+ */
+bool Channel::groupCanRescindContacts() const
+{
+ if (!isReady()) {
+ warning() << "Channel::groupCanRescindContacts() used channel not ready";
+ }
+
+ return mPriv->groupFlags & Telepathy::ChannelGroupFlagCanRescind;
+}
+
+/**
* Return if contacts can be removed from this channel.
*
* \return \c true if contacts can be removed, \c false otherwise.
@@ -1215,16 +1241,36 @@ PendingOperation *Channel::groupRemoveContacts(const QList<QSharedPointer<Contac
warning() << "Channel::groupRemoveContacts() used but removing contacts is not supported";
return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
"Channel does not support removing contacts");
- } else if (!mPriv->interfaces.contains(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_GROUP)) {
- warning() << "Channel::groupRemoveContacts() used with no group interface";
- return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
- "Channel does not support group interface");
} else if (contacts.isEmpty()) {
warning() << "Channel::groupRemoveContacts() used with empty contacts param";
return new PendingFailure(this, TELEPATHY_ERROR_INVALID_ARGUMENT,
"contacts param cannot be an empty list");
}
+ foreach (const QSharedPointer<Contact> &contact, contacts) {
+ if (!contact) {
+ warning() << "Channel::groupRemoveContacts() used but contacts param contains "
+ "invalid contact:";
+ return new PendingFailure(this, TELEPATHY_ERROR_INVALID_ARGUMENT,
+ "Unable to remove invalid contacts");
+ }
+ }
+
+ if (!groupCanRescindContacts()) {
+ foreach (const QSharedPointer<Contact> &contact, contacts) {
+ if (mPriv->groupRemotePendingContacts.contains(contact->handle()[0])) {
+ warning() << "Channel::groupRemoveContacts() used to rescind a contact "
+ "but contacts can't be rescinded on this channel";
+ return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
+ "Channel does not support rescinding contacts");
+ }
+ }
+ } else if (!mPriv->interfaces.contains(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_GROUP)) {
+ warning() << "Channel::groupRemoveContacts() used with no group interface";
+ return new PendingFailure(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
+ "Channel does not support group interface");
+ }
+
UIntList handles;
foreach (const QSharedPointer<Contact> &contact, contacts) {
handles << contact->handle()[0];
diff --git a/TelepathyQt4/Client/channel.h b/TelepathyQt4/Client/channel.h
index 88567cf..0b94941 100644
--- a/TelepathyQt4/Client/channel.h
+++ b/TelepathyQt4/Client/channel.h
@@ -89,6 +89,7 @@ public:
bool groupCanAddContacts() const;
PendingOperation *groupAddContacts(const QList<QSharedPointer<Contact> > &contacts,
const QString &message);
+ bool groupCanRescindContacts() const;
bool groupCanRemoveContacts() const;
PendingOperation *groupRemoveContacts(const QList<QSharedPointer<Contact> > &contacts,
const QString &message);
--
1.5.6.5
More information about the telepathy-commits
mailing list