|
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: General utilities for unified editor and plugin |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <centralrepository.h> // CRepository |
|
20 #include <CoreApplicationUIsSDKCRKeys.h> // offline CR keys |
|
21 #include <rcustomerserviceprofilecache.h> |
|
22 #include <MmsEngineDomainCRKeys.h> |
|
23 #include <MsgMediaResolver.h> |
|
24 #include <DRMHelper.h> |
|
25 |
|
26 #include "MessagingVariant.hrh" |
|
27 #include "MessagingInternalCRKeys.h" // Keys |
|
28 #include "UniEditorGenUtils.h" |
|
29 #include "s60qconversions.h" |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ---------------------------------------------------- |
|
34 // UniEditorGenUtils::UniEditorGenUtils |
|
35 // @see header |
|
36 // ---------------------------------------------------- |
|
37 UniEditorGenUtils::UniEditorGenUtils() : |
|
38 mAbsMaxConcatenatedSms(-1), |
|
39 mAbsMaxSmsCharacters(-1), |
|
40 mMaxMmsSize(-1) |
|
41 { |
|
42 |
|
43 } |
|
44 |
|
45 // ---------------------------------------------------- |
|
46 // UniEditorGenUtils::~UniEditorGenUtils |
|
47 // @see header |
|
48 // ---------------------------------------------------- |
|
49 UniEditorGenUtils::~UniEditorGenUtils() |
|
50 { |
|
51 |
|
52 } |
|
53 // ---------------------------------------------------- |
|
54 // UniEditorGenUtils::ReadEmailOverSmsSettingsL |
|
55 // @see header |
|
56 // ---------------------------------------------------- |
|
57 TInt UniEditorGenUtils::ReadEmailOverSmsSettingsL( |
|
58 TDes& aSmsc, |
|
59 TDes& aDestinationAddress, |
|
60 TBool& aModifiable ) |
|
61 { |
|
62 // Create storage |
|
63 CRepository* storage = CRepository::NewLC( KCRUidSmum ); |
|
64 storage->Get( KSumEmailSC, aSmsc ); |
|
65 storage->Get( KSumEmailGateway, aDestinationAddress ); |
|
66 storage->Get( KSumEmailModifiable, aModifiable ); |
|
67 CleanupStack::PopAndDestroy(); // storage |
|
68 return KErrNone; |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------- |
|
72 // UniEditorGenUtils::WriteEmailOverSmsSettingsL |
|
73 // @see header |
|
74 // ---------------------------------------------------- |
|
75 TInt UniEditorGenUtils::WriteEmailOverSmsSettingsL( |
|
76 const TDes& aSmsc, |
|
77 const TDes& aDestinationAddress, |
|
78 const TBool& aModifiable ) |
|
79 { |
|
80 // Create storage |
|
81 CRepository* storage = CRepository::NewLC( KCRUidSmum ); |
|
82 storage->Set( KSumEmailSC, aSmsc ); |
|
83 storage->Set( KSumEmailGateway, aDestinationAddress ); |
|
84 storage->Set( KSumEmailModifiable, aModifiable ); |
|
85 CleanupStack::PopAndDestroy(); // storage |
|
86 return KErrNone; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------- |
|
90 // UniEditorGenUtils::IsPhoneOfflineL |
|
91 // @see header |
|
92 // --------------------------------------------------------- |
|
93 TBool UniEditorGenUtils::IsPhoneOfflineL() |
|
94 { |
|
95 TInt connAllowed ( 1 ); |
|
96 CRepository* repository ( CRepository::NewL( KCRUidCoreApplicationUIs ) ); |
|
97 TInt err = repository->Get( KCoreAppUIsNetworkConnectionAllowed, connAllowed ); |
|
98 delete repository; |
|
99 repository = NULL; |
|
100 if ( !err && !connAllowed ) |
|
101 { |
|
102 return ETrue; |
|
103 } |
|
104 else |
|
105 { |
|
106 return EFalse; |
|
107 } |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------- |
|
111 // UniEditorGenUtils::AcceptEmailAddressesL |
|
112 // @see header |
|
113 // ---------------------------------------------------- |
|
114 TBool UniEditorGenUtils::AcceptEmailAddressesL() |
|
115 { |
|
116 CRepository* repository ( CRepository::NewL( KCRUidMuiuVariation ) ); |
|
117 TInt features = 0; |
|
118 TBool emailOverSmsVariationOn = false; |
|
119 TBool acceptEmailAddresses = false; |
|
120 |
|
121 if ( repository->Get( KMuiuSmsFeatures, features ) == KErrNone ) |
|
122 { |
|
123 if ( features & KSmsFeatureIdEmailOverSms ) |
|
124 { |
|
125 emailOverSmsVariationOn = ETrue; |
|
126 } |
|
127 } |
|
128 |
|
129 delete repository; |
|
130 |
|
131 //TODO chk with Jerry if below is needed |
|
132 RCustomerServiceProfileCache* cspProfile = new (ELeave) RCustomerServiceProfileCache; |
|
133 TInt error = cspProfile->Open(); |
|
134 |
|
135 if ( error == KErrNone ) |
|
136 { |
|
137 if ( emailOverSmsVariationOn ) |
|
138 { |
|
139 |
|
140 // EmailOverSms bit was variated ON so let's check the bit from SIM |
|
141 // Get tele services flags from CSP |
|
142 RMobilePhone::TCspValueAdded params; |
|
143 // Read the CPHS bit so we know if EmailOverSms is supported |
|
144 error = cspProfile->CspCPHSValueAddedServices( params ); |
|
145 |
|
146 |
|
147 if ( error == KErrNone && |
|
148 params >= 0 && |
|
149 params & RMobilePhone::KCspSMMOEmail ) |
|
150 { |
|
151 // It's supported |
|
152 acceptEmailAddresses= true; |
|
153 } |
|
154 } |
|
155 } |
|
156 cspProfile->Close(); |
|
157 delete cspProfile; |
|
158 |
|
159 return acceptEmailAddresses; |
|
160 } |
|
161 |
|
162 // ---------------------------------------------------- |
|
163 // UniEditorGenUtils::VerifyEmailAddressesL |
|
164 // @see header |
|
165 // ---------------------------------------------------- |
|
166 TBool UniEditorGenUtils::VerifyEmailAddressesL( ConvergedMessageAddressList addr) |
|
167 { |
|
168 TBool emailAddrPresent = EFalse; |
|
169 |
|
170 for ( int i=0; i< addr.count(); i++) |
|
171 { |
|
172 if( IsValidEmailAddress(addr[i]->address()) ) |
|
173 { |
|
174 emailAddrPresent = ETrue; |
|
175 break; |
|
176 } |
|
177 } |
|
178 |
|
179 return emailAddrPresent; |
|
180 } |
|
181 |
|
182 // ---------------------------------------------------- |
|
183 // UniEditorGenUtils::UTF8Size |
|
184 // @see header |
|
185 // ---------------------------------------------------- |
|
186 TInt UniEditorGenUtils::UTF8Size( QString aText ) |
|
187 { |
|
188 HBufC* text = S60QConversions::qStringToS60Desc(aText); |
|
189 TPtrC ptr = text->Des(); |
|
190 |
|
191 TInt count = 0; |
|
192 TInt sizeInBytes = 0; |
|
193 TUint16 charValue; |
|
194 while ( count < ptr.Length() ) |
|
195 { |
|
196 charValue = ptr[count]; |
|
197 if ( charValue < 0x80 ) |
|
198 { |
|
199 sizeInBytes += 1; |
|
200 } |
|
201 else if ( charValue < 0x800 ) |
|
202 { |
|
203 sizeInBytes += 2; |
|
204 } |
|
205 else //if ( charValue < 0x10000 ) |
|
206 { |
|
207 sizeInBytes += 3; |
|
208 } |
|
209 count++; |
|
210 } |
|
211 return sizeInBytes; |
|
212 } |
|
213 |
|
214 // ---------------------------------------------------- |
|
215 // UniEditorGenUtils::MaxSmsRecipientsL |
|
216 // @see header |
|
217 // ---------------------------------------------------- |
|
218 TInt UniEditorGenUtils::MaxSmsRecipientsL() |
|
219 { |
|
220 CRepository* repository ( CRepository::NewL( KCRUidUniEditor ) ); |
|
221 TInt maxSmsRecipients = KDefaultSmsRecipients; |
|
222 |
|
223 if ( (repository->Get( KUniEditorSoftLimitRecipientCount, maxSmsRecipients ) |
|
224 != KErrNone) || (maxSmsRecipients <= 0) ) |
|
225 { |
|
226 // Unreasonable count, change it back to default value |
|
227 maxSmsRecipients = KDefaultSmsRecipients; |
|
228 } |
|
229 delete repository; |
|
230 |
|
231 return maxSmsRecipients; |
|
232 } |
|
233 |
|
234 // ---------------------------------------------------- |
|
235 // UniEditorGenUtils::MaxMmsRecipientsL |
|
236 // @see header |
|
237 // ---------------------------------------------------- |
|
238 TInt UniEditorGenUtils::MaxMmsRecipientsL() |
|
239 { |
|
240 CRepository* repository ( CRepository::NewL( KCRUidUniEditor ) ); |
|
241 TInt maxMmsRecipients = KDefaultMmsRecipients; |
|
242 |
|
243 if ( (repository->Get( KUniEditorMaxRecipientCount, maxMmsRecipients ) |
|
244 != KErrNone) || (maxMmsRecipients <= 0)) |
|
245 { |
|
246 // Unreasonable count, change it back to default value |
|
247 maxMmsRecipients = KDefaultMmsRecipients; |
|
248 } |
|
249 delete repository; |
|
250 |
|
251 return maxMmsRecipients; |
|
252 } |
|
253 |
|
254 // ---------------------------------------------------- |
|
255 // UniEditorGenUtils::IsValidEmailAddress |
|
256 // @see header |
|
257 // ---------------------------------------------------- |
|
258 TBool UniEditorGenUtils::IsValidEmailAddress( QString addr ) |
|
259 { |
|
260 // valid email address contains at least 3 characters |
|
261 if( addr.size() >= 3 ) |
|
262 { |
|
263 // search for @ from the address. however, it can't be the first or the last item |
|
264 for ( int i = 1; i < addr.size() - 1; i++ ) |
|
265 { |
|
266 if ( addr.at(i) == '@' ) |
|
267 { |
|
268 return ETrue; |
|
269 } |
|
270 } |
|
271 } |
|
272 return EFalse; |
|
273 } |
|
274 |
|
275 // ---------------------------------------------------- |
|
276 // UniEditorGenUtils::MaxMmsMsgSizeL |
|
277 // @see header |
|
278 // ---------------------------------------------------- |
|
279 TInt UniEditorGenUtils::MaxMmsMsgSizeL() |
|
280 { |
|
281 // optimized, to read only once from CR |
|
282 if(mMaxMmsSize == -1) |
|
283 {// not read yet, so read it now |
|
284 mMaxMmsSize = KDefaultMaxSize; |
|
285 |
|
286 CRepository* repository = CRepository::NewL( KCRUidMmsEngine ); |
|
287 CleanupStack::PushL( repository ); |
|
288 |
|
289 repository->Get( KMmsEngineMaximumSendSize, mMaxMmsSize ); |
|
290 |
|
291 CleanupStack::PopAndDestroy( repository ); |
|
292 } |
|
293 |
|
294 return mMaxMmsSize; |
|
295 } |
|
296 |
|
297 // ---------------------------------------------------- |
|
298 // UniEditorGenUtils::getFileInfoL |
|
299 // @see header |
|
300 // ---------------------------------------------------- |
|
301 void UniEditorGenUtils::getFileInfoL(QString filePath, |
|
302 int& size, |
|
303 QString& mimetype, |
|
304 TMsgMediaType& mediaType) |
|
305 { |
|
306 HBufC* filepath = S60QConversions::qStringToS60Desc(filePath); |
|
307 int fileSize = 0; |
|
308 |
|
309 CMsgMediaResolver* mediaResolver; |
|
310 |
|
311 if(filepath) |
|
312 { |
|
313 CleanupStack::PushL(filepath); |
|
314 |
|
315 mediaResolver = CMsgMediaResolver::NewLC(); |
|
316 |
|
317 RFile file = mediaResolver->FileHandleL(*filepath); |
|
318 file.Size(fileSize); |
|
319 fileSize+= KEstimatedMimeHeaderSize; |
|
320 size = fileSize; |
|
321 TDataType datatype; |
|
322 mediaResolver->RecognizeL( file, datatype ); |
|
323 mimetype = S60QConversions::s60Desc8ToQString(datatype.Des8()); |
|
324 mediaType = mediaResolver->MediaType(datatype.Des8()); |
|
325 |
|
326 CleanupStack::PopAndDestroy(mediaResolver); |
|
327 CleanupStack::PopAndDestroy(filepath); |
|
328 } |
|
329 |
|
330 return; |
|
331 } |
|
332 |
|
333 // ---------------------------------------------------- |
|
334 // UniEditorGenUtils::MaxSmsMsgSizeL |
|
335 // @see header |
|
336 // ---------------------------------------------------- |
|
337 int UniEditorGenUtils::MaxSmsMsgSizeL(bool unicode) |
|
338 { |
|
339 int maxLength = 0; |
|
340 int lengthOne = 0; |
|
341 int lengthMany = 0; |
|
342 |
|
343 getSmsCharacterLimits(lengthOne, lengthMany, unicode); |
|
344 maxLength = lengthOne; |
|
345 |
|
346 int maxSmsParts = absoluteMaxSmsPartsL(); |
|
347 if(maxSmsParts > 1) |
|
348 { |
|
349 maxLength = maxSmsParts * lengthMany; |
|
350 } |
|
351 /* UniEditor soft limit, may not be needed |
|
352 int maxSmsCharacters = absoluteMaxSmsCharactersL(); |
|
353 if(maxSmsCharacters > 0) |
|
354 { |
|
355 maxLength = maxSmsCharacters; |
|
356 } |
|
357 */ |
|
358 return maxLength; |
|
359 } |
|
360 |
|
361 // ---------------------------------------------------- |
|
362 // UniEditorGenUtils::getSmsCharacterLimits |
|
363 // @see header |
|
364 // ---------------------------------------------------- |
|
365 void UniEditorGenUtils::getSmsCharacterLimits(int& singlePartLength, |
|
366 int& concatenatedPartLength, |
|
367 bool unicode) |
|
368 { |
|
369 if(unicode) |
|
370 { |
|
371 singlePartLength = KFirstUnicodeSmsLength; |
|
372 concatenatedPartLength = KUnicodeConcatenationInterval; |
|
373 } |
|
374 else |
|
375 { |
|
376 singlePartLength = KFirstNormalSmsLength; |
|
377 concatenatedPartLength = KNormalConcatenationInterval; |
|
378 } |
|
379 } |
|
380 |
|
381 // ---------------------------------------------------- |
|
382 // UniEditorGenUtils::absoluteMaxSmsPartsL |
|
383 // @see header |
|
384 // ---------------------------------------------------- |
|
385 int UniEditorGenUtils::absoluteMaxSmsPartsL() |
|
386 { |
|
387 // optimized, to read only once from CR |
|
388 if(mAbsMaxConcatenatedSms == -1) |
|
389 { // not read yet, so read it now |
|
390 mAbsMaxConcatenatedSms = KDefaultMaxSmsSize; |
|
391 CRepository* repository = CRepository::NewL( KCRUidSmum ); |
|
392 CleanupStack::PushL( repository ); |
|
393 |
|
394 if ( repository->Get( KSmumMaxSubMsgCount, mAbsMaxConcatenatedSms ) || |
|
395 mAbsMaxConcatenatedSms < 1 || |
|
396 mAbsMaxConcatenatedSms > KMaxSmsSizeByStandard ) |
|
397 { |
|
398 // Unreasonable count, change it back to 30 ( S60 default ) |
|
399 mAbsMaxConcatenatedSms = KMaxSmsSizeByStandard; |
|
400 } |
|
401 CleanupStack::PopAndDestroy( repository ); |
|
402 } |
|
403 return mAbsMaxConcatenatedSms; |
|
404 } |
|
405 |
|
406 // ---------------------------------------------------- |
|
407 // UniEditorGenUtils::absoluteMaxSmsCharactersL |
|
408 // @see header |
|
409 // ---------------------------------------------------- |
|
410 int UniEditorGenUtils::absoluteMaxSmsCharactersL() |
|
411 { |
|
412 // optimized, to read only once from CR |
|
413 if(mAbsMaxSmsCharacters == -1) |
|
414 {// not read yet, so read it now |
|
415 CRepository* repository = CRepository::NewL( KCRUidUniEditor ); |
|
416 CleanupStack::PushL( repository ); |
|
417 repository->Get( KUniEditorMaxSmsCharacterCount, mAbsMaxSmsCharacters ); |
|
418 CleanupStack::PopAndDestroy( repository ); |
|
419 } |
|
420 return mAbsMaxSmsCharacters; |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------- |
|
424 // UniEditorGenUtils::ConvertDigitsTo |
|
425 // @see header |
|
426 // --------------------------------------------------------- |
|
427 void UniEditorGenUtils::ConvertDigitsTo( TDes& aDes, TDigitType aDigitType ) |
|
428 { |
|
429 TChar toArea = aDigitType; |
|
430 TInt length = aDes.Length(); |
|
431 for(int i=0; i<length; i++) |
|
432 { |
|
433 TChar ch = aDes[i]; |
|
434 TChar base = NumberToBase(ch); |
|
435 switch (base) |
|
436 { |
|
437 case EDigitTypeWestern: |
|
438 case EDigitTypeArabicIndic: |
|
439 case EDigitTypeEasternArabicIndic: |
|
440 case EDigitTypeDevanagari: |
|
441 case EDigitTypeThai: |
|
442 ch += toArea - base; |
|
443 aDes[i] = TUint16(ch); |
|
444 break; |
|
445 default: |
|
446 break; |
|
447 }; |
|
448 } |
|
449 } |
|
450 |
|
451 // --------------------------------------------------------- |
|
452 // UniEditorGenUtils::NumberToBase |
|
453 // @see header |
|
454 // --------------------------------------------------------- |
|
455 TChar UniEditorGenUtils::NumberToBase(TChar ch) |
|
456 { |
|
457 TDigitType d[] = { EDigitTypeWestern, EDigitTypeArabicIndic, EDigitTypeEasternArabicIndic, EDigitTypeDevanagari, EDigitTypeThai }; |
|
458 TInt i = 0; |
|
459 TInt num = sizeof(d)/sizeof(d[0]); |
|
460 while(i<num) |
|
461 { |
|
462 if (ch>TChar(d[i]) && ch<TChar(d[i]+10)) { return d[i]; } |
|
463 i++; |
|
464 } |
|
465 return ch; |
|
466 } |
|
467 |
|
468 // --------------------------------------------------------- |
|
469 // UniEditorGenUtils::ReplaceCharacters |
|
470 // @see header |
|
471 // --------------------------------------------------------- |
|
472 void UniEditorGenUtils::ReplaceCharacters(TDes &aDes, const TDesC &aChars, TChar aReplacement) |
|
473 { |
|
474 TInt src = 0; |
|
475 TInt srclength = aDes.Length(); |
|
476 while(src < srclength) |
|
477 { |
|
478 TChar c = aDes[src]; |
|
479 if (aChars.LocateF(c) != KErrNotFound) |
|
480 aDes[src] = TUint16(aReplacement); |
|
481 ++src; |
|
482 } |
|
483 } |
|
484 |
|
485 // End of file |