[telepathy-qt4/master] ContactManager: Proper remove contact list group even if there are contacts in the group.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Thu Jul 23 10:35:24 PDT 2009
---
TelepathyQt4/Makefile.am | 2 +
TelepathyQt4/contact-manager-internal.h | 50 ++++++++++++++++++++++++++++++
TelepathyQt4/contact-manager.cpp | 51 ++++++++++++++++++++++++++++--
3 files changed, 99 insertions(+), 4 deletions(-)
create mode 100644 TelepathyQt4/contact-manager-internal.h
diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index ea385e1..a941076 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -142,6 +142,7 @@ nodist_libtelepathy_qt4_la_SOURCES = \
_gen/connection-manager-internal.moc.hpp \
_gen/contact.moc.hpp \
_gen/contact-manager.moc.hpp \
+ _gen/contact-manager-internal.moc.hpp \
_gen/dbus-proxy.moc.hpp \
_gen/file-transfer.moc.hpp \
_gen/pending-account.moc.hpp \
@@ -274,6 +275,7 @@ tpqt4include_HEADERS = \
constants.h \
contact.h \
contact-manager.h \
+ contact-manager-internal.h \
dbus.h \
dbus-proxy.h \
debug.h \
diff --git a/TelepathyQt4/contact-manager-internal.h b/TelepathyQt4/contact-manager-internal.h
new file mode 100644
index 0000000..c94a043
--- /dev/null
+++ b/TelepathyQt4/contact-manager-internal.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _TelepathyQt4_cli_contact_manager_internal_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_contact_manager_internal_h_HEADER_GUARD_
+
+#include <TelepathyQt4/Types>
+#include <TelepathyQt4/PendingOperation>
+
+namespace Tp
+{
+
+class PendingContactManagerRemoveContactListGroup : public PendingOperation
+{
+ Q_OBJECT
+
+public:
+ PendingContactManagerRemoveContactListGroup(const ChannelPtr &channel,
+ QObject *parent = 0);
+ ~PendingContactManagerRemoveContactListGroup() {};
+
+private Q_SLOTS:
+ void onContactsRemoved(Tp::PendingOperation *);
+ void onChannelClosed(Tp::PendingOperation *);
+
+private:
+ ChannelPtr mChannel;
+};
+
+} // Tp
+
+#endif
diff --git a/TelepathyQt4/contact-manager.cpp b/TelepathyQt4/contact-manager.cpp
index d67aff2..bd6e659 100644
--- a/TelepathyQt4/contact-manager.cpp
+++ b/TelepathyQt4/contact-manager.cpp
@@ -20,7 +20,10 @@
*/
#include <TelepathyQt4/ContactManager>
+#include "TelepathyQt4/contact-manager-internal.h"
+
#include "TelepathyQt4/_gen/contact-manager.moc.hpp"
+#include "TelepathyQt4/_gen/contact-manager-internal.moc.hpp"
#include <QMap>
#include <QString>
@@ -99,6 +102,8 @@ struct ContactManager::Private
return id;
}
+ class PendingContactManagerRemoveContactListGroup;
+
ContactManager *parent;
WeakPtr<Connection> connection;
QMap<uint, QWeakPointer<Contact> > contacts;
@@ -227,9 +232,6 @@ PendingOperation *ContactManager::addGroup(const QString &group)
/**
* Attempt to remove an user-defined contact list group named \a group.
*
- * User-defined contact list groups may only be deleted if the group is
- * already empty.
- *
* This method requires Connection::FeatureRosterGroups to be enabled.
*
* \param group Group name.
@@ -245,7 +247,9 @@ PendingOperation *ContactManager::removeGroup(const QString &group)
}
ChannelPtr channel = mPriv->contactListGroupChannels[group];
- return channel->requestClose();
+ PendingContactManagerRemoveContactListGroup *op =
+ new PendingContactManagerRemoveContactListGroup(channel, this);
+ return op;
}
/**
@@ -1160,4 +1164,43 @@ uint ContactManager::ContactListChannel::typeForIdentifier(const QString &identi
return (uint) -1;
}
+PendingContactManagerRemoveContactListGroup::PendingContactManagerRemoveContactListGroup(
+ const ChannelPtr &channel, QObject *parent)
+ : PendingOperation(parent),
+ mChannel(channel)
+{
+ Contacts contacts = channel->groupContacts();
+ if (!contacts.isEmpty()) {
+ connect(channel->groupRemoveContacts(contacts.toList()),
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onContactsRemoved(Tp::PendingOperation*)));
+ } else {
+ connect(channel->requestClose(),
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onChannelClosed(Tp::PendingOperation*)));
+ }
+}
+
+void PendingContactManagerRemoveContactListGroup::onContactsRemoved(PendingOperation *op)
+{
+ if (op->isError()) {
+ setFinishedWithError(op->errorName(), op->errorMessage());
+ return;
+ }
+
+ // Let's ignore possible errors and try to remove the group
+ connect(mChannel->requestClose(),
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onChannelClosed(Tp::PendingOperation*)));
+}
+
+void PendingContactManagerRemoveContactListGroup::onChannelClosed(PendingOperation *op)
+{
+ if (!op->isError()) {
+ setFinished();
+ } else {
+ setFinishedWithError(op->errorName(), op->errorMessage());
+ }
+}
+
} // Tp
--
1.5.6.5
More information about the telepathy-commits
mailing list