Merge lp:~phablet-team/messaging-framework/destroyable_channels into lp:messaging-framework

Proposed by Gustavo Pichorim Boiko
Status: Merged
Approved by: Roberto Mier Escandon
Approved revision: 29
Merged at revision: 26
Proposed branch: lp:~phablet-team/messaging-framework/destroyable_channels
Merge into: lp:messaging-framework
Diff against target: 379 lines (+271/-1)
8 files modified
TODO (+7/-0)
include/messaging/qt/tp/interfaces/base_channel_destroyable.h (+73/-0)
include/messaging/qt/tp/interfaces/base_channel_destroyable_internal.h (+53/-0)
include/messaging/qt/tp/text_channel.h (+5/-0)
src/CMakeLists.txt (+6/-1)
src/messaging/qt/tp/interfaces/base_channel_destroyable.cpp (+107/-0)
src/messaging/qt/tp/text_channel.cpp (+19/-0)
tests/unit/messaging/qt_telepathy_adapter_test.cpp (+1/-0)
To merge this branch: bzr merge lp:~phablet-team/messaging-framework/destroyable_channels
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Roberto Mier Escandon (community) Approve
Review via email: mp+296745@code.launchpad.net

Commit message

Add support for the Channel.Interface.Destroyable interface in chat rooms.

Description of the change

Add support for the Channel.Interface.Destroyable interface in chat rooms.

To post a comment you must log in.
Revision history for this message
Roberto Mier Escandon (rmescandon) wrote :

Nice! I thought this kind of Telepathy implementations would only be included in TelepathyQt project, but looks nice this way. I'm thinking about a bunch of other implementations that we would need in future.
Just a comment below, and a question here:
Shouldn't this interface belong to a namespace, let's say, "messaging::tp::qt" or directly "Tp"?

Maybe in future we can shorten them by removing obvious ones

review: Needs Information
Revision history for this message
Roberto Mier Escandon (rmescandon) :
27. By Gustavo Pichorim Boiko

Move all headers to include/ and make the classes local (not exported)

28. By Gustavo Pichorim Boiko

Move the classes to their own namespace.

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

> Nice! I thought this kind of Telepathy implementations would only be included
> in TelepathyQt project, but looks nice this way. I'm thinking about a bunch of
> other implementations that we would need in future.

Yes, at some point we should propose them for upstream, but to make things quicker we can keep them here for now.

> Just a comment below, and a question here:
> Shouldn't this interface belong to a namespace, let's say, "messaging::tp::qt"
> or directly "Tp"?

Good point. Moved them to messaging::qt::tp::interfaces.

>
> Maybe in future we can shorten them by removing obvious ones

Yep.

29. By Gustavo Pichorim Boiko

Update TODO

