|
1 /*! |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: dial service |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <xqserviceutil.h> |
|
19 #include <e32base.h> |
|
20 #include <qregexp.h> |
|
21 #include <featmgr.h> |
|
22 #include <settingsinternalcrkeys.h> |
|
23 #include <xqsettingsmanager.h> |
|
24 #include <e32capability.h> |
|
25 #include "dialservice.h" |
|
26 #include "qtphonelog.h" |
|
27 |
|
28 // CONSTANTS |
|
29 const XQSettingsKey dialPrefixMode(XQSettingsKey::TargetCentralRepository, KCRUidTelephonySettings.iUid, KSettingsDialPrefixChangeMode); |
|
30 const XQSettingsKey dialPrefixString(XQSettingsKey::TargetCentralRepository, KCRUidTelephonySettings.iUid, KSettingsDialPrefixText); |
|
31 |
|
32 DialService::DialService(MPECallControlIF &call, MPECallSettersIF ¶meters, QObject* parent) : |
|
33 XQServiceProvider(QLatin1String("phoneui.com.nokia.symbian.ICallDial"), parent), m_call (call), m_parameters (parameters), m_settingsManager(0) |
|
34 { |
|
35 publishAll(); |
|
36 m_settingsManager = new XQSettingsManager(this); |
|
37 Q_ASSERT(m_settingsManager != 0); |
|
38 } |
|
39 |
|
40 DialService::~DialService() |
|
41 { |
|
42 } |
|
43 |
|
44 int DialService::dial(const QString& number) |
|
45 { |
|
46 PHONE_DEBUG2("DialService::dial number:", number); |
|
47 if (!hasCapability()) { |
|
48 return KErrPermissionDenied; |
|
49 } |
|
50 QString phoneNumber = modifyPhoneNumber(number); |
|
51 TPtrC16 numberPtr(reinterpret_cast<const TUint16*>(phoneNumber.utf16())); |
|
52 m_parameters.SetPhoneNumber (numberPtr); |
|
53 m_parameters.SetCallTypeCommand (EPECallTypeCSVoice); |
|
54 return m_call.HandleDialServiceCall (); |
|
55 } |
|
56 |
|
57 int DialService::dial(const QString& number, int contactId) |
|
58 { |
|
59 PHONE_DEBUG4("DialService::dial number:", number, "contactId:", contactId); |
|
60 if (!hasCapability()) { |
|
61 return KErrPermissionDenied; |
|
62 } |
|
63 QString phoneNumber = modifyPhoneNumber(number); |
|
64 TPtrC16 numberPtr (reinterpret_cast<const TUint16*>(phoneNumber.utf16())); |
|
65 m_parameters.SetPhoneNumber (numberPtr); |
|
66 m_parameters.SetCallTypeCommand (EPECallTypeCSVoice); |
|
67 m_parameters.SetContactId2 (contactId); |
|
68 return m_call.HandleDialServiceCall (); |
|
69 } |
|
70 |
|
71 int DialService::dialVideo(const QString& number) |
|
72 { |
|
73 PHONE_DEBUG2("DialService::dialVideo number:", number); |
|
74 if (!hasCapability()) { |
|
75 return KErrPermissionDenied; |
|
76 } |
|
77 QString phoneNumber = modifyPhoneNumber(number); |
|
78 TPtrC16 numberPtr(reinterpret_cast<const TUint16*>(phoneNumber.utf16())); |
|
79 m_parameters.SetPhoneNumber (numberPtr); |
|
80 m_parameters.SetCallTypeCommand (EPECallTypeVideo); |
|
81 return m_call.HandleDialServiceCall (); |
|
82 } |
|
83 |
|
84 int DialService::dialVideo(const QString& number, int contactId) |
|
85 { |
|
86 PHONE_DEBUG4("DialService::dialVideo number:", number, "contactId:", contactId); |
|
87 if (!hasCapability()) { |
|
88 return KErrPermissionDenied; |
|
89 } |
|
90 QString phoneNumber = modifyPhoneNumber(number); |
|
91 TPtrC16 numberPtr (reinterpret_cast<const TUint16*>(phoneNumber.utf16())); |
|
92 m_parameters.SetPhoneNumber (numberPtr); |
|
93 m_parameters.SetCallTypeCommand (EPECallTypeVideo); |
|
94 m_parameters.SetContactId2 (contactId); |
|
95 return m_call.HandleDialServiceCall (); |
|
96 } |
|
97 |
|
98 int DialService::dialVoip(const QString& address) |
|
99 { |
|
100 PHONE_DEBUG2("DialService::dialVoip number:", address); |
|
101 if (!hasCapability()) { |
|
102 return KErrPermissionDenied; |
|
103 } |
|
104 TPtrC16 numberPtr(reinterpret_cast<const TUint16*>(address.utf16 ())); |
|
105 m_parameters.SetPhoneNumber(numberPtr); |
|
106 m_parameters.SetCallTypeCommand(EPECallTypeVoIP); |
|
107 return m_call.HandleDialServiceCall(); |
|
108 } |
|
109 |
|
110 int DialService::dialVoip(const QString& address, int contactId) |
|
111 { |
|
112 PHONE_DEBUG4("DialService::dialVoip number:", address, "contactId:", contactId); |
|
113 if (!hasCapability()) { |
|
114 return KErrPermissionDenied; |
|
115 } |
|
116 TPtrC16 numberPtr (reinterpret_cast<const TUint16*>(address.utf16 ())); |
|
117 m_parameters.SetPhoneNumber(numberPtr); |
|
118 m_parameters.SetCallTypeCommand(EPECallTypeVoIP); |
|
119 m_parameters.SetContactId2(contactId); |
|
120 return m_call.HandleDialServiceCall(); |
|
121 } |
|
122 |
|
123 int DialService::dialVoipService(const QString& address, int serviceId) |
|
124 { |
|
125 PHONE_DEBUG4("DialService::dialVoipService number:", address, "serviceId:", serviceId); |
|
126 if (!hasCapability()) { |
|
127 return KErrPermissionDenied; |
|
128 } |
|
129 TPtrC16 numberPtr (reinterpret_cast<const TUint16*>(address.utf16 ())); |
|
130 m_parameters.SetPhoneNumber(numberPtr); |
|
131 m_parameters.SetCallTypeCommand(EPECallTypeVoIP); |
|
132 m_parameters.SetServiceIdCommand(serviceId); |
|
133 return m_call.HandleDialServiceCall(); |
|
134 } |
|
135 |
|
136 int DialService::dialVoipService( |
|
137 const QString& address, int serviceId, int contactId) |
|
138 { |
|
139 PHONE_DEBUG2("DialService::dialVoipService number:", address); |
|
140 PHONE_DEBUG2("DialService::dialVoipService serviceId:", serviceId); |
|
141 PHONE_DEBUG2("DialService::dialVoipService contactId:", contactId); |
|
142 if (!hasCapability()) { |
|
143 return KErrPermissionDenied; |
|
144 } |
|
145 TPtrC16 numberPtr (reinterpret_cast<const TUint16*>(address.utf16 ())); |
|
146 m_parameters.SetPhoneNumber(numberPtr); |
|
147 m_parameters.SetCallTypeCommand(EPECallTypeVoIP); |
|
148 m_parameters.SetServiceIdCommand(serviceId); |
|
149 m_parameters.SetContactId2(contactId); |
|
150 return m_call.HandleDialServiceCall(); |
|
151 } |
|
152 |
|
153 QString DialService::modifyPhoneNumber(const QString &number) |
|
154 { |
|
155 PHONE_DEBUG2("DialService::modifyPhoneNumber number:", number); |
|
156 QString modifiedNumber = simplified(number); |
|
157 modifiedNumber = japanPrefixModifications(modifiedNumber); |
|
158 |
|
159 return modifiedNumber; |
|
160 } |
|
161 |
|
162 QString DialService::simplified(const QString &number) |
|
163 { |
|
164 QString simplifiedNumber = number; |
|
165 QRegExp rx(QString("[\\s,.\\[\\]\\(\\)\\-]")); |
|
166 simplifiedNumber.remove(rx); |
|
167 return simplifiedNumber; |
|
168 } |
|
169 |
|
170 QString DialService::japanPrefixModifications(const QString &number) |
|
171 { |
|
172 PHONE_DEBUG2("DialService::japanPrefixModifications number:", number); |
|
173 bool checkPrefix = FeatureManager::FeatureSupported(KFeatureIdJapanPrefixChange); |
|
174 if(checkPrefix == false) { |
|
175 // prefix change setting is off so don't play with the number |
|
176 return number; |
|
177 } |
|
178 |
|
179 QString modifiedNumber = number; |
|
180 |
|
181 int prefixMode = m_settingsManager->readItemValue(dialPrefixMode, XQSettingsManager::TypeInt).toInt(); |
|
182 PHONE_DEBUG2("DialService::japanPrefixModifications prefixMode:", prefixMode); |
|
183 |
|
184 if((m_settingsManager->error() == XQSettingsManager::NoError) && (prefixMode > 0)) { |
|
185 // No error fetching value and setting is on |
|
186 QString prefixString = m_settingsManager->readItemValue(dialPrefixString, XQSettingsManager::TypeString).toString(); |
|
187 PHONE_DEBUG2("DialService::japanPrefixModifications prefixString:", prefixString); |
|
188 |
|
189 if(m_settingsManager->error() == XQSettingsManager::NoError) { |
|
190 if(modifiedNumber.startsWith("+")) { |
|
191 modifiedNumber = modifiedNumber.remove(0, 1); |
|
192 modifiedNumber = modifiedNumber.insert(0, prefixString); |
|
193 } |
|
194 } |
|
195 } |
|
196 |
|
197 PHONE_DEBUG2("DialService::japanPrefixModifications modifiedNumber:", modifiedNumber); |
|
198 return modifiedNumber; |
|
199 } |
|
200 |
|
201 bool DialService::hasCapability() |
|
202 { |
|
203 XQRequestInfo req = requestInfo(); |
|
204 QSet<int> caps = req.clientCapabilities(); |
|
205 |
|
206 if (!caps.contains(ECapabilityNetworkServices)) { |
|
207 PHONE_TRACE1("NetworkServices capability missing"); |
|
208 return false; |
|
209 } |
|
210 if (!caps.contains(ECapabilityNetworkControl)) { |
|
211 PHONE_TRACE1("NetworkControl capability missing"); |
|
212 return false; |
|
213 } |
|
214 return true; |
|
215 } |