|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtGlobal> |
|
19 #include <rsssettings.h> |
|
20 #include <psetcontainer.h> |
|
21 #include <psetcalldiverting.h> |
|
22 #include <mmlist.h> |
|
23 #include <cphcltemergencycall.h> |
|
24 #include <badesca.h> |
|
25 #include <cvoicemailbox.h> |
|
26 #include <cvoicemailboxentry.h> |
|
27 #include "psetcalldivertingwrapper.h" |
|
28 #include "psetcalldivertingwrapper_p.h" |
|
29 #include "logging.h" |
|
30 |
|
31 //Constant |
|
32 _LIT(KCFInvalidChars,"*#pw"); |
|
33 _LIT(KCFPlusSign,"+"); |
|
34 |
|
35 /*! |
|
36 PSetCallDivertingWrapper::PSetCallDivertingWrapper |
|
37 */ |
|
38 PSetCallDivertingWrapper::PSetCallDivertingWrapper( |
|
39 CPsetContainer &psetContainer, |
|
40 QObject *parent) : |
|
41 QObject(parent), m_psetCallDiverting(NULL), m_emergencyCall(NULL), |
|
42 m_DefaultNumberListCDes(NULL), m_Priv(NULL) |
|
43 { |
|
44 DPRINT << ": IN"; |
|
45 |
|
46 m_Priv = new PSetCallDivertingWrapperPrivate(*this); |
|
47 QScopedPointer<PSetCallDivertingWrapperPrivate> privateImplGuard(m_Priv); |
|
48 |
|
49 QT_TRAP_THROWING( |
|
50 m_psetCallDiverting = psetContainer.CreateCFObjectL( *m_Priv )); |
|
51 m_psetCallDiverting->SetRequestObserver(m_Priv); |
|
52 QScopedPointer<CPsetCallDiverting> pSetCallDivertingGuard(m_psetCallDiverting); |
|
53 |
|
54 QT_TRAP_THROWING(m_emergencyCall = CPhCltEmergencyCall::NewL( m_Priv )); |
|
55 QScopedPointer<CPhCltEmergencyCall> emergencyCallGuard(m_emergencyCall); |
|
56 |
|
57 privateImplGuard.take(); |
|
58 pSetCallDivertingGuard.take(); |
|
59 emergencyCallGuard.take(); |
|
60 |
|
61 DPRINT << ": OUT"; |
|
62 } |
|
63 |
|
64 /*! |
|
65 PSetCallDivertingWrapper::~PSetCallDivertingWrapper |
|
66 */ |
|
67 PSetCallDivertingWrapper::~PSetCallDivertingWrapper() |
|
68 { |
|
69 DPRINT << ": IN"; |
|
70 |
|
71 delete m_psetCallDiverting; |
|
72 delete m_emergencyCall; |
|
73 |
|
74 if (m_DefaultNumberListCDes) { |
|
75 m_DefaultNumberListCDes->Reset(); |
|
76 delete m_DefaultNumberListCDes; |
|
77 } |
|
78 |
|
79 delete m_Priv; |
|
80 |
|
81 DPRINT << ": OUT"; |
|
82 } |
|
83 |
|
84 // -------- Wrapper interface --------- // |
|
85 /*! |
|
86 PSetCallDivertingWrapper::setCallDiverting |
|
87 */ |
|
88 int PSetCallDivertingWrapper::setCallDiverting( |
|
89 PSCallDivertingCommand& aSetting, int aBasicServiceGroup) |
|
90 { |
|
91 DPRINT << ": IN"; |
|
92 |
|
93 TCallDivertSetting param; |
|
94 param.iCondition = m_Priv->convert(aSetting.iCondition); |
|
95 param.iSetting = m_Priv->convert(aSetting.iSetting); |
|
96 param.iStatus = m_Priv->convert(aSetting.iStatus); |
|
97 param.iServiceGroup = m_Priv->convert(aSetting.iServiceGroup); |
|
98 param.iNumber = TPtrC16(aSetting.iNumber.utf16()); |
|
99 param.iNoReplyTimer = aSetting.iNoReplyTimer; |
|
100 |
|
101 int result = validateDivertNumber(param.iNumber); |
|
102 if (0 == result) { |
|
103 QT_TRAP_THROWING( |
|
104 m_psetCallDiverting->SetDivertingL( |
|
105 param, |
|
106 static_cast<TBasicServiceGroups>(aBasicServiceGroup))); |
|
107 } |
|
108 |
|
109 DPRINT << ": OUT"; |
|
110 return result; |
|
111 } |
|
112 |
|
113 /*! |
|
114 PSetCallDivertingWrapper::getCallDivertingStatus |
|
115 */ |
|
116 void PSetCallDivertingWrapper::getCallDivertingStatus( |
|
117 const PsServiceGroup aServiceGroup, |
|
118 const PsCallDivertingCondition aCondition, |
|
119 int aBsc) |
|
120 { |
|
121 DPRINT << ": IN"; |
|
122 DPRINT << "aServiceGroup : " << aServiceGroup; |
|
123 DPRINT << "aCondition : " << aCondition; |
|
124 |
|
125 QT_TRAP_THROWING( |
|
126 m_psetCallDiverting->GetDivertingStatusL( |
|
127 m_Priv->convert(aServiceGroup), |
|
128 m_Priv->convert(aCondition), |
|
129 (TBasicServiceGroups)aBsc)); |
|
130 |
|
131 DPRINT << ": OUT"; |
|
132 } |
|
133 |
|
134 /*! |
|
135 PSetCallDivertingWrapper::cancelProcess |
|
136 */ |
|
137 void PSetCallDivertingWrapper::cancelProcess() |
|
138 { |
|
139 DPRINT << ": IN"; |
|
140 |
|
141 m_psetCallDiverting->CancelCurrentRequest(); |
|
142 |
|
143 DPRINT << ": OUT"; |
|
144 } |
|
145 |
|
146 /*! |
|
147 PSetCallDivertingWrapper::getDefaultNumbers |
|
148 */ |
|
149 void PSetCallDivertingWrapper::getDefaultNumbers(QStringList &aDefNumbers) |
|
150 { |
|
151 // QStringList?, max 3 numbers to retrieve. |
|
152 |
|
153 DPRINT << ": IN"; |
|
154 |
|
155 while (!m_DefaultnumberListQSList.empty()) { |
|
156 m_DefaultnumberListQSList.removeFirst(); |
|
157 } |
|
158 m_DefaultNumberListCDes = new CDesC16ArrayFlat(3); |
|
159 QT_TRAP_THROWING( |
|
160 m_psetCallDiverting->GetDefaultNumbersL(*m_DefaultNumberListCDes)); |
|
161 int count = m_DefaultNumberListCDes->Count(); |
|
162 for (int i = 0; i < count; i++) { |
|
163 m_DefaultnumberListQSList.append(QString::fromUtf16( |
|
164 m_DefaultNumberListCDes->MdcaPoint(i).Ptr(), |
|
165 m_DefaultNumberListCDes->MdcaPoint(i).Length())); |
|
166 } |
|
167 aDefNumbers = m_DefaultnumberListQSList; |
|
168 m_DefaultNumberListCDes->Reset(); |
|
169 delete m_DefaultNumberListCDes; |
|
170 m_DefaultNumberListCDes = NULL; |
|
171 |
|
172 DPRINT << ": OUT"; |
|
173 } |
|
174 |
|
175 /*! |
|
176 PSetCallDivertingWrapper::setNewDefaultNumber |
|
177 */ |
|
178 void PSetCallDivertingWrapper::setNewDefaultNumber(QString aNumber) |
|
179 { |
|
180 DPRINT << ": IN"; |
|
181 |
|
182 TBuf<KPsetPhoneNumberLength> bufNumber(aNumber.utf16()); |
|
183 TInt found(KErrNotFound); |
|
184 TInt loc(KErrNotFound); |
|
185 m_DefaultNumberListCDes = new CDesC16ArrayFlat(3); |
|
186 QT_TRAP_THROWING( |
|
187 m_psetCallDiverting->GetDefaultNumbersL(*m_DefaultNumberListCDes)); |
|
188 found = m_DefaultNumberListCDes->Find(bufNumber, loc); |
|
189 m_DefaultNumberListCDes->Reset(); |
|
190 delete m_DefaultNumberListCDes; |
|
191 m_DefaultNumberListCDes = NULL; |
|
192 if (found != KErrNone) { //number is not part of current def.numbers |
|
193 QT_TRAP_THROWING( |
|
194 m_psetCallDiverting->SetNewDefaultNumberL(bufNumber)); |
|
195 } else { |
|
196 QT_TRAP_THROWING( |
|
197 m_psetCallDiverting->SwapDefaultNumberL(loc+1)); |
|
198 } |
|
199 |
|
200 DPRINT << ": OUT"; |
|
201 } |
|
202 |
|
203 /*! |
|
204 * PSetCallDivertingWrapper::getVoiceMailBoxNumber |
|
205 * @param aNumber empty if not set |
|
206 * @return -1 if not supported |
|
207 */ |
|
208 int PSetCallDivertingWrapper::getVoiceMailBoxNumber( |
|
209 QString &aNumber, PsService aService) |
|
210 { |
|
211 DPRINT << ": IN"; |
|
212 |
|
213 CVoiceMailboxEntry* psetVoiceMailboxEntry = NULL; |
|
214 CVoiceMailbox* psetVoiceMailBoxScoped = NULL; |
|
215 QT_TRAP_THROWING(psetVoiceMailBoxScoped = CVoiceMailbox::NewL()); |
|
216 QScopedPointer<CVoiceMailbox> psetVoiceMailBox(psetVoiceMailBoxScoped); |
|
217 |
|
218 TVoiceMailboxParams psetVoiceMailboxParams; |
|
219 // Selected mailbox type is voice |
|
220 psetVoiceMailboxParams.iType = m_Priv->convert(aService); |
|
221 psetVoiceMailboxEntry = 0; |
|
222 int ret = 0; |
|
223 TInt error = psetVoiceMailBox->GetStoredEntry( |
|
224 psetVoiceMailboxParams, psetVoiceMailboxEntry); |
|
225 DPRINT << "error: " << error; |
|
226 if (KErrNotSupported == error) { |
|
227 ret = -1; |
|
228 } else if (KErrNone == error) { |
|
229 // Entry ok, check the number |
|
230 TPtrC ptrNumber(KNullDesC); |
|
231 if (KErrNone == psetVoiceMailboxEntry->GetVmbxNumber(ptrNumber)) { |
|
232 // number ok |
|
233 aNumber = QString::fromUtf16(ptrNumber.Ptr(), |
|
234 ptrNumber.Length()); |
|
235 } |
|
236 |
|
237 } else { |
|
238 // illegal argument |
|
239 } |
|
240 |
|
241 delete psetVoiceMailboxEntry; // Entry ownership was transferred |
|
242 psetVoiceMailboxEntry = NULL; |
|
243 |
|
244 DPRINT << "aVmbxNumber: " << aNumber; |
|
245 DPRINT << ": OUT"; |
|
246 return ret; |
|
247 } |
|
248 |
|
249 /*! |
|
250 * PSetCallDivertingWrapper::queryVoiceMailBoxNumber |
|
251 * @param aNumber empty if not set |
|
252 * @return -1 if not supported |
|
253 */ |
|
254 int PSetCallDivertingWrapper::queryVoiceMailBoxNumber( |
|
255 QString &aNumber, PsService aService) |
|
256 { |
|
257 DPRINT << ": IN"; |
|
258 |
|
259 CVoiceMailboxEntry* psetVoiceMailboxEntry = NULL; |
|
260 CVoiceMailbox* psetVoiceMailBoxScoped = NULL; |
|
261 QT_TRAP_THROWING(psetVoiceMailBoxScoped = CVoiceMailbox::NewL()); |
|
262 QScopedPointer<CVoiceMailbox> psetVoiceMailBox(psetVoiceMailBoxScoped); |
|
263 |
|
264 TVoiceMailboxParams psetVoiceMailboxParams; |
|
265 // Selected mailbox type is voice |
|
266 psetVoiceMailboxParams.iType = m_Priv->convert(aService); |
|
267 psetVoiceMailboxEntry = 0; |
|
268 int ret = 0; |
|
269 TInt error = psetVoiceMailBox->GetStoredEntry( |
|
270 psetVoiceMailboxParams, psetVoiceMailboxEntry); |
|
271 |
|
272 if (KErrNotSupported == error) { |
|
273 ret = -1; |
|
274 } else if (KErrNone == error || KErrNotFound == error) { |
|
275 // No number defined, query new entry from user |
|
276 error = psetVoiceMailBox->QueryNewEntry( |
|
277 psetVoiceMailboxParams, psetVoiceMailboxEntry); |
|
278 |
|
279 if (KErrNone == error) { |
|
280 // Save new entry and get the number. |
|
281 error = psetVoiceMailBox->SaveEntry( *psetVoiceMailboxEntry ); |
|
282 TPtrC ptrNumber( KNullDesC ); |
|
283 if ( KErrNone == psetVoiceMailboxEntry->GetVmbxNumber( ptrNumber )) { |
|
284 // New number ok. |
|
285 aNumber = QString::fromUtf16(ptrNumber.Ptr(), |
|
286 ptrNumber.Length()); |
|
287 } |
|
288 |
|
289 } else { |
|
290 // New number not given. |
|
291 DPRINT << "New number error: " << error; |
|
292 } |
|
293 } else { |
|
294 // illegal argument |
|
295 DPRINT << "error: " << error; |
|
296 } |
|
297 |
|
298 delete psetVoiceMailboxEntry; // Entry ownership was transferred |
|
299 psetVoiceMailboxEntry = NULL; |
|
300 |
|
301 DPRINT << "aVmbxNumber: " << aNumber; |
|
302 DPRINT << ": OUT"; |
|
303 return ret; |
|
304 } |
|
305 |
|
306 /*! |
|
307 PSetCallDivertingWrapper::validateDivertNumber |
|
308 */ |
|
309 int PSetCallDivertingWrapper::validateDivertNumber( |
|
310 const TDesC16& aDivertTo) const |
|
311 { |
|
312 DPRINT << ": IN "; |
|
313 |
|
314 int result = 0; |
|
315 |
|
316 QString diverto = QString::fromUtf16(aDivertTo.Ptr(),aDivertTo.Length()); |
|
317 DPRINT << "aDivertTo: " << diverto; |
|
318 TInt noOfInvalidChars = KCFInvalidChars().Length(); |
|
319 TBool isEmergency(EFalse); |
|
320 TTelNumber number; |
|
321 TInt error = m_emergencyCall->IsEmergencyPhoneNumber(aDivertTo, number, |
|
322 isEmergency); |
|
323 if ((error == KErrNone) && isEmergency) { |
|
324 result = KErrGsmSSIllegalOperation; |
|
325 DPRINT << ": emergency number."; |
|
326 } else { |
|
327 // Plus is a special case, as it is accepted as first character. |
|
328 if (findPlus(aDivertTo)) { |
|
329 result = KErrGsmSSUnknownAlphabet; |
|
330 } |
|
331 for (int index = 0; index < noOfInvalidChars; index++) { |
|
332 if (aDivertTo.Find(KCFInvalidChars().Mid(index, 1)) == KErrNone) { |
|
333 result = KErrGsmSSUnknownAlphabet; |
|
334 DPRINT << ": Invalid divert number. "; |
|
335 } |
|
336 } |
|
337 } |
|
338 |
|
339 DPRINT << ": OUT : result " << result; |
|
340 return result; |
|
341 } |
|
342 |
|
343 /*! |
|
344 PSetCallDivertingWrapper::findPlus |
|
345 Seeks '+' from given number. If '+' is first character, it is ignored. |
|
346 */ |
|
347 bool PSetCallDivertingWrapper::findPlus(const TDesC16& aDivertTo) const |
|
348 { |
|
349 DPRINT << ": IN "; |
|
350 |
|
351 bool plusFound(false); |
|
352 if (!(aDivertTo.Find(KCFPlusSign) == KErrNotFound)) { |
|
353 //first char '+', but there can additional '+'s |
|
354 //ignore first '+' |
|
355 TPtrC concat = aDivertTo.Right(aDivertTo.Length() - 1); |
|
356 if (concat.Find(KCFPlusSign) == KErrNone) { |
|
357 plusFound = true; |
|
358 DPRINT << ": Invalid divert number. "; |
|
359 } |
|
360 } |
|
361 |
|
362 DPRINT << ": OUT : plusFound " << plusFound; |
|
363 return plusFound; |
|
364 } |
|
365 |
|
366 /** |
|
367 * Get CPsetCallDiverting reference. |
|
368 */ |
|
369 CPsetCallDiverting & PSetCallDivertingWrapper::getCPsetCallDiverting() const |
|
370 { |
|
371 DPRINT; |
|
372 |
|
373 return *m_psetCallDiverting; |
|
374 } |
|
375 |
|
376 // End of File. |