Revision history for this message
Roberto Mier Escandon (rmescandon) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'TODO'
2--- TODO 1970-01-01 00:00:00 +0000
3+++ TODO 2016-06-08 16:25:42 +0000
4@@ -0,0 +1,7 @@
5+General items
6+-------------
7+- Move telepathy interfaces to telepathy-qt
8+
9+Tests needed
10+------------
11+- test that calling Destroy() on DBus actually calls group_manager::dissolve_group()
12
13=== added directory 'include/messaging/qt/tp/interfaces'
14=== added file 'include/messaging/qt/tp/interfaces/base_channel_destroyable.h'
15--- include/messaging/qt/tp/interfaces/base_channel_destroyable.h 1970-01-01 00:00:00 +0000
16+++ include/messaging/qt/tp/interfaces/base_channel_destroyable.h 2016-06-08 16:25:42 +0000
17@@ -0,0 +1,73 @@
18+/*
19+ * Copyright © 2016 Canonical Ltd.
20+ *
21+ * This program is free software: you can redistribute it and/or modify it
22+ * under the terms of the GNU Lesser General Public License version 3,
23+ * as published by the Free Software Foundation.
24+ *
25+ * This program is distributed in the hope that it will be useful,
26+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+ * GNU Lesser General Public License for more details.
29+ *
30+ * You should have received a copy of the GNU Lesser General Public License
31+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
32+ */
33+
34+#ifndef MESSAGING_QT_TP_INTERFACES_BASE_CHANNEL_DESTROYABLE_H_
35+#define MESSAGING_QT_TP_INTERFACES_BASE_CHANNEL_DESTROYABLE_H_
36+
37+#include <TelepathyQt/BaseChannel>
38+#include <messaging/visibility.h>
39+
40+namespace messaging
41+{
42+namespace qt
43+{
44+namespace tp
45+{
46+namespace interfaces
47+{
48+
49+class BaseChannelDestroyableInterface;
50+typedef Tp::SharedPtr<BaseChannelDestroyableInterface> BaseChannelDestroyableInterfacePtr;
51+
52+class MESSAGING_FW_LOCAL BaseChannelDestroyableInterface : public Tp::AbstractChannelInterface
53+{
54+ Q_OBJECT
55+ Q_DISABLE_COPY(BaseChannelDestroyableInterface)
56+
57+public:
58+ static BaseChannelDestroyableInterfacePtr create() {
59+ return BaseChannelDestroyableInterfacePtr(new BaseChannelDestroyableInterface());
60+ }
61+ template<typename BaseChannelDestroyableInterfaceSubclass>
62+ static Tp::SharedPtr<BaseChannelDestroyableInterfaceSubclass> create() {
63+ return Tp::SharedPtr<BaseChannelDestroyableInterfaceSubclass>(
64+ new BaseChannelDestroyableInterfaceSubclass());
65+ }
66+ virtual ~BaseChannelDestroyableInterface();
67+
68+ QVariantMap immutableProperties() const;
69+
70+ void destroy();
71+
72+ typedef Tp::Callback1<void, Tp::DBusError*> DestroyCallback;
73+ void setDestroyCallback(const DestroyCallback &cb);
74+private:
75+ BaseChannelDestroyableInterface();
76+ void createAdaptor();
77+
78+ class Adaptee;
79+ friend class Adaptee;
80+ struct Private;
81+ friend struct Private;
82+ Private *mPriv;
83+};
84+
85+}
86+}
87+}
88+}
89+
90+#endif // MESSAGING_QT_TP_INTERFACES_BASE_CHANNEL_DESTROYABLE_H_
91
92=== added file 'include/messaging/qt/tp/interfaces/base_channel_destroyable_internal.h'
93--- include/messaging/qt/tp/interfaces/base_channel_destroyable_internal.h 1970-01-01 00:00:00 +0000
94+++ include/messaging/qt/tp/interfaces/base_channel_destroyable_internal.h 2016-06-08 16:25:42 +0000
95@@ -0,0 +1,53 @@
96+/*
97+ * Copyright © 2016 Canonical Ltd.
98+ *
99+ * This program is free software: you can redistribute it and/or modify it
100+ * under the terms of the GNU Lesser General Public License version 3,
101+ * as published by the Free Software Foundation.
102+ *
103+ * This program is distributed in the hope that it will be useful,
104+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
105+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
106+ * GNU Lesser General Public License for more details.
107+ *
108+ * You should have received a copy of the GNU Lesser General Public License
109+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
110+ */
111+
112+#ifndef MESSAGING_QT_TP_INTERFACES_BASE_CHANNEL_DESTROYABLE_INTERNAL_H_
113+#define MESSAGING_QT_TP_INTERFACES_BASE_CHANNEL_DESTROYABLE_INTERNAL_H_
114+
115+#include <TelepathyQt/_gen/svc-channel.h>
116+#include <messaging/qt/tp/interfaces/base_channel_destroyable.h>
117+#include <messaging/visibility.h>
118+
119+namespace messaging
120+{
121+namespace qt
122+{
123+namespace tp
124+{
125+namespace interfaces
126+{
127+
128+class MESSAGING_FW_LOCAL BaseChannelDestroyableInterface::Adaptee : public QObject
129+{
130+ Q_OBJECT
131+public:
132+ Adaptee(BaseChannelDestroyableInterface *interface);
133+ ~Adaptee();
134+
135+public Q_SLOTS:
136+ void destroy(const Tp::Service::ChannelInterfaceDestroyableAdaptor::DestroyContextPtr &context);
137+
138+public:
139+ BaseChannelDestroyableInterface *mInterface;
140+};
141+
142+}
143+}
144+}
145+}
146+
147+#endif // MESSAGING_QT_TP_INTERFACES_BASE_CHANNEL_DESTROYABLE_INTERNAL_H_
148+
149
150=== modified file 'include/messaging/qt/tp/text_channel.h'
151--- include/messaging/qt/tp/text_channel.h 2016-05-18 21:37:35 +0000
152+++ include/messaging/qt/tp/text_channel.h 2016-06-08 16:25:42 +0000
153@@ -20,6 +20,7 @@
154 #include <messaging/chat.h>
155 #include <messaging/messenger.h>
156 #include <messaging/qt/runtime.h>
157+#include <messaging/qt/tp/interfaces/base_channel_destroyable.h>
158
159 #include <TelepathyQt/BaseChannel>
160 #include <TelepathyQt/Types>
161@@ -167,6 +168,9 @@
162 // Handler action on remove members request
163 void remove_members(const Tp::UIntList& handles, const QString& message, Tp::DBusError* error);
164
165+ // channel destruction request. only supported in group chats
166+ void destroy(Tp::DBusError* error);
167+
168 // Helper functions encapsulating setup tasks.
169 void register_callbacks_once();
170 void plug_interfaces_once();
171@@ -177,6 +181,7 @@
172 Tp::BaseChannelRoomInterfacePtr bcri;
173 Tp::BaseChannelRoomConfigInterfacePtr bcrci;
174 Tp::BaseChannelGroupInterfacePtr bcgi;
175+ interfaces::BaseChannelDestroyableInterfacePtr bcdi;
176
177 // NOTE(rmescandon): this is a temporal member in the class not needed from Telepathy Qt >= 0.9.7.0 which
178 // includes Tp::BaseChannel::connection() method to obtain it whenever is needed.
179
180=== modified file 'src/CMakeLists.txt'
181--- src/CMakeLists.txt 2016-05-30 16:43:03 +0000
182+++ src/CMakeLists.txt 2016-06-08 16:25:42 +0000
183@@ -1,7 +1,10 @@
184 # Expose internal headers under sensible paths to the impl.
185 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/messaging ${PROCESS_CPP_INCLUDE_DIRS} ${LibPhoneNumber_INCLUDE_DIRS})
186
187-qt5_wrap_cpp(MESSAGING_FW_MOCS ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/protocol.h ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/connection.h)
188+qt5_wrap_cpp(MESSAGING_FW_MOCS ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/protocol.h
189+ ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/connection.h
190+ ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/interfaces/base_channel_destroyable.h
191+ ${CMAKE_SOURCE_DIR}/include/messaging/qt/tp/interfaces/base_channel_destroyable_internal.h)
192
193 # The general messaging-fw shared library.
194 add_library(
195@@ -40,6 +43,8 @@
196 messaging/qt/tp/protocol.cpp
197 messaging/qt/tp/text_channel.cpp
198
199+ messaging/qt/tp/interfaces/base_channel_destroyable.cpp
200+
201 messaging/runner.cpp)
202
203 target_link_libraries(
204
205=== added directory 'src/messaging/qt/tp/interfaces'
206=== added file 'src/messaging/qt/tp/interfaces/base_channel_destroyable.cpp'
207--- src/messaging/qt/tp/interfaces/base_channel_destroyable.cpp 1970-01-01 00:00:00 +0000
208+++ src/messaging/qt/tp/interfaces/base_channel_destroyable.cpp 2016-06-08 16:25:42 +0000
209@@ -0,0 +1,107 @@
210+/*
211+ * Copyright © 2016 Canonical Ltd.
212+ *
213+ * This program is free software: you can redistribute it and/or modify it
214+ * under the terms of the GNU Lesser General Public License version 3,
215+ * as published by the Free Software Foundation.
216+ *
217+ * This program is distributed in the hope that it will be useful,
218+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
219+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
220+ * GNU Lesser General Public License for more details.
221+ *
222+ * You should have received a copy of the GNU Lesser General Public License
223+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
224+ */
225+
226+#include <TelepathyQt/DBusObject>
227+#include <messaging/qt/tp/interfaces/base_channel_destroyable.h>
228+#include <messaging/qt/tp/interfaces/base_channel_destroyable_internal.h>
229+
230+namespace mqt = messaging::qt;
231+
232+// Chan.I.Destroyable
233+mqt::tp::interfaces::BaseChannelDestroyableInterface::Adaptee::Adaptee(BaseChannelDestroyableInterface *interface)
234+ : QObject(interface),
235+ mInterface(interface)
236+{
237+}
238+
239+mqt::tp::interfaces::BaseChannelDestroyableInterface::Adaptee::~Adaptee()
240+{
241+}
242+
243+struct TP_QT_NO_EXPORT mqt::tp::interfaces::BaseChannelDestroyableInterface::Private {
244+ Private(BaseChannelDestroyableInterface *parent)
245+ :adaptee(new BaseChannelDestroyableInterface::Adaptee(parent)) {
246+ }
247+
248+ DestroyCallback destroyCB;
249+ BaseChannelDestroyableInterface::Adaptee *adaptee;
250+};
251+
252+void mqt::tp::interfaces::BaseChannelDestroyableInterface::Adaptee::destroy(const Tp::Service::ChannelInterfaceDestroyableAdaptor::DestroyContextPtr &context)
253+{
254+ if (!mInterface->mPriv->destroyCB.isValid()) {
255+ context->setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented"));
256+ return;
257+ }
258+
259+ Tp::DBusError error;
260+ mInterface->mPriv->destroyCB(&error);
261+ if (error.isValid()) {
262+ context->setFinishedWithError(error.name(), error.message());
263+ return;
264+ }
265+ context->setFinished();
266+}
267+
268+/**
269+ * \class BaseChannelDestroyableInterface
270+ *
271+ * \brief Base class for implementations of Channel.Interface.Destroyable
272+ *
273+ */
274+
275+/**
276+ * Class constructor.
277+ */
278+mqt::tp::interfaces::BaseChannelDestroyableInterface::BaseChannelDestroyableInterface()
279+ : Tp::AbstractChannelInterface(TP_QT_IFACE_CHANNEL_INTERFACE_DESTROYABLE),
280+ mPriv(new Private(this))
281+{
282+}
283+
284+void mqt::tp::interfaces::BaseChannelDestroyableInterface::setDestroyCallback(const DestroyCallback &cb)
285+{
286+ mPriv->destroyCB = cb;
287+}
288+
289+/**
290+ * Class destructor.
291+ */
292+mqt::tp::interfaces::BaseChannelDestroyableInterface::~BaseChannelDestroyableInterface()
293+{
294+ delete mPriv;
295+}
296+
297+/**
298+ * Return the immutable properties of this interface.
299+ *
300+ * Immutable properties cannot change after the interface has been registered
301+ * on a service on the bus with registerInterface().
302+ *
303+ * \return The immutable properties of this interface.
304+ */
305+QVariantMap mqt::tp::interfaces::BaseChannelDestroyableInterface::immutableProperties() const
306+{
307+ QVariantMap map;
308+ return map;
309+}
310+
311+void mqt::tp::interfaces::BaseChannelDestroyableInterface::createAdaptor()
312+{
313+ (void) new Tp::Service::ChannelInterfaceDestroyableAdaptor(dbusObject()->dbusConnection(),
314+ mPriv->adaptee, dbusObject());
315+}
316+
317
318=== modified file 'src/messaging/qt/tp/text_channel.cpp'
319--- src/messaging/qt/tp/text_channel.cpp 2016-06-06 18:42:21 +0000
320+++ src/messaging/qt/tp/text_channel.cpp 2016-06-08 16:25:42 +0000
321@@ -281,6 +281,8 @@
322 Tp::ChannelGroupFlags groupFlags = Tp::ChannelGroupFlagCanAdd|Tp::ChannelGroupFlagCanRemove;
323 bcgi = Tp::BaseChannelGroupInterface::create(groupFlags, tp_connection->selfHandle());
324
325+ bcdi = mqt::tp::interfaces::BaseChannelDestroyableInterface::create();
326+
327 // we need to set the initial group members
328 on_members_updated(group->initial_invitees());
329 }
330@@ -599,6 +601,16 @@
331 group_manager->remove_members(users);
332 }
333
334+void mqt::tp::TextChannel::destroy(Tp::DBusError* error)
335+{
336+ std::shared_ptr<messaging::GroupManager> group_manager = chat->interface<GroupManager>();
337+ if (!group_manager) {
338+ error->set(TP_QT_ERROR_NOT_AVAILABLE, "Text channel is not a room");
339+ return;
340+ }
341+ group_manager->dissolve_group();
342+}
343+
344 void mqt::tp::TextChannel::register_callbacks_once()
345 {
346 bcmi->setSendMessageCallback(Tp::memFun(this, &TextChannel::send_message));
347@@ -608,6 +620,12 @@
348 bcgi->setAddMembersCallback(Tp::memFun(this, &TextChannel::add_members));
349 bcgi->setRemoveMembersCallback(Tp::memFun(this, &TextChannel::remove_members));
350 }
351+
352+ // if the room interface is available, we can plug the destroyable one too
353+ if (!bcri.isNull())
354+ {
355+ bcdi->setDestroyCallback(Tp::memFun(this, &TextChannel::destroy));
356+ }
357 }
358
359 void mqt::tp::TextChannel::plug_interfaces_once()
360@@ -617,6 +635,7 @@
361 plug_interface_if_available(bcri);
362 plug_interface_if_available(bcrci);
363 plug_interface_if_available(bcgi);
364+ plug_interface_if_available(bcdi);
365 }
366
367 void mqt::tp::TextChannel::plug_interface_if_available(const Tp::AbstractChannelInterfacePtr &interface)
368
369=== modified file 'tests/unit/messaging/qt_telepathy_adapter_test.cpp'
370--- tests/unit/messaging/qt_telepathy_adapter_test.cpp 2016-05-04 20:03:23 +0000
371+++ tests/unit/messaging/qt_telepathy_adapter_test.cpp 2016-06-08 16:25:42 +0000
372@@ -714,6 +714,7 @@
373 ASSERT_TRUE(channel->hasInterface(TP_QT_IFACE_CHANNEL_INTERFACE_ROOM));
374 ASSERT_TRUE(channel->hasInterface(TP_QT_IFACE_CHANNEL_INTERFACE_ROOM_CONFIG));
375 ASSERT_TRUE(channel->hasInterface(TP_QT_IFACE_CHANNEL_INTERFACE_GROUP));
376+ ASSERT_TRUE(channel->hasInterface(TP_QT_IFACE_CHANNEL_INTERFACE_DESTROYABLE));
377
378 // check that the group has the invitee contact
379 ASSERT_EQ(channel->groupContacts(false).count(), 1);

Subscribers

People subscribed via source and target branches

to all changes: