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