Merge lp:telephony-service/staging into lp:telephony-service
- staging
- Merge into trunk
Status: | Approved |
---|---|
Approved by: | Gustavo Pichorim Boiko |
Approved revision: | 1252 |
Proposed branch: | lp:telephony-service/staging |
Merge into: | lp:telephony-service |
Diff against target: |
7142 lines (+4636/-297) 100 files modified
CMakeLists.txt (+10/-10) TODO (+6/-0) Ubuntu/Telephony/CMakeLists.txt (+1/-0) Ubuntu/Telephony/components.cpp (+2/-0) Ubuntu/Telephony/participantsmodel.cpp (+235/-0) Ubuntu/Telephony/participantsmodel.h (+92/-0) accounts/CMakeLists.txt (+2/-0) accounts/common/DynamicField.qml (+172/-0) accounts/common/Main.qml (+106/-0) accounts/common/NewAccountInterface.qml (+314/-0) accounts/irc/CMakeLists.txt (+2/-0) accounts/irc/data/CMakeLists.txt (+5/-0) accounts/irc/data/telephony-irc-im.service (+22/-0) accounts/irc/data/telephony-irc.provider (+5/-0) accounts/irc/qml/CMakeLists.txt (+13/-0) accounts/irc/qml/NewAccount.qml (+63/-0) accounts/sip/CMakeLists.txt (+2/-0) accounts/sip/data/CMakeLists.txt (+5/-0) accounts/sip/data/telephony-sip-im.service (+22/-0) accounts/sip/data/telephony-sip.provider (+5/-0) accounts/sip/qml/CMakeLists.txt (+13/-0) accounts/sip/qml/NewAccount.qml (+48/-0) approver/approver.cpp (+23/-20) cmake/modules/GenerateTest.cmake (+1/-0) debian/account-plugin-irc-unity8.install (+3/-0) debian/account-plugin-sip-unity8.install (+3/-0) debian/control (+24/-1) handler/CMakeLists.txt (+21/-0) handler/Handler.xml (+64/-9) handler/TelephonyServiceHandler.client (+9/-0) handler/accountproperties.cpp (+71/-0) handler/accountproperties.h (+47/-0) handler/audioroutemanager.cpp (+231/-0) handler/audioroutemanager.h (+75/-0) handler/callagent.cpp (+118/-0) handler/callagent.h (+52/-0) handler/callhandler.cpp (+202/-39) handler/callhandler.h (+10/-2) handler/farstreamchannel.cpp (+326/-0) handler/farstreamchannel.h (+80/-0) handler/handler.cpp (+20/-5) handler/handler.h (+2/-1) handler/handlerdbus.cpp (+45/-6) handler/handlerdbus.h (+21/-2) handler/main.cpp (+16/-3) handler/powerd.h (+34/-0) handler/powerdaudiomodemediator.cpp (+63/-0) handler/powerdaudiomodemediator.h (+46/-0) handler/powerddbus.cpp (+43/-0) handler/powerddbus.h (+38/-0) handler/qpulseaudioengine.cpp (+853/-0) handler/qpulseaudioengine.h (+126/-0) handler/texthandler.cpp (+47/-0) handler/texthandler.h (+6/-0) indicator/callchannelobserver.cpp (+19/-3) indicator/callchannelobserver.h (+2/-1) indicator/displaynamesettings.cpp (+2/-2) indicator/messagingmenu.cpp (+14/-14) indicator/messagingmenu.h (+2/-2) indicator/textchannelobserver.cpp (+6/-0) libtelephonyservice/CMakeLists.txt (+4/-8) libtelephonyservice/accountentry.cpp (+79/-6) libtelephonyservice/accountentry.h (+24/-1) libtelephonyservice/accountlist.cpp (+11/-2) libtelephonyservice/accountlist.h (+2/-0) libtelephonyservice/applicationutils.cpp (+11/-13) libtelephonyservice/audiooutput.cpp (+17/-0) libtelephonyservice/audiooutput.h (+4/-0) libtelephonyservice/callentry.cpp (+54/-54) libtelephonyservice/callentry.h (+3/-3) libtelephonyservice/chatentry.cpp (+46/-23) libtelephonyservice/chatentry.h (+9/-1) libtelephonyservice/chatmanager.cpp (+16/-0) libtelephonyservice/chatmanager.h (+3/-1) libtelephonyservice/contactwatcher.cpp (+67/-24) libtelephonyservice/contactwatcher.h (+5/-1) libtelephonyservice/dbustypes.h (+7/-0) libtelephonyservice/greetercontacts.cpp (+17/-1) libtelephonyservice/greetercontacts.h (+3/-1) libtelephonyservice/ofonoaccountentry.cpp (+7/-1) libtelephonyservice/ofonoaccountentry.h (+3/-1) libtelephonyservice/participant.cpp (+13/-2) libtelephonyservice/participant.h (+11/-1) libtelephonyservice/phoneutils.cpp (+43/-1) libtelephonyservice/phoneutils.h (+4/-1) libtelephonyservice/protocol.cpp (+83/-3) libtelephonyservice/protocol.h (+42/-0) libtelephonyservice/protocolmanager.cpp (+2/-2) libtelephonyservice/telepathyhelper.cpp (+37/-8) libtelephonyservice/telepathyhelper.h (+5/-2) libtelephonyservice/tonegenerator.cpp (+12/-1) libtelephonyservice/tonegenerator.h (+6/-2) protocols/README.protocols (+8/-0) protocols/ofono.protocol (+5/-0) protocols/sip.protocol (+7/-0) tests/Ubuntu.Telephony/ContactWatcherTest.cpp (+13/-5) tests/libtelephonyservice/OfonoAccountEntryTest.cpp (+5/-5) tests/libtelephonyservice/ProtocolTest.cpp (+30/-2) tests/libtelephonyservice/testProtocols/foo.protocol (+7/-0) upstart/telephony-service-indicator.conf (+1/-1) |
To merge this branch: | bzr merge lp:telephony-service/staging |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gustavo Pichorim Boiko (community) | Approve | ||
system-apps-ci-bot | continuous-integration | Needs Fixing | |
Review via email: mp+320715@code.launchpad.net |
Commit message
- Add new property to .protocol files to allow join existing channels.
- Add VOIP support to telephony-service.
- Create unity8 sip and irc account packages.
- Add more properties to the .protocol files
- Expose method on dbus to leave all rooms from a certain account.
- Fix protocol filters
- Uses "ua_url_
- Add method to leave channel by properties.
- Implement AudioRouteManager in telephony-
- Multiple performance improvements on Roles Interfaces and ContactWatcher
- Changed upstart job to also launch telephony-
- Add ParticipantsModel
- Expose the account parameters to QML
- Export startChat to QML.
- Implemented contact match by online accounts (IRC).
- Monitor app and disconnect/connect accounts when appropriate.
Description of the change
- Add new property to .protocol files to allow join existing channels.
- Add VOIP support to telephony-service.
- Create unity8 sip and irc account packages.
- Add more properties to the .protocol files
- Expose method on dbus to leave all rooms from a certain account.
- Fix protocol filters
- Uses "ua_url_
- Add method to leave channel by properties.
- Implement AudioRouteManager in telephony-
- Multiple performance improvements on Roles Interfaces and ContactWatcher
- Changed upstart job to also launch telephony-
- Add ParticipantsModel
- Expose the account parameters to QML
- Export startChat to QML.
- Implemented contact match by online accounts (IRC).
- Monitor app and disconnect/connect accounts when appropriate.
system-apps-ci-bot (system-apps-ci-bot) wrote : | # |
- 1252. By Gustavo Pichorim Boiko
-
Disable PA on tests.
system-apps-ci-bot (system-apps-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:1252
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Gustavo Pichorim Boiko (boiko) wrote : | # |
The changes were reviewed individually and tested from this branch, so approving.
- 1253. By Tiago Salem Herrmann
-
- Initialize pointer to avoid crashes.
- Connect new accounts in case messaging-app is already active - 1254. By Tiago Salem Herrmann
-
- Use alsasrc as a workaround to be able to record from the microphone.
pulsesrc does not work on some environments. - 1255. By Tiago Salem Herrmann
-
Add requires to telepathy-rakia and mfw-plugin-irc
- 1256. By Gustavo Pichorim Boiko
-
Fix watching the connection status changes and properly notify the changes to displayed accounts
Unmerged revisions
- 1256. By Gustavo Pichorim Boiko
-
Fix watching the connection status changes and properly notify the changes to displayed accounts
- 1255. By Tiago Salem Herrmann
-
Add requires to telepathy-rakia and mfw-plugin-irc
- 1254. By Tiago Salem Herrmann
-
- Use alsasrc as a workaround to be able to record from the microphone.
pulsesrc does not work on some environments. - 1253. By Tiago Salem Herrmann
-
- Initialize pointer to avoid crashes.
- Connect new accounts in case messaging-app is already active - 1252. By Gustavo Pichorim Boiko
-
Disable PA on tests.
- 1251. By Gustavo Pichorim Boiko
-
Monitor app and disconnect/connect accounts when appropriate.
- 1250. By Gustavo Pichorim Boiko
-
Implemented contact match by online accounts (IRC).
- 1249. By Gustavo Pichorim Boiko
-
Export startChat to QML.
- 1248. By Gustavo Pichorim Boiko
-
Expose the account parameters to QML
- 1247. By Gustavo Pichorim Boiko
-
Add ParticipantsModel
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2016-10-06 19:41:33 +0000 | |||
3 | +++ CMakeLists.txt 2017-04-05 14:05:16 +0000 | |||
4 | @@ -15,13 +15,6 @@ | |||
5 | 15 | # just to make debug easier, print the system processor | 15 | # just to make debug easier, print the system processor |
6 | 16 | message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}") | 16 | message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}") |
7 | 17 | 17 | ||
8 | 18 | # Check if should build using ubuntu platform api | ||
9 | 19 | check_include_file_cxx("ubuntu/application/init.h" USE_UBUNTU_PLATFORM_API) | ||
10 | 20 | |||
11 | 21 | if (USE_UBUNTU_PLATFORM_API) | ||
12 | 22 | add_definitions(-DUSE_UBUNTU_PLATFORM_API) | ||
13 | 23 | endif (USE_UBUNTU_PLATFORM_API) | ||
14 | 24 | |||
15 | 25 | set(TELEPHONY_SERVICE_DIR ${CMAKE_INSTALL_DATADIR}/telephony-service) | 18 | set(TELEPHONY_SERVICE_DIR ${CMAKE_INSTALL_DATADIR}/telephony-service) |
16 | 26 | 19 | ||
17 | 27 | configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) | 20 | configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) |
18 | @@ -35,10 +28,8 @@ | |||
19 | 35 | 28 | ||
20 | 36 | find_package(Qt5Contacts) | 29 | find_package(Qt5Contacts) |
21 | 37 | find_package(Qt5DBus) | 30 | find_package(Qt5DBus) |
22 | 38 | #find_package(Qt5Gui) | ||
23 | 39 | find_package(Qt5Multimedia) | 31 | find_package(Qt5Multimedia) |
24 | 40 | find_package(Qt5Qml) | 32 | find_package(Qt5Qml) |
25 | 41 | #find_package(Qt5Quick) | ||
26 | 42 | find_package(Qt5Test) | 33 | find_package(Qt5Test) |
27 | 43 | find_package(Qt5Feedback) | 34 | find_package(Qt5Feedback) |
28 | 44 | find_package(Qt5Network) | 35 | find_package(Qt5Network) |
29 | @@ -48,7 +39,7 @@ | |||
30 | 48 | 39 | ||
31 | 49 | option(SKIP_QML_TESTS "Skip QML tests" OFF) | 40 | option(SKIP_QML_TESTS "Skip QML tests" OFF) |
32 | 50 | 41 | ||
34 | 51 | if(NOT CMAKE_CROSSCOMPILING) | 42 | if(CMAKE_CROSSCOMPILING) |
35 | 52 | find_program(QMAKE_EXECUTABLE qmake) | 43 | find_program(QMAKE_EXECUTABLE qmake) |
36 | 53 | if(QMAKE_EXECUTABLE STREQUAL "QMAKE_EXECUTABLE-NOTFOUND") | 44 | if(QMAKE_EXECUTABLE STREQUAL "QMAKE_EXECUTABLE-NOTFOUND") |
37 | 54 | message(FATAL_ERROR "qmake not found") | 45 | message(FATAL_ERROR "qmake not found") |
38 | @@ -71,10 +62,18 @@ | |||
39 | 71 | 62 | ||
40 | 72 | find_package(PkgConfig REQUIRED) | 63 | find_package(PkgConfig REQUIRED) |
41 | 73 | pkg_check_modules(TP_QT5 REQUIRED TelepathyQt5) | 64 | pkg_check_modules(TP_QT5 REQUIRED TelepathyQt5) |
42 | 65 | pkg_check_modules(TP_QT5_FS REQUIRED TelepathyQt5Farstream) | ||
43 | 74 | pkg_check_modules(NOTIFY REQUIRED libnotify) | 66 | pkg_check_modules(NOTIFY REQUIRED libnotify) |
44 | 75 | pkg_check_modules(MESSAGING_MENU REQUIRED messaging-menu) | 67 | pkg_check_modules(MESSAGING_MENU REQUIRED messaging-menu) |
45 | 76 | pkg_check_modules(UserMetrics REQUIRED libusermetricsinput-1) | 68 | pkg_check_modules(UserMetrics REQUIRED libusermetricsinput-1) |
46 | 77 | pkg_check_modules(HISTORY REQUIRED history-service) | 69 | pkg_check_modules(HISTORY REQUIRED history-service) |
47 | 70 | pkg_check_modules(TPFS REQUIRED telepathy-farstream) | ||
48 | 71 | pkg_check_modules(GST REQUIRED gstreamer-1.0) | ||
49 | 72 | pkg_check_modules(FS REQUIRED farstream-0.2) | ||
50 | 73 | pkg_check_modules(UBUNTU_PLATFORM_API ubuntu-platform-api) | ||
51 | 74 | pkg_check_modules(GSETTINGS_QT REQUIRED gsettings-qt) | ||
52 | 75 | pkg_check_modules(PULSEAUDIO libpulse) | ||
53 | 76 | pkg_check_modules(URL_DISPATCHER REQUIRED url-dispatcher-1) | ||
54 | 78 | 77 | ||
55 | 79 | add_definitions(-DQT_NO_KEYWORDS) | 78 | add_definitions(-DQT_NO_KEYWORDS) |
56 | 80 | 79 | ||
57 | @@ -110,6 +109,7 @@ | |||
58 | 110 | add_subdirectory(po) | 109 | add_subdirectory(po) |
59 | 111 | add_subdirectory(tests) | 110 | add_subdirectory(tests) |
60 | 112 | add_subdirectory(protocols) | 111 | add_subdirectory(protocols) |
61 | 112 | add_subdirectory(accounts) | ||
62 | 113 | 113 | ||
63 | 114 | include(EnableCoverageReport) | 114 | include(EnableCoverageReport) |
64 | 115 | ##################################################################### | 115 | ##################################################################### |
65 | 116 | 116 | ||
66 | === modified file 'TODO' | |||
67 | --- TODO 2012-11-27 12:21:47 +0000 | |||
68 | +++ TODO 2017-04-05 14:05:16 +0000 | |||
69 | @@ -1,6 +1,9 @@ | |||
70 | 1 | General items | 1 | General items |
71 | 2 | - Formatting of phone numbers | 2 | - Formatting of phone numbers |
72 | 3 | - Check how to import/export potfiles from the ts one | 3 | - Check how to import/export potfiles from the ts one |
73 | 4 | - Add an automated test to check if features are getting correctly exported | ||
74 | 5 | by AccountEntry | ||
75 | 6 | - Implement unit test for launching external app from indicator. | ||
76 | 4 | 7 | ||
77 | 5 | Contact integration items: | 8 | Contact integration items: |
78 | 6 | - Fix contact search when names contain accentuated characters | 9 | - Fix contact search when names contain accentuated characters |
79 | @@ -16,3 +19,6 @@ | |||
80 | 16 | places | 19 | places |
81 | 17 | - Change the ChannelObserver and the ChannelApprover code to allow using from | 20 | - Change the ChannelObserver and the ChannelApprover code to allow using from |
82 | 18 | both places. | 21 | both places. |
83 | 22 | |||
84 | 23 | Handler | ||
85 | 24 | - Move app monitoring to from TextHandler to ApplicationUtils | ||
86 | 19 | 25 | ||
87 | === modified file 'Ubuntu/Telephony/CMakeLists.txt' | |||
88 | --- Ubuntu/Telephony/CMakeLists.txt 2016-07-05 03:34:11 +0000 | |||
89 | +++ Ubuntu/Telephony/CMakeLists.txt 2017-04-05 14:05:16 +0000 | |||
90 | @@ -2,6 +2,7 @@ | |||
91 | 2 | 2 | ||
92 | 3 | set(plugin_SRCS | 3 | set(plugin_SRCS |
93 | 4 | presencerequest.cpp | 4 | presencerequest.cpp |
94 | 5 | participantsmodel.cpp | ||
95 | 5 | components.cpp | 6 | components.cpp |
96 | 6 | ) | 7 | ) |
97 | 7 | 8 | ||
98 | 8 | 9 | ||
99 | === modified file 'Ubuntu/Telephony/components.cpp' | |||
100 | --- Ubuntu/Telephony/components.cpp 2016-11-23 19:28:18 +0000 | |||
101 | +++ Ubuntu/Telephony/components.cpp 2017-04-05 14:05:16 +0000 | |||
102 | @@ -39,6 +39,7 @@ | |||
103 | 39 | #include "accountentry.h" | 39 | #include "accountentry.h" |
104 | 40 | #include "accountlist.h" | 40 | #include "accountlist.h" |
105 | 41 | #include "audiooutput.h" | 41 | #include "audiooutput.h" |
106 | 42 | #include "participantsmodel.h" | ||
107 | 42 | 43 | ||
108 | 43 | #include <QQmlEngine> | 44 | #include <QQmlEngine> |
109 | 44 | #include <qqml.h> | 45 | #include <qqml.h> |
110 | @@ -87,5 +88,6 @@ | |||
111 | 87 | qmlRegisterType<ContactWatcher>(uri, 0, 1, "ContactWatcher"); | 88 | qmlRegisterType<ContactWatcher>(uri, 0, 1, "ContactWatcher"); |
112 | 88 | qmlRegisterType<Participant>(uri, 0, 1, "Participant"); | 89 | qmlRegisterType<Participant>(uri, 0, 1, "Participant"); |
113 | 89 | qmlRegisterType<PresenceRequest>(uri, 0, 1, "PresenceRequest"); | 90 | qmlRegisterType<PresenceRequest>(uri, 0, 1, "PresenceRequest"); |
114 | 91 | qmlRegisterType<ParticipantsModel>(uri, 0, 1, "ParticipantsModel"); | ||
115 | 90 | qmlRegisterType<PhoneUtils>(uri, 0, 1, "PhoneUtils"); | 92 | qmlRegisterType<PhoneUtils>(uri, 0, 1, "PhoneUtils"); |
116 | 91 | } | 93 | } |
117 | 92 | 94 | ||
118 | === added file 'Ubuntu/Telephony/participantsmodel.cpp' | |||
119 | --- Ubuntu/Telephony/participantsmodel.cpp 1970-01-01 00:00:00 +0000 | |||
120 | +++ Ubuntu/Telephony/participantsmodel.cpp 2017-04-05 14:05:16 +0000 | |||
121 | @@ -0,0 +1,235 @@ | |||
122 | 1 | /* | ||
123 | 2 | * Copyright (C) 2013-2017 Canonical, Ltd. | ||
124 | 3 | * | ||
125 | 4 | * Authors: | ||
126 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | ||
127 | 6 | * Tiago Salem Herrmann <tiago.herrmann@canonical.com> | ||
128 | 7 | * | ||
129 | 8 | * This file is part of telephony-service. | ||
130 | 9 | * | ||
131 | 10 | * telephony-service is free software; you can redistribute it and/or modify | ||
132 | 11 | * it under the terms of the GNU General Public License as published by | ||
133 | 12 | * the Free Software Foundation; version 3. | ||
134 | 13 | * | ||
135 | 14 | * telephony-service is distributed in the hope that it will be useful, | ||
136 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
137 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
138 | 17 | * GNU General Public License for more details. | ||
139 | 18 | * | ||
140 | 19 | * You should have received a copy of the GNU General Public License | ||
141 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
142 | 21 | */ | ||
143 | 22 | |||
144 | 23 | #include "participantsmodel.h" | ||
145 | 24 | #include <participant.h> | ||
146 | 25 | #include <QDebug> | ||
147 | 26 | |||
148 | 27 | Q_DECLARE_METATYPE(Participant) | ||
149 | 28 | |||
150 | 29 | ParticipantsModel::ParticipantsModel(QObject *parent) : | ||
151 | 30 | QAbstractListModel(parent), mWaitingForQml(false), mCanFetchMore(true), mChatEntry(NULL) | ||
152 | 31 | { | ||
153 | 32 | qRegisterMetaType<Participant>(); | ||
154 | 33 | mRoles[AliasRole] = "alias"; | ||
155 | 34 | mRoles[IdentifierRole] = "identifier"; | ||
156 | 35 | mRoles[RolesRole] = "roles"; | ||
157 | 36 | mRoles[StateRole] = "state"; | ||
158 | 37 | |||
159 | 38 | connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(countChanged())); | ||
160 | 39 | connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(countChanged())); | ||
161 | 40 | connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged())); | ||
162 | 41 | } | ||
163 | 42 | |||
164 | 43 | bool ParticipantsModel::canFetchMore(const QModelIndex &parent) const | ||
165 | 44 | { | ||
166 | 45 | return !mParticipantsCache.isEmpty(); | ||
167 | 46 | } | ||
168 | 47 | |||
169 | 48 | ParticipantsModel::~ParticipantsModel() | ||
170 | 49 | { | ||
171 | 50 | } | ||
172 | 51 | |||
173 | 52 | void ParticipantsModel::fetchMore(const QModelIndex &parent) | ||
174 | 53 | { | ||
175 | 54 | if (parent.isValid() ) { | ||
176 | 55 | return; | ||
177 | 56 | } | ||
178 | 57 | |||
179 | 58 | int max = 14; | ||
180 | 59 | while (max >= 0 && !mParticipantsCache.isEmpty()) { | ||
181 | 60 | addParticipant(mParticipantsCache.takeFirst()); | ||
182 | 61 | max--; | ||
183 | 62 | } | ||
184 | 63 | |||
185 | 64 | if (mParticipantsCache.isEmpty()) { | ||
186 | 65 | mCanFetchMore = false; | ||
187 | 66 | Q_EMIT canFetchMoreChanged(); | ||
188 | 67 | } | ||
189 | 68 | } | ||
190 | 69 | |||
191 | 70 | int ParticipantsModel::rowCount(const QModelIndex &parent) const | ||
192 | 71 | { | ||
193 | 72 | if (parent.isValid()) { | ||
194 | 73 | return 0; | ||
195 | 74 | } | ||
196 | 75 | |||
197 | 76 | return mParticipants.count(); | ||
198 | 77 | } | ||
199 | 78 | |||
200 | 79 | QHash<int, QByteArray> ParticipantsModel::roleNames() const | ||
201 | 80 | { | ||
202 | 81 | return mRoles; | ||
203 | 82 | } | ||
204 | 83 | |||
205 | 84 | void ParticipantsModel::addParticipantCache(Participant *participant) | ||
206 | 85 | { | ||
207 | 86 | int pos = positionForItem(participant->identifier(), true); | ||
208 | 87 | mParticipantsCache.insert(pos, participant); | ||
209 | 88 | } | ||
210 | 89 | |||
211 | 90 | void ParticipantsModel::addParticipant(Participant *participant) | ||
212 | 91 | { | ||
213 | 92 | int pos = positionForItem(participant->identifier()); | ||
214 | 93 | beginInsertRows(QModelIndex(), pos, pos); | ||
215 | 94 | mParticipants.insert(pos, participant); | ||
216 | 95 | endInsertRows(); | ||
217 | 96 | } | ||
218 | 97 | |||
219 | 98 | void ParticipantsModel::removeParticipant(Participant *participant) | ||
220 | 99 | { | ||
221 | 100 | int pos = mParticipants.indexOf(participant); | ||
222 | 101 | if (pos >= 0) { | ||
223 | 102 | beginRemoveRows(QModelIndex(), pos, pos); | ||
224 | 103 | mParticipants.removeAt(pos); | ||
225 | 104 | endRemoveRows(); | ||
226 | 105 | } | ||
227 | 106 | pos = mParticipantsCache.indexOf(participant); | ||
228 | 107 | if (pos >= 0) { | ||
229 | 108 | mParticipantsCache.removeAt(pos); | ||
230 | 109 | } | ||
231 | 110 | } | ||
232 | 111 | |||
233 | 112 | QVariant ParticipantsModel::data(const QModelIndex &index, int role) const | ||
234 | 113 | { | ||
235 | 114 | if (!index.isValid() || index.row() < 0 || index.row() >= rowCount()) { | ||
236 | 115 | return QVariant(); | ||
237 | 116 | } | ||
238 | 117 | switch (role) { | ||
239 | 118 | case IdentifierRole: | ||
240 | 119 | return mParticipants[index.row()]->identifier(); | ||
241 | 120 | break; | ||
242 | 121 | case AliasRole: | ||
243 | 122 | return mParticipants[index.row()]->alias(); | ||
244 | 123 | break; | ||
245 | 124 | case StateRole: | ||
246 | 125 | return 0; | ||
247 | 126 | break; | ||
248 | 127 | case RolesRole: | ||
249 | 128 | return mParticipants[index.row()]->roles(); | ||
250 | 129 | break; | ||
251 | 130 | } | ||
252 | 131 | return QVariant(); | ||
253 | 132 | } | ||
254 | 133 | |||
255 | 134 | bool ParticipantsModel::lessThan(const QString &left, const QString &right) const | ||
256 | 135 | { | ||
257 | 136 | // this method will push participant with names starting with non-letter | ||
258 | 137 | // characters to the end of the list | ||
259 | 138 | if (left.isEmpty() || right.isEmpty()) { | ||
260 | 139 | return false; | ||
261 | 140 | } | ||
262 | 141 | if (left.at(0).isLetter() && right.at(0).isLetter()) { | ||
263 | 142 | return left.localeAwareCompare(right) < 0; | ||
264 | 143 | } | ||
265 | 144 | if (!left.at(0).isLetter() && right.at(0).isLetter()) { | ||
266 | 145 | return false; | ||
267 | 146 | } | ||
268 | 147 | if (left.at(0).isLetter() && !right.at(0).isLetter()) { | ||
269 | 148 | return true; | ||
270 | 149 | } | ||
271 | 150 | |||
272 | 151 | return false; | ||
273 | 152 | } | ||
274 | 153 | |||
275 | 154 | int ParticipantsModel::positionForItem(const QString &item, bool cache) const | ||
276 | 155 | { | ||
277 | 156 | // do a binary search for the item position on the list | ||
278 | 157 | int lowerBound = 0; | ||
279 | 158 | int upperBound = cache ? mParticipantsCache.count() - 1 : rowCount() - 1; | ||
280 | 159 | if (upperBound < 0) { | ||
281 | 160 | return 0; | ||
282 | 161 | } | ||
283 | 162 | |||
284 | 163 | while (true) { | ||
285 | 164 | int pos = (upperBound + lowerBound) / 2; | ||
286 | 165 | const QString posItem = cache ? mParticipantsCache[pos]->identifier() : index(pos).data(IdentifierRole).toString(); | ||
287 | 166 | if (lowerBound == pos) { | ||
288 | 167 | if (lessThan(item, posItem)) { | ||
289 | 168 | return pos; | ||
290 | 169 | } | ||
291 | 170 | } | ||
292 | 171 | if (lessThan(posItem, item)) { | ||
293 | 172 | lowerBound = pos + 1; // its in the upper | ||
294 | 173 | if (lowerBound > upperBound) { | ||
295 | 174 | return pos += 1; | ||
296 | 175 | } | ||
297 | 176 | } else if (lowerBound > upperBound) { | ||
298 | 177 | return pos; | ||
299 | 178 | } else { | ||
300 | 179 | upperBound = pos - 1; // its in the lower | ||
301 | 180 | } | ||
302 | 181 | } | ||
303 | 182 | } | ||
304 | 183 | |||
305 | 184 | void ParticipantsModel::classBegin() | ||
306 | 185 | { | ||
307 | 186 | mWaitingForQml = true; | ||
308 | 187 | } | ||
309 | 188 | |||
310 | 189 | void ParticipantsModel::componentComplete() | ||
311 | 190 | { | ||
312 | 191 | mWaitingForQml = false; | ||
313 | 192 | } | ||
314 | 193 | |||
315 | 194 | QVariant ParticipantsModel::get(int row) const | ||
316 | 195 | { | ||
317 | 196 | QVariantMap data; | ||
318 | 197 | QModelIndex idx = index(row, 0); | ||
319 | 198 | if (idx.isValid()) { | ||
320 | 199 | QHash<int, QByteArray> roles = roleNames(); | ||
321 | 200 | Q_FOREACH(int role, roles.keys()) { | ||
322 | 201 | data.insert(roles[role], idx.data(role)); | ||
323 | 202 | } | ||
324 | 203 | } | ||
325 | 204 | |||
326 | 205 | return data; | ||
327 | 206 | } | ||
328 | 207 | |||
329 | 208 | ChatEntry* ParticipantsModel::chatEntry() const | ||
330 | 209 | { | ||
331 | 210 | return mChatEntry; | ||
332 | 211 | } | ||
333 | 212 | |||
334 | 213 | void ParticipantsModel::setChatEntry(ChatEntry *entry) | ||
335 | 214 | { | ||
336 | 215 | if (mChatEntry == entry) { | ||
337 | 216 | return; | ||
338 | 217 | } | ||
339 | 218 | ChatEntry *previousChatEntry = mChatEntry; | ||
340 | 219 | mChatEntry = entry; | ||
341 | 220 | if (!entry) { | ||
342 | 221 | return; | ||
343 | 222 | } | ||
344 | 223 | if (previousChatEntry) { | ||
345 | 224 | previousChatEntry->disconnect(this); | ||
346 | 225 | } | ||
347 | 226 | connect(mChatEntry, SIGNAL(participantAdded(Participant *)), SLOT(addParticipant(Participant *))); | ||
348 | 227 | connect(mChatEntry, SIGNAL(participantRemoved(Participant *)), SLOT(removeParticipant(Participant *))); | ||
349 | 228 | Q_FOREACH(Participant *participant, mChatEntry->allParticipants()) { | ||
350 | 229 | addParticipantCache(participant); | ||
351 | 230 | } | ||
352 | 231 | fetchMore(); | ||
353 | 232 | mCanFetchMore = !mParticipantsCache.isEmpty(); | ||
354 | 233 | Q_EMIT canFetchMoreChanged(); | ||
355 | 234 | Q_EMIT chatEntryChanged(); | ||
356 | 235 | } | ||
357 | 0 | 236 | ||
358 | === added file 'Ubuntu/Telephony/participantsmodel.h' | |||
359 | --- Ubuntu/Telephony/participantsmodel.h 1970-01-01 00:00:00 +0000 | |||
360 | +++ Ubuntu/Telephony/participantsmodel.h 2017-04-05 14:05:16 +0000 | |||
361 | @@ -0,0 +1,92 @@ | |||
362 | 1 | /* | ||
363 | 2 | * Copyright (C) 2013-2017 Canonical, Ltd. | ||
364 | 3 | * | ||
365 | 4 | * Authors: | ||
366 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | ||
367 | 6 | * Tiago Salem Herrmann <tiago.herrmann@canonical.com> | ||
368 | 7 | * | ||
369 | 8 | * This file is part of telephony-service. | ||
370 | 9 | * | ||
371 | 10 | * telephony-service is free software; you can redistribute it and/or modify | ||
372 | 11 | * it under the terms of the GNU General Public License as published by | ||
373 | 12 | * the Free Software Foundation; version 3. | ||
374 | 13 | * | ||
375 | 14 | * telephony-service is distributed in the hope that it will be useful, | ||
376 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
377 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
378 | 17 | * GNU General Public License for more details. | ||
379 | 18 | * | ||
380 | 19 | * You should have received a copy of the GNU General Public License | ||
381 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
382 | 21 | */ | ||
383 | 22 | |||
384 | 23 | #ifndef PARTICIPANTSMODEL_H | ||
385 | 24 | #define PARTICIPANTSMODEL_H | ||
386 | 25 | |||
387 | 26 | #include "chatentry.h" | ||
388 | 27 | #include <QAbstractListModel> | ||
389 | 28 | #include <QStringList> | ||
390 | 29 | #include <QQmlParserStatus> | ||
391 | 30 | #include <QQmlListProperty> | ||
392 | 31 | |||
393 | 32 | class Participant; | ||
394 | 33 | |||
395 | 34 | class ParticipantsModel : public QAbstractListModel, public QQmlParserStatus | ||
396 | 35 | { | ||
397 | 36 | Q_OBJECT | ||
398 | 37 | Q_INTERFACES(QQmlParserStatus) | ||
399 | 38 | Q_PROPERTY(int count READ rowCount NOTIFY countChanged) | ||
400 | 39 | Q_PROPERTY(bool canFetchMore READ canFetchMore NOTIFY canFetchMoreChanged) | ||
401 | 40 | Q_PROPERTY(ChatEntry* chatEntry READ chatEntry WRITE setChatEntry NOTIFY chatEntryChanged) | ||
402 | 41 | Q_ENUMS(Role) | ||
403 | 42 | |||
404 | 43 | public: | ||
405 | 44 | enum Role { | ||
406 | 45 | IdentifierRole = Qt::UserRole, | ||
407 | 46 | AliasRole, | ||
408 | 47 | RolesRole, | ||
409 | 48 | StateRole | ||
410 | 49 | }; | ||
411 | 50 | |||
412 | 51 | explicit ParticipantsModel(QObject *parent = 0); | ||
413 | 52 | ~ParticipantsModel(); | ||
414 | 53 | |||
415 | 54 | Q_INVOKABLE virtual bool canFetchMore(const QModelIndex &parent = QModelIndex()) const; | ||
416 | 55 | Q_INVOKABLE virtual void fetchMore(const QModelIndex &parent = QModelIndex()); | ||
417 | 56 | virtual QHash<int, QByteArray> roleNames() const; | ||
418 | 57 | virtual QVariant data(const QModelIndex &index, int role) const; | ||
419 | 58 | int rowCount(const QModelIndex &parent = QModelIndex()) const; | ||
420 | 59 | |||
421 | 60 | Q_INVOKABLE virtual QVariant get(int row) const; | ||
422 | 61 | |||
423 | 62 | Q_INVOKABLE void setChatEntry(ChatEntry *entry); | ||
424 | 63 | ChatEntry* chatEntry() const; | ||
425 | 64 | |||
426 | 65 | void addParticipantCache(Participant *participant); | ||
427 | 66 | |||
428 | 67 | void classBegin(); | ||
429 | 68 | void componentComplete(); | ||
430 | 69 | |||
431 | 70 | private Q_SLOTS: | ||
432 | 71 | void addParticipant(Participant *participant); | ||
433 | 72 | void removeParticipant(Participant *participant); | ||
434 | 73 | |||
435 | 74 | Q_SIGNALS: | ||
436 | 75 | void countChanged(); | ||
437 | 76 | void canFetchMoreChanged(); | ||
438 | 77 | void chatEntryChanged(); | ||
439 | 78 | |||
440 | 79 | protected: | ||
441 | 80 | bool lessThan(const QString &left, const QString &right) const; | ||
442 | 81 | int positionForItem(const QString &item, bool cache = false) const; | ||
443 | 82 | |||
444 | 83 | private: | ||
445 | 84 | QHash<int, QByteArray> mRoles; | ||
446 | 85 | QList<Participant*> mParticipants; | ||
447 | 86 | bool mWaitingForQml; | ||
448 | 87 | bool mCanFetchMore; | ||
449 | 88 | ChatEntry *mChatEntry; | ||
450 | 89 | QList<Participant*> mParticipantsCache; | ||
451 | 90 | }; | ||
452 | 91 | |||
453 | 92 | #endif // PARTICIPANTSMODEL_H | ||
454 | 0 | 93 | ||
455 | === added directory 'accounts' | |||
456 | === added file 'accounts/CMakeLists.txt' | |||
457 | --- accounts/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
458 | +++ accounts/CMakeLists.txt 2017-04-05 14:05:16 +0000 | |||
459 | @@ -0,0 +1,2 @@ | |||
460 | 1 | add_subdirectory(sip) | ||
461 | 2 | add_subdirectory(irc) | ||
462 | 0 | 3 | ||
463 | === added directory 'accounts/common' | |||
464 | === added file 'accounts/common/DynamicField.qml' | |||
465 | --- accounts/common/DynamicField.qml 1970-01-01 00:00:00 +0000 | |||
466 | +++ accounts/common/DynamicField.qml 2017-04-05 14:05:16 +0000 | |||
467 | @@ -0,0 +1,172 @@ | |||
468 | 1 | /* | ||
469 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
470 | 3 | * | ||
471 | 4 | * Authors: | ||
472 | 5 | * Renato Araujo Oliveira Filho <renato.filho@canonical.com> | ||
473 | 6 | * | ||
474 | 7 | * This file is part of telephony-service. | ||
475 | 8 | * | ||
476 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
477 | 10 | * it under the terms of the GNU General Public License as published by | ||
478 | 11 | * the Free Software Foundation; version 3. | ||
479 | 12 | * | ||
480 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
481 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
482 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
483 | 16 | * GNU General Public License for more details. | ||
484 | 17 | * | ||
485 | 18 | * You should have received a copy of the GNU General Public License | ||
486 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
487 | 20 | */ | ||
488 | 21 | |||
489 | 22 | import QtQuick 2.0 | ||
490 | 23 | import Ubuntu.Components 1.3 | ||
491 | 24 | |||
492 | 25 | Loader { | ||
493 | 26 | id: root | ||
494 | 27 | |||
495 | 28 | property var model | ||
496 | 29 | readonly property string value: status === Loader.Ready ? item.value : "" | ||
497 | 30 | readonly property bool isEmpty: status === Loader.Ready ? item.isEmpty : true | ||
498 | 31 | |||
499 | 32 | Component { | ||
500 | 33 | id: stringField | ||
501 | 34 | |||
502 | 35 | TextField { | ||
503 | 36 | id: field | ||
504 | 37 | |||
505 | 38 | property alias label: field.placeholderText | ||
506 | 39 | property string defaultValue | ||
507 | 40 | |||
508 | 41 | readonly property alias value: field.text | ||
509 | 42 | readonly property bool isEmpty: value === "" || (defaultValue && value === model.defaultValue) | ||
510 | 43 | |||
511 | 44 | text: defaultValue ? defaultValue : "" | ||
512 | 45 | } | ||
513 | 46 | } | ||
514 | 47 | |||
515 | 48 | Component { | ||
516 | 49 | id: booleanField | ||
517 | 50 | |||
518 | 51 | Item { | ||
519 | 52 | property alias label: fieldLabel.text | ||
520 | 53 | property string defaultValue | ||
521 | 54 | |||
522 | 55 | readonly property string value: fieldValue.checked ? "true" : "false" | ||
523 | 56 | readonly property bool isEmpty: (defaultValue && value === model.defaultValue) | ||
524 | 57 | |||
525 | 58 | height: fieldValue.height | ||
526 | 59 | |||
527 | 60 | Label { | ||
528 | 61 | id: fieldLabel | ||
529 | 62 | |||
530 | 63 | anchors { | ||
531 | 64 | left: parent.left | ||
532 | 65 | right: fieldValue.left | ||
533 | 66 | verticalCenter: parent.verticalCenter | ||
534 | 67 | } | ||
535 | 68 | } | ||
536 | 69 | Switch { | ||
537 | 70 | id: fieldValue | ||
538 | 71 | |||
539 | 72 | anchors { | ||
540 | 73 | right: parent.right | ||
541 | 74 | verticalCenter: parent.verticalCenter | ||
542 | 75 | } | ||
543 | 76 | checked: (defaultValue && (defaultValue === 'true')) | ||
544 | 77 | } | ||
545 | 78 | } | ||
546 | 79 | } | ||
547 | 80 | |||
548 | 81 | Component { | ||
549 | 82 | id: numericField | ||
550 | 83 | |||
551 | 84 | TextField { | ||
552 | 85 | id: field | ||
553 | 86 | |||
554 | 87 | property alias label: field.placeholderText | ||
555 | 88 | property string defaultValue | ||
556 | 89 | |||
557 | 90 | readonly property alias value: field.text | ||
558 | 91 | readonly property bool isEmpty: value === "" || (defaultValue && (value === defaultValue)) | ||
559 | 92 | |||
560 | 93 | inputMethodHints: Qt.ImhDigitsOnly | ||
561 | 94 | validator: IntValidator {} | ||
562 | 95 | } | ||
563 | 96 | } | ||
564 | 97 | |||
565 | 98 | Component{ | ||
566 | 99 | id: passwordField | ||
567 | 100 | |||
568 | 101 | Item { | ||
569 | 102 | property alias label: field.placeholderText | ||
570 | 103 | readonly property alias value: field.text | ||
571 | 104 | readonly property bool isEmpty: value === "" | ||
572 | 105 | |||
573 | 106 | height: field.height + showPasswordCheck.height | ||
574 | 107 | TextField { | ||
575 | 108 | id: field | ||
576 | 109 | |||
577 | 110 | echoMode: showPasswordCheck.checked ? TextInput.Normal : TextInput.Password | ||
578 | 111 | anchors { | ||
579 | 112 | left: parent.left | ||
580 | 113 | right: parent.right | ||
581 | 114 | } | ||
582 | 115 | onTextChanged: root.changed() | ||
583 | 116 | } | ||
584 | 117 | CheckBox { | ||
585 | 118 | id: showPasswordCheck | ||
586 | 119 | anchors { | ||
587 | 120 | left: field.left | ||
588 | 121 | top: field.bottom | ||
589 | 122 | topMargin: units.gu(1) | ||
590 | 123 | } | ||
591 | 124 | } | ||
592 | 125 | Label { | ||
593 | 126 | text: i18n.tr("Show Password") | ||
594 | 127 | anchors { | ||
595 | 128 | top: showPasswordCheck.top | ||
596 | 129 | left: showPasswordCheck.right | ||
597 | 130 | leftMargin: units.gu(1) | ||
598 | 131 | right: field.right | ||
599 | 132 | } | ||
600 | 133 | } | ||
601 | 134 | } | ||
602 | 135 | } | ||
603 | 136 | |||
604 | 137 | |||
605 | 138 | sourceComponent: { | ||
606 | 139 | if (!model) | ||
607 | 140 | return null | ||
608 | 141 | |||
609 | 142 | if (!model.inputType) { | ||
610 | 143 | console.warn("Model does not contain 'inputType'") | ||
611 | 144 | return null | ||
612 | 145 | } | ||
613 | 146 | |||
614 | 147 | switch (model.inputType) { | ||
615 | 148 | case 'string': | ||
616 | 149 | return stringField | ||
617 | 150 | case 'boolean': | ||
618 | 151 | return booleanField | ||
619 | 152 | case 'numeric': | ||
620 | 153 | return numericField | ||
621 | 154 | case 'password': | ||
622 | 155 | return passwordField | ||
623 | 156 | } | ||
624 | 157 | } | ||
625 | 158 | |||
626 | 159 | Binding { | ||
627 | 160 | target: root.item | ||
628 | 161 | property: "label" | ||
629 | 162 | value: model.label | ||
630 | 163 | when: root.status == Loader.Ready | ||
631 | 164 | } | ||
632 | 165 | |||
633 | 166 | Binding { | ||
634 | 167 | target: root.item | ||
635 | 168 | property: "defaultValue" | ||
636 | 169 | value: model.defaultValue | ||
637 | 170 | when: model.hasOwnProperty('defaultValue') && root.status == Loader.Ready | ||
638 | 171 | } | ||
639 | 172 | } | ||
640 | 0 | 173 | ||
641 | === added file 'accounts/common/Main.qml' | |||
642 | --- accounts/common/Main.qml 1970-01-01 00:00:00 +0000 | |||
643 | +++ accounts/common/Main.qml 2017-04-05 14:05:16 +0000 | |||
644 | @@ -0,0 +1,106 @@ | |||
645 | 1 | /* | ||
646 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
647 | 3 | * | ||
648 | 4 | * Authors: | ||
649 | 5 | * Renato Araujo Oliveira Filho <renato.filho@canonical.com> | ||
650 | 6 | * | ||
651 | 7 | * This file is part of telephony-service. | ||
652 | 8 | * | ||
653 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
654 | 10 | * it under the terms of the GNU General Public License as published by | ||
655 | 11 | * the Free Software Foundation; version 3. | ||
656 | 12 | * | ||
657 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
658 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
659 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
660 | 16 | * GNU General Public License for more details. | ||
661 | 17 | * | ||
662 | 18 | * You should have received a copy of the GNU General Public License | ||
663 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
664 | 20 | */ | ||
665 | 21 | |||
666 | 22 | import QtQuick 2.0 | ||
667 | 23 | import Ubuntu.Components 1.3 | ||
668 | 24 | import Ubuntu.OnlineAccounts.Plugin 1.0 | ||
669 | 25 | |||
670 | 26 | Item { | ||
671 | 27 | id: rootFlickable | ||
672 | 28 | |||
673 | 29 | property int keyboardSize: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0 | ||
674 | 30 | |||
675 | 31 | signal finished | ||
676 | 32 | |||
677 | 33 | anchors.fill: parent | ||
678 | 34 | |||
679 | 35 | Flickable { | ||
680 | 36 | anchors { | ||
681 | 37 | left: parent.left | ||
682 | 38 | right: parent.right | ||
683 | 39 | top: parent.top | ||
684 | 40 | bottom: btnConfirm.top | ||
685 | 41 | } | ||
686 | 42 | contentWidth: parent.width | ||
687 | 43 | contentHeight: editPageLoader.item.height + keyboardSize | ||
688 | 44 | clip: true | ||
689 | 45 | |||
690 | 46 | Loader { | ||
691 | 47 | id: editPageLoader | ||
692 | 48 | sourceComponent: account.accountId != 0 ? existingAccountComponent : newAccountComponent | ||
693 | 49 | anchors { | ||
694 | 50 | left: parent.left | ||
695 | 51 | right: parent.right | ||
696 | 52 | } | ||
697 | 53 | |||
698 | 54 | Connections { | ||
699 | 55 | target: editPageLoader.item | ||
700 | 56 | onFinished: rootFlickable.finished() | ||
701 | 57 | } | ||
702 | 58 | } | ||
703 | 59 | |||
704 | 60 | Component { | ||
705 | 61 | id: newAccountComponent | ||
706 | 62 | NewAccount {} | ||
707 | 63 | } | ||
708 | 64 | |||
709 | 65 | Component { | ||
710 | 66 | id: existingAccountComponent | ||
711 | 67 | Options {} | ||
712 | 68 | } | ||
713 | 69 | } | ||
714 | 70 | |||
715 | 71 | Button { | ||
716 | 72 | id: btnConfirm | ||
717 | 73 | text: i18n.tr("Continue") | ||
718 | 74 | color: UbuntuColors.orange | ||
719 | 75 | anchors { | ||
720 | 76 | left: parent.left | ||
721 | 77 | right: parent.right | ||
722 | 78 | bottom: btnCancel.top | ||
723 | 79 | margins: units.gu(2) | ||
724 | 80 | bottomMargin: units.gu(1) | ||
725 | 81 | } | ||
726 | 82 | enabled: editPageLoader.item && editPageLoader.item.isValid | ||
727 | 83 | onClicked: { | ||
728 | 84 | if (editPageLoader.item) | ||
729 | 85 | editPageLoader.item.confirm() | ||
730 | 86 | } | ||
731 | 87 | |||
732 | 88 | } | ||
733 | 89 | |||
734 | 90 | Button { | ||
735 | 91 | id: btnCancel | ||
736 | 92 | |||
737 | 93 | text: i18n.tr("Cancel") | ||
738 | 94 | anchors { | ||
739 | 95 | left: parent.left | ||
740 | 96 | right: parent.right | ||
741 | 97 | bottom: parent.bottom | ||
742 | 98 | margins: units.gu(2) | ||
743 | 99 | bottomMargin: units.gu(1) | ||
744 | 100 | } | ||
745 | 101 | onClicked: { | ||
746 | 102 | if (editPageLoader.item) | ||
747 | 103 | editPageLoader.item.cancel() | ||
748 | 104 | } | ||
749 | 105 | } | ||
750 | 106 | } | ||
751 | 0 | 107 | ||
752 | === added file 'accounts/common/NewAccountInterface.qml' | |||
753 | --- accounts/common/NewAccountInterface.qml 1970-01-01 00:00:00 +0000 | |||
754 | +++ accounts/common/NewAccountInterface.qml 2017-04-05 14:05:16 +0000 | |||
755 | @@ -0,0 +1,314 @@ | |||
756 | 1 | /* | ||
757 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
758 | 3 | * | ||
759 | 4 | * Authors: | ||
760 | 5 | * Renato Araujo Oliveira Filho <renato.filho@canonical.com> | ||
761 | 6 | * | ||
762 | 7 | * This file is part of telephony-service. | ||
763 | 8 | * | ||
764 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
765 | 10 | * it under the terms of the GNU General Public License as published by | ||
766 | 11 | * the Free Software Foundation; version 3. | ||
767 | 12 | * | ||
768 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
769 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
770 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
771 | 16 | * GNU General Public License for more details. | ||
772 | 17 | * | ||
773 | 18 | * You should have received a copy of the GNU General Public License | ||
774 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
775 | 20 | */ | ||
776 | 21 | |||
777 | 22 | import QtQuick 2.0 | ||
778 | 23 | import Ubuntu.Components 1.3 | ||
779 | 24 | import Ubuntu.OnlineAccounts 0.1 | ||
780 | 25 | |||
781 | 26 | Item { | ||
782 | 27 | id: root | ||
783 | 28 | |||
784 | 29 | readonly property string keyPrefix: "telepathy/" | ||
785 | 30 | readonly property var accountObjectHandle: account ? account.objectHandle : undefined | ||
786 | 31 | readonly property alias isValid: paramsRepeater.fieldHasValues | ||
787 | 32 | |||
788 | 33 | property string manager | ||
789 | 34 | property string protocol | ||
790 | 35 | property string icon | ||
791 | 36 | property var params | ||
792 | 37 | property var advancedParams | ||
793 | 38 | property bool hasCrendentials: true | ||
794 | 39 | |||
795 | 40 | |||
796 | 41 | signal finished | ||
797 | 42 | height: fields.childrenRect.height + | ||
798 | 43 | units.gu(10) | ||
799 | 44 | |||
800 | 45 | function getAccountService() { | ||
801 | 46 | var service = serviceModel.get(0, "accountServiceHandle") | ||
802 | 47 | if (!service) { | ||
803 | 48 | console.warn("No service handle from model") | ||
804 | 49 | return null | ||
805 | 50 | } | ||
806 | 51 | |||
807 | 52 | return accountServiceComponent.createObject(null, | ||
808 | 53 | {"objectHandle": service}) | ||
809 | 54 | } | ||
810 | 55 | |||
811 | 56 | // virual | ||
812 | 57 | function extendedSettings(inputFields) | ||
813 | 58 | { | ||
814 | 59 | return {} | ||
815 | 60 | //Helper class to be extended by derived class | ||
816 | 61 | } | ||
817 | 62 | |||
818 | 63 | // virtual | ||
819 | 64 | function formatDisplayName(inputFields) | ||
820 | 65 | { | ||
821 | 66 | return inputFields['account'] | ||
822 | 67 | // Helper function that allow the derived class to format a different display name | ||
823 | 68 | } | ||
824 | 69 | |||
825 | 70 | function saveServiceSettings(serviceIM, creds) { | ||
826 | 71 | var settingsIM = serviceIM.settings | ||
827 | 72 | var inputFields = {} | ||
828 | 73 | |||
829 | 74 | settingsIM[root.keyPrefix + 'manager'] = root.manager | ||
830 | 75 | settingsIM[root.keyPrefix + 'protocol'] = root.protocol | ||
831 | 76 | settingsIM[root.keyPrefix + 'Icon'] = root.icon | ||
832 | 77 | |||
833 | 78 | // basic fields | ||
834 | 79 | for (var i=0; i < paramsRepeater.count; i++) { | ||
835 | 80 | var fieldData = root.params[i] | ||
836 | 81 | var field = paramsRepeater.itemAt(i) | ||
837 | 82 | var fieldParamName = root.keyPrefix + 'param-' + fieldData.name | ||
838 | 83 | |||
839 | 84 | if (field.isEmpty) { | ||
840 | 85 | delete settingsIM[fieldParamName] | ||
841 | 86 | } else { | ||
842 | 87 | inputFields[fieldData.name] = field.value | ||
843 | 88 | if (fieldData.store) { | ||
844 | 89 | settingsIM[fieldParamName] = field.value | ||
845 | 90 | } | ||
846 | 91 | } | ||
847 | 92 | } | ||
848 | 93 | |||
849 | 94 | // advanced fields | ||
850 | 95 | for (var i=0; i < advancedParamsRepeater.count; i++) { | ||
851 | 96 | var xFieldData = root.advancedParams[i] | ||
852 | 97 | var xField = advancedParamsRepeater.itemAt(i) | ||
853 | 98 | var xFieldParamName = root.keyPrefix + 'param-' + xFieldData.name | ||
854 | 99 | |||
855 | 100 | if (xField.isEmpty) { | ||
856 | 101 | delete settingsIM[xFieldParamName] | ||
857 | 102 | } else { | ||
858 | 103 | inputFields[xFieldData.name] = xField.value | ||
859 | 104 | |||
860 | 105 | if (xFieldData.store) { | ||
861 | 106 | settingsIM[xFieldParamName] = xField.value | ||
862 | 107 | } | ||
863 | 108 | } | ||
864 | 109 | } | ||
865 | 110 | |||
866 | 111 | |||
867 | 112 | var xSettings = extendedSettings(inputFields) | ||
868 | 113 | for (var key in xSettings) { | ||
869 | 114 | settingsIM[root.keyPrefix + key] = xSettings[key] | ||
870 | 115 | } | ||
871 | 116 | |||
872 | 117 | account.updateDisplayName(formatDisplayName(inputFields)) | ||
873 | 118 | |||
874 | 119 | serviceIM.updateSettings(settingsIM) | ||
875 | 120 | //serviceIM.credentials = creds | ||
876 | 121 | //serviceIM.updateServiceEnabled(true) | ||
877 | 122 | } | ||
878 | 123 | |||
879 | 124 | function continueAccountSave(creds) { | ||
880 | 125 | var imService = root.getAccountService() | ||
881 | 126 | if (!imService) { | ||
882 | 127 | console.warn("Fail to retrieve account service") | ||
883 | 128 | return | ||
884 | 129 | } | ||
885 | 130 | |||
886 | 131 | root.saveServiceSettings(imService, creds) | ||
887 | 132 | if (creds) | ||
888 | 133 | globalAccountService.credentials = creds | ||
889 | 134 | globalAccountService.updateServiceEnabled(true) | ||
890 | 135 | |||
891 | 136 | account.synced.connect(root.finished) | ||
892 | 137 | account.sync() | ||
893 | 138 | } | ||
894 | 139 | |||
895 | 140 | function credentialsStored() { | ||
896 | 141 | if (creds.credentialsId === 0) { | ||
897 | 142 | console.warn("Credentials not stored correct") | ||
898 | 143 | return | ||
899 | 144 | } | ||
900 | 145 | |||
901 | 146 | var imService = root.getAccountService() | ||
902 | 147 | if (!imService) { | ||
903 | 148 | console.warn("Fail to retrieve account service") | ||
904 | 149 | return | ||
905 | 150 | } | ||
906 | 151 | |||
907 | 152 | continueAccountSave(creds) | ||
908 | 153 | } | ||
909 | 154 | |||
910 | 155 | function parseCrendentials() { | ||
911 | 156 | var credentials = {'userName': '', 'password': ''} | ||
912 | 157 | |||
913 | 158 | for (var i=0; i < paramsRepeater.count; i++) { | ||
914 | 159 | var fieldData = root.params[i] | ||
915 | 160 | var field = paramsRepeater.itemAt(i) | ||
916 | 161 | |||
917 | 162 | if (fieldData.name === 'account') | ||
918 | 163 | credentials['userName'] = field.value | ||
919 | 164 | |||
920 | 165 | if (fieldData.name === 'password') | ||
921 | 166 | credentials['password'] = field.value | ||
922 | 167 | } | ||
923 | 168 | |||
924 | 169 | return credentials | ||
925 | 170 | } | ||
926 | 171 | |||
927 | 172 | function cancel() { | ||
928 | 173 | account.removed.connect(root.finished) | ||
929 | 174 | account.remove(Account.RemoveCredentials) | ||
930 | 175 | } | ||
931 | 176 | |||
932 | 177 | function confirm() { | ||
933 | 178 | var info = root.parseCrendentials() | ||
934 | 179 | // save account | ||
935 | 180 | account.updateDisplayName(info.userName) | ||
936 | 181 | if (root.hasCrendentials) { | ||
937 | 182 | creds.userName = info.userName | ||
938 | 183 | creds.secret = info.password | ||
939 | 184 | creds.sync() | ||
940 | 185 | } else { | ||
941 | 186 | continueAccountSave(null) | ||
942 | 187 | } | ||
943 | 188 | } | ||
944 | 189 | |||
945 | 190 | Column { | ||
946 | 191 | id: fields | ||
947 | 192 | |||
948 | 193 | anchors { | ||
949 | 194 | top: parent.top | ||
950 | 195 | topMargin: units.gu(5) | ||
951 | 196 | left: parent.left | ||
952 | 197 | right: parent.right | ||
953 | 198 | } | ||
954 | 199 | height: childrenRect.height | ||
955 | 200 | spacing: units.gu(2) | ||
956 | 201 | |||
957 | 202 | Icon { | ||
958 | 203 | anchors.horizontalCenter: fields.horizontalCenter | ||
959 | 204 | name: root.icon | ||
960 | 205 | } | ||
961 | 206 | |||
962 | 207 | Repeater { | ||
963 | 208 | id: paramsRepeater | ||
964 | 209 | |||
965 | 210 | property bool fieldHasValues: false | ||
966 | 211 | |||
967 | 212 | function checkFieldsHasValues() | ||
968 | 213 | { | ||
969 | 214 | var hasEmptyField = false | ||
970 | 215 | for (var i = 0; i < paramsRepeater.count; i++) { | ||
971 | 216 | |||
972 | 217 | var child = paramsRepeater.itemAt(i) | ||
973 | 218 | if (child && child.isEmpty) { | ||
974 | 219 | hasEmptyField = true | ||
975 | 220 | break | ||
976 | 221 | } | ||
977 | 222 | } | ||
978 | 223 | fieldHasValues = !hasEmptyField | ||
979 | 224 | } | ||
980 | 225 | |||
981 | 226 | width: parent.width | ||
982 | 227 | model: root.params | ||
983 | 228 | DynamicField { | ||
984 | 229 | model: modelData | ||
985 | 230 | anchors{ | ||
986 | 231 | left: parent.left | ||
987 | 232 | right: parent.right | ||
988 | 233 | margins: units.gu(4) | ||
989 | 234 | } | ||
990 | 235 | onValueChanged: paramsRepeater.checkFieldsHasValues() | ||
991 | 236 | } | ||
992 | 237 | } | ||
993 | 238 | |||
994 | 239 | Item { | ||
995 | 240 | id: div | ||
996 | 241 | |||
997 | 242 | anchors{ | ||
998 | 243 | left: parent.left | ||
999 | 244 | right: parent.right | ||
1000 | 245 | } | ||
1001 | 246 | height: units.gu(3) | ||
1002 | 247 | visible: root.advancedParams.length > 0 | ||
1003 | 248 | } | ||
1004 | 249 | |||
1005 | 250 | Label { | ||
1006 | 251 | id: advancedParamsTitle | ||
1007 | 252 | |||
1008 | 253 | anchors{ | ||
1009 | 254 | left: parent.left | ||
1010 | 255 | right: parent.right | ||
1011 | 256 | margins: units.gu(4) | ||
1012 | 257 | } | ||
1013 | 258 | visible: root.advancedParams.length > 0 | ||
1014 | 259 | text: i18n.tr("Advanced Options") | ||
1015 | 260 | textSize: Label.Medium | ||
1016 | 261 | } | ||
1017 | 262 | |||
1018 | 263 | Repeater { | ||
1019 | 264 | id: advancedParamsRepeater | ||
1020 | 265 | |||
1021 | 266 | width: parent.width | ||
1022 | 267 | model: root.advancedParams | ||
1023 | 268 | DynamicField { | ||
1024 | 269 | model: modelData | ||
1025 | 270 | anchors{ | ||
1026 | 271 | left: parent.left | ||
1027 | 272 | right: parent.right | ||
1028 | 273 | margins: units.gu(4) | ||
1029 | 274 | } | ||
1030 | 275 | } | ||
1031 | 276 | } | ||
1032 | 277 | } | ||
1033 | 278 | |||
1034 | 279 | AccountService { | ||
1035 | 280 | id: globalAccountService | ||
1036 | 281 | |||
1037 | 282 | objectHandle: account.accountServiceHandle | ||
1038 | 283 | autoSync: false | ||
1039 | 284 | } | ||
1040 | 285 | |||
1041 | 286 | Credentials { | ||
1042 | 287 | id: creds | ||
1043 | 288 | |||
1044 | 289 | caption: account.provider.id | ||
1045 | 290 | acl: "*" // untill later | ||
1046 | 291 | storeSecret: true | ||
1047 | 292 | onCredentialsIdChanged: { | ||
1048 | 293 | console.debug("Credetials id changed") | ||
1049 | 294 | root.credentialsStored() | ||
1050 | 295 | } | ||
1051 | 296 | } | ||
1052 | 297 | |||
1053 | 298 | // necessary to store settings on the "IM" service | ||
1054 | 299 | AccountServiceModel { | ||
1055 | 300 | id: serviceModel | ||
1056 | 301 | |||
1057 | 302 | includeDisabled: true | ||
1058 | 303 | account: root.accountObjectHandle | ||
1059 | 304 | serviceType: "IM" | ||
1060 | 305 | } | ||
1061 | 306 | |||
1062 | 307 | Component { | ||
1063 | 308 | id: accountServiceComponent | ||
1064 | 309 | |||
1065 | 310 | AccountService { | ||
1066 | 311 | autoSync: false | ||
1067 | 312 | } | ||
1068 | 313 | } | ||
1069 | 314 | } | ||
1070 | 0 | 315 | ||
1071 | === added directory 'accounts/irc' | |||
1072 | === added file 'accounts/irc/CMakeLists.txt' | |||
1073 | --- accounts/irc/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1074 | +++ accounts/irc/CMakeLists.txt 2017-04-05 14:05:16 +0000 | |||
1075 | @@ -0,0 +1,2 @@ | |||
1076 | 1 | add_subdirectory(qml) | ||
1077 | 2 | add_subdirectory(data) | ||
1078 | 0 | 3 | ||
1079 | === added directory 'accounts/irc/data' | |||
1080 | === added file 'accounts/irc/data/CMakeLists.txt' | |||
1081 | --- accounts/irc/data/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1082 | +++ accounts/irc/data/CMakeLists.txt 2017-04-05 14:05:16 +0000 | |||
1083 | @@ -0,0 +1,5 @@ | |||
1084 | 1 | file(GLOB PROVIDER_FILES *.provider) | ||
1085 | 2 | install(FILES ${PROVIDER_FILES} DESTINATION share/accounts/providers/) | ||
1086 | 3 | |||
1087 | 4 | file(GLOB SERVICE_FILES *.service) | ||
1088 | 5 | install(FILES ${SERVICE_FILES} DESTINATION share/accounts/services/) | ||
1089 | 0 | 6 | ||
1090 | === added file 'accounts/irc/data/telephony-irc-im.service' | |||
1091 | --- accounts/irc/data/telephony-irc-im.service 1970-01-01 00:00:00 +0000 | |||
1092 | +++ accounts/irc/data/telephony-irc-im.service 2017-04-05 14:05:16 +0000 | |||
1093 | @@ -0,0 +1,22 @@ | |||
1094 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
1095 | 2 | <service id="telephony-irc-im"> | ||
1096 | 3 | <type>IM</type> | ||
1097 | 4 | <name>IRC</name> | ||
1098 | 5 | <icon>irc</icon> | ||
1099 | 6 | <provider>telephony-irc</provider> | ||
1100 | 7 | |||
1101 | 8 | <!-- default settings (account settings have precedence over these) --> | ||
1102 | 9 | <template> | ||
1103 | 10 | <group name="telepathy"> | ||
1104 | 11 | <setting name="manager">irc</setting> | ||
1105 | 12 | <setting name="protocol">irc</setting> | ||
1106 | 13 | <setting name="ConnectAutomatically">false</setting> | ||
1107 | 14 | <setting type="s" name="AutomaticPresence">1;offline;;</setting> | ||
1108 | 15 | </group> | ||
1109 | 16 | <group name="auth"> | ||
1110 | 17 | <setting name="method">password</setting> | ||
1111 | 18 | <setting name="mechanism">password</setting> | ||
1112 | 19 | </group> | ||
1113 | 20 | </template> | ||
1114 | 21 | |||
1115 | 22 | </service> | ||
1116 | 0 | 23 | ||
1117 | === added file 'accounts/irc/data/telephony-irc.provider' | |||
1118 | --- accounts/irc/data/telephony-irc.provider 1970-01-01 00:00:00 +0000 | |||
1119 | +++ accounts/irc/data/telephony-irc.provider 2017-04-05 14:05:16 +0000 | |||
1120 | @@ -0,0 +1,5 @@ | |||
1121 | 1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
1122 | 2 | <provider id="telephony-irc"> | ||
1123 | 3 | <name>IRC</name> | ||
1124 | 4 | <icon>irc</icon> | ||
1125 | 5 | </provider> | ||
1126 | 0 | 6 | ||
1127 | === added directory 'accounts/irc/qml' | |||
1128 | === added file 'accounts/irc/qml/AccountInfo.qml' | |||
1129 | === added file 'accounts/irc/qml/CMakeLists.txt' | |||
1130 | --- accounts/irc/qml/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1131 | +++ accounts/irc/qml/CMakeLists.txt 2017-04-05 14:05:16 +0000 | |||
1132 | @@ -0,0 +1,13 @@ | |||
1133 | 1 | file(GLOB QML_PLUGIN_FILES *.qml) | ||
1134 | 2 | |||
1135 | 3 | # The path (including plug-in name) where the QML files are installed | ||
1136 | 4 | set(QML_PLUGIN_INSTALL_DIR share/accounts/qml-plugins/telephony-irc/) | ||
1137 | 5 | |||
1138 | 6 | # Do not install symbolic links | ||
1139 | 7 | set (QML_PLUGIN_RESOLVED_FILES "") | ||
1140 | 8 | foreach (QML_PLUGIN_FILE ${QML_PLUGIN_FILES}) | ||
1141 | 9 | get_filename_component(resolvedFile "${QML_PLUGIN_FILE}" REALPATH) | ||
1142 | 10 | list (APPEND QML_PLUGIN_RESOLVED_FILES "${resolvedFile}") | ||
1143 | 11 | endforeach() | ||
1144 | 12 | |||
1145 | 13 | install(FILES ${QML_PLUGIN_RESOLVED_FILES} DESTINATION ${QML_PLUGIN_INSTALL_DIR}) | ||
1146 | 0 | 14 | ||
1147 | === added symlink 'accounts/irc/qml/DynamicField.qml' | |||
1148 | === target is u'../../common/DynamicField.qml' | |||
1149 | === added symlink 'accounts/irc/qml/Main.qml' | |||
1150 | === target is u'../../common/Main.qml' | |||
1151 | === added file 'accounts/irc/qml/NewAccount.qml' | |||
1152 | --- accounts/irc/qml/NewAccount.qml 1970-01-01 00:00:00 +0000 | |||
1153 | +++ accounts/irc/qml/NewAccount.qml 2017-04-05 14:05:16 +0000 | |||
1154 | @@ -0,0 +1,63 @@ | |||
1155 | 1 | /* | ||
1156 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
1157 | 3 | * | ||
1158 | 4 | * Authors: | ||
1159 | 5 | * Renato Araujo Oliveira Filho <renato.filho@canonical.com> | ||
1160 | 6 | * | ||
1161 | 7 | * This file is part of telephony-service. | ||
1162 | 8 | * | ||
1163 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
1164 | 10 | * it under the terms of the GNU General Public License as published by | ||
1165 | 11 | * the Free Software Foundation; version 3. | ||
1166 | 12 | * | ||
1167 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
1168 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1169 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1170 | 16 | * GNU General Public License for more details. | ||
1171 | 17 | * | ||
1172 | 18 | * You should have received a copy of the GNU General Public License | ||
1173 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1174 | 20 | */ | ||
1175 | 21 | |||
1176 | 22 | import QtQuick 2.0 | ||
1177 | 23 | |||
1178 | 24 | NewAccountInterface { | ||
1179 | 25 | id: root | ||
1180 | 26 | |||
1181 | 27 | anchors { | ||
1182 | 28 | left: parent.left | ||
1183 | 29 | right: parent.right | ||
1184 | 30 | verticalCenter: parent.verticalCenter | ||
1185 | 31 | } | ||
1186 | 32 | |||
1187 | 33 | manager: 'irc' | ||
1188 | 34 | protocol: 'irc' | ||
1189 | 35 | icon: 'irc' | ||
1190 | 36 | hasCrendentials: false | ||
1191 | 37 | params: [ | ||
1192 | 38 | {'name': 'server', 'inputType': 'string', 'label': i18n.tr('Network. (Eg: chat.freenode.net)'), 'store': true}, | ||
1193 | 39 | {'name': 'nickname', 'inputType': 'string', 'label': i18n.tr('Nickname'), 'store': true}, | ||
1194 | 40 | ] | ||
1195 | 41 | advancedParams: [ | ||
1196 | 42 | {'name': 'port', 'inputType': 'numeric', 'label': i18n.tr('Port'), 'store': true}, | ||
1197 | 43 | {'name': 'use-ssl', 'inputType': 'boolean', 'label': i18n.tr('Use ssl'), 'store': true}, | ||
1198 | 44 | {'name': 'verify-ssl-cert', 'inputType': 'boolean', 'label': i18n.tr('Verify ssl certificate'), 'store': true}, | ||
1199 | 45 | {'name': 'username', 'inputType': 'string', 'label': i18n.tr('Username'), 'store': true}, | ||
1200 | 46 | {'name': 'password', 'inputType': 'password', 'label': i18n.tr('Password'), 'store': true}, | ||
1201 | 47 | {'name': 'fullname', 'inputType': 'string', 'label': i18n.tr('Real name'), 'store': true}, | ||
1202 | 48 | ] | ||
1203 | 49 | |||
1204 | 50 | function extendedSettings(inputFields) | ||
1205 | 51 | { | ||
1206 | 52 | var settings = {} | ||
1207 | 53 | settings['param-account'] = inputFields['nickname'] + "@" + inputFields['server'] | ||
1208 | 54 | if (settings['param-port'] == "") | ||
1209 | 55 | settings['param-port'] = "6667" | ||
1210 | 56 | return settings | ||
1211 | 57 | } | ||
1212 | 58 | |||
1213 | 59 | function formatDisplayName(inputFields) | ||
1214 | 60 | { | ||
1215 | 61 | return inputFields['nickname'] + "@" + inputFields['server'] | ||
1216 | 62 | } | ||
1217 | 63 | } | ||
1218 | 0 | 64 | ||
1219 | === added symlink 'accounts/irc/qml/NewAccountInterface.qml' | |||
1220 | === target is u'../../common/NewAccountInterface.qml' | |||
1221 | === added directory 'accounts/sip' | |||
1222 | === added file 'accounts/sip/CMakeLists.txt' | |||
1223 | --- accounts/sip/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1224 | +++ accounts/sip/CMakeLists.txt 2017-04-05 14:05:16 +0000 | |||
1225 | @@ -0,0 +1,2 @@ | |||
1226 | 1 | add_subdirectory(qml) | ||
1227 | 2 | add_subdirectory(data) | ||
1228 | 0 | 3 | ||
1229 | === added directory 'accounts/sip/data' | |||
1230 | === added file 'accounts/sip/data/CMakeLists.txt' | |||
1231 | --- accounts/sip/data/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1232 | +++ accounts/sip/data/CMakeLists.txt 2017-04-05 14:05:16 +0000 | |||
1233 | @@ -0,0 +1,5 @@ | |||
1234 | 1 | file(GLOB PROVIDER_FILES *.provider) | ||
1235 | 2 | install(FILES ${PROVIDER_FILES} DESTINATION share/accounts/providers/) | ||
1236 | 3 | |||
1237 | 4 | file(GLOB SERVICE_FILES *.service) | ||
1238 | 5 | install(FILES ${SERVICE_FILES} DESTINATION share/accounts/services/) | ||
1239 | 0 | 6 | ||
1240 | === added file 'accounts/sip/data/telephony-sip-im.service' | |||
1241 | --- accounts/sip/data/telephony-sip-im.service 1970-01-01 00:00:00 +0000 | |||
1242 | +++ accounts/sip/data/telephony-sip-im.service 2017-04-05 14:05:16 +0000 | |||
1243 | @@ -0,0 +1,22 @@ | |||
1244 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
1245 | 2 | <service id="telephony-sip-im"> | ||
1246 | 3 | <type>IM</type> | ||
1247 | 4 | <name>SIP</name> | ||
1248 | 5 | <icon>sip</icon> | ||
1249 | 6 | <provider>telephony-sip</provider> | ||
1250 | 7 | |||
1251 | 8 | <!-- default settings (account settings have precedence over these) --> | ||
1252 | 9 | <template> | ||
1253 | 10 | <group name="telepathy"> | ||
1254 | 11 | <setting name="manager">sofiasip</setting> | ||
1255 | 12 | <setting name="protocol">sip</setting> | ||
1256 | 13 | <setting name="ConnectAutomatically">true</setting> | ||
1257 | 14 | <setting type="s" name="AutomaticPresence">2;available;;</setting> | ||
1258 | 15 | </group> | ||
1259 | 16 | <group name="auth"> | ||
1260 | 17 | <setting name="method">password</setting> | ||
1261 | 18 | <setting name="mechanism">password</setting> | ||
1262 | 19 | </group> | ||
1263 | 20 | </template> | ||
1264 | 21 | |||
1265 | 22 | </service> | ||
1266 | 0 | 23 | ||
1267 | === added file 'accounts/sip/data/telephony-sip.provider' | |||
1268 | --- accounts/sip/data/telephony-sip.provider 1970-01-01 00:00:00 +0000 | |||
1269 | +++ accounts/sip/data/telephony-sip.provider 2017-04-05 14:05:16 +0000 | |||
1270 | @@ -0,0 +1,5 @@ | |||
1271 | 1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
1272 | 2 | <provider id="telephony-sip"> | ||
1273 | 3 | <name>SIP</name> | ||
1274 | 4 | <icon>sip</icon> | ||
1275 | 5 | </provider> | ||
1276 | 0 | 6 | ||
1277 | === added directory 'accounts/sip/qml' | |||
1278 | === added file 'accounts/sip/qml/AccountInfo.qml' | |||
1279 | === added file 'accounts/sip/qml/CMakeLists.txt' | |||
1280 | --- accounts/sip/qml/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1281 | +++ accounts/sip/qml/CMakeLists.txt 2017-04-05 14:05:16 +0000 | |||
1282 | @@ -0,0 +1,13 @@ | |||
1283 | 1 | file(GLOB QML_PLUGIN_FILES *.qml) | ||
1284 | 2 | |||
1285 | 3 | # The path (including plug-in name) where the QML files are installed | ||
1286 | 4 | set(QML_PLUGIN_INSTALL_DIR share/accounts/qml-plugins/telephony-sip/) | ||
1287 | 5 | |||
1288 | 6 | # Do not install symbolic links | ||
1289 | 7 | set (QML_PLUGIN_RESOLVED_FILES "") | ||
1290 | 8 | foreach (QML_PLUGIN_FILE ${QML_PLUGIN_FILES}) | ||
1291 | 9 | get_filename_component(resolvedFile "${QML_PLUGIN_FILE}" REALPATH) | ||
1292 | 10 | list (APPEND QML_PLUGIN_RESOLVED_FILES "${resolvedFile}") | ||
1293 | 11 | endforeach() | ||
1294 | 12 | |||
1295 | 13 | install(FILES ${QML_PLUGIN_RESOLVED_FILES} DESTINATION ${QML_PLUGIN_INSTALL_DIR}) | ||
1296 | 0 | 14 | ||
1297 | === added symlink 'accounts/sip/qml/DynamicField.qml' | |||
1298 | === target is u'../../common/DynamicField.qml' | |||
1299 | === added symlink 'accounts/sip/qml/Main.qml' | |||
1300 | === target is u'../../common/Main.qml' | |||
1301 | === added file 'accounts/sip/qml/NewAccount.qml' | |||
1302 | --- accounts/sip/qml/NewAccount.qml 1970-01-01 00:00:00 +0000 | |||
1303 | +++ accounts/sip/qml/NewAccount.qml 2017-04-05 14:05:16 +0000 | |||
1304 | @@ -0,0 +1,48 @@ | |||
1305 | 1 | /* | ||
1306 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
1307 | 3 | * | ||
1308 | 4 | * Authors: | ||
1309 | 5 | * Renato Araujo Oliveira Filho <renato.filho@canonical.com> | ||
1310 | 6 | * | ||
1311 | 7 | * This file is part of telephony-service. | ||
1312 | 8 | * | ||
1313 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
1314 | 10 | * it under the terms of the GNU General Public License as published by | ||
1315 | 11 | * the Free Software Foundation; version 3. | ||
1316 | 12 | * | ||
1317 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
1318 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1319 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1320 | 16 | * GNU General Public License for more details. | ||
1321 | 17 | * | ||
1322 | 18 | * You should have received a copy of the GNU General Public License | ||
1323 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1324 | 20 | */ | ||
1325 | 21 | |||
1326 | 22 | import QtQuick 2.0 | ||
1327 | 23 | |||
1328 | 24 | NewAccountInterface { | ||
1329 | 25 | id: root | ||
1330 | 26 | |||
1331 | 27 | manager: 'sofiasip' | ||
1332 | 28 | protocol: 'sip' | ||
1333 | 29 | icon: 'sip' | ||
1334 | 30 | hasCrendentials: false | ||
1335 | 31 | params: [ | ||
1336 | 32 | {'name': 'account', 'inputType': 'string', 'label': i18n.tr('Sip Id. (Eg: user@my.sip.net)'), 'store': true}, | ||
1337 | 33 | {'name': 'password', 'inputType': 'password', 'label': i18n.tr('Password'), 'store': true} | ||
1338 | 34 | ] | ||
1339 | 35 | advancedParams: [ | ||
1340 | 36 | {'name': 'discover-stun', 'inputType': 'boolean', 'label': i18n.tr('Discover the STUN server automatically'), 'store': true, 'defaultValue' : 'false' }, | ||
1341 | 37 | {'name': 'stun-server', 'inputType': 'string', 'label': i18n.tr('STUN server'), 'store': true}, | ||
1342 | 38 | {'name': 'stun-port', 'inputType': 'numeric', 'label': i18n.tr('STUN port'), 'store': true}, | ||
1343 | 39 | {'name': 'discover-binding', 'inputType': 'boolean', 'label': i18n.tr('Divscover Binding'), 'store': true, 'defaultValue': 'true'}, | ||
1344 | 40 | {'name': 'proxy-host', 'inputType': 'string', 'label': i18n.tr('Proxy server'), 'store': true}, | ||
1345 | 41 | {'name': 'port', 'inputType': 'numeric', 'label': i18n.tr('Proxy port'), 'store': true}, | ||
1346 | 42 | {'name': 'keepalive-mechanism', 'inputType': 'string', 'label': i18n.tr('Keep alive mechanism'), 'store': true, 'defaultValue': 'auto'}, | ||
1347 | 43 | {'name': 'keepalive-interval', 'inputType': 'numeric', 'label': i18n.tr('Keep alive interval'), 'store': true}, | ||
1348 | 44 | {'name': 'auth-user', 'inputType': 'string', 'label': i18n.tr('Authentication username'), 'store': true}, | ||
1349 | 45 | {'name': 'transport', 'inputType': 'string', 'label': i18n.tr('Transport'), 'store': true, 'defaultValue': 'auto'}, | ||
1350 | 46 | {'name': 'loose-routing', 'inputType': 'boolean', 'label': i18n.tr('Loose Routing'), 'store': true, 'defaultValue': 'false'} | ||
1351 | 47 | ] | ||
1352 | 48 | } | ||
1353 | 0 | 49 | ||
1354 | === added symlink 'accounts/sip/qml/NewAccountInterface.qml' | |||
1355 | === target is u'../../common/NewAccountInterface.qml' | |||
1356 | === modified file 'approver/approver.cpp' | |||
1357 | --- approver/approver.cpp 2016-11-23 19:28:18 +0000 | |||
1358 | +++ approver/approver.cpp 2017-04-05 14:05:16 +0000 | |||
1359 | @@ -1,5 +1,5 @@ | |||
1360 | 1 | /* | 1 | /* |
1362 | 2 | * Copyright (C) 2012-2016 Canonical, Ltd. | 2 | * Copyright (C) 2012-2017 Canonical, Ltd. |
1363 | 3 | * | 3 | * |
1364 | 4 | * Authors: | 4 | * Authors: |
1365 | 5 | * Tiago Salem Herrmann <tiago.herrmann@canonical.com> | 5 | * Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
1366 | @@ -27,10 +27,12 @@ | |||
1367 | 27 | #include "chatmanager.h" | 27 | #include "chatmanager.h" |
1368 | 28 | #include "config.h" | 28 | #include "config.h" |
1369 | 29 | #include "contactutils.h" | 29 | #include "contactutils.h" |
1370 | 30 | #include "contactwatcher.h" | ||
1371 | 30 | #include "greetercontacts.h" | 31 | #include "greetercontacts.h" |
1372 | 31 | #include "ringtone.h" | 32 | #include "ringtone.h" |
1373 | 32 | #include "callmanager.h" | 33 | #include "callmanager.h" |
1374 | 33 | #include "callentry.h" | 34 | #include "callentry.h" |
1375 | 35 | #include "protocol.h" | ||
1376 | 34 | #include "protocolmanager.h" | 36 | #include "protocolmanager.h" |
1377 | 35 | #include "tonegenerator.h" | 37 | #include "tonegenerator.h" |
1378 | 36 | #include "telepathyhelper.h" | 38 | #include "telepathyhelper.h" |
1379 | @@ -315,11 +317,13 @@ | |||
1380 | 315 | 317 | ||
1381 | 316 | mChannels.remove(pr); | 318 | mChannels.remove(pr); |
1382 | 317 | 319 | ||
1383 | 320 | QString id = ContactWatcher::normalizeIdentifier(contact->id(), true); | ||
1384 | 321 | |||
1385 | 318 | // and now set up the contact matching for either greeter mode or regular mode | 322 | // and now set up the contact matching for either greeter mode or regular mode |
1386 | 319 | if (GreeterContacts::isGreeterMode()) { | 323 | if (GreeterContacts::isGreeterMode()) { |
1387 | 320 | // show the snap decision right away because contact info might never arrive | 324 | // show the snap decision right away because contact info might never arrive |
1388 | 321 | showSnapDecision(dispatchOp, channel); | 325 | showSnapDecision(dispatchOp, channel); |
1390 | 322 | GreeterContacts::instance()->setContactFilter(QContactPhoneNumber::match(contact->id())); | 326 | GreeterContacts::instance()->setContactFilter(QContactPhoneNumber::match(id)); |
1391 | 323 | } else { | 327 | } else { |
1392 | 324 | AccountEntry *account = TelepathyHelper::instance()->accountForConnection(callChannel->connection()); | 328 | AccountEntry *account = TelepathyHelper::instance()->accountForConnection(callChannel->connection()); |
1393 | 325 | if (!account) { | 329 | if (!account) { |
1394 | @@ -329,7 +333,7 @@ | |||
1395 | 329 | 333 | ||
1396 | 330 | // try to match the contact info | 334 | // try to match the contact info |
1397 | 331 | QContactFetchRequest *request = new QContactFetchRequest(this); | 335 | QContactFetchRequest *request = new QContactFetchRequest(this); |
1399 | 332 | request->setFilter(QContactPhoneNumber::match(contact->id())); | 336 | request->setFilter(QContactPhoneNumber::match(id)); |
1400 | 333 | 337 | ||
1401 | 334 | // lambda function to update the notification | 338 | // lambda function to update the notification |
1402 | 335 | QObject::connect(request, &QContactAbstractRequest::stateChanged, [this, request, dispatchOp, channel](QContactAbstractRequest::State state) { | 339 | QObject::connect(request, &QContactAbstractRequest::stateChanged, [this, request, dispatchOp, channel](QContactAbstractRequest::State state) { |
1403 | @@ -350,14 +354,9 @@ | |||
1404 | 350 | showSnapDecision(dispatchOp, channel, contact); | 354 | showSnapDecision(dispatchOp, channel, contact); |
1405 | 351 | }); | 355 | }); |
1406 | 352 | 356 | ||
1415 | 353 | // FIXME: For accounts not based on phone numbers, don't try to match contacts for now | 357 | // FIXME: For accounts not based on phone numbers, check what to do |
1416 | 354 | if (account->type() == AccountEntry::PhoneAccount) { | 358 | request->setManager(ContactUtils::sharedManager()); |
1417 | 355 | request->setManager(ContactUtils::sharedManager()); | 359 | request->start(); |
1410 | 356 | request->start(); | ||
1411 | 357 | } else { | ||
1412 | 358 | // just emit the signal to pretend we did a contact search | ||
1413 | 359 | Q_EMIT request->stateChanged(QContactAbstractRequest::FinishedState); | ||
1414 | 360 | } | ||
1418 | 361 | } | 360 | } |
1419 | 362 | } | 361 | } |
1420 | 363 | 362 | ||
1421 | @@ -440,42 +439,46 @@ | |||
1422 | 440 | data->channel = channel; | 439 | data->channel = channel; |
1423 | 441 | bool unknownNumber = false; | 440 | bool unknownNumber = false; |
1424 | 442 | 441 | ||
1425 | 442 | QString id = ContactWatcher::normalizeIdentifier(telepathyContact->id(), true); | ||
1426 | 443 | |||
1427 | 443 | AccountEntry *account = TelepathyHelper::instance()->accountForConnection(channel->connection()); | 444 | AccountEntry *account = TelepathyHelper::instance()->accountForConnection(channel->connection()); |
1428 | 444 | if (!account) { | 445 | if (!account) { |
1429 | 445 | qCritical() << "Call exists with no account for connection"; | 446 | qCritical() << "Call exists with no account for connection"; |
1430 | 446 | return false; | 447 | return false; |
1431 | 447 | } | 448 | } |
1432 | 448 | 449 | ||
1433 | 450 | bool supportsText = (account->protocolInfo()->features() & Protocol::TextChats); | ||
1434 | 451 | |||
1435 | 449 | mCachedBody = QString(); | 452 | mCachedBody = QString(); |
1436 | 450 | 453 | ||
1437 | 451 | if (account->type() == AccountEntry::PhoneAccount && | 454 | if (account->type() == AccountEntry::PhoneAccount && |
1438 | 452 | TelepathyHelper::instance()->multiplePhoneAccounts()) { | 455 | TelepathyHelper::instance()->multiplePhoneAccounts()) { |
1439 | 453 | mCachedBody = QString::fromUtf8(C::gettext("On [%1]")).arg(account->displayName()); | 456 | mCachedBody = QString::fromUtf8(C::gettext("On [%1]")).arg(account->displayName()); |
1440 | 454 | mCachedBody += "\n"; | 457 | mCachedBody += "\n"; |
1443 | 455 | if (!telepathyContact->id().isEmpty()) { | 458 | if (!id.isEmpty()) { |
1444 | 456 | if (telepathyContact->id().startsWith(OFONO_PRIVATE_NUMBER)) { | 459 | if (id.startsWith(OFONO_PRIVATE_NUMBER)) { |
1445 | 457 | mCachedBody += QString::fromUtf8(C::gettext("Private number")); | 460 | mCachedBody += QString::fromUtf8(C::gettext("Private number")); |
1446 | 458 | unknownNumber = true; | 461 | unknownNumber = true; |
1448 | 459 | } else if (telepathyContact->id().startsWith(OFONO_UNKNOWN_NUMBER)) { | 462 | } else if (id.startsWith(OFONO_UNKNOWN_NUMBER)) { |
1449 | 460 | mCachedBody += QString::fromUtf8(C::gettext("Unknown number")); | 463 | mCachedBody += QString::fromUtf8(C::gettext("Unknown number")); |
1450 | 461 | unknownNumber = true; | 464 | unknownNumber = true; |
1451 | 462 | } else { | 465 | } else { |
1453 | 463 | mCachedBody += telepathyContact->id(); | 466 | mCachedBody += id; |
1454 | 464 | } | 467 | } |
1455 | 465 | } else { | 468 | } else { |
1456 | 466 | mCachedBody += C::gettext("Caller number is not available"); | 469 | mCachedBody += C::gettext("Caller number is not available"); |
1457 | 467 | unknownNumber = true; | 470 | unknownNumber = true; |
1458 | 468 | } | 471 | } |
1459 | 469 | } else { | 472 | } else { |
1462 | 470 | if (!telepathyContact->id().isEmpty()) { | 473 | if (!id.isEmpty()) { |
1463 | 471 | if (telepathyContact->id().startsWith(OFONO_PRIVATE_NUMBER)) { | 474 | if (id.startsWith(OFONO_PRIVATE_NUMBER)) { |
1464 | 472 | mCachedBody = QString::fromUtf8(C::gettext("Calling from private number")); | 475 | mCachedBody = QString::fromUtf8(C::gettext("Calling from private number")); |
1465 | 473 | unknownNumber = true; | 476 | unknownNumber = true; |
1467 | 474 | } else if (telepathyContact->id().startsWith(OFONO_UNKNOWN_NUMBER)) { | 477 | } else if (id.startsWith(OFONO_UNKNOWN_NUMBER)) { |
1468 | 475 | mCachedBody = QString::fromUtf8(C::gettext("Calling from unknown number")); | 478 | mCachedBody = QString::fromUtf8(C::gettext("Calling from unknown number")); |
1469 | 476 | unknownNumber = true; | 479 | unknownNumber = true; |
1470 | 477 | } else { | 480 | } else { |
1472 | 478 | mCachedBody = QString::fromUtf8(C::gettext("Calling from %1")).arg(telepathyContact->id()); | 481 | mCachedBody = QString::fromUtf8(C::gettext("Calling from %1")).arg(id); |
1473 | 479 | } | 482 | } |
1474 | 480 | } else { | 483 | } else { |
1475 | 481 | mCachedBody = C::gettext("Caller number is not available"); | 484 | mCachedBody = C::gettext("Caller number is not available"); |
1476 | @@ -544,7 +547,7 @@ | |||
1477 | 544 | data, | 547 | data, |
1478 | 545 | delete_event_data); | 548 | delete_event_data); |
1479 | 546 | 549 | ||
1481 | 547 | if (!unknownNumber) { | 550 | if (!unknownNumber && supportsText) { |
1482 | 548 | notify_notification_add_action(notification, | 551 | notify_notification_add_action(notification, |
1483 | 549 | "action_decline_expansion", | 552 | "action_decline_expansion", |
1484 | 550 | C::gettext("Message & decline"), | 553 | C::gettext("Message & decline"), |
1485 | 551 | 554 | ||
1486 | === modified file 'cmake/modules/GenerateTest.cmake' | |||
1487 | --- cmake/modules/GenerateTest.cmake 2016-12-13 01:51:47 +0000 | |||
1488 | +++ cmake/modules/GenerateTest.cmake 2017-04-05 14:05:16 +0000 | |||
1489 | @@ -78,6 +78,7 @@ | |||
1490 | 78 | MC_ACCOUNT_DIR=${TMPDIR} | 78 | MC_ACCOUNT_DIR=${TMPDIR} |
1491 | 79 | MC_MANAGER_DIR=${TMPDIR} | 79 | MC_MANAGER_DIR=${TMPDIR} |
1492 | 80 | MC_CLIENTS_DIR=${TMPDIR} | 80 | MC_CLIENTS_DIR=${TMPDIR} |
1493 | 81 | PA_DISABLED=1 | ||
1494 | 81 | TELEPHONY_SERVICE_TEST=1 | 82 | TELEPHONY_SERVICE_TEST=1 |
1495 | 82 | TELEPHONY_SERVICE_PROTOCOLS_DIR=${CMAKE_SOURCE_DIR}/tests/common/protocols | 83 | TELEPHONY_SERVICE_PROTOCOLS_DIR=${CMAKE_SOURCE_DIR}/tests/common/protocols |
1496 | 83 | TEST_DATA_DIR=${CMAKE_SOURCE_DIR}/tests/common/data) | 84 | TEST_DATA_DIR=${CMAKE_SOURCE_DIR}/tests/common/data) |
1497 | 84 | 85 | ||
1498 | === added file 'debian/account-plugin-irc-unity8.install' | |||
1499 | --- debian/account-plugin-irc-unity8.install 1970-01-01 00:00:00 +0000 | |||
1500 | +++ debian/account-plugin-irc-unity8.install 2017-04-05 14:05:16 +0000 | |||
1501 | @@ -0,0 +1,3 @@ | |||
1502 | 1 | usr/share/accounts/qml-plugins/telephony-irc/* | ||
1503 | 2 | usr/share/accounts/providers/telephony-irc.provider | ||
1504 | 3 | usr/share/accounts/services/telephony-irc-im.service | ||
1505 | 0 | 4 | ||
1506 | === added file 'debian/account-plugin-sip-unity8.install' | |||
1507 | --- debian/account-plugin-sip-unity8.install 1970-01-01 00:00:00 +0000 | |||
1508 | +++ debian/account-plugin-sip-unity8.install 2017-04-05 14:05:16 +0000 | |||
1509 | @@ -0,0 +1,3 @@ | |||
1510 | 1 | usr/share/accounts/qml-plugins/telephony-sip/* | ||
1511 | 2 | usr/share/accounts/providers/telephony-sip.provider | ||
1512 | 3 | usr/share/accounts/services/telephony-sip-im.service | ||
1513 | 0 | 4 | ||
1514 | === modified file 'debian/control' | |||
1515 | --- debian/control 2016-12-05 15:14:33 +0000 | |||
1516 | +++ debian/control 2017-04-05 14:05:16 +0000 | |||
1517 | @@ -13,10 +13,12 @@ | |||
1518 | 13 | libicu-dev, | 13 | libicu-dev, |
1519 | 14 | libmessaging-menu-dev, | 14 | libmessaging-menu-dev, |
1520 | 15 | libnotify-dev, | 15 | libnotify-dev, |
1521 | 16 | libgsettings-qt-dev, | ||
1522 | 16 | libphonenumber-dev, | 17 | libphonenumber-dev, |
1523 | 17 | libtelepathy-qt5-dev, | 18 | libtelepathy-qt5-dev, |
1524 | 18 | libubuntu-application-api-dev [armhf], | ||
1525 | 19 | libprotobuf-dev, | 19 | libprotobuf-dev, |
1526 | 20 | libpulse-dev, | ||
1527 | 21 | liburl-dispatcher1-dev, | ||
1528 | 20 | pkg-config, | 22 | pkg-config, |
1529 | 21 | python:any, | 23 | python:any, |
1530 | 22 | qml-module-qttest, | 24 | qml-module-qttest, |
1531 | @@ -92,3 +94,24 @@ | |||
1532 | 92 | This package contains the QML plugin providing the features from the telephony | 94 | This package contains the QML plugin providing the features from the telephony |
1533 | 93 | PhoneNumber to applications. | 95 | PhoneNumber to applications. |
1534 | 94 | 96 | ||
1535 | 97 | Package: account-plugin-sip-unity8 | ||
1536 | 98 | Architecture: all | ||
1537 | 99 | Pre-Depends: dpkg (>= 1.15.6~) | ||
1538 | 100 | Depends: mcp-account-manager-uoa-common, | ||
1539 | 101 | telepathy-accounts-signon, | ||
1540 | 102 | telepathy-rakia | ||
1541 | 103 | Description: Online account plugin for unity8 | ||
1542 | 104 | Online account plugin for unity8. | ||
1543 | 105 | . | ||
1544 | 106 | This package contains the online account plugin providing sip account. | ||
1545 | 107 | |||
1546 | 108 | Package: account-plugin-irc-unity8 | ||
1547 | 109 | Architecture: all | ||
1548 | 110 | Pre-Depends: dpkg (>= 1.15.6~) | ||
1549 | 111 | Depends: mcp-account-manager-uoa-common, | ||
1550 | 112 | mfw-plugin-irc | ||
1551 | 113 | Description: Online account plugin for unity8 | ||
1552 | 114 | Online account plugin for unity8. | ||
1553 | 115 | . | ||
1554 | 116 | This package contains the online account plugin providing irc account. | ||
1555 | 117 | |||
1556 | 95 | 118 | ||
1557 | === modified file 'handler/CMakeLists.txt' | |||
1558 | --- handler/CMakeLists.txt 2016-12-06 16:45:01 +0000 | |||
1559 | +++ handler/CMakeLists.txt 2017-04-05 14:05:16 +0000 | |||
1560 | @@ -1,12 +1,24 @@ | |||
1561 | 1 | if (PULSEAUDIO_FOUND) | ||
1562 | 2 | add_definitions(-DUSE_PULSEAUDIO) | ||
1563 | 3 | set(USE_PULSEAUDIO ON) | ||
1564 | 4 | set(QPULSEAUDIOENGINE_CPP qpulseaudioengine.cpp) | ||
1565 | 5 | endif (PULSEAUDIO_FOUND) | ||
1566 | 1 | 6 | ||
1567 | 2 | set(qt_SRCS | 7 | set(qt_SRCS |
1568 | 8 | accountproperties.cpp | ||
1569 | 9 | callagent.cpp | ||
1570 | 10 | audioroutemanager.cpp | ||
1571 | 3 | callhandler.cpp | 11 | callhandler.cpp |
1572 | 4 | chatstartingjob.cpp | 12 | chatstartingjob.cpp |
1573 | 13 | farstreamchannel.cpp | ||
1574 | 5 | handler.cpp | 14 | handler.cpp |
1575 | 6 | handlerdbus.cpp | 15 | handlerdbus.cpp |
1576 | 7 | messagejob.cpp | 16 | messagejob.cpp |
1577 | 8 | messagesendingjob.cpp | 17 | messagesendingjob.cpp |
1578 | 18 | powerdaudiomodemediator.cpp | ||
1579 | 19 | powerddbus.cpp | ||
1580 | 9 | texthandler.cpp | 20 | texthandler.cpp |
1581 | 21 | ${QPULSEAUDIOENGINE_CPP} | ||
1582 | 10 | ) | 22 | ) |
1583 | 11 | 23 | ||
1584 | 12 | set(handler_SRCS main.cpp ${qt_SRCS}) | 24 | set(handler_SRCS main.cpp ${qt_SRCS}) |
1585 | @@ -16,8 +28,13 @@ | |||
1586 | 16 | 28 | ||
1587 | 17 | include_directories( | 29 | include_directories( |
1588 | 18 | ${TP_QT5_INCLUDE_DIRS} | 30 | ${TP_QT5_INCLUDE_DIRS} |
1589 | 31 | ${TPFS_INCLUDE_DIRS} | ||
1590 | 32 | ${FS_INCLUDE_DIRS} | ||
1591 | 33 | ${GST_INCLUDE_DIRS} | ||
1592 | 19 | ${CMAKE_SOURCE_DIR}/libtelephonyservice | 34 | ${CMAKE_SOURCE_DIR}/libtelephonyservice |
1593 | 20 | ${CMAKE_CURRENT_BINARY_DIR} | 35 | ${CMAKE_CURRENT_BINARY_DIR} |
1594 | 36 | ${GSETTINGS_QT_INCLUDE_DIRS} | ||
1595 | 37 | ${PULSEAUDIO_INCLUDE_DIRS} | ||
1596 | 21 | ) | 38 | ) |
1597 | 22 | 39 | ||
1598 | 23 | add_executable(telephony-service-handler ${handler_SRCS} ${handler_HDRS}) | 40 | add_executable(telephony-service-handler ${handler_SRCS} ${handler_HDRS}) |
1599 | @@ -25,7 +42,11 @@ | |||
1600 | 25 | 42 | ||
1601 | 26 | target_link_libraries(telephony-service-handler | 43 | target_link_libraries(telephony-service-handler |
1602 | 27 | ${TP_QT5_LIBRARIES} | 44 | ${TP_QT5_LIBRARIES} |
1603 | 45 | ${TP_QT5_FS_LIBRARIES} | ||
1604 | 46 | ${TPFS_LIBRARIES} | ||
1605 | 47 | ${FS_LIBRARIES} | ||
1606 | 28 | telephonyservice | 48 | telephonyservice |
1607 | 49 | ${PULSEAUDIO_LIBRARIES} | ||
1608 | 29 | ) | 50 | ) |
1609 | 30 | 51 | ||
1610 | 31 | enable_coverage(telephony-service-handler) | 52 | enable_coverage(telephony-service-handler) |
1611 | 32 | 53 | ||
1612 | === modified file 'handler/Handler.xml' | |||
1613 | --- handler/Handler.xml 2016-12-06 16:45:01 +0000 | |||
1614 | +++ handler/Handler.xml 2017-04-05 14:05:16 +0000 | |||
1615 | @@ -114,13 +114,6 @@ | |||
1616 | 114 | <arg name="objectPath" type="s" direction="in"/> | 114 | <arg name="objectPath" type="s" direction="in"/> |
1617 | 115 | <arg name="muted" type="b" direction="in"/> | 115 | <arg name="muted" type="b" direction="in"/> |
1618 | 116 | </method> | 116 | </method> |
1619 | 117 | <method name="SetActiveAudioOutput"> | ||
1620 | 118 | <dox:d><![CDATA[ | ||
1621 | 119 | Change the current active audio output | ||
1622 | 120 | ]]></dox:d> | ||
1623 | 121 | <arg name="objectPath" type="s" direction="in"/> | ||
1624 | 122 | <arg name="id" type="s" direction="in"/> | ||
1625 | 123 | </method> | ||
1626 | 124 | <method name="SendDTMF"> | 117 | <method name="SendDTMF"> |
1627 | 125 | <dox:d><![CDATA[ | 118 | <dox:d><![CDATA[ |
1628 | 126 | Send a DTMF to the given channel | 119 | Send a DTMF to the given channel |
1629 | @@ -177,9 +170,48 @@ | |||
1630 | 177 | <dox:d><![CDATA[ | 170 | <dox:d><![CDATA[ |
1631 | 178 | Get the list of current available protocols | 171 | Get the list of current available protocols |
1632 | 179 | ]]></dox:d> | 172 | ]]></dox:d> |
1634 | 180 | <arg name="result" type="a(sussss)" direction="out"/> | 173 | <arg name="result" type="a(susussbbssssbbbbbbb)" direction="out"/> |
1635 | 181 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ProtocolList"/> | 174 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ProtocolList"/> |
1636 | 182 | </method> | 175 | </method> |
1637 | 176 | <method name="LeaveRooms"> | ||
1638 | 177 | <dox:d><![CDATA[ | ||
1639 | 178 | Close all rooms of a given account | ||
1640 | 179 | ]]></dox:d> | ||
1641 | 180 | <arg name="accountId" type="s" direction="in"/> | ||
1642 | 181 | <arg name="message" type="s" direction="in"/> | ||
1643 | 182 | </method> | ||
1644 | 183 | <method name="GetAllAccountsProperties"> | ||
1645 | 184 | <dox:d><![CDATA[ | ||
1646 | 185 | Get the properties of all available accounts | ||
1647 | 186 | ]]></dox:d> | ||
1648 | 187 | <arg name="result" type="a{sa{sv}}" direction="out"/> | ||
1649 | 188 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="AllAccountsProperties"/> | ||
1650 | 189 | </method> | ||
1651 | 190 | <method name="GetAccountProperties"> | ||
1652 | 191 | <dox:d><![CDATA[ | ||
1653 | 192 | Get the properties of the given accountId | ||
1654 | 193 | ]]></dox:d> | ||
1655 | 194 | <arg name="accoundId" type="s" direction="in"/> | ||
1656 | 195 | <arg name="result" type="a{sv}" direction="out"/> | ||
1657 | 196 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> | ||
1658 | 197 | </method> | ||
1659 | 198 | <method name="SetAccountProperties"> | ||
1660 | 199 | <dox:d><![CDATA[ | ||
1661 | 200 | Set the properties of the given accountId | ||
1662 | 201 | ]]></dox:d> | ||
1663 | 202 | <arg name="accoundId" type="s" direction="in"/> | ||
1664 | 203 | <arg name="properties" type="a{sv}" direction="in"/> | ||
1665 | 204 | <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> | ||
1666 | 205 | </method> | ||
1667 | 206 | <signal name="AccountPropertiesChanged"> | ||
1668 | 207 | <dox:d><![CDATA[ | ||
1669 | 208 | The properties of a given account changed. | ||
1670 | 209 | ]]></dox:d> | ||
1671 | 210 | <arg name="accountId" type="s"/> | ||
1672 | 211 | <arg name="properties" type="a{sv}"/> | ||
1673 | 212 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/> | ||
1674 | 213 | <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> | ||
1675 | 214 | </signal> | ||
1676 | 183 | <signal name="CallPropertiesChanged"> | 215 | <signal name="CallPropertiesChanged"> |
1677 | 184 | <dox:d><![CDATA[ | 216 | <dox:d><![CDATA[ |
1678 | 185 | The properties of a given call changed. | 217 | The properties of a given call changed. |
1679 | @@ -213,9 +245,32 @@ | |||
1680 | 213 | <dox:d><![CDATA[ | 245 | <dox:d><![CDATA[ |
1681 | 214 | The protocols files in protocols dir have changed | 246 | The protocols files in protocols dir have changed |
1682 | 215 | ]]></dox:d> | 247 | ]]></dox:d> |
1684 | 216 | <arg name="protocols" type="a(sussss)"/> | 248 | <arg name="protocols" type="a(susussbbssssbbbbbbb)"/> |
1685 | 217 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ProtocolList"/> | 249 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ProtocolList"/> |
1686 | 218 | <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="ProtocolList"/> | 250 | <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="ProtocolList"/> |
1687 | 219 | </signal> | 251 | </signal> |
1688 | 252 | <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> | ||
1689 | 253 | <property name="ActiveAudioOutput" type="s" access="readwrite"/> | ||
1690 | 254 | <signal name="ActiveAudioOutputChanged"> | ||
1691 | 255 | <dox:d><![CDATA[ | ||
1692 | 256 | The active audio output has changed | ||
1693 | 257 | ]]></dox:d> | ||
1694 | 258 | <arg name="id" type="s"/> | ||
1695 | 259 | </signal> | ||
1696 | 260 | <method name="AudioOutputs"> | ||
1697 | 261 | <dox:d><![CDATA[ | ||
1698 | 262 | ]]></dox:d> | ||
1699 | 263 | <arg name="outputs" type="a(sss)" direction="out"/> | ||
1700 | 264 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="AudioOutputDBusList"/> | ||
1701 | 265 | <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="AudioOutputDBusList"/> | ||
1702 | 266 | </method> | ||
1703 | 267 | <signal name="AudioOutputsChanged"> | ||
1704 | 268 | <dox:d><![CDATA[ | ||
1705 | 269 | The available audio outputs have changed | ||
1706 | 270 | ]]></dox:d> | ||
1707 | 271 | <arg name="outputs" type="a(sss)"/> | ||
1708 | 272 | <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="AudioOutputDBusList"/> | ||
1709 | 273 | <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="AudioOutputDBusList"/> | ||
1710 | 274 | </signal> | ||
1711 | 220 | </interface> | 275 | </interface> |
1712 | 221 | </node> | 276 | </node> |
1713 | 222 | 277 | ||
1714 | === modified file 'handler/TelephonyServiceHandler.client' | |||
1715 | --- handler/TelephonyServiceHandler.client 2016-04-15 22:25:51 +0000 | |||
1716 | +++ handler/TelephonyServiceHandler.client 2017-04-05 14:05:16 +0000 | |||
1717 | @@ -6,3 +6,12 @@ | |||
1718 | 6 | 6 | ||
1719 | 7 | [org.freedesktop.Telepathy.Client.Handler.HandlerChannelFilter 3] | 7 | [org.freedesktop.Telepathy.Client.Handler.HandlerChannelFilter 3] |
1720 | 8 | org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.Call1 | 8 | org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.Call1 |
1721 | 9 | |||
1722 | 10 | [org.freedesktop.Telepathy.Client.Handler.HandlerChannelFilter 1] | ||
1723 | 11 | org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.Call1 | ||
1724 | 12 | org.freedesktop.Telepathy.Channel.Type.Call1.InitialAudio b=true | ||
1725 | 13 | |||
1726 | 14 | [org.freedesktop.Telepathy.Client.Handler.Capabilities] | ||
1727 | 15 | org.freedesktop.Telepathy.Channel.Type.Call1/audio=true | ||
1728 | 16 | org.freedesktop.Telepathy.Channel.Type.Call1/ice=true | ||
1729 | 17 | org.freedesktop.Telepathy.Channel.Type.Call1/gtalk-p2p=true | ||
1730 | 9 | 18 | ||
1731 | === added file 'handler/accountproperties.cpp' | |||
1732 | --- handler/accountproperties.cpp 1970-01-01 00:00:00 +0000 | |||
1733 | +++ handler/accountproperties.cpp 2017-04-05 14:05:16 +0000 | |||
1734 | @@ -0,0 +1,71 @@ | |||
1735 | 1 | /* | ||
1736 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
1737 | 3 | * | ||
1738 | 4 | * Authors: | ||
1739 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | ||
1740 | 6 | * | ||
1741 | 7 | * This file is part of telephony-service. | ||
1742 | 8 | * | ||
1743 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
1744 | 10 | * it under the terms of the GNU General Public License as published by | ||
1745 | 11 | * the Free Software Foundation; version 3. | ||
1746 | 12 | * | ||
1747 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
1748 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1749 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1750 | 16 | * GNU General Public License for more details. | ||
1751 | 17 | * | ||
1752 | 18 | * You should have received a copy of the GNU General Public License | ||
1753 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1754 | 20 | */ | ||
1755 | 21 | |||
1756 | 22 | #include "accountproperties.h" | ||
1757 | 23 | #include "telepathyhelper.h" | ||
1758 | 24 | #include <QSettings> | ||
1759 | 25 | |||
1760 | 26 | #define SETTINGS_DOMAIN "com.canonical.TelephonyServiceHandler" | ||
1761 | 27 | |||
1762 | 28 | AccountProperties *AccountProperties::instance() | ||
1763 | 29 | { | ||
1764 | 30 | static AccountProperties *self = new AccountProperties(); | ||
1765 | 31 | return self; | ||
1766 | 32 | } | ||
1767 | 33 | |||
1768 | 34 | QMap<QString, QVariantMap> AccountProperties::allProperties() | ||
1769 | 35 | { | ||
1770 | 36 | QMap<QString,QVariantMap> props; | ||
1771 | 37 | for (auto accountId : TelepathyHelper::instance()->accountIds()) { | ||
1772 | 38 | props[accountId] = accountProperties(accountId); | ||
1773 | 39 | } | ||
1774 | 40 | } | ||
1775 | 41 | |||
1776 | 42 | QVariantMap AccountProperties::accountProperties(const QString &accountId) | ||
1777 | 43 | { | ||
1778 | 44 | QVariantMap props; | ||
1779 | 45 | mSettings->beginGroup(formatAccountId(accountId)); | ||
1780 | 46 | for (auto key : mSettings->allKeys()) { | ||
1781 | 47 | props[key] = mSettings->value(key); | ||
1782 | 48 | } | ||
1783 | 49 | mSettings->endGroup(); | ||
1784 | 50 | return props; | ||
1785 | 51 | } | ||
1786 | 52 | |||
1787 | 53 | void AccountProperties::setAccountProperties(const QString &accountId, const QVariantMap &properties) | ||
1788 | 54 | { | ||
1789 | 55 | mSettings->beginGroup(formatAccountId(accountId)); | ||
1790 | 56 | for (auto key : properties.keys()) { | ||
1791 | 57 | mSettings->setValue(key, properties[key]); | ||
1792 | 58 | } | ||
1793 | 59 | mSettings->endGroup(); | ||
1794 | 60 | } | ||
1795 | 61 | |||
1796 | 62 | QString AccountProperties::formatAccountId(const QString &accountId) | ||
1797 | 63 | { | ||
1798 | 64 | return QUrl::toPercentEncoding(accountId); | ||
1799 | 65 | } | ||
1800 | 66 | |||
1801 | 67 | AccountProperties::AccountProperties(QObject *parent) | ||
1802 | 68 | : QObject(parent), | ||
1803 | 69 | mSettings(new QSettings(SETTINGS_DOMAIN, QString(), parent)) | ||
1804 | 70 | { | ||
1805 | 71 | } | ||
1806 | 0 | 72 | ||
1807 | === added file 'handler/accountproperties.h' | |||
1808 | --- handler/accountproperties.h 1970-01-01 00:00:00 +0000 | |||
1809 | +++ handler/accountproperties.h 2017-04-05 14:05:16 +0000 | |||
1810 | @@ -0,0 +1,47 @@ | |||
1811 | 1 | /* | ||
1812 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
1813 | 3 | * | ||
1814 | 4 | * Authors: | ||
1815 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | ||
1816 | 6 | * | ||
1817 | 7 | * This file is part of telephony-service. | ||
1818 | 8 | * | ||
1819 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
1820 | 10 | * it under the terms of the GNU General Public License as published by | ||
1821 | 11 | * the Free Software Foundation; version 3. | ||
1822 | 12 | * | ||
1823 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
1824 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1825 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1826 | 16 | * GNU General Public License for more details. | ||
1827 | 17 | * | ||
1828 | 18 | * You should have received a copy of the GNU General Public License | ||
1829 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1830 | 20 | */ | ||
1831 | 21 | |||
1832 | 22 | #ifndef ACCOUNTPROPERTIES_H | ||
1833 | 23 | #define ACCOUNTPROPERTIES_H | ||
1834 | 24 | |||
1835 | 25 | #include <QObject> | ||
1836 | 26 | |||
1837 | 27 | class QSettings; | ||
1838 | 28 | |||
1839 | 29 | class AccountProperties : public QObject | ||
1840 | 30 | { | ||
1841 | 31 | Q_OBJECT | ||
1842 | 32 | public: | ||
1843 | 33 | static AccountProperties *instance(); | ||
1844 | 34 | |||
1845 | 35 | QMap<QString,QVariantMap> allProperties(); | ||
1846 | 36 | QVariantMap accountProperties(const QString &accountId); | ||
1847 | 37 | void setAccountProperties(const QString &accountId, const QVariantMap &properties); | ||
1848 | 38 | QString formatAccountId(const QString &accountId); | ||
1849 | 39 | |||
1850 | 40 | protected: | ||
1851 | 41 | explicit AccountProperties(QObject *parent = 0); | ||
1852 | 42 | |||
1853 | 43 | private: | ||
1854 | 44 | QSettings *mSettings; | ||
1855 | 45 | }; | ||
1856 | 46 | |||
1857 | 47 | #endif // ACCOUNTPROPERTIES_H | ||
1858 | 0 | 48 | ||
1859 | === added file 'handler/audioroutemanager.cpp' | |||
1860 | --- handler/audioroutemanager.cpp 1970-01-01 00:00:00 +0000 | |||
1861 | +++ handler/audioroutemanager.cpp 2017-04-05 14:05:16 +0000 | |||
1862 | @@ -0,0 +1,231 @@ | |||
1863 | 1 | /* | ||
1864 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
1865 | 3 | * | ||
1866 | 4 | * Authors: | ||
1867 | 5 | * Tiago Salem Herrmann <tiago.herrmann@canonical.com> | ||
1868 | 6 | * | ||
1869 | 7 | * This file is part of telephony-service. | ||
1870 | 8 | * | ||
1871 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
1872 | 10 | * it under the terms of the GNU General Public License as published by | ||
1873 | 11 | * the Free Software Foundation; version 3. | ||
1874 | 12 | * | ||
1875 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
1876 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1877 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1878 | 16 | * GNU General Public License for more details. | ||
1879 | 17 | * | ||
1880 | 18 | * You should have received a copy of the GNU General Public License | ||
1881 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1882 | 20 | */ | ||
1883 | 21 | |||
1884 | 22 | #include "audioroutemanager.h" | ||
1885 | 23 | #include "telepathyhelper.h" | ||
1886 | 24 | #include "accountentry.h" | ||
1887 | 25 | #include <TelepathyQt/Contact> | ||
1888 | 26 | #include <TelepathyQt/Functors> | ||
1889 | 27 | |||
1890 | 28 | |||
1891 | 29 | static void enable_earpiece() | ||
1892 | 30 | { | ||
1893 | 31 | #ifdef USE_PULSEAUDIO | ||
1894 | 32 | QPulseAudioEngine::instance()->setCallMode(CallActive, AudioModeBtOrWiredOrEarpiece); | ||
1895 | 33 | #endif | ||
1896 | 34 | } | ||
1897 | 35 | |||
1898 | 36 | static void enable_normal() | ||
1899 | 37 | { | ||
1900 | 38 | #ifdef USE_PULSEAUDIO | ||
1901 | 39 | QTimer* timer = new QTimer(); | ||
1902 | 40 | timer->setSingleShot(true); | ||
1903 | 41 | QObject::connect(timer, &QTimer::timeout, [=](){ | ||
1904 | 42 | QPulseAudioEngine::instance()->setMicMute(false); | ||
1905 | 43 | QPulseAudioEngine::instance()->setCallMode(CallEnded, AudioModeWiredOrSpeaker); | ||
1906 | 44 | timer->deleteLater(); | ||
1907 | 45 | }); | ||
1908 | 46 | timer->start(2000); | ||
1909 | 47 | #endif | ||
1910 | 48 | } | ||
1911 | 49 | |||
1912 | 50 | static void enable_speaker() | ||
1913 | 51 | { | ||
1914 | 52 | #ifdef USE_PULSEAUDIO | ||
1915 | 53 | QPulseAudioEngine::instance()->setCallMode(CallActive, AudioModeSpeaker); | ||
1916 | 54 | #endif | ||
1917 | 55 | } | ||
1918 | 56 | |||
1919 | 57 | static void enable_ringtone() | ||
1920 | 58 | { | ||
1921 | 59 | #ifdef USE_PULSEAUDIO | ||
1922 | 60 | QPulseAudioEngine::instance()->setCallMode(CallRinging, AudioModeBtOrWiredOrSpeaker); | ||
1923 | 61 | #endif | ||
1924 | 62 | } | ||
1925 | 63 | |||
1926 | 64 | AudioRouteManager *AudioRouteManager::instance() | ||
1927 | 65 | { | ||
1928 | 66 | static AudioRouteManager *self = new AudioRouteManager(); | ||
1929 | 67 | return self; | ||
1930 | 68 | } | ||
1931 | 69 | |||
1932 | 70 | AudioRouteManager::AudioRouteManager(QObject *parent) : | ||
1933 | 71 | QObject(parent), mAudioModeMediator(mPowerDDBus) | ||
1934 | 72 | { | ||
1935 | 73 | TelepathyHelper::instance()->registerChannelObserver("TelephonyServiceHandlerAudioRouteManager"); | ||
1936 | 74 | |||
1937 | 75 | QObject::connect(TelepathyHelper::instance()->channelObserver(), SIGNAL(callChannelAvailable(Tp::CallChannelPtr)), | ||
1938 | 76 | this, SLOT(onCallChannelAvailable(Tp::CallChannelPtr))); | ||
1939 | 77 | |||
1940 | 78 | #ifdef USE_PULSEAUDIO | ||
1941 | 79 | // update audio modes | ||
1942 | 80 | QObject::connect(QPulseAudioEngine::instance(), SIGNAL(audioModeChanged(AudioMode)), SLOT(onAudioModeChanged(AudioMode))); | ||
1943 | 81 | QObject::connect(QPulseAudioEngine::instance(), SIGNAL(availableAudioModesChanged(AudioModes)), SLOT(onAvailableAudioModesChanged(AudioModes))); | ||
1944 | 82 | |||
1945 | 83 | // check if we should indeed use pulseaudio | ||
1946 | 84 | QByteArray pulseAudioDisabled = qgetenv("PA_DISABLED"); | ||
1947 | 85 | mHasPulseAudio = true; | ||
1948 | 86 | if (!pulseAudioDisabled.isEmpty()) | ||
1949 | 87 | mHasPulseAudio = false; | ||
1950 | 88 | #endif | ||
1951 | 89 | |||
1952 | 90 | connect(this, &AudioRouteManager::activeAudioOutputChanged, Tp::memFun(&mAudioModeMediator, &PowerDAudioModeMediator::audioModeChanged)); | ||
1953 | 91 | connect(this, &AudioRouteManager::lastChannelClosed, Tp::memFun(&mAudioModeMediator, &PowerDAudioModeMediator::audioOutputClosed)); | ||
1954 | 92 | } | ||
1955 | 93 | |||
1956 | 94 | void AudioRouteManager::onCallChannelAvailable(Tp::CallChannelPtr callChannel) | ||
1957 | 95 | { | ||
1958 | 96 | connect(callChannel.data(), | ||
1959 | 97 | SIGNAL(callStateChanged(Tp::CallState)), | ||
1960 | 98 | SLOT(onCallStateChanged(Tp::CallState))); | ||
1961 | 99 | |||
1962 | 100 | mChannels.append(callChannel); | ||
1963 | 101 | updateAudioRoute(true); | ||
1964 | 102 | } | ||
1965 | 103 | |||
1966 | 104 | void AudioRouteManager::onCallStateChanged(Tp::CallState state) | ||
1967 | 105 | { | ||
1968 | 106 | Tp::CallChannelPtr channel(qobject_cast<Tp::CallChannel*>(sender())); | ||
1969 | 107 | if (!channel) { | ||
1970 | 108 | return; | ||
1971 | 109 | } | ||
1972 | 110 | |||
1973 | 111 | if (channel->callState() == Tp::CallStateEnded) { | ||
1974 | 112 | mChannels.removeOne(channel); | ||
1975 | 113 | } | ||
1976 | 114 | updateAudioRoute(false); | ||
1977 | 115 | } | ||
1978 | 116 | |||
1979 | 117 | void AudioRouteManager::setActiveAudioOutput(const QString &id) | ||
1980 | 118 | { | ||
1981 | 119 | #ifdef USE_PULSEAUDIO | ||
1982 | 120 | // fallback to earpiece/headset | ||
1983 | 121 | AudioMode mode = AudioModeWiredOrEarpiece; | ||
1984 | 122 | if (id == "bluetooth") { | ||
1985 | 123 | mode = AudioModeBluetooth; | ||
1986 | 124 | } else if (id == "speaker") { | ||
1987 | 125 | mode = AudioModeSpeaker; | ||
1988 | 126 | } | ||
1989 | 127 | if (mHasPulseAudio) | ||
1990 | 128 | QPulseAudioEngine::instance()->setCallMode(CallActive, mode); | ||
1991 | 129 | #endif | ||
1992 | 130 | } | ||
1993 | 131 | |||
1994 | 132 | QString AudioRouteManager::activeAudioOutput() | ||
1995 | 133 | { | ||
1996 | 134 | return mActiveAudioOutput; | ||
1997 | 135 | } | ||
1998 | 136 | |||
1999 | 137 | AudioOutputDBusList AudioRouteManager::audioOutputs() const | ||
2000 | 138 | { | ||
2001 | 139 | return mAudioOutputs; | ||
2002 | 140 | } | ||
2003 | 141 | |||
2004 | 142 | void AudioRouteManager::updateAudioRoute(bool newCall) | ||
2005 | 143 | { | ||
2006 | 144 | #ifdef USE_PULSEAUDIO | ||
2007 | 145 | if (!mHasPulseAudio) | ||
2008 | 146 | return; | ||
2009 | 147 | #endif | ||
2010 | 148 | |||
2011 | 149 | int currentCalls = mChannels.size(); | ||
2012 | 150 | if (currentCalls != 0) { | ||
2013 | 151 | if (currentCalls == 1) { | ||
2014 | 152 | // if we have only one call, check if it's incoming and | ||
2015 | 153 | // enable speaker mode so the ringtone is audible | ||
2016 | 154 | Tp::CallChannelPtr callChannel = mChannels.first(); | ||
2017 | 155 | AccountEntry *accountEntry = TelepathyHelper::instance()->accountForConnection(callChannel->connection()); | ||
2018 | 156 | if (!accountEntry || !callChannel) { | ||
2019 | 157 | return; | ||
2020 | 158 | } | ||
2021 | 159 | |||
2022 | 160 | bool incoming = callChannel->initiatorContact() != accountEntry->account()->connection()->selfContact(); | ||
2023 | 161 | Tp::CallState state = callChannel->callState(); | ||
2024 | 162 | if (incoming && newCall) { | ||
2025 | 163 | enable_ringtone(); | ||
2026 | 164 | return; | ||
2027 | 165 | } | ||
2028 | 166 | if (state == Tp::CallStateEnded) { | ||
2029 | 167 | enable_normal(); | ||
2030 | 168 | return; | ||
2031 | 169 | } | ||
2032 | 170 | // if only one call and dialing, or incoming call just accepted, then default to earpiece | ||
2033 | 171 | if (newCall || (state == Tp::CallStateAccepted && incoming)) { | ||
2034 | 172 | enable_earpiece(); | ||
2035 | 173 | return; | ||
2036 | 174 | } | ||
2037 | 175 | } | ||
2038 | 176 | } else { | ||
2039 | 177 | enable_normal(); | ||
2040 | 178 | Q_EMIT lastChannelClosed(); | ||
2041 | 179 | } | ||
2042 | 180 | } | ||
2043 | 181 | |||
2044 | 182 | #ifdef USE_PULSEAUDIO | ||
2045 | 183 | void AudioRouteManager::onAudioModeChanged(AudioMode mode) | ||
2046 | 184 | { | ||
2047 | 185 | qDebug("PulseAudio audio mode changed: 0x%x", mode); | ||
2048 | 186 | |||
2049 | 187 | if (mode == AudioModeEarpiece && mActiveAudioOutput != "earpiece") { | ||
2050 | 188 | mActiveAudioOutput = "earpiece"; | ||
2051 | 189 | } else if (mode == AudioModeWiredHeadset && mActiveAudioOutput != "wired_headset") { | ||
2052 | 190 | mActiveAudioOutput = "wired_headset"; | ||
2053 | 191 | } else if (mode == AudioModeSpeaker && mActiveAudioOutput != "speaker") { | ||
2054 | 192 | mActiveAudioOutput = "speaker"; | ||
2055 | 193 | } else if (mode == AudioModeBluetooth && mActiveAudioOutput != "bluetooth") { | ||
2056 | 194 | mActiveAudioOutput = "bluetooth"; | ||
2057 | 195 | } | ||
2058 | 196 | Q_EMIT activeAudioOutputChanged(mActiveAudioOutput); | ||
2059 | 197 | } | ||
2060 | 198 | |||
2061 | 199 | void AudioRouteManager::onAvailableAudioModesChanged(AudioModes modes) | ||
2062 | 200 | { | ||
2063 | 201 | qDebug("PulseAudio available audio modes changed"); | ||
2064 | 202 | bool defaultFound = false; | ||
2065 | 203 | mAudioOutputs.clear(); | ||
2066 | 204 | Q_FOREACH(const AudioMode &mode, modes) { | ||
2067 | 205 | AudioOutputDBus output; | ||
2068 | 206 | if (mode == AudioModeBluetooth) { | ||
2069 | 207 | // there can be only one bluetooth | ||
2070 | 208 | output.id = "bluetooth"; | ||
2071 | 209 | output.type = "bluetooth"; | ||
2072 | 210 | // we dont support names for now, so we set a default value | ||
2073 | 211 | output.name = "bluetooth"; | ||
2074 | 212 | } else if (mode == AudioModeEarpiece || mode == AudioModeWiredHeadset) { | ||
2075 | 213 | if (!defaultFound) { | ||
2076 | 214 | defaultFound = true; | ||
2077 | 215 | output.id = "default"; | ||
2078 | 216 | output.type = "default"; | ||
2079 | 217 | output.name = "default"; | ||
2080 | 218 | } else { | ||
2081 | 219 | continue; | ||
2082 | 220 | } | ||
2083 | 221 | } else if (mode == AudioModeSpeaker) { | ||
2084 | 222 | output.id = "speaker"; | ||
2085 | 223 | output.type = "speaker"; | ||
2086 | 224 | output.name = "speaker"; | ||
2087 | 225 | } | ||
2088 | 226 | mAudioOutputs << output; | ||
2089 | 227 | } | ||
2090 | 228 | Q_EMIT audioOutputsChanged(mAudioOutputs); | ||
2091 | 229 | } | ||
2092 | 230 | #endif | ||
2093 | 231 | |||
2094 | 0 | 232 | ||
2095 | === added file 'handler/audioroutemanager.h' | |||
2096 | --- handler/audioroutemanager.h 1970-01-01 00:00:00 +0000 | |||
2097 | +++ handler/audioroutemanager.h 2017-04-05 14:05:16 +0000 | |||
2098 | @@ -0,0 +1,75 @@ | |||
2099 | 1 | /* | ||
2100 | 2 | * Copyright (C) 2016 Canonical, Ltd. | ||
2101 | 3 | * | ||
2102 | 4 | * Authors: | ||
2103 | 5 | * Tiago Salem Herrmann <tiago.herrmann@canonical.com> | ||
2104 | 6 | * | ||
2105 | 7 | * This file is part of telephony-service. | ||
2106 | 8 | * | ||
2107 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
2108 | 10 | * it under the terms of the GNU General Public License as published by | ||
2109 | 11 | * the Free Software Foundation; version 3. | ||
2110 | 12 | * | ||
2111 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
2112 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2113 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2114 | 16 | * GNU General Public License for more details. | ||
2115 | 17 | * | ||
2116 | 18 | * You should have received a copy of the GNU General Public License | ||
2117 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2118 | 20 | */ | ||
2119 | 21 | |||
2120 | 22 | #ifndef AUDIOROUTEMANAGER_H | ||
2121 | 23 | #define AUDIOROUTEMANAGER_H | ||
2122 | 24 | |||
2123 | 25 | #ifdef USE_PULSEAUDIO | ||
2124 | 26 | #include "qpulseaudioengine.h" | ||
2125 | 27 | #endif | ||
2126 | 28 | #include "audiooutput.h" | ||
2127 | 29 | #include "powerdaudiomodemediator.h" | ||
2128 | 30 | #include "powerddbus.h" | ||
2129 | 31 | #include <QObject> | ||
2130 | 32 | #include <TelepathyQt/CallChannel> | ||
2131 | 33 | |||
2132 | 34 | |||
2133 | 35 | class AudioRouteManager : public QObject | ||
2134 | 36 | { | ||
2135 | 37 | Q_OBJECT | ||
2136 | 38 | |||
2137 | 39 | public: | ||
2138 | 40 | static AudioRouteManager *instance(); | ||
2139 | 41 | void setActiveAudioOutput(const QString &id); | ||
2140 | 42 | QString activeAudioOutput(); | ||
2141 | 43 | AudioOutputDBusList audioOutputs() const; | ||
2142 | 44 | void updateAudioRoute(bool newCall = false); | ||
2143 | 45 | |||
2144 | 46 | public Q_SLOTS: | ||
2145 | 47 | void onCallChannelAvailable(Tp::CallChannelPtr callChannel); | ||
2146 | 48 | |||
2147 | 49 | Q_SIGNALS: | ||
2148 | 50 | void audioOutputsChanged(const AudioOutputDBusList &outputs); | ||
2149 | 51 | void activeAudioOutputChanged(const QString &id); | ||
2150 | 52 | void lastChannelClosed(); | ||
2151 | 53 | |||
2152 | 54 | protected Q_SLOTS: | ||
2153 | 55 | void onCallStateChanged(Tp::CallState state); | ||
2154 | 56 | |||
2155 | 57 | private Q_SLOTS: | ||
2156 | 58 | #ifdef USE_PULSEAUDIO | ||
2157 | 59 | void onAudioModeChanged(AudioMode mode); | ||
2158 | 60 | void onAvailableAudioModesChanged(AudioModes modes); | ||
2159 | 61 | #endif | ||
2160 | 62 | |||
2161 | 63 | private: | ||
2162 | 64 | explicit AudioRouteManager(QObject *parent = 0); | ||
2163 | 65 | QList<Tp::CallChannelPtr> mChannels; | ||
2164 | 66 | AudioOutputDBusList mAudioOutputs; | ||
2165 | 67 | QString mActiveAudioOutput; | ||
2166 | 68 | PowerDDBus mPowerDDBus; | ||
2167 | 69 | PowerDAudioModeMediator mAudioModeMediator; | ||
2168 | 70 | #ifdef USE_PULSEAUDIO | ||
2169 | 71 | bool mHasPulseAudio; | ||
2170 | 72 | #endif | ||
2171 | 73 | }; | ||
2172 | 74 | |||
2173 | 75 | #endif // AUDIOROUTEMANAGER_H | ||
2174 | 0 | 76 | ||
2175 | === added file 'handler/callagent.cpp' | |||
2176 | --- handler/callagent.cpp 1970-01-01 00:00:00 +0000 | |||
2177 | +++ handler/callagent.cpp 2017-04-05 14:05:16 +0000 | |||
2178 | @@ -0,0 +1,118 @@ | |||
2179 | 1 | /* | ||
2180 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
2181 | 3 | * | ||
2182 | 4 | * Authors: | ||
2183 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | ||
2184 | 6 | * | ||
2185 | 7 | * This file is part of telephony-service. | ||
2186 | 8 | * | ||
2187 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
2188 | 10 | * it under the terms of the GNU General Public License as published by | ||
2189 | 11 | * the Free Software Foundation; version 3. | ||
2190 | 12 | * | ||
2191 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
2192 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2193 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2194 | 16 | * GNU General Public License for more details. | ||
2195 | 17 | * | ||
2196 | 18 | * You should have received a copy of the GNU General Public License | ||
2197 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2198 | 20 | */ | ||
2199 | 21 | |||
2200 | 22 | #include "callagent.h" | ||
2201 | 23 | #include <TelepathyQt/CallContent> | ||
2202 | 24 | #include <TelepathyQt/Contact> | ||
2203 | 25 | #include <TelepathyQt/Farstream/Channel> | ||
2204 | 26 | #include <QDebug> | ||
2205 | 27 | |||
2206 | 28 | CallAgent::CallAgent(const Tp::CallChannelPtr &channel, QObject *parent) : | ||
2207 | 29 | QObject(parent), mChannel(channel), mFarstreamChannel(0) | ||
2208 | 30 | { | ||
2209 | 31 | connect(mChannel.data(), | ||
2210 | 32 | SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)), | ||
2211 | 33 | SLOT(onCallChannelInvalidated())); | ||
2212 | 34 | connect(mChannel.data(), | ||
2213 | 35 | SIGNAL(callStateChanged(Tp::CallState)), | ||
2214 | 36 | SLOT(onCallStateChanged(Tp::CallState))); | ||
2215 | 37 | connect(mChannel.data(), | ||
2216 | 38 | SIGNAL(contentAdded(Tp::CallContentPtr)), | ||
2217 | 39 | SLOT(onContentAdded(Tp::CallContentPtr))); | ||
2218 | 40 | |||
2219 | 41 | Q_FOREACH(const Tp::CallContentPtr &content, mChannel->contents()) { | ||
2220 | 42 | onContentAdded(content); | ||
2221 | 43 | } | ||
2222 | 44 | |||
2223 | 45 | if (!mChannel->handlerStreamingRequired()) { | ||
2224 | 46 | return; | ||
2225 | 47 | } | ||
2226 | 48 | |||
2227 | 49 | Tp::Farstream::PendingChannel *pendingChannel = Tp::Farstream::createChannel(mChannel); | ||
2228 | 50 | connect(pendingChannel, | ||
2229 | 51 | SIGNAL(finished(Tp::PendingOperation*)), | ||
2230 | 52 | SLOT(onFarstreamChannelCreated(Tp::PendingOperation*))); | ||
2231 | 53 | } | ||
2232 | 54 | |||
2233 | 55 | CallAgent::~CallAgent() | ||
2234 | 56 | { | ||
2235 | 57 | if (mFarstreamChannel) { | ||
2236 | 58 | mFarstreamChannel->deleteLater(); | ||
2237 | 59 | } | ||
2238 | 60 | } | ||
2239 | 61 | |||
2240 | 62 | void CallAgent::setMute(bool mute) | ||
2241 | 63 | { | ||
2242 | 64 | if (!mFarstreamChannel) { | ||
2243 | 65 | return; | ||
2244 | 66 | } | ||
2245 | 67 | |||
2246 | 68 | mFarstreamChannel->setMute(mute); | ||
2247 | 69 | } | ||
2248 | 70 | |||
2249 | 71 | void CallAgent::onCallChannelInvalidated() | ||
2250 | 72 | { | ||
2251 | 73 | deleteLater(); | ||
2252 | 74 | } | ||
2253 | 75 | |||
2254 | 76 | void CallAgent::onCallStateChanged(Tp::CallState state) | ||
2255 | 77 | { | ||
2256 | 78 | if (state == Tp::CallStatePendingInitiator) { | ||
2257 | 79 | mChannel->accept(); | ||
2258 | 80 | } | ||
2259 | 81 | } | ||
2260 | 82 | |||
2261 | 83 | void CallAgent::onContentAdded(const Tp::CallContentPtr &content) | ||
2262 | 84 | { | ||
2263 | 85 | if (!mChannel->handlerStreamingRequired()) { | ||
2264 | 86 | return; | ||
2265 | 87 | } | ||
2266 | 88 | |||
2267 | 89 | qDebug() << "Content Added, name: " << content->name() << " type: " << content->type(); | ||
2268 | 90 | |||
2269 | 91 | connect(content.data(), | ||
2270 | 92 | SIGNAL(streamAdded(Tp::CallStreamPtr)), | ||
2271 | 93 | SLOT(onStreamAdded(Tp::CallStreamPtr))); | ||
2272 | 94 | |||
2273 | 95 | Q_FOREACH(const Tp::CallStreamPtr &stream, content->streams()) { | ||
2274 | 96 | onStreamAdded(stream); | ||
2275 | 97 | } | ||
2276 | 98 | } | ||
2277 | 99 | |||
2278 | 100 | void CallAgent::onStreamAdded(const Tp::CallStreamPtr &stream) | ||
2279 | 101 | { | ||
2280 | 102 | qDebug() << "Stream present: " << stream->localSendingState(); | ||
2281 | 103 | |||
2282 | 104 | qDebug() << " members " << stream->remoteMembers().size(); | ||
2283 | 105 | Q_FOREACH(const Tp::ContactPtr contact, stream->remoteMembers()) { | ||
2284 | 106 | qDebug() << " member " << contact->id() << " remoteSendingState=" << stream->remoteSendingState(contact); | ||
2285 | 107 | } | ||
2286 | 108 | } | ||
2287 | 109 | |||
2288 | 110 | void CallAgent::onFarstreamChannelCreated(Tp::PendingOperation *op) | ||
2289 | 111 | { | ||
2290 | 112 | Tp::Farstream::PendingChannel *pendingChannel = qobject_cast<Tp::Farstream::PendingChannel*>(op); | ||
2291 | 113 | if (!pendingChannel) { | ||
2292 | 114 | return; | ||
2293 | 115 | } | ||
2294 | 116 | |||
2295 | 117 | mFarstreamChannel = new FarstreamChannel(pendingChannel->tfChannel(), this); | ||
2296 | 118 | } | ||
2297 | 0 | 119 | ||
2298 | === added file 'handler/callagent.h' | |||
2299 | --- handler/callagent.h 1970-01-01 00:00:00 +0000 | |||
2300 | +++ handler/callagent.h 2017-04-05 14:05:16 +0000 | |||
2301 | @@ -0,0 +1,52 @@ | |||
2302 | 1 | /* | ||
2303 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
2304 | 3 | * | ||
2305 | 4 | * Authors: | ||
2306 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | ||
2307 | 6 | * | ||
2308 | 7 | * This file is part of telephony-service. | ||
2309 | 8 | * | ||
2310 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
2311 | 10 | * it under the terms of the GNU General Public License as published by | ||
2312 | 11 | * the Free Software Foundation; version 3. | ||
2313 | 12 | * | ||
2314 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
2315 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2316 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2317 | 16 | * GNU General Public License for more details. | ||
2318 | 17 | * | ||
2319 | 18 | * You should have received a copy of the GNU General Public License | ||
2320 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2321 | 20 | */ | ||
2322 | 21 | |||
2323 | 22 | #ifndef CALLAGENT_H | ||
2324 | 23 | #define CALLAGENT_H | ||
2325 | 24 | |||
2326 | 25 | #include <QObject> | ||
2327 | 26 | #include <TelepathyQt/CallChannel> | ||
2328 | 27 | #include <TelepathyQt/Farstream/Channel> | ||
2329 | 28 | #include "farstreamchannel.h" | ||
2330 | 29 | |||
2331 | 30 | class CallAgent : public QObject | ||
2332 | 31 | { | ||
2333 | 32 | Q_OBJECT | ||
2334 | 33 | public: | ||
2335 | 34 | explicit CallAgent(const Tp::CallChannelPtr &channel, QObject *parent = 0); | ||
2336 | 35 | ~CallAgent(); | ||
2337 | 36 | |||
2338 | 37 | void setMute(bool mute); | ||
2339 | 38 | |||
2340 | 39 | protected Q_SLOTS: | ||
2341 | 40 | void onCallChannelInvalidated(); | ||
2342 | 41 | void onCallStateChanged(Tp::CallState state); | ||
2343 | 42 | void onContentAdded(const Tp::CallContentPtr &content); | ||
2344 | 43 | void onStreamAdded(const Tp::CallStreamPtr &stream); | ||
2345 | 44 | |||
2346 | 45 | void onFarstreamChannelCreated(Tp::PendingOperation *op); | ||
2347 | 46 | |||
2348 | 47 | private: | ||
2349 | 48 | Tp::CallChannelPtr mChannel; | ||
2350 | 49 | FarstreamChannel *mFarstreamChannel; | ||
2351 | 50 | }; | ||
2352 | 51 | |||
2353 | 52 | #endif // CALLAGENT_H | ||
2354 | 0 | 53 | ||
2355 | === modified file 'handler/callhandler.cpp' | |||
2356 | --- handler/callhandler.cpp 2015-07-06 23:32:13 +0000 | |||
2357 | +++ handler/callhandler.cpp 2017-04-05 14:05:16 +0000 | |||
2358 | @@ -1,5 +1,5 @@ | |||
2359 | 1 | /* | 1 | /* |
2361 | 2 | * Copyright (C) 2012-2014 Canonical, Ltd. | 2 | * Copyright (C) 2012-2017 Canonical, Ltd. |
2362 | 3 | * | 3 | * |
2363 | 4 | * Authors: | 4 | * Authors: |
2364 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
2365 | @@ -20,15 +20,19 @@ | |||
2366 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2367 | 21 | */ | 21 | */ |
2368 | 22 | 22 | ||
2369 | 23 | #include "accountproperties.h" | ||
2370 | 24 | #include "callagent.h" | ||
2371 | 23 | #include "callhandler.h" | 25 | #include "callhandler.h" |
2372 | 24 | #include "phoneutils.h" | ||
2373 | 25 | #include "telepathyhelper.h" | 26 | #include "telepathyhelper.h" |
2374 | 26 | #include "accountentry.h" | 27 | #include "accountentry.h" |
2375 | 27 | #include "tonegenerator.h" | 28 | #include "tonegenerator.h" |
2376 | 28 | #include "greetercontacts.h" | 29 | #include "greetercontacts.h" |
2377 | 30 | #include "phoneutils.h" | ||
2378 | 29 | #include <TelepathyQt/ContactManager> | 31 | #include <TelepathyQt/ContactManager> |
2379 | 30 | #include <TelepathyQt/PendingContacts> | 32 | #include <TelepathyQt/PendingContacts> |
2380 | 31 | #include <TelepathyQt/PendingChannelRequest> | 33 | #include <TelepathyQt/PendingChannelRequest> |
2381 | 34 | #include <TelepathyQt/PendingVariant> | ||
2382 | 35 | #include <memory> | ||
2383 | 32 | 36 | ||
2384 | 33 | #define TELEPATHY_MUTE_IFACE "org.freedesktop.Telepathy.Call1.Interface.Mute" | 37 | #define TELEPATHY_MUTE_IFACE "org.freedesktop.Telepathy.Call1.Interface.Mute" |
2385 | 34 | #define DBUS_PROPERTIES_IFACE "org.freedesktop.DBus.Properties" | 38 | #define DBUS_PROPERTIES_IFACE "org.freedesktop.DBus.Properties" |
2386 | @@ -72,8 +76,7 @@ | |||
2387 | 72 | bool hasActiveCalls = false; | 76 | bool hasActiveCalls = false; |
2388 | 73 | 77 | ||
2389 | 74 | Q_FOREACH(const Tp::CallChannelPtr channel, mCallChannels) { | 78 | Q_FOREACH(const Tp::CallChannelPtr channel, mCallChannels) { |
2392 | 75 | AccountEntry *accountEntry = TelepathyHelper::instance()->accountForConnection(channel->connection()); | 79 | bool incoming = isIncoming(channel); |
2391 | 76 | bool incoming = channel->initiatorContact() != accountEntry->account()->connection()->selfContact(); | ||
2393 | 77 | bool dialing = !incoming && (channel->callState() == Tp::CallStateInitialised); | 80 | bool dialing = !incoming && (channel->callState() == Tp::CallStateInitialised); |
2394 | 78 | bool active = channel->callState() == Tp::CallStateActive; | 81 | bool active = channel->callState() == Tp::CallStateActive; |
2395 | 79 | 82 | ||
2396 | @@ -94,6 +97,7 @@ | |||
2397 | 94 | 97 | ||
2398 | 95 | void CallHandler::startCall(const QString &targetId, const QString &accountId) | 98 | void CallHandler::startCall(const QString &targetId, const QString &accountId) |
2399 | 96 | { | 99 | { |
2400 | 100 | QString finalId = targetId; | ||
2401 | 97 | // Request the contact to start audio call | 101 | // Request the contact to start audio call |
2402 | 98 | AccountEntry *accountEntry = TelepathyHelper::instance()->accountForId(accountId); | 102 | AccountEntry *accountEntry = TelepathyHelper::instance()->accountForId(accountId); |
2403 | 99 | if (!accountEntry) { | 103 | if (!accountEntry) { |
2404 | @@ -105,7 +109,24 @@ | |||
2405 | 105 | return; | 109 | return; |
2406 | 106 | } | 110 | } |
2407 | 107 | 111 | ||
2409 | 108 | connect(connection->contactManager()->contactsForIdentifiers(QStringList() << targetId), | 112 | // FIXME: this is a workaround, there might be a better way of handling this. |
2410 | 113 | // One idea is to implement the Addressing interface on the SIP connection manager such that | ||
2411 | 114 | // we can request a handle based on the vCard field "tel" | ||
2412 | 115 | if (accountEntry->protocolInfo()->name() == "sip") { | ||
2413 | 116 | // check if the phone number needs rewriting | ||
2414 | 117 | QVariantMap accountProperties = AccountProperties::instance()->accountProperties(accountId); | ||
2415 | 118 | finalId = applyNumberRewritingRules(finalId, accountProperties); | ||
2416 | 119 | |||
2417 | 120 | // replace the numbers by a SIP URI | ||
2418 | 121 | QString domain = accountEntry->account()->parameters()["account"].toString(); | ||
2419 | 122 | if (domain.contains("@")) { | ||
2420 | 123 | domain = domain.split("@")[1]; | ||
2421 | 124 | |||
2422 | 125 | finalId = QString("sip:%1@%2").arg(PhoneUtils::normalizePhoneNumber(finalId)).arg(domain); | ||
2423 | 126 | } | ||
2424 | 127 | } | ||
2425 | 128 | |||
2426 | 129 | connect(connection->contactManager()->contactsForIdentifiers(QStringList() << finalId), | ||
2427 | 109 | SIGNAL(finished(Tp::PendingOperation*)), | 130 | SIGNAL(finished(Tp::PendingOperation*)), |
2428 | 110 | SLOT(onContactsAvailable(Tp::PendingOperation*))); | 131 | SLOT(onContactsAvailable(Tp::PendingOperation*))); |
2429 | 111 | } | 132 | } |
2430 | @@ -146,41 +167,30 @@ | |||
2431 | 146 | return; | 167 | return; |
2432 | 147 | } | 168 | } |
2433 | 148 | 169 | ||
2445 | 149 | // FIXME: replace by a proper TpQt implementation of mute | 170 | if (channel->handlerStreamingRequired()) { |
2446 | 150 | QDBusInterface muteInterface(channel->busName(), channel->objectPath(), TELEPATHY_MUTE_IFACE); | 171 | CallAgent *agent = mCallAgents[channel.data()]; |
2447 | 151 | muteInterface.call("RequestMuted", muted); | 172 | if (!agent) { |
2448 | 152 | } | 173 | return; |
2449 | 153 | 174 | } | |
2450 | 154 | void CallHandler::setActiveAudioOutput(const QString &objectPath, const QString &id) | 175 | agent->setMute(muted); |
2451 | 155 | { | 176 | } else { |
2452 | 156 | Tp::CallChannelPtr channel = callFromObjectPath(objectPath); | 177 | // FIXME: replace by a proper TpQt implementation of mute |
2453 | 157 | 178 | QDBusInterface muteInterface(channel->busName(), channel->objectPath(), TELEPATHY_MUTE_IFACE); | |
2454 | 158 | QDBusInterface audioOutputsInterface(channel->busName(), channel->objectPath(), CANONICAL_TELEPHONY_AUDIOOUTPUTS_IFACE); | 179 | muteInterface.call("RequestMuted", muted); |
2455 | 159 | audioOutputsInterface.call("SetActiveAudioOutput", id); | 180 | } |
2456 | 160 | } | 181 | } |
2457 | 161 | 182 | ||
2458 | 162 | void CallHandler::sendDTMF(const QString &objectPath, const QString &key) | 183 | void CallHandler::sendDTMF(const QString &objectPath, const QString &key) |
2459 | 163 | { | 184 | { |
2460 | 164 | bool ok; | ||
2461 | 165 | Tp::DTMFEvent event = (Tp::DTMFEvent)key.toInt(&ok); | ||
2462 | 166 | if (!ok) { | ||
2463 | 167 | if (!key.compare("*")) { | ||
2464 | 168 | event = Tp::DTMFEventAsterisk; | ||
2465 | 169 | } else if (!key.compare("#")) { | ||
2466 | 170 | event = Tp::DTMFEventHash; | ||
2467 | 171 | } else { | ||
2468 | 172 | qWarning() << "Tone not recognized. DTMF failed"; | ||
2469 | 173 | return; | ||
2470 | 174 | } | ||
2471 | 175 | } | ||
2472 | 176 | /* | 185 | /* |
2474 | 177 | * play locally (via tone generator) only if we are on a call, or if this is | 186 | * play locally (via tone generator) only if we are on a call, or if this is |
2475 | 178 | * dialpad sounds | 187 | * dialpad sounds |
2476 | 179 | */ | 188 | */ |
2478 | 180 | if (GreeterContacts::instance()->dialpadSoundsEnabled() && | 189 | int event = toDTMFEvent(key); |
2479 | 190 | if (GreeterContacts::instance()->dialpadSoundsEnabled() && | ||
2480 | 181 | !GreeterContacts::instance()->silentMode() && objectPath.isEmpty() | 191 | !GreeterContacts::instance()->silentMode() && objectPath.isEmpty() |
2481 | 182 | || !objectPath.isEmpty()) { | 192 | || !objectPath.isEmpty()) { |
2483 | 183 | ToneGenerator::instance()->playDTMFTone((uint)event); | 193 | ToneGenerator::instance()->playDTMFTone(event); |
2484 | 184 | } | 194 | } |
2485 | 185 | 195 | ||
2486 | 186 | Tp::CallChannelPtr channel = callFromObjectPath(objectPath); | 196 | Tp::CallChannelPtr channel = callFromObjectPath(objectPath); |
2487 | @@ -190,14 +200,15 @@ | |||
2488 | 190 | 200 | ||
2489 | 191 | // save the dtmfString to send to clients that request it | 201 | // save the dtmfString to send to clients that request it |
2490 | 192 | QString dtmfString = channel->property("dtmfString").toString(); | 202 | QString dtmfString = channel->property("dtmfString").toString(); |
2491 | 203 | QString pendingDTMF = channel->property("pendingDTMF").toString(); | ||
2492 | 204 | pendingDTMF += key; | ||
2493 | 193 | dtmfString += key; | 205 | dtmfString += key; |
2494 | 194 | channel->setProperty("dtmfString", dtmfString); | 206 | channel->setProperty("dtmfString", dtmfString); |
2495 | 207 | channel->setProperty("pendingDTMF", pendingDTMF); | ||
2496 | 195 | 208 | ||
2502 | 196 | Q_FOREACH(const Tp::CallContentPtr &content, channel->contents()) { | 209 | // if there is only one pending DTMF event, start playing it |
2503 | 197 | if (content->supportsDTMF()) { | 210 | if (pendingDTMF.length() == 1) { |
2504 | 198 | /* send DTMF to network (via telepathy and oFono) */ | 211 | playNextDTMFTone(channel); |
2500 | 199 | content->startDTMFTone(event); | ||
2501 | 200 | } | ||
2505 | 201 | } | 212 | } |
2506 | 202 | 213 | ||
2507 | 203 | Q_EMIT callPropertiesChanged(channel->objectPath(), getCallProperties(channel->objectPath())); | 214 | Q_EMIT callPropertiesChanged(channel->objectPath(), getCallProperties(channel->objectPath())); |
2508 | @@ -266,13 +277,12 @@ | |||
2509 | 266 | void CallHandler::onCallChannelAvailable(Tp::CallChannelPtr channel) | 277 | void CallHandler::onCallChannelAvailable(Tp::CallChannelPtr channel) |
2510 | 267 | { | 278 | { |
2511 | 268 | QDBusInterface callChannelIface(channel->busName(), channel->objectPath(), DBUS_PROPERTIES_IFACE); | 279 | QDBusInterface callChannelIface(channel->busName(), channel->objectPath(), DBUS_PROPERTIES_IFACE); |
2512 | 269 | QDBusMessage reply = callChannelIface.call("GetAll", CANONICAL_TELEPHONY_AUDIOOUTPUTS_IFACE); | ||
2513 | 270 | QVariantList args = reply.arguments(); | ||
2514 | 271 | QMap<QString, QVariant> map = qdbus_cast<QMap<QString, QVariant> >(args[0]); | ||
2515 | 272 | channel->setProperty("timestamp", QDateTime::currentDateTimeUtc()); | 280 | channel->setProperty("timestamp", QDateTime::currentDateTimeUtc()); |
2516 | 273 | 281 | ||
2517 | 274 | if (channel->callState() == Tp::CallStateActive) { | 282 | if (channel->callState() == Tp::CallStateActive) { |
2518 | 275 | channel->setProperty("activeTimestamp", QDateTime::currentDateTimeUtc()); | 283 | channel->setProperty("activeTimestamp", QDateTime::currentDateTimeUtc()); |
2519 | 284 | } else if (channel->callState() == Tp::CallStatePendingInitiator) { | ||
2520 | 285 | channel->accept(); | ||
2521 | 276 | } | 286 | } |
2522 | 277 | 287 | ||
2523 | 278 | connect(channel.data(), | 288 | connect(channel.data(), |
2524 | @@ -282,6 +292,10 @@ | |||
2525 | 282 | SIGNAL(callStateChanged(Tp::CallState)), | 292 | SIGNAL(callStateChanged(Tp::CallState)), |
2526 | 283 | SLOT(onCallStateChanged(Tp::CallState))); | 293 | SLOT(onCallStateChanged(Tp::CallState))); |
2527 | 284 | 294 | ||
2528 | 295 | // FIXME: save this to a list | ||
2529 | 296 | CallAgent *agent = new CallAgent(channel, this); | ||
2530 | 297 | mCallAgents[channel.data()] = agent; | ||
2531 | 298 | |||
2532 | 285 | mCallChannels.append(channel); | 299 | mCallChannels.append(channel); |
2533 | 286 | Q_EMIT callPropertiesChanged(channel->objectPath(), getCallProperties(channel->objectPath())); | 300 | Q_EMIT callPropertiesChanged(channel->objectPath(), getCallProperties(channel->objectPath())); |
2534 | 287 | } | 301 | } |
2535 | @@ -331,7 +345,12 @@ | |||
2536 | 331 | } | 345 | } |
2537 | 332 | 346 | ||
2538 | 333 | mCallChannels.removeAll(channel); | 347 | mCallChannels.removeAll(channel); |
2539 | 348 | if (mCallAgents.contains(channel.data())) { | ||
2540 | 349 | CallAgent *agent = mCallAgents.take(channel.data()); | ||
2541 | 350 | agent->deleteLater(); | ||
2542 | 351 | } | ||
2543 | 334 | 352 | ||
2544 | 353 | ToneGenerator::instance()->stopTone(); | ||
2545 | 335 | if (mCallChannels.isEmpty() && !mHangupRequested) { | 354 | if (mCallChannels.isEmpty() && !mHangupRequested) { |
2546 | 336 | ToneGenerator::instance()->playCallEndedTone(); | 355 | ToneGenerator::instance()->playCallEndedTone(); |
2547 | 337 | } | 356 | } |
2548 | @@ -346,10 +365,29 @@ | |||
2549 | 346 | } | 365 | } |
2550 | 347 | 366 | ||
2551 | 348 | switch (state) { | 367 | switch (state) { |
2552 | 368 | case Tp::CallStatePendingInitiator: | ||
2553 | 369 | case Tp::CallStateInitialising: | ||
2554 | 370 | if (!isIncoming(channel) && channel->handlerStreamingRequired()) { | ||
2555 | 371 | ToneGenerator::instance()->playDialingTone(); | ||
2556 | 372 | } | ||
2557 | 373 | break; | ||
2558 | 374 | case Tp::CallStateInitialised: | ||
2559 | 375 | if (!isIncoming(channel) && channel->handlerStreamingRequired()) { | ||
2560 | 376 | ToneGenerator::instance()->stopTone(); | ||
2561 | 377 | ToneGenerator::instance()->playRingingTone(); | ||
2562 | 378 | } | ||
2563 | 379 | break; | ||
2564 | 349 | case Tp::CallStateActive: | 380 | case Tp::CallStateActive: |
2565 | 381 | if (channel->handlerStreamingRequired()) { | ||
2566 | 382 | ToneGenerator::instance()->stopTone(); | ||
2567 | 383 | } | ||
2568 | 350 | channel->setProperty("activeTimestamp", QDateTime::currentDateTimeUtc()); | 384 | channel->setProperty("activeTimestamp", QDateTime::currentDateTimeUtc()); |
2569 | 351 | Q_EMIT callPropertiesChanged(channel->objectPath(), getCallProperties(channel->objectPath())); | 385 | Q_EMIT callPropertiesChanged(channel->objectPath(), getCallProperties(channel->objectPath())); |
2570 | 352 | break; | 386 | break; |
2571 | 387 | case Tp::CallStateEnded: | ||
2572 | 388 | ToneGenerator::instance()->stopTone(); | ||
2573 | 389 | channel->requestClose(); | ||
2574 | 390 | break; | ||
2575 | 353 | } | 391 | } |
2576 | 354 | } | 392 | } |
2577 | 355 | 393 | ||
2578 | @@ -387,3 +425,128 @@ | |||
2579 | 387 | 425 | ||
2580 | 388 | return channel; | 426 | return channel; |
2581 | 389 | } | 427 | } |
2582 | 428 | |||
2583 | 429 | void CallHandler::playNextDTMFTone(Tp::CallChannelPtr channel) | ||
2584 | 430 | { | ||
2585 | 431 | // the channel might have been closed already | ||
2586 | 432 | if (!channel) { | ||
2587 | 433 | return; | ||
2588 | 434 | } | ||
2589 | 435 | |||
2590 | 436 | QString pendingDTMF = channel->property("pendingDTMF").toString(); | ||
2591 | 437 | QString key = ""; | ||
2592 | 438 | if (!pendingDTMF.isEmpty()) { | ||
2593 | 439 | key = pendingDTMF[0]; | ||
2594 | 440 | } | ||
2595 | 441 | |||
2596 | 442 | int event = toDTMFEvent(key); | ||
2597 | 443 | |||
2598 | 444 | Q_FOREACH(const Tp::CallContentPtr &content, channel->contents()) { | ||
2599 | 445 | if (content->supportsDTMF()) { | ||
2600 | 446 | |||
2601 | 447 | /* stop any previous DTMF tone before sending the new one*/ | ||
2602 | 448 | connect(content->stopDTMFTone(), &Tp::PendingOperation::finished, [=](Tp::PendingOperation *op){ | ||
2603 | 449 | // in case stopDTMFTone, it might mean the service automatically stops the tone, | ||
2604 | 450 | // so try playing the next one | ||
2605 | 451 | if (op->isError()) { | ||
2606 | 452 | /* send DTMF to network (via telepathy) */ | ||
2607 | 453 | if (event >= 0) { | ||
2608 | 454 | content->startDTMFTone((Tp::DTMFEvent)event); | ||
2609 | 455 | } | ||
2610 | 456 | triggerNextDTMFTone(channel); | ||
2611 | 457 | return; | ||
2612 | 458 | } | ||
2613 | 459 | |||
2614 | 460 | Tp::Client::CallContentInterfaceDTMFInterface *dtmfInterface = content->interface<Tp::Client::CallContentInterfaceDTMFInterface>(); | ||
2615 | 461 | Tp::PendingVariant *pv = dtmfInterface->requestPropertyCurrentlySendingTones(); | ||
2616 | 462 | connect(pv, &Tp::PendingOperation::finished, [=](){ | ||
2617 | 463 | bool sendingTones = pv->result().toBool(); | ||
2618 | 464 | // if we already stopped sending tones, we can send the next one | ||
2619 | 465 | if (!sendingTones) { | ||
2620 | 466 | /* send DTMF to network (via telepathy) */ | ||
2621 | 467 | if (event >= 0) { | ||
2622 | 468 | content->startDTMFTone((Tp::DTMFEvent)event); | ||
2623 | 469 | } | ||
2624 | 470 | triggerNextDTMFTone(channel); | ||
2625 | 471 | return; | ||
2626 | 472 | } | ||
2627 | 473 | |||
2628 | 474 | // in case the previous tone is not finished, we need to wait for it | ||
2629 | 475 | auto conn = std::make_shared<QMetaObject::Connection>(); | ||
2630 | 476 | *conn = connect(dtmfInterface, &Tp::Client::CallContentInterfaceDTMFInterface::StoppedTones, [=](){ | ||
2631 | 477 | QObject::disconnect(*conn); | ||
2632 | 478 | |||
2633 | 479 | /* send DTMF to network (via telepathy) */ | ||
2634 | 480 | if (event >= 0) { | ||
2635 | 481 | content->startDTMFTone((Tp::DTMFEvent)event); | ||
2636 | 482 | } | ||
2637 | 483 | triggerNextDTMFTone(channel); | ||
2638 | 484 | }); | ||
2639 | 485 | }); | ||
2640 | 486 | |||
2641 | 487 | }); | ||
2642 | 488 | } | ||
2643 | 489 | } | ||
2644 | 490 | } | ||
2645 | 491 | |||
2646 | 492 | void CallHandler::triggerNextDTMFTone(Tp::CallChannelPtr channel) | ||
2647 | 493 | { | ||
2648 | 494 | QTimer::singleShot(250, [=](){ | ||
2649 | 495 | QString pendingDTMF = channel->property("pendingDTMF").toString(); | ||
2650 | 496 | if (pendingDTMF.isEmpty()) { | ||
2651 | 497 | return; | ||
2652 | 498 | } | ||
2653 | 499 | pendingDTMF.remove(0, 1); | ||
2654 | 500 | channel->setProperty("pendingDTMF", pendingDTMF); | ||
2655 | 501 | playNextDTMFTone(channel); | ||
2656 | 502 | }); | ||
2657 | 503 | } | ||
2658 | 504 | |||
2659 | 505 | int CallHandler::toDTMFEvent(const QString &key) | ||
2660 | 506 | { | ||
2661 | 507 | bool ok; | ||
2662 | 508 | int ev = key.toInt(&ok); | ||
2663 | 509 | if (!ok) { | ||
2664 | 510 | if (key == "*") { | ||
2665 | 511 | ev = Tp::DTMFEventAsterisk; | ||
2666 | 512 | } else if (key == "#") { | ||
2667 | 513 | ev = Tp::DTMFEventHash; | ||
2668 | 514 | } else { | ||
2669 | 515 | ev = -1; | ||
2670 | 516 | } | ||
2671 | 517 | } | ||
2672 | 518 | return ev; | ||
2673 | 519 | } | ||
2674 | 520 | |||
2675 | 521 | bool CallHandler::isIncoming(const Tp::CallChannelPtr &channel) const | ||
2676 | 522 | { | ||
2677 | 523 | AccountEntry *accountEntry = TelepathyHelper::instance()->accountForConnection(channel->connection()); | ||
2678 | 524 | return channel->initiatorContact() != accountEntry->account()->connection()->selfContact(); | ||
2679 | 525 | } | ||
2680 | 526 | |||
2681 | 527 | QString CallHandler::applyNumberRewritingRules(const QString &originalNumber, const QVariantMap &properties) | ||
2682 | 528 | { | ||
2683 | 529 | QString finalNumber = originalNumber; | ||
2684 | 530 | if (properties.contains("numberRewrite") && properties["numberRewrite"].toBool()) { | ||
2685 | 531 | // FIXME: do a proper phone number identification implementation | ||
2686 | 532 | // for now consider anything bigger than 6 digits to be a phone number | ||
2687 | 533 | if (finalNumber.length() <= 6) { | ||
2688 | 534 | return finalNumber; | ||
2689 | 535 | } | ||
2690 | 536 | |||
2691 | 537 | QString defaultCountryCode = properties["defaultCountryCode"].toString(); | ||
2692 | 538 | QString defaultAreaCode = properties["defaultAreaCode"].toString(); | ||
2693 | 539 | QString removeCharacters = properties["removeCharacters"].toString(); | ||
2694 | 540 | QString prefix = properties["prefix"].toString(); | ||
2695 | 541 | |||
2696 | 542 | if (!defaultCountryCode.startsWith("+")) { | ||
2697 | 543 | defaultCountryCode.prepend("+"); | ||
2698 | 544 | } | ||
2699 | 545 | |||
2700 | 546 | finalNumber = PhoneUtils::getFullNumber(finalNumber, defaultCountryCode, defaultAreaCode); | ||
2701 | 547 | finalNumber.remove(removeCharacters); | ||
2702 | 548 | finalNumber.prepend(prefix); | ||
2703 | 549 | } | ||
2704 | 550 | |||
2705 | 551 | return finalNumber; | ||
2706 | 552 | } | ||
2707 | 390 | 553 | ||
2708 | === modified file 'handler/callhandler.h' | |||
2709 | --- handler/callhandler.h 2015-03-04 18:02:13 +0000 | |||
2710 | +++ handler/callhandler.h 2017-04-05 14:05:16 +0000 | |||
2711 | @@ -1,5 +1,5 @@ | |||
2712 | 1 | /* | 1 | /* |
2714 | 2 | * Copyright (C) 2012-2013 Canonical, Ltd. | 2 | * Copyright (C) 2012-2017 Canonical, Ltd. |
2715 | 3 | * | 3 | * |
2716 | 4 | * Authors: | 4 | * Authors: |
2717 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
2718 | @@ -28,6 +28,7 @@ | |||
2719 | 28 | #include <TelepathyQt/CallChannel> | 28 | #include <TelepathyQt/CallChannel> |
2720 | 29 | 29 | ||
2721 | 30 | class TelepathyHelper; | 30 | class TelepathyHelper; |
2722 | 31 | class CallAgent; | ||
2723 | 31 | 32 | ||
2724 | 32 | class CallHandler : public QObject | 33 | class CallHandler : public QObject |
2725 | 33 | { | 34 | { |
2726 | @@ -44,7 +45,6 @@ | |||
2727 | 44 | void hangUpCall(const QString &objectPath); | 45 | void hangUpCall(const QString &objectPath); |
2728 | 45 | void setHold(const QString &objectPath, bool hold); | 46 | void setHold(const QString &objectPath, bool hold); |
2729 | 46 | void setMuted(const QString &objectPath, bool muted); | 47 | void setMuted(const QString &objectPath, bool muted); |
2730 | 47 | void setActiveAudioOutput(const QString &objectPath, const QString &id); | ||
2731 | 48 | void sendDTMF(const QString &objectPath, const QString &key); | 48 | void sendDTMF(const QString &objectPath, const QString &key); |
2732 | 49 | 49 | ||
2733 | 50 | // conference call related | 50 | // conference call related |
2734 | @@ -61,6 +61,13 @@ | |||
2735 | 61 | Tp::CallChannelPtr existingCall(const QString &targetId); | 61 | Tp::CallChannelPtr existingCall(const QString &targetId); |
2736 | 62 | Tp::CallChannelPtr callFromObjectPath(const QString &objectPath); | 62 | Tp::CallChannelPtr callFromObjectPath(const QString &objectPath); |
2737 | 63 | 63 | ||
2738 | 64 | void playNextDTMFTone(Tp::CallChannelPtr channel); | ||
2739 | 65 | void triggerNextDTMFTone(Tp::CallChannelPtr channel); | ||
2740 | 66 | static int toDTMFEvent(const QString &key); | ||
2741 | 67 | bool isIncoming(const Tp::CallChannelPtr &channel) const; | ||
2742 | 68 | |||
2743 | 69 | QString applyNumberRewritingRules(const QString &originalNumber, const QVariantMap &properties); | ||
2744 | 70 | |||
2745 | 64 | protected Q_SLOTS: | 71 | protected Q_SLOTS: |
2746 | 65 | void onContactsAvailable(Tp::PendingOperation *op); | 72 | void onContactsAvailable(Tp::PendingOperation *op); |
2747 | 66 | void onCallHangupFinished(Tp::PendingOperation *op); | 73 | void onCallHangupFinished(Tp::PendingOperation *op); |
2748 | @@ -72,6 +79,7 @@ | |||
2749 | 72 | 79 | ||
2750 | 73 | QMap<QString, Tp::ContactPtr> mContacts; | 80 | QMap<QString, Tp::ContactPtr> mContacts; |
2751 | 74 | QList<Tp::CallChannelPtr> mCallChannels; | 81 | QList<Tp::CallChannelPtr> mCallChannels; |
2752 | 82 | QMap<Tp::CallChannel*,CallAgent*> mCallAgents; | ||
2753 | 75 | QMap<Tp::PendingOperation*,Tp::CallChannelPtr> mClosingChannels; | 83 | QMap<Tp::PendingOperation*,Tp::CallChannelPtr> mClosingChannels; |
2754 | 76 | bool mHangupRequested; | 84 | bool mHangupRequested; |
2755 | 77 | }; | 85 | }; |
2756 | 78 | 86 | ||
2757 | === added file 'handler/farstreamchannel.cpp' | |||
2758 | --- handler/farstreamchannel.cpp 1970-01-01 00:00:00 +0000 | |||
2759 | +++ handler/farstreamchannel.cpp 2017-04-05 14:05:16 +0000 | |||
2760 | @@ -0,0 +1,326 @@ | |||
2761 | 1 | /* | ||
2762 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
2763 | 3 | * | ||
2764 | 4 | * Authors: | ||
2765 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | ||
2766 | 6 | * | ||
2767 | 7 | * This file is part of telephony-service. | ||
2768 | 8 | * | ||
2769 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
2770 | 10 | * it under the terms of the GNU General Public License as published by | ||
2771 | 11 | * the Free Software Foundation; version 3. | ||
2772 | 12 | * | ||
2773 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
2774 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2775 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2776 | 16 | * GNU General Public License for more details. | ||
2777 | 17 | * | ||
2778 | 18 | * You should have received a copy of the GNU General Public License | ||
2779 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2780 | 20 | */ | ||
2781 | 21 | |||
2782 | 22 | #include "farstreamchannel.h" | ||
2783 | 23 | #include <farstream/fs-utils.h> | ||
2784 | 24 | #include <QDebug> | ||
2785 | 25 | |||
2786 | 26 | FarstreamChannel::FarstreamChannel(TfChannel *channel, QObject *parent) : | ||
2787 | 27 | mChannel(channel), QObject(parent), mPipeline(0), mBus(0), mBusSource(0), | ||
2788 | 28 | mConferenceAddedSignal(0), mConferenceRemovedSignal(0), mContentAddedSignal(0), | ||
2789 | 29 | mContentRemovedSignal(0), mAudioInput(0), mAudioOutput(0) | ||
2790 | 30 | { | ||
2791 | 31 | qDebug() << __PRETTY_FUNCTION__; | ||
2792 | 32 | initialize(); | ||
2793 | 33 | } | ||
2794 | 34 | |||
2795 | 35 | FarstreamChannel::~FarstreamChannel() | ||
2796 | 36 | { | ||
2797 | 37 | // stop audio input and output | ||
2798 | 38 | if (mAudioInput) { | ||
2799 | 39 | setState(mAudioInput, GST_STATE_NULL); | ||
2800 | 40 | gst_object_unref(mAudioInput); | ||
2801 | 41 | } | ||
2802 | 42 | |||
2803 | 43 | if (mAudioOutput) { | ||
2804 | 44 | setState(mAudioOutput, GST_STATE_NULL); | ||
2805 | 45 | gst_object_unref(mAudioOutput); | ||
2806 | 46 | } | ||
2807 | 47 | |||
2808 | 48 | // now clear the notifiers | ||
2809 | 49 | Q_FOREACH(FsElementAddedNotifier *notifier, mNotifiers) { | ||
2810 | 50 | fs_element_added_notifier_remove(notifier, GST_BIN(mPipeline)); | ||
2811 | 51 | g_object_unref(notifier); | ||
2812 | 52 | } | ||
2813 | 53 | mNotifiers.clear(); | ||
2814 | 54 | |||
2815 | 55 | // clear the bus stuff | ||
2816 | 56 | if (mBusSource) { | ||
2817 | 57 | g_source_remove(mBusSource); | ||
2818 | 58 | } | ||
2819 | 59 | |||
2820 | 60 | if (mBus) { | ||
2821 | 61 | gst_object_unref(mBus); | ||
2822 | 62 | } | ||
2823 | 63 | |||
2824 | 64 | // and finally the pipeline | ||
2825 | 65 | if (mPipeline) { | ||
2826 | 66 | setState(mPipeline, GST_STATE_NULL); | ||
2827 | 67 | gst_object_unref(mPipeline); | ||
2828 | 68 | } | ||
2829 | 69 | } | ||
2830 | 70 | |||
2831 | 71 | void FarstreamChannel::setMute(bool mute) | ||
2832 | 72 | { | ||
2833 | 73 | GstElement *input_volume = gst_bin_get_by_name(GST_BIN(mPipeline), "input_volume"); | ||
2834 | 74 | g_object_set(input_volume, "mute", mute, NULL); | ||
2835 | 75 | g_object_unref(input_volume); | ||
2836 | 76 | } | ||
2837 | 77 | |||
2838 | 78 | void FarstreamChannel::initialize() | ||
2839 | 79 | { | ||
2840 | 80 | qDebug() << __PRETTY_FUNCTION__; | ||
2841 | 81 | // connect all the signals | ||
2842 | 82 | mConferenceAddedSignal = g_signal_connect(mChannel, "fs-conference-added", | ||
2843 | 83 | G_CALLBACK(&FarstreamChannel::onConferenceAdded), | ||
2844 | 84 | this); | ||
2845 | 85 | mConferenceRemovedSignal = g_signal_connect(mChannel, "fs-conference-removed", | ||
2846 | 86 | G_CALLBACK(&FarstreamChannel::onConferenceRemoved), | ||
2847 | 87 | this); | ||
2848 | 88 | mContentAddedSignal = g_signal_connect(mChannel, "content-added", | ||
2849 | 89 | G_CALLBACK(&FarstreamChannel::onContentAdded), | ||
2850 | 90 | this); | ||
2851 | 91 | mContentRemovedSignal = g_signal_connect(mChannel, "content-removed", | ||
2852 | 92 | G_CALLBACK(&FarstreamChannel::onContentRemoved), | ||
2853 | 93 | this); | ||
2854 | 94 | |||
2855 | 95 | // and initialize the gstreamer pipeline | ||
2856 | 96 | mPipeline = gst_pipeline_new(NULL); | ||
2857 | 97 | if (!mPipeline) { | ||
2858 | 98 | qCritical() << "Failed to create GStreamer pipeline."; | ||
2859 | 99 | return; | ||
2860 | 100 | } | ||
2861 | 101 | |||
2862 | 102 | mBus = gst_pipeline_get_bus(GST_PIPELINE(mPipeline)); | ||
2863 | 103 | if (!mBus) { | ||
2864 | 104 | qCritical() << "Failed to get GStreamer pipeline bus."; | ||
2865 | 105 | return; | ||
2866 | 106 | } | ||
2867 | 107 | |||
2868 | 108 | mBusSource = gst_bus_add_watch(mBus, (GstBusFunc) &FarstreamChannel::onBusWatch, this); | ||
2869 | 109 | |||
2870 | 110 | if (!setState(mPipeline, GST_STATE_PLAYING)) { | ||
2871 | 111 | return; | ||
2872 | 112 | } | ||
2873 | 113 | } | ||
2874 | 114 | |||
2875 | 115 | GstElement *FarstreamChannel::initializeAudioSource(TfContent *content) | ||
2876 | 116 | { | ||
2877 | 117 | qDebug() << __PRETTY_FUNCTION__; | ||
2878 | 118 | GstElement *element = gst_parse_bin_from_description ("alsasrc ! audio/x-raw, rate=8000 ! queue" | ||
2879 | 119 | " ! audioconvert ! audioresample" | ||
2880 | 120 | " ! volume name=input_volume ! audioconvert ", | ||
2881 | 121 | TRUE, NULL); | ||
2882 | 122 | gint input_volume = 0; | ||
2883 | 123 | g_object_get (content, "requested-input-volume", &input_volume, NULL); | ||
2884 | 124 | |||
2885 | 125 | if (input_volume >= 0) { | ||
2886 | 126 | GstElement *volume = gst_bin_get_by_name (GST_BIN (element), "input_volume"); | ||
2887 | 127 | g_object_set (volume, "volume", (double)input_volume / 255.0, NULL); | ||
2888 | 128 | gst_object_unref (volume); | ||
2889 | 129 | } | ||
2890 | 130 | |||
2891 | 131 | // FIXME: we probably need to handle input volume request changes | ||
2892 | 132 | mAudioOutput = element; | ||
2893 | 133 | return element; | ||
2894 | 134 | } | ||
2895 | 135 | |||
2896 | 136 | bool FarstreamChannel::addToPipeline(GstElement *element) | ||
2897 | 137 | { | ||
2898 | 138 | qDebug() << __PRETTY_FUNCTION__ << GST_ELEMENT_NAME(element); | ||
2899 | 139 | if (!mPipeline) { | ||
2900 | 140 | qWarning() << "No gstreamer pipeline found."; | ||
2901 | 141 | return false; | ||
2902 | 142 | } | ||
2903 | 143 | |||
2904 | 144 | if (!gst_bin_add(GST_BIN(mPipeline), element)) { | ||
2905 | 145 | qCritical() << "Failed to add bin" << GST_ELEMENT_NAME(element) << "to pipeline."; | ||
2906 | 146 | return false; | ||
2907 | 147 | } | ||
2908 | 148 | qDebug() << "Succeeded adding to pipeline!"; | ||
2909 | 149 | return true; | ||
2910 | 150 | } | ||
2911 | 151 | |||
2912 | 152 | void FarstreamChannel::removeFromPipeline(GstElement *element) | ||
2913 | 153 | { | ||
2914 | 154 | qDebug() << __PRETTY_FUNCTION__ << GST_ELEMENT_NAME(element); | ||
2915 | 155 | gst_element_set_locked_state(element, TRUE); | ||
2916 | 156 | setState(element, GST_STATE_NULL); | ||
2917 | 157 | gst_bin_remove (GST_BIN (mPipeline), element); | ||
2918 | 158 | } | ||
2919 | 159 | |||
2920 | 160 | bool FarstreamChannel::setState(GstElement *element, GstState state) | ||
2921 | 161 | { | ||
2922 | 162 | qDebug() << __PRETTY_FUNCTION__ << GST_ELEMENT_NAME(element) << gst_element_state_get_name(state); | ||
2923 | 163 | GstStateChangeReturn result = gst_element_set_state(element, state); | ||
2924 | 164 | if (result == GST_STATE_CHANGE_FAILURE) { | ||
2925 | 165 | qCritical() << "Failed to set GStreamer element" << GST_ELEMENT_NAME(element) << "state to" << gst_element_state_get_name(state); | ||
2926 | 166 | return false; | ||
2927 | 167 | } | ||
2928 | 168 | qDebug() << "Succeeded playing!"; | ||
2929 | 169 | return true; | ||
2930 | 170 | } | ||
2931 | 171 | |||
2932 | 172 | gboolean FarstreamChannel::onBusWatch(GstBus *bus, GstMessage *message, FarstreamChannel *self) | ||
2933 | 173 | { | ||
2934 | 174 | Q_UNUSED(bus) | ||
2935 | 175 | if (!self->mChannel) { | ||
2936 | 176 | return TRUE; | ||
2937 | 177 | } | ||
2938 | 178 | |||
2939 | 179 | // FIXME: maybe we need to do some error handling here? | ||
2940 | 180 | tf_channel_bus_message(self->mChannel, message); | ||
2941 | 181 | return TRUE; | ||
2942 | 182 | } | ||
2943 | 183 | |||
2944 | 184 | void FarstreamChannel::onConferenceAdded(TfChannel *channel, FsConference *conference, FarstreamChannel *self) | ||
2945 | 185 | { | ||
2946 | 186 | qDebug() << __PRETTY_FUNCTION__; | ||
2947 | 187 | Q_UNUSED(channel) | ||
2948 | 188 | |||
2949 | 189 | /* Add notifier to set the various element properties as needed */ | ||
2950 | 190 | GKeyFile *keyfile = fs_utils_get_default_element_properties (GST_ELEMENT(conference)); | ||
2951 | 191 | if (keyfile != NULL) { | ||
2952 | 192 | qDebug() << "Loaded default properties for" << GST_ELEMENT_NAME(conference); | ||
2953 | 193 | FsElementAddedNotifier *notifier = fs_element_added_notifier_new(); | ||
2954 | 194 | fs_element_added_notifier_set_properties_from_keyfile(notifier, keyfile); | ||
2955 | 195 | fs_element_added_notifier_add(notifier, GST_BIN(self->mPipeline)); | ||
2956 | 196 | |||
2957 | 197 | // FIXME: right now we are leaking the notifiers, check when to remove them | ||
2958 | 198 | self->mNotifiers.append(notifier); | ||
2959 | 199 | } | ||
2960 | 200 | |||
2961 | 201 | if (!self->addToPipeline(GST_ELEMENT(conference))) { | ||
2962 | 202 | return; | ||
2963 | 203 | } | ||
2964 | 204 | |||
2965 | 205 | self->setState(GST_ELEMENT(conference), GST_STATE_PLAYING); | ||
2966 | 206 | } | ||
2967 | 207 | |||
2968 | 208 | void FarstreamChannel::onConferenceRemoved(TfChannel *channel, FsConference *conference, FarstreamChannel *self) | ||
2969 | 209 | { | ||
2970 | 210 | qDebug() << __PRETTY_FUNCTION__; | ||
2971 | 211 | Q_UNUSED(channel); | ||
2972 | 212 | |||
2973 | 213 | // just remove the conference from the pipeline | ||
2974 | 214 | self->removeFromPipeline(GST_ELEMENT(conference)); | ||
2975 | 215 | } | ||
2976 | 216 | |||
2977 | 217 | void FarstreamChannel::onContentAdded(TfChannel *channel, TfContent *content, FarstreamChannel *self) | ||
2978 | 218 | { | ||
2979 | 219 | qDebug() << __PRETTY_FUNCTION__; | ||
2980 | 220 | Q_UNUSED(channel) | ||
2981 | 221 | |||
2982 | 222 | g_signal_connect(content, "src-pad-added", | ||
2983 | 223 | G_CALLBACK(&FarstreamChannel::onSrcPadAdded), self); | ||
2984 | 224 | g_signal_connect(content, "start-sending", | ||
2985 | 225 | G_CALLBACK(&FarstreamChannel::onStartSending), self); | ||
2986 | 226 | g_signal_connect(content, "stop-sending", | ||
2987 | 227 | G_CALLBACK(&FarstreamChannel::onStopSending), self); | ||
2988 | 228 | } | ||
2989 | 229 | |||
2990 | 230 | void FarstreamChannel::onContentRemoved(TfChannel *channel, TfContent *content, FarstreamChannel *self) | ||
2991 | 231 | { | ||
2992 | 232 | qDebug() << __PRETTY_FUNCTION__; | ||
2993 | 233 | // FIXME: implement | ||
2994 | 234 | } | ||
2995 | 235 | |||
2996 | 236 | bool FarstreamChannel::onStartSending(TfContent *content, FarstreamChannel *self) | ||
2997 | 237 | { | ||
2998 | 238 | qDebug() << __PRETTY_FUNCTION__; | ||
2999 | 239 | GstPad *sinkPad; | ||
3000 | 240 | FsMediaType mediaType; | ||
3001 | 241 | GstElement *element; | ||
3002 | 242 | |||
3003 | 243 | g_object_get (content, "sink-pad", &sinkPad, "media-type", &mediaType, NULL); | ||
3004 | 244 | |||
3005 | 245 | switch (mediaType) { | ||
3006 | 246 | case FS_MEDIA_TYPE_AUDIO: | ||
3007 | 247 | element = self->initializeAudioSource(content); | ||
3008 | 248 | break; | ||
3009 | 249 | // FIXME: add video support | ||
3010 | 250 | default: | ||
3011 | 251 | qWarning() << "Unsupported media type:" << mediaType; | ||
3012 | 252 | g_object_unref(sinkPad); | ||
3013 | 253 | return false; | ||
3014 | 254 | } | ||
3015 | 255 | |||
3016 | 256 | if (!self->addToPipeline(element)) { | ||
3017 | 257 | g_object_unref(sinkPad); | ||
3018 | 258 | return false; | ||
3019 | 259 | } | ||
3020 | 260 | |||
3021 | 261 | GstPad *sourcePad = gst_element_get_static_pad (element, "src"); | ||
3022 | 262 | if (GST_PAD_LINK_FAILED (gst_pad_link (sourcePad, sinkPad))) { | ||
3023 | 263 | qCritical() << "Failed to link source pad to content's sink pad"; | ||
3024 | 264 | g_object_unref(sinkPad); | ||
3025 | 265 | g_object_unref(sourcePad); | ||
3026 | 266 | return false; | ||
3027 | 267 | } | ||
3028 | 268 | |||
3029 | 269 | self->setState(element, GST_STATE_PLAYING); | ||
3030 | 270 | self->mAudioInput = element; | ||
3031 | 271 | |||
3032 | 272 | g_object_unref(sinkPad); | ||
3033 | 273 | g_object_unref(sourcePad); | ||
3034 | 274 | |||
3035 | 275 | return true; | ||
3036 | 276 | } | ||
3037 | 277 | |||
3038 | 278 | void FarstreamChannel::onStopSending(TfContent *content, FarstreamChannel *self) | ||
3039 | 279 | { | ||
3040 | 280 | qDebug() << __PRETTY_FUNCTION__; | ||
3041 | 281 | // FIXME: implement | ||
3042 | 282 | } | ||
3043 | 283 | |||
3044 | 284 | void FarstreamChannel::onSrcPadAdded(TfContent *content, uint handle, FsStream *stream, GstPad *pad, FsCodec *codec, FarstreamChannel *self) | ||
3045 | 285 | { | ||
3046 | 286 | qDebug() << __PRETTY_FUNCTION__; | ||
3047 | 287 | gchar *codecString = fs_codec_to_string (codec); | ||
3048 | 288 | qDebug() << __PRETTY_FUNCTION__ << "Codec:" << codecString; | ||
3049 | 289 | |||
3050 | 290 | FsMediaType mediaType; | ||
3051 | 291 | GstElement *element; | ||
3052 | 292 | |||
3053 | 293 | g_object_get (content, "media-type", &mediaType, NULL); | ||
3054 | 294 | |||
3055 | 295 | switch (mediaType) { | ||
3056 | 296 | case FS_MEDIA_TYPE_AUDIO: { | ||
3057 | 297 | QString outputVolume = QString("output_volume%1").arg(codecString); | ||
3058 | 298 | QString description = QString("audioconvert ! audioresample " | ||
3059 | 299 | "! volume name=\"%1\" " | ||
3060 | 300 | "! audioconvert ! autoaudiosink").arg(outputVolume); | ||
3061 | 301 | element = gst_parse_bin_from_description (description.toUtf8().data(), TRUE, NULL); | ||
3062 | 302 | GstElement *volume = gst_bin_get_by_name (GST_BIN (element), outputVolume.toUtf8().data()); | ||
3063 | 303 | |||
3064 | 304 | // FIXME: we need to handle volume request changes in the volume element | ||
3065 | 305 | gst_object_unref (volume); | ||
3066 | 306 | break; | ||
3067 | 307 | } | ||
3068 | 308 | // FIXME: handle video | ||
3069 | 309 | default: | ||
3070 | 310 | qWarning() << "Unsupported media type:" << mediaType; | ||
3071 | 311 | return; | ||
3072 | 312 | } | ||
3073 | 313 | |||
3074 | 314 | if (!self->addToPipeline(element)) { | ||
3075 | 315 | return; | ||
3076 | 316 | } | ||
3077 | 317 | |||
3078 | 318 | GstPad *sinkPad = gst_element_get_static_pad (element, "sink"); | ||
3079 | 319 | if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sinkPad))) { | ||
3080 | 320 | qCritical() << "Failed to link content's source pad to local sink pad"; | ||
3081 | 321 | } | ||
3082 | 322 | |||
3083 | 323 | self->setState(element, GST_STATE_PLAYING); | ||
3084 | 324 | |||
3085 | 325 | g_object_unref (sinkPad); | ||
3086 | 326 | } | ||
3087 | 0 | 327 | ||
3088 | === added file 'handler/farstreamchannel.h' | |||
3089 | --- handler/farstreamchannel.h 1970-01-01 00:00:00 +0000 | |||
3090 | +++ handler/farstreamchannel.h 2017-04-05 14:05:16 +0000 | |||
3091 | @@ -0,0 +1,80 @@ | |||
3092 | 1 | /* | ||
3093 | 2 | * Copyright (C) 2017 Canonical, Ltd. | ||
3094 | 3 | * | ||
3095 | 4 | * Authors: | ||
3096 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | ||
3097 | 6 | * | ||
3098 | 7 | * This file is part of telephony-service. | ||
3099 | 8 | * | ||
3100 | 9 | * telephony-service is free software; you can redistribute it and/or modify | ||
3101 | 10 | * it under the terms of the GNU General Public License as published by | ||
3102 | 11 | * the Free Software Foundation; version 3. | ||
3103 | 12 | * | ||
3104 | 13 | * telephony-service is distributed in the hope that it will be useful, | ||
3105 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3106 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3107 | 16 | * GNU General Public License for more details. | ||
3108 | 17 | * | ||
3109 | 18 | * You should have received a copy of the GNU General Public License | ||
3110 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3111 | 20 | */ | ||
3112 | 21 | |||
3113 | 22 | #ifndef FARSTREAMCHANNEL_H | ||
3114 | 23 | #define FARSTREAMCHANNEL_H | ||
3115 | 24 | |||
3116 | 25 | #include <QObject> | ||
3117 | 26 | #include <QList> | ||
3118 | 27 | #include <telepathy-farstream/telepathy-farstream.h> | ||
3119 | 28 | #include <farstream/fs-conference.h> | ||
3120 | 29 | #include <farstream/fs-stream.h> | ||
3121 | 30 | #include <farstream/fs-element-added-notifier.h> | ||
3122 | 31 | |||
3123 | 32 | class FarstreamChannel : public QObject | ||
3124 | 33 | { | ||
3125 | 34 | Q_OBJECT | ||
3126 | 35 | public: | ||
3127 | 36 | explicit FarstreamChannel(TfChannel *channel, QObject *parent = 0); | ||
3128 | 37 | ~FarstreamChannel(); | ||
3129 | 38 | |||
3130 | 39 | void setMute(bool mute); | ||
3131 | 40 | |||
3132 | 41 | protected: | ||
3133 | 42 | void initialize(); | ||
3134 | 43 | GstElement *initializeAudioSource(TfContent *content); | ||
3135 | 44 | |||
3136 | 45 | // gstreamer helpers | ||
3137 | 46 | bool addToPipeline(GstElement *element); | ||
3138 | 47 | void removeFromPipeline(GstElement *bin); | ||
3139 | 48 | bool setState(GstElement *element, GstState state); | ||
3140 | 49 | |||
3141 | 50 | // glib signal handlers | ||
3142 | 51 | static gboolean onBusWatch(GstBus *bus, GstMessage *message, FarstreamChannel *self); | ||
3143 | 52 | static void onConferenceAdded(TfChannel *channel, FsConference *conference, FarstreamChannel *self); | ||
3144 | 53 | static void onConferenceRemoved(TfChannel *channel, FsConference *conference, FarstreamChannel *self); | ||
3145 | 54 | static void onContentAdded(TfChannel *channel, TfContent * content, FarstreamChannel *self); | ||
3146 | 55 | static void onContentRemoved(TfChannel *channel, TfContent * content, FarstreamChannel *self); | ||
3147 | 56 | static bool onStartSending(TfContent *content, FarstreamChannel *self); | ||
3148 | 57 | static void onStopSending(TfContent *content, FarstreamChannel *self); | ||
3149 | 58 | static void onSrcPadAdded(TfContent *content, uint handle, FsStream *stream, GstPad *pad, FsCodec *codec, FarstreamChannel *self); | ||
3150 | 59 | |||
3151 | 60 | private: | ||
3152 | 61 | TfChannel *mChannel; | ||
3153 | 62 | |||
3154 | 63 | // gstreamer stuff | ||
3155 | 64 | GstElement *mPipeline; | ||
3156 | 65 | GstBus *mBus; | ||
3157 | 66 | uint mBusSource; | ||
3158 | 67 | GstElement *mAudioInput; | ||
3159 | 68 | GstElement *mAudioOutput; | ||
3160 | 69 | |||
3161 | 70 | // signal IDs | ||
3162 | 71 | gulong mConferenceAddedSignal; | ||
3163 | 72 | gulong mConferenceRemovedSignal; | ||
3164 | 73 | gulong mContentAddedSignal; | ||
3165 | 74 | gulong mContentRemovedSignal; | ||
3166 | 75 | |||
3167 | 76 | // farstream stuff | ||
3168 | 77 | QList<FsElementAddedNotifier*> mNotifiers; | ||
3169 | 78 | }; | ||
3170 | 79 | |||
3171 | 80 | #endif // FARSTREAMCHANNEL_H | ||
3172 | 0 | 81 | ||
3173 | === modified file 'handler/handler.cpp' | |||
3174 | --- handler/handler.cpp 2016-11-23 19:28:18 +0000 | |||
3175 | +++ handler/handler.cpp 2017-04-05 14:05:16 +0000 | |||
3176 | @@ -1,5 +1,5 @@ | |||
3177 | 1 | /* | 1 | /* |
3179 | 2 | * Copyright (C) 2012-2016 Canonical, Ltd. | 2 | * Copyright (C) 2012-2017 Canonical, Ltd. |
3180 | 3 | * | 3 | * |
3181 | 4 | * Authors: | 4 | * Authors: |
3182 | 5 | * Tiago Salem Herrmann <tiago.herrmann@canonical.com> | 5 | * Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
3183 | @@ -32,7 +32,7 @@ | |||
3184 | 32 | #include <TelepathyQt/PendingReady> | 32 | #include <TelepathyQt/PendingReady> |
3185 | 33 | 33 | ||
3186 | 34 | Handler::Handler(QObject *parent) | 34 | Handler::Handler(QObject *parent) |
3188 | 35 | : QObject(parent), Tp::AbstractClientHandler(channelFilters()) | 35 | : QObject(parent), Tp::AbstractClientHandler(channelFilters(), capabilities()) |
3189 | 36 | { | 36 | { |
3190 | 37 | } | 37 | } |
3191 | 38 | 38 | ||
3192 | @@ -102,9 +102,22 @@ | |||
3193 | 102 | specList << Tp::ChannelClassSpec::textChatroom(); | 102 | specList << Tp::ChannelClassSpec::textChatroom(); |
3194 | 103 | specList << Tp::ChannelClassSpec::unnamedTextChat(); | 103 | specList << Tp::ChannelClassSpec::unnamedTextChat(); |
3195 | 104 | 104 | ||
3196 | 105 | QVariantMap props; | ||
3197 | 106 | props[TP_QT_IFACE_CHANNEL_TYPE_CALL + ".InitialAudio"] = true; | ||
3198 | 107 | specList << Tp::ChannelClassSpec::audioCall(props); | ||
3199 | 108 | |||
3200 | 105 | return specList; | 109 | return specList; |
3201 | 106 | } | 110 | } |
3202 | 107 | 111 | ||
3203 | 112 | Tp::AbstractClientHandler::Capabilities Handler::capabilities() | ||
3204 | 113 | { | ||
3205 | 114 | QStringList caps; | ||
3206 | 115 | caps << TP_QT_IFACE_CHANNEL_TYPE_CALL + "/shm" | ||
3207 | 116 | << TP_QT_IFACE_CHANNEL_TYPE_CALL + "/ice" | ||
3208 | 117 | << TP_QT_IFACE_CHANNEL_TYPE_CALL + "/gtalk-p2p"; | ||
3209 | 118 | return Tp::AbstractClientHandler::Capabilities(caps); | ||
3210 | 119 | } | ||
3211 | 120 | |||
3212 | 108 | void Handler::onTextChannelReady(Tp::PendingOperation *op) | 121 | void Handler::onTextChannelReady(Tp::PendingOperation *op) |
3213 | 109 | { | 122 | { |
3214 | 110 | Tp::PendingReady *pr = qobject_cast<Tp::PendingReady*>(op); | 123 | Tp::PendingReady *pr = qobject_cast<Tp::PendingReady*>(op); |
3215 | @@ -155,10 +168,12 @@ | |||
3216 | 155 | // if the call is neither Accepted nor Active, it means it got dispatched directly to the handler without passing | 168 | // if the call is neither Accepted nor Active, it means it got dispatched directly to the handler without passing |
3217 | 156 | // through any approver. For phone calls, this would mean calls getting auto-accepted which is not desirable | 169 | // through any approver. For phone calls, this would mean calls getting auto-accepted which is not desirable |
3218 | 157 | // so we return an error here | 170 | // so we return an error here |
3220 | 158 | bool incoming = false; | 171 | bool incoming = !callChannel->isRequested(); |
3221 | 159 | AccountEntry *accountEntry = TelepathyHelper::instance()->accountForConnection(callChannel->connection()); | 172 | AccountEntry *accountEntry = TelepathyHelper::instance()->accountForConnection(callChannel->connection()); |
3224 | 160 | if (accountEntry) { | 173 | if (accountEntry && |
3225 | 161 | incoming = callChannel->initiatorContact() != accountEntry->account()->connection()->selfContact(); | 174 | !callChannel->initiatorContact().isNull() && |
3226 | 175 | callChannel->initiatorContact() != accountEntry->account()->connection()->selfContact()) { | ||
3227 | 176 | incoming = true; | ||
3228 | 162 | } | 177 | } |
3229 | 163 | if (incoming && callChannel->callState() != Tp::CallStateAccepted && callChannel->callState() != Tp::CallStateActive) { | 178 | if (incoming && callChannel->callState() != Tp::CallStateAccepted && callChannel->callState() != Tp::CallStateActive) { |
3230 | 164 | qWarning() << "Available channel was not approved by telephony-service-approver, ignoring it."; | 179 | qWarning() << "Available channel was not approved by telephony-service-approver, ignoring it."; |
3231 | 165 | 180 | ||
3232 | === modified file 'handler/handler.h' | |||
3233 | --- handler/handler.h 2015-07-01 22:04:30 +0000 | |||
3234 | +++ handler/handler.h 2017-04-05 14:05:16 +0000 | |||
3235 | @@ -1,5 +1,5 @@ | |||
3236 | 1 | /* | 1 | /* |
3238 | 2 | * Copyright (C) 2012-2013 Canonical, Ltd. | 2 | * Copyright (C) 2012-2017 Canonical, Ltd. |
3239 | 3 | * | 3 | * |
3240 | 4 | * Authors: | 4 | * Authors: |
3241 | 5 | * Tiago Salem Herrmann <tiago.herrmann@canonical.com> | 5 | * Tiago Salem Herrmann <tiago.herrmann@canonical.com> |
3242 | @@ -45,6 +45,7 @@ | |||
3243 | 45 | const QDateTime &userActionTime, | 45 | const QDateTime &userActionTime, |
3244 | 46 | const Tp::AbstractClientHandler::HandlerInfo &handlerInfo); | 46 | const Tp::AbstractClientHandler::HandlerInfo &handlerInfo); |
3245 | 47 | Tp::ChannelClassSpecList channelFilters(); | 47 | Tp::ChannelClassSpecList channelFilters(); |
3246 | 48 | Tp::AbstractClientHandler::Capabilities capabilities(); | ||
3247 | 48 | 49 | ||
3248 | 49 | Q_SIGNALS: | 50 | Q_SIGNALS: |
3249 | 50 | void textChannelAvailable(Tp::TextChannelPtr textChannel); | 51 | void textChannelAvailable(Tp::TextChannelPtr textChannel); |
3250 | 51 | 52 | ||
3251 | === modified file 'handler/handlerdbus.cpp' | |||
3252 | --- handler/handlerdbus.cpp 2016-12-06 16:45:01 +0000 | |||
3253 | +++ handler/handlerdbus.cpp 2017-04-05 14:05:16 +0000 | |||
3254 | @@ -1,5 +1,5 @@ | |||
3255 | 1 | /* | 1 | /* |
3257 | 2 | * Copyright (C) 2012-2016 Canonical, Ltd. | 2 | * Copyright (C) 2012-2017 Canonical, Ltd. |
3258 | 3 | * | 3 | * |
3259 | 4 | * Authors: | 4 | * Authors: |
3260 | 5 | * Ugo Riboni <ugo.riboni@canonical.com> | 5 | * Ugo Riboni <ugo.riboni@canonical.com> |
3261 | @@ -21,6 +21,9 @@ | |||
3262 | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3263 | 22 | */ | 22 | */ |
3264 | 23 | 23 | ||
3265 | 24 | #include "accountproperties.h" | ||
3266 | 25 | #include "audiooutput.h" | ||
3267 | 26 | #include "audioroutemanager.h" | ||
3268 | 24 | #include "callhandler.h" | 27 | #include "callhandler.h" |
3269 | 25 | #include "handlerdbus.h" | 28 | #include "handlerdbus.h" |
3270 | 26 | #include "handleradaptor.h" | 29 | #include "handleradaptor.h" |
3271 | @@ -53,6 +56,12 @@ | |||
3272 | 53 | &ProtocolManager::protocolsChanged, [this]() { | 56 | &ProtocolManager::protocolsChanged, [this]() { |
3273 | 54 | Q_EMIT ProtocolsChanged(ProtocolManager::instance()->protocols().dbusType()); | 57 | Q_EMIT ProtocolsChanged(ProtocolManager::instance()->protocols().dbusType()); |
3274 | 55 | }); | 58 | }); |
3275 | 59 | connect(AudioRouteManager::instance(), | ||
3276 | 60 | SIGNAL(audioOutputsChanged(AudioOutputDBusList)), | ||
3277 | 61 | SIGNAL(AudioOutputsChanged(AudioOutputDBusList))); | ||
3278 | 62 | connect(AudioRouteManager::instance(), | ||
3279 | 63 | SIGNAL(activeAudioOutputChanged(QString)), | ||
3280 | 64 | SIGNAL(ActiveAudioOutputChanged(QString))); | ||
3281 | 56 | } | 65 | } |
3282 | 57 | 66 | ||
3283 | 58 | HandlerDBus::~HandlerDBus() | 67 | HandlerDBus::~HandlerDBus() |
3284 | @@ -95,6 +104,21 @@ | |||
3285 | 95 | return ProtocolManager::instance()->protocols().dbusType(); | 104 | return ProtocolManager::instance()->protocols().dbusType(); |
3286 | 96 | } | 105 | } |
3287 | 97 | 106 | ||
3288 | 107 | AllAccountsProperties HandlerDBus::GetAllAccountsProperties() | ||
3289 | 108 | { | ||
3290 | 109 | return AccountProperties::instance()->allProperties(); | ||
3291 | 110 | } | ||
3292 | 111 | |||
3293 | 112 | QVariantMap HandlerDBus::GetAccountProperties(const QString &accountId) | ||
3294 | 113 | { | ||
3295 | 114 | return AccountProperties::instance()->accountProperties(accountId); | ||
3296 | 115 | } | ||
3297 | 116 | |||
3298 | 117 | void HandlerDBus::SetAccountProperties(const QString &accountId, const QVariantMap &properties) | ||
3299 | 118 | { | ||
3300 | 119 | AccountProperties::instance()->setAccountProperties(accountId, properties); | ||
3301 | 120 | } | ||
3302 | 121 | |||
3303 | 98 | QString HandlerDBus::registerObject(QObject *object, const QString &path) | 122 | QString HandlerDBus::registerObject(QObject *object, const QString &path) |
3304 | 99 | { | 123 | { |
3305 | 100 | QString fullPath = QString("%1/%2").arg(DBUS_OBJECT_PATH, path); | 124 | QString fullPath = QString("%1/%2").arg(DBUS_OBJECT_PATH, path); |
3306 | @@ -125,6 +149,11 @@ | |||
3307 | 125 | TextHandler::instance()->removeParticipants(objectPath, participants, message); | 149 | TextHandler::instance()->removeParticipants(objectPath, participants, message); |
3308 | 126 | } | 150 | } |
3309 | 127 | 151 | ||
3310 | 152 | void HandlerDBus::LeaveRooms(const QString &accountId, const QString &message) | ||
3311 | 153 | { | ||
3312 | 154 | return TextHandler::instance()->leaveRooms(accountId, message); | ||
3313 | 155 | } | ||
3314 | 156 | |||
3315 | 128 | bool HandlerDBus::LeaveChat(const QString &objectPath, const QString &message) | 157 | bool HandlerDBus::LeaveChat(const QString &objectPath, const QString &message) |
3316 | 129 | { | 158 | { |
3317 | 130 | return TextHandler::instance()->leaveChat(objectPath, message); | 159 | return TextHandler::instance()->leaveChat(objectPath, message); |
3318 | @@ -140,6 +169,21 @@ | |||
3319 | 140 | return TextHandler::instance()->changeRoomTitle(objectPath, title); | 169 | return TextHandler::instance()->changeRoomTitle(objectPath, title); |
3320 | 141 | } | 170 | } |
3321 | 142 | 171 | ||
3322 | 172 | void HandlerDBus::setActiveAudioOutput(const QString &id) | ||
3323 | 173 | { | ||
3324 | 174 | AudioRouteManager::instance()->setActiveAudioOutput(id); | ||
3325 | 175 | } | ||
3326 | 176 | |||
3327 | 177 | QString HandlerDBus::activeAudioOutput() const | ||
3328 | 178 | { | ||
3329 | 179 | return AudioRouteManager::instance()->activeAudioOutput(); | ||
3330 | 180 | } | ||
3331 | 181 | |||
3332 | 182 | AudioOutputDBusList HandlerDBus::AudioOutputs() const | ||
3333 | 183 | { | ||
3334 | 184 | return AudioRouteManager::instance()->audioOutputs(); | ||
3335 | 185 | } | ||
3336 | 186 | |||
3337 | 143 | bool HandlerDBus::connectToBus() | 187 | bool HandlerDBus::connectToBus() |
3338 | 144 | { | 188 | { |
3339 | 145 | new TelephonyServiceHandlerAdaptor(this); | 189 | new TelephonyServiceHandlerAdaptor(this); |
3340 | @@ -187,11 +231,6 @@ | |||
3341 | 187 | CallHandler::instance()->setMuted(objectPath, muted); | 231 | CallHandler::instance()->setMuted(objectPath, muted); |
3342 | 188 | } | 232 | } |
3343 | 189 | 233 | ||
3344 | 190 | void HandlerDBus::SetActiveAudioOutput(const QString &objectPath, const QString &id) | ||
3345 | 191 | { | ||
3346 | 192 | CallHandler::instance()->setActiveAudioOutput(objectPath, id); | ||
3347 | 193 | } | ||
3348 | 194 | |||
3349 | 195 | void HandlerDBus::SendDTMF(const QString &objectPath, const QString &key) | 234 | void HandlerDBus::SendDTMF(const QString &objectPath, const QString &key) |
3350 | 196 | { | 235 | { |
3351 | 197 | CallHandler::instance()->sendDTMF(objectPath, key); | 236 | CallHandler::instance()->sendDTMF(objectPath, key); |
3352 | 198 | 237 | ||
3353 | === modified file 'handler/handlerdbus.h' | |||
3354 | --- handler/handlerdbus.h 2016-12-06 16:45:01 +0000 | |||
3355 | +++ handler/handlerdbus.h 2017-04-05 14:05:16 +0000 | |||
3356 | @@ -1,5 +1,5 @@ | |||
3357 | 1 | /* | 1 | /* |
3359 | 2 | * Copyright (C) 2012-2016 Canonical, Ltd. | 2 | * Copyright (C) 2012-2017 Canonical, Ltd. |
3360 | 3 | * | 3 | * |
3361 | 4 | * Authors: | 4 | * Authors: |
3362 | 5 | * Ugo Riboni <ugo.riboni@canonical.com> | 5 | * Ugo Riboni <ugo.riboni@canonical.com> |
3363 | @@ -28,6 +28,9 @@ | |||
3364 | 28 | #include <QtDBus/QDBusContext> | 28 | #include <QtDBus/QDBusContext> |
3365 | 29 | #include "chatmanager.h" | 29 | #include "chatmanager.h" |
3366 | 30 | #include "dbustypes.h" | 30 | #include "dbustypes.h" |
3367 | 31 | #include "audiooutput.h" | ||
3368 | 32 | |||
3369 | 33 | typedef QMap<QString,QVariantMap> AllAccountsProperties; | ||
3370 | 31 | 34 | ||
3371 | 32 | /** | 35 | /** |
3372 | 33 | * DBus interface for the phone handler | 36 | * DBus interface for the phone handler |
3373 | @@ -40,6 +43,11 @@ | |||
3374 | 40 | WRITE setCallIndicatorVisible | 43 | WRITE setCallIndicatorVisible |
3375 | 41 | NOTIFY CallIndicatorVisibleChanged) | 44 | NOTIFY CallIndicatorVisibleChanged) |
3376 | 42 | 45 | ||
3377 | 46 | Q_PROPERTY(QString ActiveAudioOutput | ||
3378 | 47 | READ activeAudioOutput | ||
3379 | 48 | WRITE setActiveAudioOutput | ||
3380 | 49 | NOTIFY ActiveAudioOutputChanged) | ||
3381 | 50 | |||
3382 | 43 | public: | 51 | public: |
3383 | 44 | HandlerDBus(QObject* parent=0); | 52 | HandlerDBus(QObject* parent=0); |
3384 | 45 | ~HandlerDBus(); | 53 | ~HandlerDBus(); |
3385 | @@ -52,11 +60,16 @@ | |||
3386 | 52 | void setCallIndicatorVisible(bool visible); | 60 | void setCallIndicatorVisible(bool visible); |
3387 | 53 | // configuration related | 61 | // configuration related |
3388 | 54 | ProtocolList GetProtocols(); | 62 | ProtocolList GetProtocols(); |
3389 | 63 | AllAccountsProperties GetAllAccountsProperties(); | ||
3390 | 64 | QVariantMap GetAccountProperties(const QString &accountId); | ||
3391 | 65 | void SetAccountProperties(const QString &accountId, const QVariantMap &properties); | ||
3392 | 55 | 66 | ||
3393 | 56 | QString registerObject(QObject *object, const QString &path); | 67 | QString registerObject(QObject *object, const QString &path); |
3394 | 57 | void unregisterObject(const QString &path); | 68 | void unregisterObject(const QString &path); |
3395 | 58 | 69 | ||
3396 | 59 | static HandlerDBus *instance(); | 70 | static HandlerDBus *instance(); |
3397 | 71 | QString activeAudioOutput() const; | ||
3398 | 72 | void setActiveAudioOutput(const QString &id); | ||
3399 | 60 | 73 | ||
3400 | 61 | public Q_SLOTS: | 74 | public Q_SLOTS: |
3401 | 62 | bool connectToBus(); | 75 | bool connectToBus(); |
3402 | @@ -71,27 +84,33 @@ | |||
3403 | 71 | Q_NOREPLY void InviteParticipants(const QString &objectPath, const QStringList &participants, const QString &message); | 84 | Q_NOREPLY void InviteParticipants(const QString &objectPath, const QStringList &participants, const QString &message); |
3404 | 72 | Q_NOREPLY void RemoveParticipants(const QString &objectPath, const QStringList &participants, const QString &message); | 85 | Q_NOREPLY void RemoveParticipants(const QString &objectPath, const QStringList &participants, const QString &message); |
3405 | 73 | bool LeaveChat(const QString &objectPath, const QString &message); | 86 | bool LeaveChat(const QString &objectPath, const QString &message); |
3406 | 87 | Q_NOREPLY void LeaveRooms(const QString &accountId, const QString &message); | ||
3407 | 74 | 88 | ||
3408 | 75 | // call related | 89 | // call related |
3409 | 76 | Q_NOREPLY void StartCall(const QString &number, const QString &accountId); | 90 | Q_NOREPLY void StartCall(const QString &number, const QString &accountId); |
3410 | 77 | Q_NOREPLY void HangUpCall(const QString &objectPath); | 91 | Q_NOREPLY void HangUpCall(const QString &objectPath); |
3411 | 78 | Q_NOREPLY void SetHold(const QString &objectPath, bool hold); | 92 | Q_NOREPLY void SetHold(const QString &objectPath, bool hold); |
3412 | 79 | Q_NOREPLY void SetMuted(const QString &objectPath, bool muted); | 93 | Q_NOREPLY void SetMuted(const QString &objectPath, bool muted); |
3413 | 80 | Q_NOREPLY void SetActiveAudioOutput(const QString &objectPath, const QString &id); | ||
3414 | 81 | Q_NOREPLY void SendDTMF(const QString &objectPath, const QString &key); | 94 | Q_NOREPLY void SendDTMF(const QString &objectPath, const QString &key); |
3415 | 82 | 95 | ||
3416 | 83 | // conference call related | 96 | // conference call related |
3417 | 84 | Q_NOREPLY void CreateConferenceCall(const QStringList &objectPaths); | 97 | Q_NOREPLY void CreateConferenceCall(const QStringList &objectPaths); |
3418 | 85 | Q_NOREPLY void MergeCall(const QString &conferenceObjectPath, const QString &callObjectPath); | 98 | Q_NOREPLY void MergeCall(const QString &conferenceObjectPath, const QString &callObjectPath); |
3419 | 86 | Q_NOREPLY void SplitCall(const QString &objectPath); | 99 | Q_NOREPLY void SplitCall(const QString &objectPath); |
3420 | 100 | AudioOutputDBusList AudioOutputs() const; | ||
3421 | 101 | |||
3422 | 102 | |||
3423 | 87 | 103 | ||
3424 | 88 | Q_SIGNALS: | 104 | Q_SIGNALS: |
3425 | 89 | void onMessageSent(const QString &number, const QString &message); | 105 | void onMessageSent(const QString &number, const QString &message); |
3426 | 90 | void CallPropertiesChanged(const QString &objectPath, const QVariantMap &properties); | 106 | void CallPropertiesChanged(const QString &objectPath, const QVariantMap &properties); |
3427 | 107 | void AccountPropertiesChanged(const QString &accountId, const QVariantMap &properties); | ||
3428 | 91 | void CallIndicatorVisibleChanged(bool visible); | 108 | void CallIndicatorVisibleChanged(bool visible); |
3429 | 92 | void ConferenceCallRequestFinished(bool succeeded); | 109 | void ConferenceCallRequestFinished(bool succeeded); |
3430 | 93 | void CallHoldingFailed(const QString &objectPath); | 110 | void CallHoldingFailed(const QString &objectPath); |
3431 | 94 | void ProtocolsChanged(const ProtocolList &protocols); | 111 | void ProtocolsChanged(const ProtocolList &protocols); |
3432 | 112 | void ActiveAudioOutputChanged(const QString &id); | ||
3433 | 113 | void AudioOutputsChanged(const AudioOutputDBusList &audioOutputs); | ||
3434 | 95 | 114 | ||
3435 | 96 | private: | 115 | private: |
3436 | 97 | bool mCallIndicatorVisible; | 116 | bool mCallIndicatorVisible; |
3437 | 98 | 117 | ||
3438 | === modified file 'handler/main.cpp' | |||
3439 | --- handler/main.cpp 2016-11-23 19:28:18 +0000 | |||
3440 | +++ handler/main.cpp 2017-04-05 14:05:16 +0000 | |||
3441 | @@ -1,5 +1,5 @@ | |||
3442 | 1 | /* | 1 | /* |
3444 | 2 | * Copyright (C) 2013-2016 Canonical, Ltd. | 2 | * Copyright (C) 2013-2017 Canonical, Ltd. |
3445 | 3 | * | 3 | * |
3446 | 4 | * Authors: | 4 | * Authors: |
3447 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
3448 | @@ -30,6 +30,10 @@ | |||
3449 | 30 | #include <TelepathyQt/AbstractClient> | 30 | #include <TelepathyQt/AbstractClient> |
3450 | 31 | #include <TelepathyQt/AccountManager> | 31 | #include <TelepathyQt/AccountManager> |
3451 | 32 | #include <TelepathyQt/Contact> | 32 | #include <TelepathyQt/Contact> |
3452 | 33 | #include <telepathy-farstream/telepathy-farstream.h> | ||
3453 | 34 | #include <TelepathyQt/CallChannel> | ||
3454 | 35 | |||
3455 | 36 | Q_DECLARE_METATYPE(Tp::CallChannelPtr) | ||
3456 | 33 | 37 | ||
3457 | 34 | int main(int argc, char **argv) | 38 | int main(int argc, char **argv) |
3458 | 35 | { | 39 | { |
3459 | @@ -37,6 +41,13 @@ | |||
3460 | 37 | QCoreApplication::setApplicationName("telephony-service-handler"); | 41 | QCoreApplication::setApplicationName("telephony-service-handler"); |
3461 | 38 | 42 | ||
3462 | 39 | Tp::registerTypes(); | 43 | Tp::registerTypes(); |
3463 | 44 | gst_init(&argc, &argv); | ||
3464 | 45 | qRegisterMetaType<Tp::CallChannelPtr>(); | ||
3465 | 46 | qRegisterMetaType<AudioOutputDBus>(); | ||
3466 | 47 | qRegisterMetaType<AudioOutputDBusList>(); | ||
3467 | 48 | |||
3468 | 49 | qDBusRegisterMetaType<AudioOutputDBus>(); | ||
3469 | 50 | qDBusRegisterMetaType<AudioOutputDBusList>(); | ||
3470 | 40 | 51 | ||
3471 | 41 | // check if there is already an instance of the handler running | 52 | // check if there is already an instance of the handler running |
3472 | 42 | if (ApplicationUtils::checkApplicationRunning(TP_QT_IFACE_CLIENT + ".TelephonyServiceHandler")) { | 53 | if (ApplicationUtils::checkApplicationRunning(TP_QT_IFACE_CLIENT + ".TelephonyServiceHandler")) { |
3473 | @@ -44,11 +55,13 @@ | |||
3474 | 44 | return 1; | 55 | return 1; |
3475 | 45 | } | 56 | } |
3476 | 46 | 57 | ||
3477 | 58 | HandlerDBus dbus; | ||
3478 | 47 | Handler *handler = new Handler(); | 59 | Handler *handler = new Handler(); |
3480 | 48 | QObject::connect(TelepathyHelper::instance(), &TelepathyHelper::setupReady, [handler]() { | 60 | QObject::connect(TelepathyHelper::instance(), &TelepathyHelper::setupReady, [&]() { |
3481 | 49 | TelepathyHelper::instance()->registerClient(handler, "TelephonyServiceHandler"); | 61 | TelepathyHelper::instance()->registerClient(handler, "TelephonyServiceHandler"); |
3482 | 62 | dbus.connectToBus(); | ||
3483 | 50 | }); | 63 | }); |
3485 | 51 | 64 | ||
3486 | 52 | QObject::connect(handler, SIGNAL(callChannelAvailable(Tp::CallChannelPtr)), | 65 | QObject::connect(handler, SIGNAL(callChannelAvailable(Tp::CallChannelPtr)), |
3487 | 53 | CallHandler::instance(), SLOT(onCallChannelAvailable(Tp::CallChannelPtr))); | 66 | CallHandler::instance(), SLOT(onCallChannelAvailable(Tp::CallChannelPtr))); |
3488 | 54 | QObject::connect(handler, SIGNAL(textChannelAvailable(Tp::TextChannelPtr)), | 67 | QObject::connect(handler, SIGNAL(textChannelAvailable(Tp::TextChannelPtr)), |
3489 | 55 | 68 | ||
3490 | === added file 'handler/powerd.h' | |||
3491 | --- handler/powerd.h 1970-01-01 00:00:00 +0000 | |||
3492 | +++ handler/powerd.h 2017-04-05 14:05:16 +0000 | |||
3493 | @@ -0,0 +1,34 @@ | |||
3494 | 1 | /** | ||
3495 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
3496 | 3 | * | ||
3497 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
3498 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
3499 | 6 | * the Free Software Foundation. | ||
3500 | 7 | * | ||
3501 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
3502 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
3503 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3504 | 11 | * Lesser General Public License for more details. | ||
3505 | 12 | * | ||
3506 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3507 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3508 | 15 | * | ||
3509 | 16 | * Authors: Andreas Pokorny <andreas.pokorny@canonical.com> | ||
3510 | 17 | */ | ||
3511 | 18 | |||
3512 | 19 | #ifndef POWERD_H | ||
3513 | 20 | #define POWERD_H | ||
3514 | 21 | |||
3515 | 22 | class PowerD | ||
3516 | 23 | { | ||
3517 | 24 | public: | ||
3518 | 25 | PowerD() = default; | ||
3519 | 26 | virtual ~PowerD() = default; | ||
3520 | 27 | PowerD(PowerD const&) = delete; | ||
3521 | 28 | PowerD& operator=(PowerD const&) = delete; | ||
3522 | 29 | |||
3523 | 30 | virtual void enableProximityHandling() = 0; | ||
3524 | 31 | virtual void disableProximityHandling() = 0; | ||
3525 | 32 | }; | ||
3526 | 33 | |||
3527 | 34 | #endif // POWERD_H | ||
3528 | 0 | 35 | ||
3529 | === added file 'handler/powerdaudiomodemediator.cpp' | |||
3530 | --- handler/powerdaudiomodemediator.cpp 1970-01-01 00:00:00 +0000 | |||
3531 | +++ handler/powerdaudiomodemediator.cpp 2017-04-05 14:05:16 +0000 | |||
3532 | @@ -0,0 +1,63 @@ | |||
3533 | 1 | /** | ||
3534 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
3535 | 3 | * | ||
3536 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
3537 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
3538 | 6 | * the Free Software Foundation. | ||
3539 | 7 | * | ||
3540 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
3541 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
3542 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3543 | 11 | * Lesser General Public License for more details. | ||
3544 | 12 | * | ||
3545 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3546 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3547 | 15 | * | ||
3548 | 16 | * Authors: Andreas Pokorny <andreas.pokorny@canonical.com> | ||
3549 | 17 | */ | ||
3550 | 18 | |||
3551 | 19 | #include <QDBusInterface> | ||
3552 | 20 | #include "powerdaudiomodemediator.h" | ||
3553 | 21 | |||
3554 | 22 | PowerDAudioModeMediator::PowerDAudioModeMediator(PowerD &powerd) | ||
3555 | 23 | : powerd(powerd) | ||
3556 | 24 | { | ||
3557 | 25 | } | ||
3558 | 26 | |||
3559 | 27 | void PowerDAudioModeMediator::audioModeChanged(const QString &mode) | ||
3560 | 28 | { | ||
3561 | 29 | bool enableProximity = !(mode == "speaker" || mode == "bluetooth" || mode == "wired_headset"); | ||
3562 | 30 | |||
3563 | 31 | if (mProximityEnabled != enableProximity) | ||
3564 | 32 | { | ||
3565 | 33 | mProximityEnabled = enableProximity; | ||
3566 | 34 | apply(); | ||
3567 | 35 | } | ||
3568 | 36 | } | ||
3569 | 37 | |||
3570 | 38 | void PowerDAudioModeMediator::apply() const | ||
3571 | 39 | { | ||
3572 | 40 | if (mProximityEnabled) { | ||
3573 | 41 | powerd.enableProximityHandling(); | ||
3574 | 42 | } else { | ||
3575 | 43 | // we need to power the screen on before disabling the proximity handling | ||
3576 | 44 | QDBusInterface unityIface("com.canonical.Unity.Screen", | ||
3577 | 45 | "/com/canonical/Unity/Screen", | ||
3578 | 46 | "com.canonical.Unity.Screen", | ||
3579 | 47 | QDBusConnection::systemBus()); | ||
3580 | 48 | QList<QVariant> args; | ||
3581 | 49 | args.append("on"); | ||
3582 | 50 | args.append(3); | ||
3583 | 51 | unityIface.callWithArgumentList(QDBus::NoBlock, "setScreenPowerMode", args); | ||
3584 | 52 | powerd.disableProximityHandling(); | ||
3585 | 53 | } | ||
3586 | 54 | } | ||
3587 | 55 | |||
3588 | 56 | void PowerDAudioModeMediator::audioOutputClosed() | ||
3589 | 57 | { | ||
3590 | 58 | if (mProximityEnabled) | ||
3591 | 59 | { | ||
3592 | 60 | mProximityEnabled = false; | ||
3593 | 61 | apply(); | ||
3594 | 62 | } | ||
3595 | 63 | } | ||
3596 | 0 | 64 | ||
3597 | === added file 'handler/powerdaudiomodemediator.h' | |||
3598 | --- handler/powerdaudiomodemediator.h 1970-01-01 00:00:00 +0000 | |||
3599 | +++ handler/powerdaudiomodemediator.h 2017-04-05 14:05:16 +0000 | |||
3600 | @@ -0,0 +1,46 @@ | |||
3601 | 1 | /**************************************************************************** | ||
3602 | 2 | ** | ||
3603 | 3 | ** Copyright (C) 2014 Canonical, Ltd. | ||
3604 | 4 | ** | ||
3605 | 5 | ** Authors: | ||
3606 | 6 | ** Andreas Pokorny <andreas.pokorny@canonical.com> | ||
3607 | 7 | ** | ||
3608 | 8 | ** GNU Lesser General Public License Usage | ||
3609 | 9 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
3610 | 10 | ** General Public License version 2.1 as published by the Free Software | ||
3611 | 11 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
3612 | 12 | ** packaging of this file. Please review the following information to | ||
3613 | 13 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
3614 | 14 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
3615 | 15 | ** | ||
3616 | 16 | ****************************************************************************/ | ||
3617 | 17 | |||
3618 | 18 | #ifndef POWERDAUDIOMODEMEDIATOR_H | ||
3619 | 19 | #define POWERDAUDIOMODEMEDIATOR_H | ||
3620 | 20 | |||
3621 | 21 | #include "powerd.h" | ||
3622 | 22 | |||
3623 | 23 | #include <QString> | ||
3624 | 24 | #include <fstream> | ||
3625 | 25 | #include <memory> | ||
3626 | 26 | |||
3627 | 27 | class PowerD; | ||
3628 | 28 | /*! | ||
3629 | 29 | * \brief PowerDAudioModeMediator is responsible for configuring proximity | ||
3630 | 30 | * handling of powerd during different call states and used audio outputs. | ||
3631 | 31 | * In General that mean enabling sreen blanking on proximity events, when | ||
3632 | 32 | * a call is active and neither a bluetooth headset nor the speakers are used. | ||
3633 | 33 | */ | ||
3634 | 34 | class PowerDAudioModeMediator | ||
3635 | 35 | { | ||
3636 | 36 | public: | ||
3637 | 37 | PowerDAudioModeMediator(PowerD &powerd); | ||
3638 | 38 | void audioModeChanged(const QString &mode); | ||
3639 | 39 | void audioOutputClosed(); | ||
3640 | 40 | private: | ||
3641 | 41 | void apply() const; | ||
3642 | 42 | PowerD &powerd; | ||
3643 | 43 | bool mProximityEnabled{false}; | ||
3644 | 44 | }; | ||
3645 | 45 | |||
3646 | 46 | #endif | ||
3647 | 0 | 47 | ||
3648 | === added file 'handler/powerddbus.cpp' | |||
3649 | --- handler/powerddbus.cpp 1970-01-01 00:00:00 +0000 | |||
3650 | +++ handler/powerddbus.cpp 2017-04-05 14:05:16 +0000 | |||
3651 | @@ -0,0 +1,43 @@ | |||
3652 | 1 | /** | ||
3653 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
3654 | 3 | * | ||
3655 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
3656 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
3657 | 6 | * the Free Software Foundation. | ||
3658 | 7 | * | ||
3659 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
3660 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
3661 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3662 | 11 | * Lesser General Public License for more details. | ||
3663 | 12 | * | ||
3664 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3665 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3666 | 15 | * | ||
3667 | 16 | * Authors: Andreas Pokorny <andreas.pokorny@canonical.com> | ||
3668 | 17 | */ | ||
3669 | 18 | |||
3670 | 19 | #include "powerddbus.h" | ||
3671 | 20 | |||
3672 | 21 | #include <QDBusConnection> | ||
3673 | 22 | #include <QDBusInterface> | ||
3674 | 23 | #include <QDBusReply> | ||
3675 | 24 | |||
3676 | 25 | PowerDDBus::PowerDDBus() | ||
3677 | 26 | : mPowerDIface{ | ||
3678 | 27 | new QDBusInterface( | ||
3679 | 28 | "com.canonical.powerd", | ||
3680 | 29 | "/com/canonical/powerd", | ||
3681 | 30 | "com.canonical.powerd", | ||
3682 | 31 | QDBusConnection::systemBus())} | ||
3683 | 32 | { | ||
3684 | 33 | } | ||
3685 | 34 | |||
3686 | 35 | void PowerDDBus::enableProximityHandling() | ||
3687 | 36 | { | ||
3688 | 37 | mPowerDIface->call("enableProximityHandling", "telephony-service-handler"); | ||
3689 | 38 | } | ||
3690 | 39 | |||
3691 | 40 | void PowerDDBus::disableProximityHandling() | ||
3692 | 41 | { | ||
3693 | 42 | mPowerDIface->call("disableProximityHandling", "telephony-service-handler"); | ||
3694 | 43 | } | ||
3695 | 0 | 44 | ||
3696 | === added file 'handler/powerddbus.h' | |||
3697 | --- handler/powerddbus.h 1970-01-01 00:00:00 +0000 | |||
3698 | +++ handler/powerddbus.h 2017-04-05 14:05:16 +0000 | |||
3699 | @@ -0,0 +1,38 @@ | |||
3700 | 1 | /** | ||
3701 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
3702 | 3 | * | ||
3703 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
3704 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
3705 | 6 | * the Free Software Foundation. | ||
3706 | 7 | * | ||
3707 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
3708 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
3709 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3710 | 11 | * Lesser General Public License for more details. | ||
3711 | 12 | * | ||
3712 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
3713 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3714 | 15 | * | ||
3715 | 16 | * Authors: Andreas Pokorny <andreas.pokorny@canonical.com> | ||
3716 | 17 | */ | ||
3717 | 18 | |||
3718 | 19 | #ifndef POWERD_DUBS_H | ||
3719 | 20 | #define POWERD_DBUS_H | ||
3720 | 21 | |||
3721 | 22 | #include "powerd.h" | ||
3722 | 23 | |||
3723 | 24 | #include <memory> | ||
3724 | 25 | |||
3725 | 26 | class QDBusInterface; | ||
3726 | 27 | |||
3727 | 28 | class PowerDDBus : public PowerD | ||
3728 | 29 | { | ||
3729 | 30 | public: | ||
3730 | 31 | PowerDDBus(); | ||
3731 | 32 | void enableProximityHandling() override; | ||
3732 | 33 | void disableProximityHandling() override; | ||
3733 | 34 | private: | ||
3734 | 35 | std::unique_ptr<QDBusInterface> mPowerDIface; | ||
3735 | 36 | }; | ||
3736 | 37 | |||
3737 | 38 | #endif | ||
3738 | 0 | 39 | ||
3739 | === added file 'handler/qpulseaudioengine.cpp' | |||
3740 | --- handler/qpulseaudioengine.cpp 1970-01-01 00:00:00 +0000 | |||
3741 | +++ handler/qpulseaudioengine.cpp 2017-04-05 14:05:16 +0000 | |||
3742 | @@ -0,0 +1,853 @@ | |||
3743 | 1 | /**************************************************************************** | ||
3744 | 2 | ** | ||
3745 | 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | ||
3746 | 4 | ** Contact: http://www.qt-project.org/legal | ||
3747 | 5 | ** | ||
3748 | 6 | ** This file was taken from qt5 and modified by | ||
3749 | 7 | ** David Henningsson <david.henningsson@canonical.com> for usage in | ||
3750 | 8 | ** telepathy-ofono. | ||
3751 | 9 | ** | ||
3752 | 10 | ** GNU Lesser General Public License Usage | ||
3753 | 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
3754 | 12 | ** General Public License version 2.1 as published by the Free Software | ||
3755 | 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
3756 | 14 | ** packaging of this file. Please review the following information to | ||
3757 | 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
3758 | 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
3759 | 17 | ** | ||
3760 | 18 | ****************************************************************************/ | ||
3761 | 19 | |||
3762 | 20 | #include <QtCore/qdebug.h> | ||
3763 | 21 | |||
3764 | 22 | #include "qpulseaudioengine.h" | ||
3765 | 23 | #include <sys/types.h> | ||
3766 | 24 | #include <unistd.h> | ||
3767 | 25 | |||
3768 | 26 | #define PULSEAUDIO_PROFILE_HSP "headset_head_unit" | ||
3769 | 27 | #define PULSEAUDIO_PROFILE_A2DP "a2dp_sink" | ||
3770 | 28 | |||
3771 | 29 | QT_BEGIN_NAMESPACE | ||
3772 | 30 | |||
3773 | 31 | static void contextStateCallbackInit(pa_context *context, void *userdata) | ||
3774 | 32 | { | ||
3775 | 33 | Q_UNUSED(context); | ||
3776 | 34 | QPulseAudioEngineWorker *pulseEngine = reinterpret_cast<QPulseAudioEngineWorker*>(userdata); | ||
3777 | 35 | pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); | ||
3778 | 36 | } | ||
3779 | 37 | |||
3780 | 38 | static void contextStateCallback(pa_context *context, void *userdata) | ||
3781 | 39 | { | ||
3782 | 40 | Q_UNUSED(userdata); | ||
3783 | 41 | Q_UNUSED(context); | ||
3784 | 42 | } | ||
3785 | 43 | |||
3786 | 44 | static void success_cb(pa_context *context, int success, void *userdata) | ||
3787 | 45 | { | ||
3788 | 46 | QPulseAudioEngineWorker *pulseEngine = reinterpret_cast<QPulseAudioEngineWorker*>(userdata); | ||
3789 | 47 | pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); | ||
3790 | 48 | } | ||
3791 | 49 | |||
3792 | 50 | /* Callbacks used when handling events from PulseAudio */ | ||
3793 | 51 | static void plug_card_cb(pa_context *c, const pa_card_info *info, int isLast, void *userdata) | ||
3794 | 52 | { | ||
3795 | 53 | QPulseAudioEngineWorker *pulseEngine = static_cast<QPulseAudioEngineWorker*>(userdata); | ||
3796 | 54 | if (isLast != 0 || !pulseEngine || !info) { | ||
3797 | 55 | pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); | ||
3798 | 56 | return; | ||
3799 | 57 | } | ||
3800 | 58 | pulseEngine->plugCardCallback(info); | ||
3801 | 59 | } | ||
3802 | 60 | |||
3803 | 61 | static void update_card_cb(pa_context *c, const pa_card_info *info, int isLast, void *userdata) | ||
3804 | 62 | { | ||
3805 | 63 | QPulseAudioEngineWorker *pulseEngine = static_cast<QPulseAudioEngineWorker*>(userdata); | ||
3806 | 64 | if (isLast != 0 || !pulseEngine || !info) { | ||
3807 | 65 | pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); | ||
3808 | 66 | return; | ||
3809 | 67 | } | ||
3810 | 68 | pulseEngine->updateCardCallback(info); | ||
3811 | 69 | } | ||
3812 | 70 | |||
3813 | 71 | static void unplug_card_cb(pa_context *c, const pa_card_info *info, int isLast, void *userdata) | ||
3814 | 72 | { | ||
3815 | 73 | QPulseAudioEngineWorker *pulseEngine = static_cast<QPulseAudioEngineWorker*>(userdata); | ||
3816 | 74 | if (!pulseEngine) { | ||
3817 | 75 | pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); | ||
3818 | 76 | return; | ||
3819 | 77 | } | ||
3820 | 78 | |||
3821 | 79 | if (info == NULL) { | ||
3822 | 80 | /* That means that the card used to query card_info was removed */ | ||
3823 | 81 | pulseEngine->unplugCardCallback(); | ||
3824 | 82 | } | ||
3825 | 83 | } | ||
3826 | 84 | |||
3827 | 85 | static void subscribeCallback(pa_context *context, pa_subscription_event_type_t t, uint32_t idx, void *userdata) | ||
3828 | 86 | { | ||
3829 | 87 | /* For card change events (slot plug/unplug and add/remove card) */ | ||
3830 | 88 | if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_CARD) { | ||
3831 | 89 | if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_CHANGE) { | ||
3832 | 90 | QMetaObject::invokeMethod((QPulseAudioEngineWorker *) userdata, "handleCardEvent", | ||
3833 | 91 | Qt::QueuedConnection, Q_ARG(int, PA_SUBSCRIPTION_EVENT_CHANGE), Q_ARG(unsigned int, idx)); | ||
3834 | 92 | } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { | ||
3835 | 93 | QMetaObject::invokeMethod((QPulseAudioEngineWorker *) userdata, "handleCardEvent", | ||
3836 | 94 | Qt::QueuedConnection, Q_ARG(int, PA_SUBSCRIPTION_EVENT_NEW), Q_ARG(unsigned int, idx)); | ||
3837 | 95 | } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { | ||
3838 | 96 | QMetaObject::invokeMethod((QPulseAudioEngineWorker *) userdata, "handleCardEvent", | ||
3839 | 97 | Qt::QueuedConnection, Q_ARG(int, PA_SUBSCRIPTION_EVENT_REMOVE), Q_ARG(unsigned int, idx)); | ||
3840 | 98 | } | ||
3841 | 99 | } | ||
3842 | 100 | } | ||
3843 | 101 | |||
3844 | 102 | QPulseAudioEngineWorker::QPulseAudioEngineWorker(QObject *parent) | ||
3845 | 103 | : QObject(parent) | ||
3846 | 104 | , m_mainLoopApi(0) | ||
3847 | 105 | , m_context(0) | ||
3848 | 106 | , m_callstatus(CallEnded) | ||
3849 | 107 | , m_audiomode(AudioModeSpeaker) | ||
3850 | 108 | , m_micmute(false) | ||
3851 | 109 | , m_defaultsink("sink.primary") | ||
3852 | 110 | , m_defaultsource("source.primary") | ||
3853 | 111 | , m_voicecallcard("") | ||
3854 | 112 | , m_voicecallhighest("") | ||
3855 | 113 | , m_voicecallprofile("") | ||
3856 | 114 | , m_bt_hsp("") | ||
3857 | 115 | , m_bt_hsp_a2dp("") | ||
3858 | 116 | , m_default_bt_card_fallback("") | ||
3859 | 117 | |||
3860 | 118 | { | ||
3861 | 119 | m_mainLoop = pa_threaded_mainloop_new(); | ||
3862 | 120 | if (m_mainLoop == 0) { | ||
3863 | 121 | qWarning("Unable to create pulseaudio mainloop"); | ||
3864 | 122 | return; | ||
3865 | 123 | } | ||
3866 | 124 | |||
3867 | 125 | if (pa_threaded_mainloop_start(m_mainLoop) != 0) { | ||
3868 | 126 | qWarning("Unable to start pulseaudio mainloop"); | ||
3869 | 127 | pa_threaded_mainloop_free(m_mainLoop); | ||
3870 | 128 | m_mainLoop = 0; | ||
3871 | 129 | return; | ||
3872 | 130 | } | ||
3873 | 131 | |||
3874 | 132 | createPulseContext(); | ||
3875 | 133 | } | ||
3876 | 134 | |||
3877 | 135 | bool QPulseAudioEngineWorker::createPulseContext() | ||
3878 | 136 | { | ||
3879 | 137 | bool keepGoing = true; | ||
3880 | 138 | bool ok = true; | ||
3881 | 139 | |||
3882 | 140 | if (m_context) | ||
3883 | 141 | return true; | ||
3884 | 142 | |||
3885 | 143 | m_mainLoopApi = pa_threaded_mainloop_get_api(m_mainLoop); | ||
3886 | 144 | |||
3887 | 145 | pa_threaded_mainloop_lock(m_mainLoop); | ||
3888 | 146 | |||
3889 | 147 | m_context = pa_context_new(m_mainLoopApi, QString(QLatin1String("QtmPulseContext:%1")).arg(::getpid()).toLatin1().constData()); | ||
3890 | 148 | pa_context_set_state_callback(m_context, contextStateCallbackInit, this); | ||
3891 | 149 | |||
3892 | 150 | if (!m_context) { | ||
3893 | 151 | qWarning("Unable to create new pulseaudio context"); | ||
3894 | 152 | pa_threaded_mainloop_unlock(m_mainLoop); | ||
3895 | 153 | return false; | ||
3896 | 154 | } | ||
3897 | 155 | |||
3898 | 156 | if (pa_context_connect(m_context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) { | ||
3899 | 157 | qWarning("Unable to create a connection to the pulseaudio context"); | ||
3900 | 158 | pa_threaded_mainloop_unlock(m_mainLoop); | ||
3901 | 159 | releasePulseContext(); | ||
3902 | 160 | return false; | ||
3903 | 161 | } | ||
3904 | 162 | |||
3905 | 163 | pa_threaded_mainloop_wait(m_mainLoop); | ||
3906 | 164 | |||
3907 | 165 | while (keepGoing) { | ||
3908 | 166 | switch (pa_context_get_state(m_context)) { | ||
3909 | 167 | case PA_CONTEXT_CONNECTING: | ||
3910 | 168 | case PA_CONTEXT_AUTHORIZING: | ||
3911 | 169 | case PA_CONTEXT_SETTING_NAME: | ||
3912 | 170 | break; | ||
3913 | 171 | |||
3914 | 172 | case PA_CONTEXT_READY: | ||
3915 | 173 | qDebug("Pulseaudio connection established."); | ||
3916 | 174 | keepGoing = false; | ||
3917 | 175 | break; | ||
3918 | 176 | |||
3919 | 177 | case PA_CONTEXT_TERMINATED: | ||
3920 | 178 | qCritical("Pulseaudio context terminated."); | ||
3921 | 179 | keepGoing = false; | ||
3922 | 180 | ok = false; | ||
3923 | 181 | break; | ||
3924 | 182 | |||
3925 | 183 | case PA_CONTEXT_FAILED: | ||
3926 | 184 | default: | ||
3927 | 185 | qCritical() << QString("Pulseaudio connection failure: %1").arg(pa_strerror(pa_context_errno(m_context))); | ||
3928 | 186 | keepGoing = false; | ||
3929 | 187 | ok = false; | ||
3930 | 188 | } | ||
3931 | 189 | |||
3932 | 190 | if (keepGoing) { | ||
3933 | 191 | pa_threaded_mainloop_wait(m_mainLoop); | ||
3934 | 192 | } | ||
3935 | 193 | } | ||
3936 | 194 | |||
3937 | 195 | if (ok) { | ||
3938 | 196 | pa_context_set_state_callback(m_context, contextStateCallback, this); | ||
3939 | 197 | pa_context_set_subscribe_callback(m_context, subscribeCallback, this); | ||
3940 | 198 | pa_context_subscribe(m_context, PA_SUBSCRIPTION_MASK_CARD, NULL, this); | ||
3941 | 199 | } else { | ||
3942 | 200 | if (m_context) { | ||
3943 | 201 | pa_context_unref(m_context); | ||
3944 | 202 | m_context = 0; | ||
3945 | 203 | } | ||
3946 | 204 | } | ||
3947 | 205 | |||
3948 | 206 | pa_threaded_mainloop_unlock(m_mainLoop); | ||
3949 | 207 | return true; | ||
3950 | 208 | } | ||
3951 | 209 | |||
3952 | 210 | |||
3953 | 211 | void QPulseAudioEngineWorker::releasePulseContext() | ||
3954 | 212 | { | ||
3955 | 213 | if (m_context) { | ||
3956 | 214 | pa_threaded_mainloop_lock(m_mainLoop); | ||
3957 | 215 | pa_context_disconnect(m_context); | ||
3958 | 216 | pa_context_unref(m_context); | ||
3959 | 217 | pa_threaded_mainloop_unlock(m_mainLoop); | ||
3960 | 218 | m_context = 0; | ||
3961 | 219 | } | ||
3962 | 220 | |||
3963 | 221 | } | ||
3964 | 222 | |||
3965 | 223 | QPulseAudioEngineWorker::~QPulseAudioEngineWorker() | ||
3966 | 224 | { | ||
3967 | 225 | releasePulseContext(); | ||
3968 | 226 | |||
3969 | 227 | if (m_mainLoop) { | ||
3970 | 228 | pa_threaded_mainloop_stop(m_mainLoop); | ||
3971 | 229 | pa_threaded_mainloop_free(m_mainLoop); | ||
3972 | 230 | m_mainLoop = 0; | ||
3973 | 231 | } | ||
3974 | 232 | } | ||
3975 | 233 | |||
3976 | 234 | void QPulseAudioEngineWorker::cardInfoCallback(const pa_card_info *info) | ||
3977 | 235 | { | ||
3978 | 236 | pa_card_profile_info2 *voice_call = NULL, *highest = NULL; | ||
3979 | 237 | pa_card_profile_info2 *hsp = NULL, *a2dp = NULL; | ||
3980 | 238 | |||
3981 | 239 | /* For now we only support one card with the voicecall feature */ | ||
3982 | 240 | for (int i = 0; i < info->n_profiles; i++) { | ||
3983 | 241 | if (!highest || info->profiles2[i]->priority > highest->priority) | ||
3984 | 242 | highest = info->profiles2[i]; | ||
3985 | 243 | if (!strcmp(info->profiles2[i]->name, "voicecall")) | ||
3986 | 244 | voice_call = info->profiles2[i]; | ||
3987 | 245 | else if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_HSP) && | ||
3988 | 246 | info->profiles2[i]->available != 0) | ||
3989 | 247 | hsp = info->profiles2[i]; | ||
3990 | 248 | else if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_A2DP) && | ||
3991 | 249 | info->profiles2[i]->available != 0) | ||
3992 | 250 | a2dp = info->profiles2[i]; | ||
3993 | 251 | } | ||
3994 | 252 | |||
3995 | 253 | /* Record the card that supports voicecall (default one to be used) */ | ||
3996 | 254 | if (voice_call) { | ||
3997 | 255 | qDebug("Found card that supports voicecall: '%s'", info->name); | ||
3998 | 256 | m_voicecallcard = info->name; | ||
3999 | 257 | m_voicecallhighest = highest->name; | ||
4000 | 258 | qDebug("1"); | ||
4001 | 259 | m_voicecallprofile = voice_call->name; | ||
4002 | 260 | qDebug("2"); | ||
4003 | 261 | } | ||
4004 | 262 | |||
4005 | 263 | /* Handle the use cases needed for bluetooth */ | ||
4006 | 264 | if (hsp && a2dp) { | ||
4007 | 265 | qDebug("Found card that supports hsp and a2dp: '%s'", info->name); | ||
4008 | 266 | m_bt_hsp_a2dp = info->name; | ||
4009 | 267 | } else if (hsp && (a2dp == NULL)) { | ||
4010 | 268 | /* This card only provides the hsp profile */ | ||
4011 | 269 | qDebug("Found card that supports only hsp: '%s'", info->name); | ||
4012 | 270 | m_bt_hsp = info->name; | ||
4013 | 271 | } | ||
4014 | 272 | qDebug("3"); | ||
4015 | 273 | } | ||
4016 | 274 | |||
4017 | 275 | void QPulseAudioEngineWorker::sinkInfoCallback(const pa_sink_info *info) | ||
4018 | 276 | { | ||
4019 | 277 | pa_sink_port_info *earpiece = NULL, *speaker = NULL; | ||
4020 | 278 | pa_sink_port_info *wired_headset = NULL, *wired_headphone = NULL; | ||
4021 | 279 | pa_sink_port_info *preferred = NULL; | ||
4022 | 280 | pa_sink_port_info *bluetooth_sco = NULL; | ||
4023 | 281 | pa_sink_port_info *speaker_and_wired_headphone = NULL; | ||
4024 | 282 | AudioMode audiomodetoset; | ||
4025 | 283 | AudioModes modes; | ||
4026 | 284 | |||
4027 | 285 | for (int i = 0; i < info->n_ports; i++) { | ||
4028 | 286 | if (!strcmp(info->ports[i]->name, "output-earpiece")) | ||
4029 | 287 | earpiece = info->ports[i]; | ||
4030 | 288 | else if (!strcmp(info->ports[i]->name, "output-wired_headset") && | ||
4031 | 289 | (info->ports[i]->available != PA_PORT_AVAILABLE_NO)) | ||
4032 | 290 | wired_headset = info->ports[i]; | ||
4033 | 291 | else if (!strcmp(info->ports[i]->name, "output-wired_headphone") && | ||
4034 | 292 | (info->ports[i]->available != PA_PORT_AVAILABLE_NO)) | ||
4035 | 293 | wired_headphone = info->ports[i]; | ||
4036 | 294 | else if (!strcmp(info->ports[i]->name, "output-speaker")) | ||
4037 | 295 | speaker = info->ports[i]; | ||
4038 | 296 | else if (!strcmp(info->ports[i]->name, "output-bluetooth_sco")) | ||
4039 | 297 | bluetooth_sco = info->ports[i]; | ||
4040 | 298 | else if (!strcmp(info->ports[i]->name, "output-speaker+wired_headphone")) | ||
4041 | 299 | speaker_and_wired_headphone = info->ports[i]; | ||
4042 | 300 | } | ||
4043 | 301 | |||
4044 | 302 | if (!earpiece || !speaker) | ||
4045 | 303 | return; /* Not the right sink */ | ||
4046 | 304 | |||
4047 | 305 | /* Refresh list of available audio modes */ | ||
4048 | 306 | modes.append(AudioModeEarpiece); | ||
4049 | 307 | modes.append(AudioModeSpeaker); | ||
4050 | 308 | if (wired_headset || wired_headphone) | ||
4051 | 309 | modes.append(AudioModeWiredHeadset); | ||
4052 | 310 | if (bluetooth_sco && ((m_bt_hsp != "") || (m_bt_hsp_a2dp != ""))) | ||
4053 | 311 | modes.append(AudioModeBluetooth); | ||
4054 | 312 | |||
4055 | 313 | /* Check if the requested mode is available (earpiece*/ | ||
4056 | 314 | if (((m_audiomode == AudioModeWiredHeadset) && !modes.contains(AudioModeWiredHeadset)) || | ||
4057 | 315 | ((m_audiomode == AudioModeBluetooth) && !modes.contains(AudioModeBluetooth))) | ||
4058 | 316 | return; | ||
4059 | 317 | |||
4060 | 318 | /* Now to decide which output to be used, depending on the active mode */ | ||
4061 | 319 | if (m_audiomode & AudioModeEarpiece) { | ||
4062 | 320 | preferred = earpiece; | ||
4063 | 321 | audiomodetoset = AudioModeEarpiece; | ||
4064 | 322 | } | ||
4065 | 323 | if (m_audiomode & AudioModeSpeaker) { | ||
4066 | 324 | preferred = speaker; | ||
4067 | 325 | audiomodetoset = AudioModeSpeaker; | ||
4068 | 326 | } | ||
4069 | 327 | if ((m_audiomode & AudioModeWiredHeadset) && (modes.contains(AudioModeWiredHeadset))) { | ||
4070 | 328 | preferred = wired_headset ? wired_headset : wired_headphone; | ||
4071 | 329 | audiomodetoset = AudioModeWiredHeadset; | ||
4072 | 330 | } | ||
4073 | 331 | if (m_callstatus == CallRinging && speaker_and_wired_headphone) { | ||
4074 | 332 | preferred = speaker_and_wired_headphone; | ||
4075 | 333 | } | ||
4076 | 334 | if ((m_audiomode & AudioModeBluetooth) && (modes.contains(AudioModeBluetooth))) { | ||
4077 | 335 | preferred = bluetooth_sco; | ||
4078 | 336 | audiomodetoset = AudioModeBluetooth; | ||
4079 | 337 | } | ||
4080 | 338 | |||
4081 | 339 | m_audiomode = audiomodetoset; | ||
4082 | 340 | |||
4083 | 341 | m_nametoset = info->name; | ||
4084 | 342 | if (info->active_port != preferred) | ||
4085 | 343 | m_valuetoset = preferred->name; | ||
4086 | 344 | |||
4087 | 345 | if (modes != m_availableAudioModes) | ||
4088 | 346 | m_availableAudioModes = modes; | ||
4089 | 347 | } | ||
4090 | 348 | |||
4091 | 349 | void QPulseAudioEngineWorker::sourceInfoCallback(const pa_source_info *info) | ||
4092 | 350 | { | ||
4093 | 351 | pa_source_port_info *builtin_mic = NULL, *preferred = NULL; | ||
4094 | 352 | pa_source_port_info *wired_headset = NULL, *bluetooth_sco = NULL; | ||
4095 | 353 | |||
4096 | 354 | if (info->monitor_of_sink != PA_INVALID_INDEX) | ||
4097 | 355 | return; /* Not the right source */ | ||
4098 | 356 | |||
4099 | 357 | for (int i = 0; i < info->n_ports; i++) { | ||
4100 | 358 | if (!strcmp(info->ports[i]->name, "input-builtin_mic")) | ||
4101 | 359 | builtin_mic = info->ports[i]; | ||
4102 | 360 | else if (!strcmp(info->ports[i]->name, "input-wired_headset") && | ||
4103 | 361 | (info->ports[i]->available != PA_PORT_AVAILABLE_NO)) | ||
4104 | 362 | wired_headset = info->ports[i]; | ||
4105 | 363 | else if (!strcmp(info->ports[i]->name, "input-bluetooth_sco_headset")) | ||
4106 | 364 | bluetooth_sco = info->ports[i]; | ||
4107 | 365 | } | ||
4108 | 366 | |||
4109 | 367 | if (!builtin_mic) | ||
4110 | 368 | return; /* Not the right source */ | ||
4111 | 369 | |||
4112 | 370 | /* Now to decide which output to be used, depending on the active mode */ | ||
4113 | 371 | if ((m_audiomode & AudioModeEarpiece) || (m_audiomode & AudioModeSpeaker)) | ||
4114 | 372 | preferred = builtin_mic; | ||
4115 | 373 | if ((m_audiomode & AudioModeWiredHeadset) && (m_availableAudioModes.contains(AudioModeWiredHeadset))) | ||
4116 | 374 | preferred = wired_headset ? wired_headset : builtin_mic; | ||
4117 | 375 | if ((m_audiomode & AudioModeBluetooth) && (m_availableAudioModes.contains(AudioModeBluetooth))) | ||
4118 | 376 | preferred = bluetooth_sco; | ||
4119 | 377 | |||
4120 | 378 | m_nametoset = info->name; | ||
4121 | 379 | if (info->active_port != preferred) | ||
4122 | 380 | m_valuetoset = preferred->name; | ||
4123 | 381 | } | ||
4124 | 382 | |||
4125 | 383 | void QPulseAudioEngineWorker::serverInfoCallback(const pa_server_info *info) | ||
4126 | 384 | { | ||
4127 | 385 | /* Saving default sink/source to restore after call hangup */ | ||
4128 | 386 | m_defaultsink = info->default_sink_name; | ||
4129 | 387 | m_defaultsource = info->default_source_name; | ||
4130 | 388 | |||
4131 | 389 | /* In the case of a server callback we need to signal the mainloop */ | ||
4132 | 390 | pa_threaded_mainloop_signal(mainloop(), 0); | ||
4133 | 391 | } | ||
4134 | 392 | |||
4135 | 393 | static void cardinfo_cb(pa_context *context, const pa_card_info *info, int isLast, void *userdata) | ||
4136 | 394 | { | ||
4137 | 395 | QPulseAudioEngineWorker *pulseEngine = static_cast<QPulseAudioEngineWorker*>(userdata); | ||
4138 | 396 | if (isLast != 0 || !pulseEngine || !info) { | ||
4139 | 397 | pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); | ||
4140 | 398 | return; | ||
4141 | 399 | } | ||
4142 | 400 | pulseEngine->cardInfoCallback(info); | ||
4143 | 401 | } | ||
4144 | 402 | |||
4145 | 403 | static void sinkinfo_cb(pa_context *context, const pa_sink_info *info, int isLast, void *userdata) | ||
4146 | 404 | { | ||
4147 | 405 | QPulseAudioEngineWorker *pulseEngine = static_cast<QPulseAudioEngineWorker*>(userdata); | ||
4148 | 406 | if (isLast != 0 || !pulseEngine || !info) { | ||
4149 | 407 | pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); | ||
4150 | 408 | return; | ||
4151 | 409 | } | ||
4152 | 410 | pulseEngine->sinkInfoCallback(info); | ||
4153 | 411 | } | ||
4154 | 412 | |||
4155 | 413 | static void sourceinfo_cb(pa_context *context, const pa_source_info *info, int isLast, void *userdata) | ||
4156 | 414 | { | ||
4157 | 415 | QPulseAudioEngineWorker *pulseEngine = static_cast<QPulseAudioEngineWorker*>(userdata); | ||
4158 | 416 | if (isLast != 0 || !pulseEngine || !info) { | ||
4159 | 417 | pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); | ||
4160 | 418 | return; | ||
4161 | 419 | } | ||
4162 | 420 | pulseEngine->sourceInfoCallback(info); | ||
4163 | 421 | } | ||
4164 | 422 | |||
4165 | 423 | static void serverinfo_cb(pa_context *context, const pa_server_info *info, void *userdata) | ||
4166 | 424 | { | ||
4167 | 425 | QPulseAudioEngineWorker *pulseEngine = static_cast<QPulseAudioEngineWorker*>(userdata); | ||
4168 | 426 | if (!pulseEngine || !info) { | ||
4169 | 427 | pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); | ||
4170 | 428 | return; | ||
4171 | 429 | } | ||
4172 | 430 | pulseEngine->serverInfoCallback(info); | ||
4173 | 431 | } | ||
4174 | 432 | |||
4175 | 433 | bool QPulseAudioEngineWorker::handleOperation(pa_operation *operation, const char *func_name) | ||
4176 | 434 | { | ||
4177 | 435 | if (!operation) { | ||
4178 | 436 | qCritical("'%s' failed (lost PulseAudio connection?)", func_name); | ||
4179 | 437 | /* Free resources so it can retry a new connection during next operation */ | ||
4180 | 438 | pa_threaded_mainloop_unlock(m_mainLoop); | ||
4181 | 439 | releasePulseContext(); | ||
4182 | 440 | return false; | ||
4183 | 441 | } | ||
4184 | 442 | |||
4185 | 443 | while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) | ||
4186 | 444 | pa_threaded_mainloop_wait(m_mainLoop); | ||
4187 | 445 | pa_operation_unref(operation); | ||
4188 | 446 | return true; | ||
4189 | 447 | } | ||
4190 | 448 | |||
4191 | 449 | int QPulseAudioEngineWorker::setupVoiceCall() | ||
4192 | 450 | { | ||
4193 | 451 | pa_operation *o; | ||
4194 | 452 | |||
4195 | 453 | qDebug("Setting up pulseaudio for voice call"); | ||
4196 | 454 | |||
4197 | 455 | pa_threaded_mainloop_lock(m_mainLoop); | ||
4198 | 456 | |||
4199 | 457 | /* Get and set the default sink/source to be restored later */ | ||
4200 | 458 | o = pa_context_get_server_info(m_context, serverinfo_cb, this); | ||
4201 | 459 | if (!handleOperation(o, "pa_context_get_server_info")) | ||
4202 | 460 | return -1; | ||
4203 | 461 | |||
4204 | 462 | qDebug("Recorded default sink: %s default source: %s", | ||
4205 | 463 | m_defaultsink.c_str(), m_defaultsource.c_str()); | ||
4206 | 464 | |||
4207 | 465 | /* Walk through the list of devices, find the voice call capable card and | ||
4208 | 466 | * identify if we have bluetooth capable devices (hsp and a2dp) */ | ||
4209 | 467 | m_voicecallcard = m_voicecallhighest = m_voicecallprofile = ""; | ||
4210 | 468 | m_bt_hsp = m_bt_hsp_a2dp = ""; | ||
4211 | 469 | o = pa_context_get_card_info_list(m_context, cardinfo_cb, this); | ||
4212 | 470 | if (!handleOperation(o, "pa_context_get_card_info_list")) | ||
4213 | 471 | return -1; | ||
4214 | 472 | /* In case we have only one bt device that provides hsp and a2dp, we need | ||
4215 | 473 | * to make sure we switch the default profile for that card (to hsp) */ | ||
4216 | 474 | if ((m_bt_hsp_a2dp != "") && (m_bt_hsp == "")) { | ||
4217 | 475 | qDebug("Setting PulseAudio card '%s' profile '%s'", | ||
4218 | 476 | m_bt_hsp_a2dp.c_str(), PULSEAUDIO_PROFILE_HSP); | ||
4219 | 477 | o = pa_context_set_card_profile_by_name(m_context, | ||
4220 | 478 | m_bt_hsp_a2dp.c_str(), PULSEAUDIO_PROFILE_HSP, success_cb, this); | ||
4221 | 479 | if (!handleOperation(o, "pa_context_set_card_profile_by_name")) | ||
4222 | 480 | return -1; | ||
4223 | 481 | } | ||
4224 | 482 | |||
4225 | 483 | pa_threaded_mainloop_unlock(m_mainLoop); | ||
4226 | 484 | |||
4227 | 485 | return 0; | ||
4228 | 486 | } | ||
4229 | 487 | |||
4230 | 488 | void QPulseAudioEngineWorker::restoreVoiceCall() | ||
4231 | 489 | { | ||
4232 | 490 | pa_operation *o; | ||
4233 | 491 | |||
4234 | 492 | qDebug("Restoring pulseaudio previous state"); | ||
4235 | 493 | |||
4236 | 494 | /* Then restore previous settings */ | ||
4237 | 495 | pa_threaded_mainloop_lock(m_mainLoop); | ||
4238 | 496 | |||
4239 | 497 | /* See if we need to restore any HSP+AD2P device state */ | ||
4240 | 498 | if ((m_bt_hsp_a2dp != "") && (m_bt_hsp == "")) { | ||
4241 | 499 | qDebug("Restoring PulseAudio card '%s' to profile '%s'", | ||
4242 | 500 | m_bt_hsp_a2dp.c_str(), PULSEAUDIO_PROFILE_A2DP); | ||
4243 | 501 | o = pa_context_set_card_profile_by_name(m_context, | ||
4244 | 502 | m_bt_hsp_a2dp.c_str(), PULSEAUDIO_PROFILE_A2DP, success_cb, this); | ||
4245 | 503 | if (!handleOperation(o, "pa_context_set_card_profile_by_name")) | ||
4246 | 504 | return; | ||
4247 | 505 | } | ||
4248 | 506 | |||
4249 | 507 | /* Restore default sink/source */ | ||
4250 | 508 | if (m_defaultsink != "") { | ||
4251 | 509 | qDebug("Restoring PulseAudio default sink to '%s'", m_defaultsink.c_str()); | ||
4252 | 510 | o = pa_context_set_default_sink(m_context, m_defaultsink.c_str(), success_cb, this); | ||
4253 | 511 | if (!handleOperation(o, "pa_context_set_default_sink")) | ||
4254 | 512 | return; | ||
4255 | 513 | } | ||
4256 | 514 | if (m_defaultsource != "") { | ||
4257 | 515 | qDebug("Restoring PulseAudio default source to '%s'", m_defaultsource.c_str()); | ||
4258 | 516 | o = pa_context_set_default_source(m_context, m_defaultsource.c_str(), success_cb, this); | ||
4259 | 517 | if (!handleOperation(o, "pa_context_set_default_source")) | ||
4260 | 518 | return; | ||
4261 | 519 | } | ||
4262 | 520 | |||
4263 | 521 | pa_threaded_mainloop_unlock(m_mainLoop); | ||
4264 | 522 | } | ||
4265 | 523 | |||
4266 | 524 | void QPulseAudioEngineWorker::setCallMode(CallStatus callstatus, AudioMode audiomode) | ||
4267 | 525 | { | ||
4268 | 526 | if (!createPulseContext()) { | ||
4269 | 527 | return; | ||
4270 | 528 | } | ||
4271 | 529 | CallStatus p_callstatus = m_callstatus; | ||
4272 | 530 | AudioMode p_audiomode = m_audiomode; | ||
4273 | 531 | AudioModes p_availableAudioModes = m_availableAudioModes; | ||
4274 | 532 | pa_operation *o; | ||
4275 | 533 | |||
4276 | 534 | /* Check if we need to save the current pulseaudio state (e.g. when starting a call) */ | ||
4277 | 535 | if ((callstatus != CallEnded) && (p_callstatus == CallEnded)) { | ||
4278 | 536 | if (setupVoiceCall() < 0) { | ||
4279 | 537 | qCritical("Failed to setup PulseAudio for Voice Call"); | ||
4280 | 538 | return; | ||
4281 | 539 | } | ||
4282 | 540 | } | ||
4283 | 541 | |||
4284 | 542 | /* If we have an active call, update internal state (used later when updating sink/source ports) */ | ||
4285 | 543 | m_callstatus = callstatus; | ||
4286 | 544 | m_audiomode = audiomode; | ||
4287 | 545 | |||
4288 | 546 | pa_threaded_mainloop_lock(m_mainLoop); | ||
4289 | 547 | |||
4290 | 548 | /* Switch the virtual card mode when call is active and not active | ||
4291 | 549 | * This needs to be done before sink/source gets updated, because after changing mode | ||
4292 | 550 | * it will automatically move to input/output-parking */ | ||
4293 | 551 | if ((m_callstatus == CallActive) && (p_callstatus != CallActive) && | ||
4294 | 552 | (m_voicecallcard != "") && (m_voicecallprofile != "")) { | ||
4295 | 553 | qDebug("Setting PulseAudio card '%s' profile '%s'", | ||
4296 | 554 | m_voicecallcard.c_str(), m_voicecallprofile.c_str()); | ||
4297 | 555 | o = pa_context_set_card_profile_by_name(m_context, | ||
4298 | 556 | m_voicecallcard.c_str(), m_voicecallprofile.c_str(), success_cb, this); | ||
4299 | 557 | if (!handleOperation(o, "pa_context_set_card_profile_by_name")) | ||
4300 | 558 | return; | ||
4301 | 559 | } else if ((m_callstatus == CallEnded) && (m_voicecallcard != "") && (m_voicecallhighest != "")) { | ||
4302 | 560 | /* If using droid, make sure to restore to the profile that has the highest score */ | ||
4303 | 561 | qDebug("Restoring PulseAudio card '%s' to profile '%s'", | ||
4304 | 562 | m_voicecallcard.c_str(), m_voicecallhighest.c_str()); | ||
4305 | 563 | o = pa_context_set_card_profile_by_name(m_context, | ||
4306 | 564 | m_voicecallcard.c_str(), m_voicecallhighest.c_str(), success_cb, this); | ||
4307 | 565 | if (!handleOperation(o, "pa_context_set_card_profile_by_name")) | ||
4308 | 566 | return; | ||
4309 | 567 | } | ||
4310 | 568 | |||
4311 | 569 | /* Find highest compatible sink/source elements from the voicecall | ||
4312 | 570 | compatible card (on touch this means the pulse droid element) */ | ||
4313 | 571 | m_nametoset = m_valuetoset = ""; | ||
4314 | 572 | o = pa_context_get_sink_info_list(m_context, sinkinfo_cb, this); | ||
4315 | 573 | if (!handleOperation(o, "pa_context_get_sink_info_list")) | ||
4316 | 574 | return; | ||
4317 | 575 | if ((m_nametoset != "") && (m_nametoset != m_defaultsink)) { | ||
4318 | 576 | qDebug("Setting PulseAudio default sink to '%s'", m_nametoset.c_str()); | ||
4319 | 577 | o = pa_context_set_default_sink(m_context, m_nametoset.c_str(), success_cb, this); | ||
4320 | 578 | if (!handleOperation(o, "pa_context_set_default_sink")) | ||
4321 | 579 | return; | ||
4322 | 580 | } | ||
4323 | 581 | if (m_valuetoset != "") { | ||
4324 | 582 | qDebug("Setting PulseAudio sink '%s' port '%s'", | ||
4325 | 583 | m_nametoset.c_str(), m_valuetoset.c_str()); | ||
4326 | 584 | o = pa_context_set_sink_port_by_name(m_context, m_nametoset.c_str(), | ||
4327 | 585 | m_valuetoset.c_str(), success_cb, this); | ||
4328 | 586 | if (!handleOperation(o, "pa_context_set_sink_port_by_name")) | ||
4329 | 587 | return; | ||
4330 | 588 | } | ||
4331 | 589 | |||
4332 | 590 | /* Same for source */ | ||
4333 | 591 | m_nametoset = m_valuetoset = ""; | ||
4334 | 592 | o = pa_context_get_source_info_list(m_context, sourceinfo_cb, this); | ||
4335 | 593 | if (!handleOperation(o, "pa_context_get_source_info_list")) | ||
4336 | 594 | return; | ||
4337 | 595 | if ((m_nametoset != "") && (m_nametoset != m_defaultsource)) { | ||
4338 | 596 | qDebug("Setting PulseAudio default source to '%s'", m_nametoset.c_str()); | ||
4339 | 597 | o = pa_context_set_default_source(m_context, m_nametoset.c_str(), success_cb, this); | ||
4340 | 598 | if (!handleOperation(o, "pa_context_set_default_source")) | ||
4341 | 599 | return; | ||
4342 | 600 | } | ||
4343 | 601 | if (m_valuetoset != "") { | ||
4344 | 602 | qDebug("Setting PulseAudio source '%s' port '%s'", | ||
4345 | 603 | m_nametoset.c_str(), m_valuetoset.c_str()); | ||
4346 | 604 | o = pa_context_set_source_port_by_name(m_context, m_nametoset.c_str(), | ||
4347 | 605 | m_valuetoset.c_str(), success_cb, this); | ||
4348 | 606 | if (!handleOperation(o, "pa_context_set_source_port_by_name")) | ||
4349 | 607 | return; | ||
4350 | 608 | } | ||
4351 | 609 | |||
4352 | 610 | pa_threaded_mainloop_unlock(m_mainLoop); | ||
4353 | 611 | |||
4354 | 612 | /* Notify if the list of audio modes changed */ | ||
4355 | 613 | if (p_availableAudioModes != m_availableAudioModes) | ||
4356 | 614 | Q_EMIT availableAudioModesChanged(m_availableAudioModes); | ||
4357 | 615 | |||
4358 | 616 | /* Notify if call mode changed */ | ||
4359 | 617 | if (p_audiomode != m_audiomode) { | ||
4360 | 618 | Q_EMIT audioModeChanged(m_audiomode); | ||
4361 | 619 | } | ||
4362 | 620 | |||
4363 | 621 | /* If no more active voicecall, restore previous saved pulseaudio state */ | ||
4364 | 622 | if (callstatus == CallEnded) { | ||
4365 | 623 | restoreVoiceCall(); | ||
4366 | 624 | } | ||
4367 | 625 | |||
4368 | 626 | /* In case the app had set mute when the call wasn't active, make sure we reflect it here */ | ||
4369 | 627 | if (m_callstatus != CallEnded) | ||
4370 | 628 | setMicMute(m_micmute); | ||
4371 | 629 | } | ||
4372 | 630 | |||
4373 | 631 | void QPulseAudioEngineWorker::setMicMute(bool muted) | ||
4374 | 632 | { | ||
4375 | 633 | if (!createPulseContext()) { | ||
4376 | 634 | return; | ||
4377 | 635 | } | ||
4378 | 636 | |||
4379 | 637 | m_micmute = muted; | ||
4380 | 638 | |||
4381 | 639 | if (m_callstatus == CallEnded) | ||
4382 | 640 | return; | ||
4383 | 641 | |||
4384 | 642 | pa_threaded_mainloop_lock(m_mainLoop); | ||
4385 | 643 | |||
4386 | 644 | m_nametoset = ""; | ||
4387 | 645 | pa_operation *o = pa_context_get_source_info_list(m_context, sourceinfo_cb, this); | ||
4388 | 646 | if (!handleOperation(o, "pa_context_get_source_info_list")) | ||
4389 | 647 | return; | ||
4390 | 648 | |||
4391 | 649 | if (m_nametoset != "") { | ||
4392 | 650 | int m = m_micmute ? 1 : 0; | ||
4393 | 651 | qDebug("Setting PulseAudio source '%s' muted '%d'", m_nametoset.c_str(), m); | ||
4394 | 652 | o = pa_context_set_source_mute_by_name(m_context, | ||
4395 | 653 | m_nametoset.c_str(), m, success_cb, this); | ||
4396 | 654 | if (!handleOperation(o, "pa_context_set_source_mute_by_name")) | ||
4397 | 655 | return; | ||
4398 | 656 | } | ||
4399 | 657 | |||
4400 | 658 | pa_threaded_mainloop_unlock(m_mainLoop); | ||
4401 | 659 | } | ||
4402 | 660 | |||
4403 | 661 | void QPulseAudioEngineWorker::plugCardCallback(const pa_card_info *info) | ||
4404 | 662 | { | ||
4405 | 663 | qDebug("Notified about card (%s) add event from PulseAudio", info->name); | ||
4406 | 664 | |||
4407 | 665 | /* Check if it's indeed a BT device (with at least one hsp profile) */ | ||
4408 | 666 | pa_card_profile_info2 *hsp = NULL, *a2dp = NULL; | ||
4409 | 667 | for (int i = 0; i < info->n_profiles; i++) { | ||
4410 | 668 | if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_HSP)) | ||
4411 | 669 | hsp = info->profiles2[i]; | ||
4412 | 670 | else if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_A2DP) && | ||
4413 | 671 | info->profiles2[i]->available != 0) { | ||
4414 | 672 | qDebug("Found a2dp"); | ||
4415 | 673 | a2dp = info->profiles2[i]; | ||
4416 | 674 | } | ||
4417 | 675 | qDebug("%s", info->profiles2[i]->name); | ||
4418 | 676 | } | ||
4419 | 677 | |||
4420 | 678 | if ((!info->active_profile || !strcmp(info->active_profile->name, "off")) && a2dp) { | ||
4421 | 679 | qDebug("No profile set"); | ||
4422 | 680 | m_default_bt_card_fallback = info->name; | ||
4423 | 681 | } | ||
4424 | 682 | |||
4425 | 683 | /* We only care about BT (HSP) devices, and if one is not already available */ | ||
4426 | 684 | if ((m_callstatus != CallEnded) && ((m_bt_hsp == "") || (m_bt_hsp_a2dp == ""))) { | ||
4427 | 685 | if (hsp) | ||
4428 | 686 | m_handleevent = true; | ||
4429 | 687 | } | ||
4430 | 688 | } | ||
4431 | 689 | |||
4432 | 690 | void QPulseAudioEngineWorker::updateCardCallback(const pa_card_info *info) | ||
4433 | 691 | { | ||
4434 | 692 | qDebug("Notified about card (%s) changes event from PulseAudio", info->name); | ||
4435 | 693 | |||
4436 | 694 | /* Check if it's indeed a BT device (with at least one hsp profile) */ | ||
4437 | 695 | pa_card_profile_info2 *hsp = NULL, *a2dp = NULL; | ||
4438 | 696 | for (int i = 0; i < info->n_profiles; i++) { | ||
4439 | 697 | if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_HSP)) | ||
4440 | 698 | hsp = info->profiles2[i]; | ||
4441 | 699 | else if (!strcmp(info->profiles2[i]->name, PULSEAUDIO_PROFILE_A2DP) && | ||
4442 | 700 | info->profiles2[i]->available != 0) { | ||
4443 | 701 | qDebug("Found a2dp"); | ||
4444 | 702 | a2dp = info->profiles2[i]; | ||
4445 | 703 | } | ||
4446 | 704 | qDebug("%s", info->profiles2[i]->name); | ||
4447 | 705 | } | ||
4448 | 706 | |||
4449 | 707 | if ((!info->active_profile || !strcmp(info->active_profile->name, "off")) && a2dp) { | ||
4450 | 708 | qDebug("No profile set"); | ||
4451 | 709 | m_default_bt_card_fallback = info->name; | ||
4452 | 710 | } | ||
4453 | 711 | |||
4454 | 712 | |||
4455 | 713 | /* We only care if the card event for the voicecall capable card */ | ||
4456 | 714 | if ((m_callstatus == CallActive) && (!strcmp(info->name, m_voicecallcard.c_str()))) { | ||
4457 | 715 | if (m_audiomode == AudioModeWiredHeadset) { | ||
4458 | 716 | /* If previous mode is wired, it means it got unplugged */ | ||
4459 | 717 | m_handleevent = true; | ||
4460 | 718 | m_audiomodetoset = AudioModeBtOrWiredOrEarpiece; | ||
4461 | 719 | } else if ((m_audiomode == AudioModeEarpiece) || ((m_audiomode == AudioModeSpeaker))) { | ||
4462 | 720 | /* Now only trigger the event in case wired headset/headphone is now available */ | ||
4463 | 721 | pa_card_port_info *port_info = NULL; | ||
4464 | 722 | for (int i = 0; i < info->n_ports; i++) { | ||
4465 | 723 | if (info->ports[i] && (info->ports[i]->available == PA_PORT_AVAILABLE_YES) && ( | ||
4466 | 724 | !strcmp(info->ports[i]->name, "output-wired_headset") || | ||
4467 | 725 | !strcmp(info->ports[i]->name, "output-wired_headphone"))) { | ||
4468 | 726 | m_handleevent = true; | ||
4469 | 727 | m_audiomodetoset = AudioModeWiredOrEarpiece; | ||
4470 | 728 | } | ||
4471 | 729 | } | ||
4472 | 730 | } else if (m_audiomode == AudioModeBluetooth) { | ||
4473 | 731 | /* Handle the event so we can update the audiomodes */ | ||
4474 | 732 | m_handleevent = true; | ||
4475 | 733 | m_audiomodetoset = AudioModeBluetooth; | ||
4476 | 734 | } | ||
4477 | 735 | } | ||
4478 | 736 | } | ||
4479 | 737 | |||
4480 | 738 | void QPulseAudioEngineWorker::unplugCardCallback() | ||
4481 | 739 | { | ||
4482 | 740 | if (m_callstatus != CallEnded) { | ||
4483 | 741 | m_handleevent = true; | ||
4484 | 742 | } | ||
4485 | 743 | } | ||
4486 | 744 | |||
4487 | 745 | void QPulseAudioEngineWorker::handleCardEvent(const int evt, const unsigned int idx) | ||
4488 | 746 | { | ||
4489 | 747 | pa_operation *o = NULL; | ||
4490 | 748 | |||
4491 | 749 | /* Internal state var used to know if we need to update our internal state */ | ||
4492 | 750 | m_handleevent = false; | ||
4493 | 751 | |||
4494 | 752 | if (evt == PA_SUBSCRIPTION_EVENT_NEW) { | ||
4495 | 753 | o = pa_context_get_card_info_by_index(m_context, idx, plug_card_cb, this); | ||
4496 | 754 | if (!handleOperation(o, "pa_context_get_card_info_by_index")) | ||
4497 | 755 | return; | ||
4498 | 756 | |||
4499 | 757 | if (m_default_bt_card_fallback != "") { | ||
4500 | 758 | o = pa_context_set_card_profile_by_name(m_context, | ||
4501 | 759 | m_default_bt_card_fallback.c_str(), PULSEAUDIO_PROFILE_A2DP, success_cb, this); | ||
4502 | 760 | if (!handleOperation(o, "pa_context_set_card_profile_by_name")) | ||
4503 | 761 | return; | ||
4504 | 762 | m_default_bt_card_fallback = ""; | ||
4505 | 763 | } | ||
4506 | 764 | |||
4507 | 765 | if (m_handleevent) { | ||
4508 | 766 | qDebug("Adding new BT-HSP capable device"); | ||
4509 | 767 | /* In case A2DP is available, switch to HSP */ | ||
4510 | 768 | if (setupVoiceCall() < 0) | ||
4511 | 769 | return; | ||
4512 | 770 | /* Enable the HSP output port */ | ||
4513 | 771 | setCallMode(m_callstatus, AudioModeBluetooth); | ||
4514 | 772 | } | ||
4515 | 773 | } else if (evt == PA_SUBSCRIPTION_EVENT_CHANGE) { | ||
4516 | 774 | o = pa_context_get_card_info_by_index(m_context, idx, update_card_cb, this); | ||
4517 | 775 | if (!handleOperation(o, "pa_context_get_card_info_by_index")) | ||
4518 | 776 | return; | ||
4519 | 777 | |||
4520 | 778 | if (m_default_bt_card_fallback != "") { | ||
4521 | 779 | o = pa_context_set_card_profile_by_name(m_context, | ||
4522 | 780 | m_default_bt_card_fallback.c_str(), PULSEAUDIO_PROFILE_A2DP, success_cb, this); | ||
4523 | 781 | if (!handleOperation(o, "pa_context_set_card_profile_by_name")) | ||
4524 | 782 | return; | ||
4525 | 783 | m_default_bt_card_fallback = ""; | ||
4526 | 784 | } | ||
4527 | 785 | |||
4528 | 786 | if (m_handleevent) { | ||
4529 | 787 | /* In this case it means the handset state changed */ | ||
4530 | 788 | qDebug("Notifying card changes for the voicecall capable card"); | ||
4531 | 789 | setCallMode(m_callstatus, m_audiomodetoset); | ||
4532 | 790 | } | ||
4533 | 791 | } else if (evt == PA_SUBSCRIPTION_EVENT_REMOVE) { | ||
4534 | 792 | /* Check if the main HSP card was removed */ | ||
4535 | 793 | if (m_bt_hsp != "") { | ||
4536 | 794 | o = pa_context_get_card_info_by_name(m_context, m_bt_hsp.c_str(), unplug_card_cb, this); | ||
4537 | 795 | if (!handleOperation(o, "pa_context_get_sink_info_by_name")) | ||
4538 | 796 | return; | ||
4539 | 797 | } | ||
4540 | 798 | if (m_bt_hsp_a2dp != "") { | ||
4541 | 799 | o = pa_context_get_card_info_by_name(m_context, m_bt_hsp_a2dp.c_str(), unplug_card_cb, this); | ||
4542 | 800 | if (!handleOperation(o, "pa_context_get_sink_info_by_name")) | ||
4543 | 801 | return; | ||
4544 | 802 | } | ||
4545 | 803 | if (m_handleevent) { | ||
4546 | 804 | qDebug("Notifying about BT-HSP card removal"); | ||
4547 | 805 | /* Needed in order to save the default sink/source */ | ||
4548 | 806 | if (setupVoiceCall() < 0) | ||
4549 | 807 | return; | ||
4550 | 808 | /* Enable the default handset output port */ | ||
4551 | 809 | setCallMode(m_callstatus, AudioModeWiredOrEarpiece); | ||
4552 | 810 | } | ||
4553 | 811 | } | ||
4554 | 812 | } | ||
4555 | 813 | |||
4556 | 814 | Q_GLOBAL_STATIC(QPulseAudioEngine, pulseEngine); | ||
4557 | 815 | |||
4558 | 816 | QPulseAudioEngine::QPulseAudioEngine(QObject *parent) : | ||
4559 | 817 | QObject(parent) | ||
4560 | 818 | { | ||
4561 | 819 | qRegisterMetaType<CallStatus>(); | ||
4562 | 820 | qRegisterMetaType<AudioMode>(); | ||
4563 | 821 | qRegisterMetaType<AudioModes>(); | ||
4564 | 822 | mWorker = new QPulseAudioEngineWorker(); | ||
4565 | 823 | QObject::connect(mWorker, SIGNAL(audioModeChanged(const AudioMode)), this, SIGNAL(audioModeChanged(const AudioMode)), Qt::QueuedConnection); | ||
4566 | 824 | QObject::connect(mWorker, SIGNAL(availableAudioModesChanged(const AudioModes)), this, SIGNAL(availableAudioModesChanged(const AudioModes)), Qt::QueuedConnection); | ||
4567 | 825 | mWorker->createPulseContext(); | ||
4568 | 826 | mWorker->moveToThread(&mThread); | ||
4569 | 827 | mThread.start(); | ||
4570 | 828 | } | ||
4571 | 829 | |||
4572 | 830 | QPulseAudioEngine::~QPulseAudioEngine() | ||
4573 | 831 | { | ||
4574 | 832 | mThread.quit(); | ||
4575 | 833 | mThread.wait(); | ||
4576 | 834 | } | ||
4577 | 835 | |||
4578 | 836 | QPulseAudioEngine *QPulseAudioEngine::instance() | ||
4579 | 837 | { | ||
4580 | 838 | QPulseAudioEngine *engine = pulseEngine(); | ||
4581 | 839 | return engine; | ||
4582 | 840 | } | ||
4583 | 841 | |||
4584 | 842 | void QPulseAudioEngine::setCallMode(CallStatus callstatus, AudioMode audiomode) | ||
4585 | 843 | { | ||
4586 | 844 | QMetaObject::invokeMethod(mWorker, "setCallMode", Qt::QueuedConnection, Q_ARG(CallStatus, callstatus), Q_ARG(AudioMode, audiomode)); | ||
4587 | 845 | } | ||
4588 | 846 | |||
4589 | 847 | void QPulseAudioEngine::setMicMute(bool muted) | ||
4590 | 848 | { | ||
4591 | 849 | QMetaObject::invokeMethod(mWorker, "setMicMute", Qt::QueuedConnection, Q_ARG(bool, muted)); | ||
4592 | 850 | } | ||
4593 | 851 | |||
4594 | 852 | QT_END_NAMESPACE | ||
4595 | 853 | |||
4596 | 0 | 854 | ||
4597 | === added file 'handler/qpulseaudioengine.h' | |||
4598 | --- handler/qpulseaudioengine.h 1970-01-01 00:00:00 +0000 | |||
4599 | +++ handler/qpulseaudioengine.h 2017-04-05 14:05:16 +0000 | |||
4600 | @@ -0,0 +1,126 @@ | |||
4601 | 1 | /**************************************************************************** | ||
4602 | 2 | ** | ||
4603 | 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | ||
4604 | 4 | ** Contact: http://www.qt-project.org/legal | ||
4605 | 5 | ** | ||
4606 | 6 | ** This file was taken from qt5 and modified by | ||
4607 | 7 | ** David Henningsson <david.henningsson@canonical.com> for usage in | ||
4608 | 8 | ** telepathy-ofono. | ||
4609 | 9 | ** | ||
4610 | 10 | ** GNU Lesser General Public License Usage | ||
4611 | 11 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
4612 | 12 | ** General Public License version 2.1 as published by the Free Software | ||
4613 | 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
4614 | 14 | ** packaging of this file. Please review the following information to | ||
4615 | 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
4616 | 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
4617 | 17 | ** | ||
4618 | 18 | ****************************************************************************/ | ||
4619 | 19 | |||
4620 | 20 | #ifndef QPULSEAUDIOENGINE_H | ||
4621 | 21 | #define QPULSEAUDIOENGINE_H | ||
4622 | 22 | |||
4623 | 23 | #include <QtCore/qmap.h> | ||
4624 | 24 | #include <QtCore/qbytearray.h> | ||
4625 | 25 | #include <QThread> | ||
4626 | 26 | #include <pulse/pulseaudio.h> | ||
4627 | 27 | |||
4628 | 28 | enum AudioMode { | ||
4629 | 29 | AudioModeEarpiece = 0x0001, | ||
4630 | 30 | AudioModeWiredHeadset = 0x0002, | ||
4631 | 31 | AudioModeSpeaker = 0x0004, | ||
4632 | 32 | AudioModeBluetooth = 0x0008, | ||
4633 | 33 | AudioModeBtOrWiredOrEarpiece = AudioModeBluetooth | AudioModeWiredHeadset | AudioModeEarpiece, | ||
4634 | 34 | AudioModeWiredOrEarpiece = AudioModeWiredHeadset | AudioModeEarpiece, | ||
4635 | 35 | AudioModeWiredOrSpeaker = AudioModeWiredHeadset | AudioModeSpeaker, | ||
4636 | 36 | AudioModeBtOrWiredOrSpeaker = AudioModeBluetooth | AudioModeWiredOrSpeaker | ||
4637 | 37 | }; | ||
4638 | 38 | |||
4639 | 39 | Q_DECLARE_METATYPE(AudioMode) | ||
4640 | 40 | |||
4641 | 41 | typedef QList<AudioMode> AudioModes; | ||
4642 | 42 | Q_DECLARE_METATYPE(AudioModes) | ||
4643 | 43 | |||
4644 | 44 | enum CallStatus { | ||
4645 | 45 | CallRinging, | ||
4646 | 46 | CallActive, | ||
4647 | 47 | CallEnded | ||
4648 | 48 | }; | ||
4649 | 49 | |||
4650 | 50 | Q_DECLARE_METATYPE(CallStatus) | ||
4651 | 51 | |||
4652 | 52 | QT_BEGIN_NAMESPACE | ||
4653 | 53 | |||
4654 | 54 | class QPulseAudioEngineWorker : public QObject | ||
4655 | 55 | { | ||
4656 | 56 | Q_OBJECT | ||
4657 | 57 | |||
4658 | 58 | public: | ||
4659 | 59 | QPulseAudioEngineWorker(QObject *parent = 0); | ||
4660 | 60 | ~QPulseAudioEngineWorker(); | ||
4661 | 61 | |||
4662 | 62 | pa_threaded_mainloop *mainloop() { return m_mainLoop; } | ||
4663 | 63 | pa_context *context() { return m_context; } | ||
4664 | 64 | bool createPulseContext(void); | ||
4665 | 65 | int setupVoiceCall(void); | ||
4666 | 66 | void restoreVoiceCall(void); | ||
4667 | 67 | /* Callbacks to be used internally */ | ||
4668 | 68 | void cardInfoCallback(const pa_card_info *card); | ||
4669 | 69 | void sinkInfoCallback(const pa_sink_info *sink); | ||
4670 | 70 | void sourceInfoCallback(const pa_source_info *source); | ||
4671 | 71 | void serverInfoCallback(const pa_server_info *server); | ||
4672 | 72 | void plugCardCallback(const pa_card_info *card); | ||
4673 | 73 | void updateCardCallback(const pa_card_info *card); | ||
4674 | 74 | void unplugCardCallback(); | ||
4675 | 75 | |||
4676 | 76 | Q_SIGNALS: | ||
4677 | 77 | void audioModeChanged(const AudioMode mode); | ||
4678 | 78 | void availableAudioModesChanged(const AudioModes modes); | ||
4679 | 79 | |||
4680 | 80 | public Q_SLOTS: | ||
4681 | 81 | void handleCardEvent(const int evt, const unsigned int idx); | ||
4682 | 82 | void setCallMode(CallStatus callstatus, AudioMode audiomode); | ||
4683 | 83 | void setMicMute(bool muted); /* True if muted, false if unmuted */ | ||
4684 | 84 | |||
4685 | 85 | private: | ||
4686 | 86 | pa_mainloop_api *m_mainLoopApi; | ||
4687 | 87 | pa_threaded_mainloop *m_mainLoop; | ||
4688 | 88 | pa_context *m_context; | ||
4689 | 89 | |||
4690 | 90 | AudioModes m_availableAudioModes; | ||
4691 | 91 | CallStatus m_callstatus; | ||
4692 | 92 | AudioMode m_audiomode; | ||
4693 | 93 | AudioMode m_audiomodetoset; | ||
4694 | 94 | bool m_micmute, m_handleevent; | ||
4695 | 95 | std::string m_nametoset, m_valuetoset; | ||
4696 | 96 | std::string m_defaultsink, m_defaultsource; | ||
4697 | 97 | std::string m_bt_hsp, m_bt_hsp_a2dp; | ||
4698 | 98 | std::string m_default_bt_card_fallback; | ||
4699 | 99 | std::string m_voicecallcard, m_voicecallhighest, m_voicecallprofile; | ||
4700 | 100 | |||
4701 | 101 | bool handleOperation(pa_operation *operation, const char *func_name); | ||
4702 | 102 | void releasePulseContext(void); | ||
4703 | 103 | }; | ||
4704 | 104 | |||
4705 | 105 | class QPulseAudioEngine : public QObject | ||
4706 | 106 | { | ||
4707 | 107 | Q_OBJECT | ||
4708 | 108 | public: | ||
4709 | 109 | explicit QPulseAudioEngine(QObject *parent = 0); | ||
4710 | 110 | ~QPulseAudioEngine(); | ||
4711 | 111 | static QPulseAudioEngine *instance(); | ||
4712 | 112 | |||
4713 | 113 | void setCallMode(CallStatus callstatus, AudioMode audiomode); | ||
4714 | 114 | void setMicMute(bool muted); /* True if muted, false if unmuted */ | ||
4715 | 115 | |||
4716 | 116 | Q_SIGNALS: | ||
4717 | 117 | void audioModeChanged(const AudioMode mode); | ||
4718 | 118 | void availableAudioModesChanged(const AudioModes modes); | ||
4719 | 119 | private: | ||
4720 | 120 | QPulseAudioEngineWorker *mWorker; | ||
4721 | 121 | QThread mThread; | ||
4722 | 122 | }; | ||
4723 | 123 | |||
4724 | 124 | QT_END_NAMESPACE | ||
4725 | 125 | |||
4726 | 126 | #endif | ||
4727 | 0 | 127 | ||
4728 | === modified file 'handler/texthandler.cpp' | |||
4729 | --- handler/texthandler.cpp 2016-11-23 19:37:30 +0000 | |||
4730 | +++ handler/texthandler.cpp 2017-04-05 14:05:16 +0000 | |||
4731 | @@ -35,10 +35,39 @@ | |||
4732 | 35 | 35 | ||
4733 | 36 | TextHandler::TextHandler(QObject *parent) | 36 | TextHandler::TextHandler(QObject *parent) |
4734 | 37 | : QObject(parent) | 37 | : QObject(parent) |
4735 | 38 | , mMessagingAppMonitor("com.canonical.MessagingApp", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration|QDBusServiceWatcher::WatchForUnregistration), mMessagingAppRegistered(false) | ||
4736 | 38 | { | 39 | { |
4737 | 39 | qDBusRegisterMetaType<AttachmentStruct>(); | 40 | qDBusRegisterMetaType<AttachmentStruct>(); |
4738 | 40 | qDBusRegisterMetaType<AttachmentList>(); | 41 | qDBusRegisterMetaType<AttachmentList>(); |
4739 | 41 | qRegisterMetaType<PendingMessage>(); | 42 | qRegisterMetaType<PendingMessage>(); |
4740 | 43 | connect(&mMessagingAppMonitor, SIGNAL(serviceRegistered(const QString&)), SLOT(onMessagingAppOpen())); | ||
4741 | 44 | connect(&mMessagingAppMonitor, SIGNAL(serviceUnregistered(const QString&)), SLOT(onMessagingAppClosed())); | ||
4742 | 45 | connect(TelepathyHelper::instance(), &TelepathyHelper::accountAdded, [=](AccountEntry *account) { | ||
4743 | 46 | if (mMessagingAppRegistered && !account->active() && account->protocolInfo()->leaveRoomsOnClose()) { | ||
4744 | 47 | account->reconnect(); | ||
4745 | 48 | } | ||
4746 | 49 | }); | ||
4747 | 50 | } | ||
4748 | 51 | |||
4749 | 52 | void TextHandler::onMessagingAppOpen() | ||
4750 | 53 | { | ||
4751 | 54 | mMessagingAppRegistered = true; | ||
4752 | 55 | Q_FOREACH(AccountEntry *account, TelepathyHelper::instance()->accounts()) { | ||
4753 | 56 | if (!account->active() && account->protocolInfo()->leaveRoomsOnClose()) { | ||
4754 | 57 | account->reconnect(); | ||
4755 | 58 | } | ||
4756 | 59 | } | ||
4757 | 60 | } | ||
4758 | 61 | |||
4759 | 62 | void TextHandler::onMessagingAppClosed() | ||
4760 | 63 | { | ||
4761 | 64 | mMessagingAppRegistered = false; | ||
4762 | 65 | Q_FOREACH(AccountEntry *account, TelepathyHelper::instance()->accounts()) { | ||
4763 | 66 | if (account->protocolInfo()->leaveRoomsOnClose()) { | ||
4764 | 67 | account->requestDisconnect(); | ||
4765 | 68 | } | ||
4766 | 69 | } | ||
4767 | 70 | |||
4768 | 42 | } | 71 | } |
4769 | 43 | 72 | ||
4770 | 44 | TextHandler *TextHandler::instance() | 73 | TextHandler *TextHandler::instance() |
4771 | @@ -168,8 +197,14 @@ | |||
4772 | 168 | if (chatType == Tp::HandleTypeNone && targetIds.size() == 1) { | 197 | if (chatType == Tp::HandleTypeNone && targetIds.size() == 1) { |
4773 | 169 | chatType = Tp::HandleTypeContact; | 198 | chatType = Tp::HandleTypeContact; |
4774 | 170 | } | 199 | } |
4775 | 200 | |||
4776 | 171 | QString roomId = properties["threadId"].toString(); | 201 | QString roomId = properties["threadId"].toString(); |
4777 | 172 | 202 | ||
4778 | 203 | // try to use the threadId as participantId if empty | ||
4779 | 204 | if (chatType == Tp::HandleTypeContact && targetIds.isEmpty()) { | ||
4780 | 205 | targetIds << roomId; | ||
4781 | 206 | } | ||
4782 | 207 | |||
4783 | 173 | Q_FOREACH(const Tp::TextChannelPtr &channel, mChannels) { | 208 | Q_FOREACH(const Tp::TextChannelPtr &channel, mChannels) { |
4784 | 174 | int count = 0; | 209 | int count = 0; |
4785 | 175 | AccountEntry *channelAccount = TelepathyHelper::instance()->accountForConnection(channel->connection()); | 210 | AccountEntry *channelAccount = TelepathyHelper::instance()->accountForConnection(channel->connection()); |
4786 | @@ -275,3 +310,15 @@ | |||
4787 | 275 | return true; | 310 | return true; |
4788 | 276 | } | 311 | } |
4789 | 277 | 312 | ||
4790 | 313 | void TextHandler::leaveRooms(const QString &accountId, const QString &message) | ||
4791 | 314 | { | ||
4792 | 315 | Q_FOREACH(const Tp::TextChannelPtr &channel, mChannels) { | ||
4793 | 316 | if (channel->targetHandleType() != Tp::HandleTypeRoom) { | ||
4794 | 317 | continue; | ||
4795 | 318 | } | ||
4796 | 319 | AccountEntry *account = TelepathyHelper::instance()->accountForConnection(channel->connection()); | ||
4797 | 320 | if (account && account->accountId() == accountId) { | ||
4798 | 321 | leaveChat(channel->objectPath(), message); | ||
4799 | 322 | } | ||
4800 | 323 | } | ||
4801 | 324 | } | ||
4802 | 278 | 325 | ||
4803 | === modified file 'handler/texthandler.h' | |||
4804 | --- handler/texthandler.h 2016-11-23 19:28:18 +0000 | |||
4805 | +++ handler/texthandler.h 2017-04-05 14:05:16 +0000 | |||
4806 | @@ -48,11 +48,15 @@ | |||
4807 | 48 | void inviteParticipants(const QString &objectPath, const QStringList &participants, const QString &message); | 48 | void inviteParticipants(const QString &objectPath, const QStringList &participants, const QString &message); |
4808 | 49 | void removeParticipants(const QString &objectPath, const QStringList &participants, const QString &message); | 49 | void removeParticipants(const QString &objectPath, const QStringList &participants, const QString &message); |
4809 | 50 | bool leaveChat(const QString &objectPath, const QString &message); | 50 | bool leaveChat(const QString &objectPath, const QString &message); |
4810 | 51 | void leaveRooms(const QString &accountId, const QString &message); | ||
4811 | 51 | 52 | ||
4812 | 52 | protected Q_SLOTS: | 53 | protected Q_SLOTS: |
4813 | 53 | void onTextChannelAvailable(Tp::TextChannelPtr channel); | 54 | void onTextChannelAvailable(Tp::TextChannelPtr channel); |
4814 | 54 | void onTextChannelInvalidated(); | 55 | void onTextChannelInvalidated(); |
4815 | 55 | 56 | ||
4816 | 57 | void onMessagingAppOpen(); | ||
4817 | 58 | void onMessagingAppClosed(); | ||
4818 | 59 | |||
4819 | 56 | protected: | 60 | protected: |
4820 | 57 | QList<Tp::TextChannelPtr> existingChannels(const QString &accountId, const QVariantMap &properties); | 61 | QList<Tp::TextChannelPtr> existingChannels(const QString &accountId, const QVariantMap &properties); |
4821 | 58 | Tp::TextChannelPtr existingChannelFromObjectPath(const QString &objectPath); | 62 | Tp::TextChannelPtr existingChannelFromObjectPath(const QString &objectPath); |
4822 | @@ -60,6 +64,8 @@ | |||
4823 | 60 | private: | 64 | private: |
4824 | 61 | explicit TextHandler(QObject *parent = 0); | 65 | explicit TextHandler(QObject *parent = 0); |
4825 | 62 | QList<Tp::TextChannelPtr> mChannels; | 66 | QList<Tp::TextChannelPtr> mChannels; |
4826 | 67 | QDBusServiceWatcher mMessagingAppMonitor; | ||
4827 | 68 | bool mMessagingAppRegistered; | ||
4828 | 63 | }; | 69 | }; |
4829 | 64 | 70 | ||
4830 | 65 | #endif // TEXTHANDLER_H | 71 | #endif // TEXTHANDLER_H |
4831 | 66 | 72 | ||
4832 | === modified file 'indicator/callchannelobserver.cpp' | |||
4833 | --- indicator/callchannelobserver.cpp 2014-11-19 21:45:35 +0000 | |||
4834 | +++ indicator/callchannelobserver.cpp 2017-04-05 14:05:16 +0000 | |||
4835 | @@ -1,5 +1,5 @@ | |||
4836 | 1 | /* | 1 | /* |
4838 | 2 | * Copyright (C) 2013 Canonical, Ltd. | 2 | * Copyright (C) 2013-2017 Canonical, Ltd. |
4839 | 3 | * | 3 | * |
4840 | 4 | * Authors: | 4 | * Authors: |
4841 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
4842 | @@ -21,6 +21,7 @@ | |||
4843 | 21 | 21 | ||
4844 | 22 | #include "callchannelobserver.h" | 22 | #include "callchannelobserver.h" |
4845 | 23 | #include "callnotification.h" | 23 | #include "callnotification.h" |
4846 | 24 | #include "contactwatcher.h" | ||
4847 | 24 | #include "messagingmenu.h" | 25 | #include "messagingmenu.h" |
4848 | 25 | #include "metrics.h" | 26 | #include "metrics.h" |
4849 | 26 | #include "telepathyhelper.h" | 27 | #include "telepathyhelper.h" |
4850 | @@ -49,6 +50,13 @@ | |||
4851 | 49 | SLOT(onHoldChanged())); | 50 | SLOT(onHoldChanged())); |
4852 | 50 | 51 | ||
4853 | 51 | mChannels.append(callChannel); | 52 | mChannels.append(callChannel); |
4854 | 53 | if (callChannel->isReady(Tp::CallChannel::FeatureCallState)) { | ||
4855 | 54 | mCallStates[callChannel.data()] = callChannel->callState(); | ||
4856 | 55 | } else { | ||
4857 | 56 | connect(callChannel->becomeReady(Tp::CallChannel::FeatureCallState), &Tp::PendingReady::finished, [&](){ | ||
4858 | 57 | mCallStates[callChannel.data()] = callChannel->callState(); | ||
4859 | 58 | }); | ||
4860 | 59 | } | ||
4861 | 52 | } | 60 | } |
4862 | 53 | 61 | ||
4863 | 54 | void CallChannelObserver::onCallStateChanged(Tp::CallState state) | 62 | void CallChannelObserver::onCallStateChanged(Tp::CallState state) |
4864 | @@ -70,16 +78,23 @@ | |||
4865 | 70 | switch (state) { | 78 | switch (state) { |
4866 | 71 | case Tp::CallStateEnded: | 79 | case Tp::CallStateEnded: |
4867 | 72 | Q_EMIT callEnded(channel); | 80 | Q_EMIT callEnded(channel); |
4868 | 81 | |||
4869 | 82 | // if the missed flag is false, we still have to check if transitioning directly from Initialized to Ended | ||
4870 | 83 | if (!missed && incoming) { | ||
4871 | 84 | missed = mCallStates[channel.data()] == Tp::CallStateInitialised; | ||
4872 | 85 | } | ||
4873 | 86 | |||
4874 | 73 | // add the missed call to the messaging menu | 87 | // add the missed call to the messaging menu |
4875 | 74 | if (missed) { | 88 | if (missed) { |
4876 | 75 | // FIXME: handle conf call | 89 | // FIXME: handle conf call |
4878 | 76 | MessagingMenu::instance()->addCall(channel->targetContact()->id(), accountEntry->accountId(), QDateTime::currentDateTime()); | 90 | MessagingMenu::instance()->addCall(ContactWatcher::normalizeIdentifier(channel->targetContact()->id()), accountEntry->accountId(), QDateTime::currentDateTime()); |
4879 | 77 | } else { | 91 | } else { |
4880 | 78 | // and show a notification | 92 | // and show a notification |
4881 | 79 | // FIXME: handle conf call | 93 | // FIXME: handle conf call |
4883 | 80 | CallNotification::instance()->showNotificationForCall(QStringList() << channel->targetContact()->id(), CallNotification::CallEnded); | 94 | CallNotification::instance()->showNotificationForCall(QStringList() << ContactWatcher::normalizeIdentifier(channel->targetContact()->id()), CallNotification::CallEnded); |
4884 | 81 | } | 95 | } |
4885 | 82 | 96 | ||
4886 | 97 | mCallStates.remove(channel.data()); | ||
4887 | 83 | mChannels.removeOne(channel); | 98 | mChannels.removeOne(channel); |
4888 | 84 | 99 | ||
4889 | 85 | // update the metrics | 100 | // update the metrics |
4890 | @@ -93,6 +108,7 @@ | |||
4891 | 93 | channel->setProperty("activeTimestamp", QDateTime::currentDateTime()); | 108 | channel->setProperty("activeTimestamp", QDateTime::currentDateTime()); |
4892 | 94 | break; | 109 | break; |
4893 | 95 | } | 110 | } |
4894 | 111 | mCallStates[channel.data()] = state; | ||
4895 | 96 | } | 112 | } |
4896 | 97 | 113 | ||
4897 | 98 | void CallChannelObserver::onHoldChanged() | 114 | void CallChannelObserver::onHoldChanged() |
4898 | 99 | 115 | ||
4899 | === modified file 'indicator/callchannelobserver.h' | |||
4900 | --- indicator/callchannelobserver.h 2014-01-20 12:57:43 +0000 | |||
4901 | +++ indicator/callchannelobserver.h 2017-04-05 14:05:16 +0000 | |||
4902 | @@ -1,5 +1,5 @@ | |||
4903 | 1 | /* | 1 | /* |
4905 | 2 | * Copyright (C) 2013 Canonical, Ltd. | 2 | * Copyright (C) 2013-2017 Canonical, Ltd. |
4906 | 3 | * | 3 | * |
4907 | 4 | * Authors: | 4 | * Authors: |
4908 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
4909 | @@ -43,6 +43,7 @@ | |||
4910 | 43 | 43 | ||
4911 | 44 | private: | 44 | private: |
4912 | 45 | QList<Tp::CallChannelPtr> mChannels; | 45 | QList<Tp::CallChannelPtr> mChannels; |
4913 | 46 | QMap<Tp::CallChannel*,Tp::CallState> mCallStates; | ||
4914 | 46 | }; | 47 | }; |
4915 | 47 | 48 | ||
4916 | 48 | #endif // CALLCHANNELOBSERVER_H | 49 | #endif // CALLCHANNELOBSERVER_H |
4917 | 49 | 50 | ||
4918 | === modified file 'indicator/displaynamesettings.cpp' | |||
4919 | --- indicator/displaynamesettings.cpp 2016-03-18 19:02:50 +0000 | |||
4920 | +++ indicator/displaynamesettings.cpp 2017-04-05 14:05:16 +0000 | |||
4921 | @@ -1,5 +1,5 @@ | |||
4922 | 1 | /* | 1 | /* |
4924 | 2 | * Copyright (C) 2016 Canonical, Ltd. | 2 | * Copyright (C) 2016-2017 Canonical, Ltd. |
4925 | 3 | * | 3 | * |
4926 | 4 | * Authors: | 4 | * Authors: |
4927 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
4928 | @@ -86,7 +86,7 @@ | |||
4929 | 86 | 86 | ||
4930 | 87 | void DisplayNameSettings::onAccountsChanged() | 87 | void DisplayNameSettings::onAccountsChanged() |
4931 | 88 | { | 88 | { |
4933 | 89 | Q_FOREACH(AccountEntry *account, TelepathyHelper::instance()->accounts()) { | 89 | Q_FOREACH(AccountEntry *account, TelepathyHelper::instance()->phoneAccounts()) { |
4934 | 90 | QString modemObjName = account->account()->parameters().value("modem-objpath").toString(); | 90 | QString modemObjName = account->account()->parameters().value("modem-objpath").toString(); |
4935 | 91 | if (mAccountNames.contains(modemObjName) && account->displayName() != mAccountNames[modemObjName]) { | 91 | if (mAccountNames.contains(modemObjName) && account->displayName() != mAccountNames[modemObjName]) { |
4936 | 92 | account->setDisplayName(mAccountNames[modemObjName]); | 92 | account->setDisplayName(mAccountNames[modemObjName]); |
4937 | 93 | 93 | ||
4938 | === modified file 'indicator/messagingmenu.cpp' | |||
4939 | --- indicator/messagingmenu.cpp 2016-11-23 19:28:18 +0000 | |||
4940 | +++ indicator/messagingmenu.cpp 2017-04-05 14:05:16 +0000 | |||
4941 | @@ -1,5 +1,5 @@ | |||
4942 | 1 | /* | 1 | /* |
4944 | 2 | * Copyright (C) 2012-2016 Canonical, Ltd. | 2 | * Copyright (C) 2012-2017 Canonical, Ltd. |
4945 | 3 | * | 3 | * |
4946 | 4 | * Authors: | 4 | * Authors: |
4947 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
4948 | @@ -244,6 +244,8 @@ | |||
4949 | 244 | file = g_file_new_for_uri(avatar.toString().toUtf8().data()); | 244 | file = g_file_new_for_uri(avatar.toString().toUtf8().data()); |
4950 | 245 | icon = g_file_icon_new(file); | 245 | icon = g_file_icon_new(file); |
4951 | 246 | } | 246 | } |
4952 | 247 | |||
4953 | 248 | qDebug() << "notify message received:" << notificationData.encodedEventId.toUtf8(); | ||
4954 | 247 | MessagingMenuMessage *message = messaging_menu_message_new(notificationData.encodedEventId.toUtf8().data(), | 249 | MessagingMenuMessage *message = messaging_menu_message_new(notificationData.encodedEventId.toUtf8().data(), |
4955 | 248 | icon, | 250 | icon, |
4956 | 249 | displayLabel.toUtf8().data(), | 251 | displayLabel.toUtf8().data(), |
4957 | @@ -287,8 +289,9 @@ | |||
4958 | 287 | mMessages.remove(messageId); | 289 | mMessages.remove(messageId); |
4959 | 288 | } | 290 | } |
4960 | 289 | 291 | ||
4962 | 290 | void MessagingMenu::addCallToMessagingMenu(Call call, const QString &text) | 292 | void MessagingMenu::addCallToMessagingMenu(Call call, const QString &text, bool supportsTextReply) |
4963 | 291 | { | 293 | { |
4964 | 294 | qDebug() << __PRETTY_FUNCTION__; | ||
4965 | 292 | GVariant *messages = NULL; | 295 | GVariant *messages = NULL; |
4966 | 293 | GFile *file = g_file_new_for_uri(call.contactIcon.toString().toUtf8().data()); | 296 | GFile *file = g_file_new_for_uri(call.contactIcon.toString().toUtf8().data()); |
4967 | 294 | GIcon *icon = g_file_icon_new(file); | 297 | GIcon *icon = g_file_icon_new(file); |
4968 | @@ -300,7 +303,7 @@ | |||
4969 | 300 | call.timestamp.toMSecsSinceEpoch() * 1000); // the value is expected to be in microseconds | 303 | call.timestamp.toMSecsSinceEpoch() * 1000); // the value is expected to be in microseconds |
4970 | 301 | 304 | ||
4971 | 302 | call.messageId = messaging_menu_message_get_id(message); | 305 | call.messageId = messaging_menu_message_get_id(message); |
4973 | 303 | if (call.targetId != OFONO_PRIVATE_NUMBER && call.targetId != OFONO_UNKNOWN_NUMBER) { | 306 | if (supportsTextReply && call.targetId != OFONO_PRIVATE_NUMBER && call.targetId != OFONO_UNKNOWN_NUMBER) { |
4974 | 304 | messaging_menu_message_add_action(message, | 307 | messaging_menu_message_add_action(message, |
4975 | 305 | "callBack", | 308 | "callBack", |
4976 | 306 | C::gettext("Call back"), // label | 309 | C::gettext("Call back"), // label |
4977 | @@ -334,6 +337,7 @@ | |||
4978 | 334 | 337 | ||
4979 | 335 | void MessagingMenu::addCall(const QString &targetId, const QString &accountId, const QDateTime ×tamp) | 338 | void MessagingMenu::addCall(const QString &targetId, const QString &accountId, const QDateTime ×tamp) |
4980 | 336 | { | 339 | { |
4981 | 340 | qDebug() << __PRETTY_FUNCTION__; | ||
4982 | 337 | Call call; | 341 | Call call; |
4983 | 338 | bool found = false; | 342 | bool found = false; |
4984 | 339 | AccountEntry *account = TelepathyHelper::instance()->accountForId(accountId); | 343 | AccountEntry *account = TelepathyHelper::instance()->accountForId(accountId); |
4985 | @@ -392,7 +396,7 @@ | |||
4986 | 392 | // so we just disable it | 396 | // so we just disable it |
4987 | 393 | #ifndef __aarch64__ | 397 | #ifndef __aarch64__ |
4988 | 394 | // place the messaging-menu item only after the contact fetch request is finished, as we can´t simply update | 398 | // place the messaging-menu item only after the contact fetch request is finished, as we can´t simply update |
4990 | 395 | QObject::connect(request, &QContactAbstractRequest::stateChanged, [request, call, text, this]() { | 399 | QObject::connect(request, &QContactAbstractRequest::stateChanged, [=]() { |
4991 | 396 | // only process the results after the finished state is reached | 400 | // only process the results after the finished state is reached |
4992 | 397 | if (request->state() != QContactAbstractRequest::FinishedState) { | 401 | if (request->state() != QContactAbstractRequest::FinishedState) { |
4993 | 398 | return; | 402 | return; |
4994 | @@ -412,19 +416,13 @@ | |||
4995 | 412 | newCall.contactIcon = avatar; | 416 | newCall.contactIcon = avatar; |
4996 | 413 | } | 417 | } |
4997 | 414 | } | 418 | } |
4999 | 415 | addCallToMessagingMenu(newCall, text); | 419 | addCallToMessagingMenu(newCall, text, account->protocolInfo()->features() & Protocol::TextChats); |
5000 | 416 | #ifndef __aarch64__ | 420 | #ifndef __aarch64__ |
FAILED: Continuous integration, rev:1251 /jenkins. canonical. com/system- apps/job/ lp-telephony- service- ci/1/ /jenkins. canonical. com/system- apps/job/ build/2343/ console /jenkins. canonical. com/system- apps/job/ build-0- fetch/2343 /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 2161 /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=amd64, release= xenial+ overlay/ 2161/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=amd64, release= zesty/2161/ console /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=armhf, release= xenial+ overlay/ 2161/console /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=armhf, release= zesty/2161 /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=armhf, release= zesty/2161/ artifact/ output/ *zip*/output. zip /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 2161 /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=i386, release= xenial+ overlay/ 2161/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=i386, release= zesty/2161 /jenkins. canonical. com/system- apps/job/ build-2- binpkg/ arch=i386, release= zesty/2161/ artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/system- apps/job/ lp-telephony- service- ci/1/rebuild
https:/