Merge lp:~boiko/telephony-service/rtm-fix_1398427 into lp:telephony-service/rtm-14.09

Proposed by Gustavo Pichorim Boiko on 2015-01-20
Status: Merged
Approved by: Gustavo Pichorim Boiko on 2015-01-23
Approved revision: 926
Merged at revision: 928
Proposed branch: lp:~boiko/telephony-service/rtm-fix_1398427
Merge into: lp:telephony-service/rtm-14.09
Diff against target: 299 lines (+106/-8)
10 files modified
approver/Approver.xml (+7/-0)
approver/approver.cpp (+53/-2)
approver/approver.h (+4/-0)
approver/approverdbus.cpp (+6/-1)
approver/approverdbus.h (+5/-1)
approver/main.cpp (+4/-4)
libtelephonyservice/callmanager.cpp (+11/-0)
libtelephonyservice/callmanager.h (+1/-0)
libtelephonyservice/telepathyhelper.cpp (+13/-0)
libtelephonyservice/telepathyhelper.h (+2/-0)
To merge this branch: bzr merge lp:~boiko/telephony-service/rtm-fix_1398427
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team 2015-01-20 Pending
Review via email: mp+246996@code.launchpad.net

Commit Message

Expose HandleMediaKey(bool doubleClick) to DBus

Description of the Change

Expose HandleMediaKey(bool doubleClick) to DBus

To post a comment you must log in.
926. By Gustavo Pichorim Boiko on 2015-01-22

Merge latest changes from parent branch.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'approver/Approver.xml'
2--- approver/Approver.xml 2014-01-20 12:57:43 +0000
3+++ approver/Approver.xml 2015-01-22 20:45:31 +0000
4@@ -27,5 +27,12 @@
5 this method has no effect.
6 ]]></dox:d>
7 </method>
8+ <method name="HandleMediaKey">
9+ <dox:d><![CDATA[
10+ Handle events generated by media key buttons usually present on headsets.
11+ ]]></dox:d>
12+ <arg name="doubleClick" type="b" direction="in"/>
13+ <arg name="accepted" type="b" direction="out"/>
14+ </method>
15 </interface>
16 </node>
17
18=== modified file 'approver/approver.cpp'
19--- approver/approver.cpp 2015-01-21 12:49:44 +0000
20+++ approver/approver.cpp 2015-01-22 20:45:31 +0000
21@@ -32,6 +32,7 @@
22 #include "callmanager.h"
23 #include "callentry.h"
24 #include "tonegenerator.h"
25+#include "telepathyhelper.h"
26
27 #include <QContactAvatar>
28 #include <QContactDisplayLabel>
29@@ -54,18 +55,20 @@
30
31 Approver::Approver()
32 : Tp::AbstractClientApprover(channelFilters()),
33- mPendingSnapDecision(NULL)
34+ mPendingSnapDecision(NULL),
35+ mSettleTimer(new QTimer(this))
36 {
37 mDefaultTitle = C::gettext("Unknown caller");
38 mDefaultIcon = QUrl(telephonyServiceDir() + "assets/avatar-default@18.png").toEncoded();
39
40- ApproverDBus *dbus = new ApproverDBus();
41+ ApproverDBus *dbus = new ApproverDBus(this);
42 connect(dbus,
43 SIGNAL(acceptCallRequested()),
44 SLOT(onAcceptCallRequested()));
45 connect(dbus,
46 SIGNAL(rejectCallRequested()),
47 SLOT(onRejectCallRequested()));
48+
49 dbus->connectToBus();
50
51 if (GreeterContacts::isGreeterMode()) {
52@@ -86,6 +89,17 @@
53 mRejectActions["rejectMessage1"] = C::gettext("I'm busy at the moment. I'll call later.");
54 mRejectActions["rejectMessage2"] = C::gettext("I'm running late, on my way now.");
55 mRejectActions["rejectMessage3"] = C::gettext("Please call me back later.");
56+
57+ mSettleTimer->setInterval(500);
58+ mSettleTimer->setSingleShot(true);
59+ connect(mSettleTimer, SIGNAL(timeout()), this, SLOT(onSettleTimerTimeout()));
60+ mSettleTimer->start();
61+}
62+
63+void Approver::onSettleTimerTimeout()
64+{
65+ mSettleTimer->deleteLater();
66+ mSettleTimer = NULL;
67 }
68
69 void Approver::onUnityStateChanged(int state, int reason)
70@@ -686,3 +700,40 @@
71 }
72 }
73
74+bool Approver::handleMediaKey(bool doubleClick)
75+{
76+ Q_UNUSED(doubleClick)
77+
78+ // hasCalls gets the value from handler, so even if CallManager isn't ready right now, we know
79+ // if the event will be handled later
80+ bool accepted = mPendingSnapDecision || CallManager::instance()->hasCalls();
81+
82+ // FIXME: Telepathy-qt does not let us know if existing channels are being recovered,
83+ // so if this is the first run, call this method again when mSettleTimer is done
84+ if (mSettleTimer) {
85+ QObject::connect(mSettleTimer, &QTimer::timeout, [=]() {
86+ handleMediaKey(doubleClick);
87+ });
88+ return accepted;
89+ }
90+
91+ // postpone this to avoid blocking dbus method callers
92+ QMetaObject::invokeMethod(this, "processHandleMediaKey", Qt::QueuedConnection, Q_ARG(bool, doubleClick));
93+ return accepted;
94+}
95+
96+void Approver::processHandleMediaKey(bool doubleClick)
97+{
98+ Q_UNUSED(doubleClick)
99+
100+ if (mPendingSnapDecision) {
101+ onAcceptCallRequested();
102+ } else if (CallManager::instance()->hasCalls()) {
103+ // if there is no incoming call, we have to hangup the current active call
104+ CallEntry *call = CallManager::instance()->foregroundCall();
105+ if (call) {
106+ call->endCall();
107+ }
108+ }
109+}
110+
111
112=== modified file 'approver/approver.h'
113--- approver/approver.h 2015-01-21 12:49:44 +0000
114+++ approver/approver.h 2015-01-22 20:45:31 +0000
115@@ -56,6 +56,7 @@
116 bool showSnapDecision(const Tp::ChannelDispatchOperationPtr dispatchOperation,
117 const Tp::ChannelPtr channel,
118 const QContact &contact = QContact());
119+ bool handleMediaKey(bool doubleClick);
120
121 protected:
122 Tp::ChannelDispatchOperationPtr dispatchOperationForIncomingCall();
123@@ -71,6 +72,8 @@
124 void onAcceptCallRequested();
125 void onRejectCallRequested();
126 void updateNotification(const QtContacts::QContact &contact);
127+ void onSettleTimerTimeout();
128+ void processHandleMediaKey(bool doubleClick);
129 void onUnityStateChanged(int state, int reason);
130
131 private:
132@@ -82,6 +85,7 @@
133 QString mCachedBody;
134 QFeedbackHapticsEffect mVibrateEffect;
135 QTimer mVibrateTimer;
136+ QTimer *mSettleTimer;
137 QMap<QString,QString> mRejectActions;
138 };
139
140
141=== modified file 'approver/approverdbus.cpp'
142--- approver/approverdbus.cpp 2014-01-20 12:57:43 +0000
143+++ approver/approverdbus.cpp 2015-01-22 20:45:31 +0000
144@@ -29,7 +29,7 @@
145 static const char* DBUS_SERVICE = "com.canonical.Approver";
146 static const char* DBUS_OBJECT_PATH = "/com/canonical/Approver";
147
148-ApproverDBus::ApproverDBus(QObject* parent) : QObject(parent)
149+ApproverDBus::ApproverDBus(Approver *approver, QObject* parent) : QObject(parent), mApprover(approver)
150 {
151 }
152
153@@ -64,3 +64,8 @@
154 {
155 Q_EMIT rejectCallRequested();
156 }
157+
158+bool ApproverDBus::HandleMediaKey(bool doubleClick)
159+{
160+ return mApprover->handleMediaKey(doubleClick);
161+}
162
163=== modified file 'approver/approverdbus.h'
164--- approver/approverdbus.h 2014-01-20 12:57:43 +0000
165+++ approver/approverdbus.h 2015-01-22 20:45:31 +0000
166@@ -26,6 +26,7 @@
167 #include <QtCore/QObject>
168 #include <QtDBus/QDBusContext>
169 #include "chatmanager.h"
170+#include "approver.h"
171
172 /**
173 * DBus interface for the phone approver
174@@ -35,7 +36,7 @@
175 Q_OBJECT
176
177 public:
178- ApproverDBus(QObject* parent=0);
179+ ApproverDBus(Approver *approver, QObject* parent=0);
180 ~ApproverDBus();
181
182 bool connectToBus();
183@@ -44,11 +45,14 @@
184 Q_NOREPLY void HangUpAndAcceptCall();
185 Q_NOREPLY void AcceptCall();
186 Q_NOREPLY void RejectCall();
187+ bool HandleMediaKey(bool doubleClick);
188
189 Q_SIGNALS:
190 void hangUpAndAcceptCallRequested();
191 void acceptCallRequested();
192 void rejectCallRequested();
193+private:
194+ Approver *mApprover;
195 };
196
197 #endif // APPROVERDBUS_H
198
199=== modified file 'approver/main.cpp'
200--- approver/main.cpp 2015-01-12 11:41:27 +0000
201+++ approver/main.cpp 2015-01-22 20:45:31 +0000
202@@ -58,11 +58,11 @@
203 qputenv("UBUNTU_PLATFORM_API_BACKEND", "touch_mirclient");
204 #endif
205
206- // register the approver
207- Approver *approver = new Approver();
208- QObject::connect(TelepathyHelper::instance(), &TelepathyHelper::setupReady, [approver]() {
209+ QObject::connect(TelepathyHelper::instance(), &TelepathyHelper::setupReady, []() {
210+ // register the approver
211+ TelepathyHelper::instance()->registerChannelObserver("TelephonyServiceObserver");
212+ Approver *approver = new Approver();
213 TelepathyHelper::instance()->registerClient(approver, "TelephonyServiceApprover");
214- TelepathyHelper::instance()->registerChannelObserver("TelephonyServiceObserver");
215 });
216
217 return app.exec();
218
219=== modified file 'libtelephonyservice/callmanager.cpp'
220--- libtelephonyservice/callmanager.cpp 2014-09-11 18:12:50 +0000
221+++ libtelephonyservice/callmanager.cpp 2015-01-22 20:45:31 +0000
222@@ -380,3 +380,14 @@
223 /* calling without channel, DTMF tone is played only locally */
224 phoneAppHandler->call("SendDTMF", "" , key);
225 }
226+
227+bool CallManager::handleMediaKey(bool doubleClick)
228+{
229+ QDBusInterface *approverInterface = TelepathyHelper::instance()->approverInterface();
230+ QDBusReply<bool> reply = approverInterface->call("HandleMediaKey", doubleClick);
231+ if (reply.isValid()) {
232+ return reply.value();
233+ }
234+ return false;
235+}
236+
237
238=== modified file 'libtelephonyservice/callmanager.h'
239--- libtelephonyservice/callmanager.h 2014-08-22 19:01:46 +0000
240+++ libtelephonyservice/callmanager.h 2015-01-22 20:45:31 +0000
241@@ -61,6 +61,7 @@
242 Q_INVOKABLE void mergeCalls(CallEntry *firstCall, CallEntry *secondCall);
243 Q_INVOKABLE void splitCall(CallEntry *callEntry);
244 Q_INVOKABLE void playTone(const QString &key);
245+ Q_INVOKABLE bool handleMediaKey(bool doubleClick);
246
247 CallEntry *foregroundCall() const;
248 CallEntry *backgroundCall() const;
249
250=== modified file 'libtelephonyservice/telepathyhelper.cpp'
251--- libtelephonyservice/telepathyhelper.cpp 2014-12-16 20:16:26 +0000
252+++ libtelephonyservice/telepathyhelper.cpp 2015-01-22 20:45:31 +0000
253@@ -43,6 +43,7 @@
254 mFirstTime(true),
255 mConnected(false),
256 mHandlerInterface(0),
257+ mApproverInterface(0),
258 mDefaultSimSettings(new QGSettings("com.ubuntu.phone")),
259 mFlightModeInterface("org.freedesktop.URfkill",
260 "/org/freedesktop/URfkill",
261@@ -172,6 +173,18 @@
262 return mHandlerInterface;
263 }
264
265+QDBusInterface *TelepathyHelper::approverInterface() const
266+{
267+ if (!mApproverInterface) {
268+ mApproverInterface = new QDBusInterface("org.freedesktop.Telepathy.Client.TelephonyServiceApprover",
269+ "/com/canonical/Approver",
270+ "com.canonical.TelephonyServiceApprover",
271+ QDBusConnection::sessionBus(),
272+ const_cast<TelepathyHelper*>(this));
273+ }
274+ return mApproverInterface;
275+}
276+
277 bool TelepathyHelper::connected() const
278 {
279 if (QCoreApplication::applicationName() != "telephony-service-handler" &&
280
281=== modified file 'libtelephonyservice/telepathyhelper.h'
282--- libtelephonyservice/telepathyhelper.h 2014-12-16 18:14:15 +0000
283+++ libtelephonyservice/telepathyhelper.h 2015-01-22 20:45:31 +0000
284@@ -67,6 +67,7 @@
285 QQmlListProperty<AccountEntry> qmlActiveAccounts();
286 ChannelObserver *channelObserver() const;
287 QDBusInterface *handlerInterface() const;
288+ QDBusInterface *approverInterface() const;
289 AccountEntry *defaultMessagingAccount() const;
290 AccountEntry *defaultCallAccount() const;
291
292@@ -136,6 +137,7 @@
293 bool mFirstTime;
294 bool mConnected;
295 mutable QDBusInterface *mHandlerInterface;
296+ mutable QDBusInterface *mApproverInterface;
297 QGSettings *mDefaultSimSettings;
298 QDBusInterface mFlightModeInterface;
299 };

Subscribers

People subscribed via source and target branches