|
1 /* |
|
2 * Copyright (c) 2005-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: Static helper methods |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "emailtrace.h" |
|
21 #include "esmrhelper.h" |
|
22 #include "esmrentryhelper.h" |
|
23 #include <f32file.h> |
|
24 #include <caluser.h> |
|
25 #include <miuthdr.h> |
|
26 #include <msvapi.h> |
|
27 #include <msvuids.h> |
|
28 #include <miutpars.h> |
|
29 #include <bautils.h> |
|
30 #include <coemain.h> |
|
31 #include <msvids.h> |
|
32 #include <SendUiConsts.h> |
|
33 #include <data_caging_path_literals.hrh> |
|
34 //<cmail> hardcoded paths removal |
|
35 #include <pathinfo.h> |
|
36 //</cmail> |
|
37 |
|
38 // CONSTANTS |
|
39 |
|
40 /// Unnamed namespace for local definitions |
|
41 namespace { // codescanner::namespace |
|
42 |
|
43 _LIT( KMailtoMatchPattern, "mailto:*" ); // these are never localized |
|
44 const TInt KMailtoLength = 7; // "mailto:" length |
|
45 |
|
46 // Resource file format |
|
47 _LIT( KResourceFileLocFormat1, "r%02d"); |
|
48 _LIT( KResourceFileLocFormat2, "r%d"); |
|
49 |
|
50 const TInt KMinTwoDigitLanguageCode = 10; |
|
51 |
|
52 _LIT (KResourceFormat, "rsc" ); |
|
53 |
|
54 #ifdef _DEBUG |
|
55 |
|
56 enum TPanicCode |
|
57 { |
|
58 EPanicNullMsvId = 1, |
|
59 EIllegalMsvEntryType, |
|
60 EPanicNoOrganizer |
|
61 }; |
|
62 |
|
63 // Panic message definition |
|
64 _LIT( KPanicMsg, "ESMRHelper" ); |
|
65 |
|
66 void Panic( TPanicCode aReason ) |
|
67 { |
|
68 User::Panic( KPanicMsg, aReason ); |
|
69 } |
|
70 |
|
71 #endif // _DEBUG |
|
72 |
|
73 } // namespace |
|
74 |
|
75 // ======== MEMBER FUNCTIONS ======== |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // ESMRHelper::CopyAttendeeL |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C CCalAttendee* ESMRHelper::CopyAttendeeL( CCalAttendee& aSource ) |
|
82 { |
|
83 FUNC_LOG; |
|
84 CCalAttendee* copy = CopyAttendeeLC( aSource ); |
|
85 CleanupStack::Pop( copy ); |
|
86 return copy; |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // ESMRHelper::CopyAttendeeLC |
|
91 // ---------------------------------------------------------------------------- |
|
92 // |
|
93 EXPORT_C CCalAttendee* ESMRHelper::CopyAttendeeLC( CCalAttendee& aSource ) |
|
94 { |
|
95 FUNC_LOG; |
|
96 CCalAttendee* copy = CCalAttendee::NewL( aSource.Address(), |
|
97 aSource.SentBy() ); |
|
98 CleanupStack::PushL( copy ); |
|
99 copy->SetCommonNameL( aSource.CommonName() ); |
|
100 copy->SetRoleL( aSource.RoleL() ); |
|
101 copy->SetStatusL( aSource.StatusL() ); |
|
102 copy->SetResponseRequested( aSource.ResponseRequested() ); |
|
103 return copy; |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // ESMRHelper::CopyUserL |
|
108 // ---------------------------------------------------------------------------- |
|
109 // |
|
110 EXPORT_C CCalUser* ESMRHelper::CopyUserL( CCalUser& aSource ) |
|
111 { |
|
112 FUNC_LOG; |
|
113 CCalUser* copy = CopyUserLC( aSource ); |
|
114 CleanupStack::Pop( copy ); |
|
115 return copy; |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // ESMRHelper::CopyUserLC |
|
120 // ---------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C CCalUser* ESMRHelper::CopyUserLC( CCalUser& aSource ) |
|
123 { |
|
124 FUNC_LOG; |
|
125 CCalUser* copy = CCalUser::NewL( aSource.Address(), |
|
126 aSource.SentBy() ); |
|
127 CleanupStack::PushL( copy ); |
|
128 copy->SetCommonNameL( aSource.CommonName() ); |
|
129 return copy; |
|
130 } |
|
131 |
|
132 // ---------------------------------------------------------------------------- |
|
133 // ESMRHelper::CopyEntryL |
|
134 // ---------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C CCalEntry* ESMRHelper::CopyEntryL( |
|
137 const CCalEntry& aEntry, |
|
138 CCalEntry::TMethod aMethod, |
|
139 TCopyFields aCopyType ) |
|
140 { |
|
141 FUNC_LOG; |
|
142 CCalEntry* copy = CopyEntryLC( aEntry, aMethod, aCopyType ); |
|
143 CleanupStack::Pop( copy ); |
|
144 return copy; |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------------------------- |
|
148 // ESMRHelper::CopyEntryLC |
|
149 // ---------------------------------------------------------------------------- |
|
150 // |
|
151 EXPORT_C CCalEntry* ESMRHelper::CopyEntryLC( |
|
152 const CCalEntry& aEntry, |
|
153 CCalEntry::TMethod aMethod, |
|
154 TCopyFields aCopyType ) |
|
155 { |
|
156 FUNC_LOG; |
|
157 CCalEntry* copy = NULL; |
|
158 HBufC8* uid = aEntry.UidL().AllocLC(); |
|
159 if ( ESMREntryHelper::IsModifyingEntryL( aEntry ) ) |
|
160 { |
|
161 copy = CCalEntry::NewL( aEntry.EntryTypeL(), |
|
162 uid, |
|
163 aMethod, |
|
164 aEntry.SequenceNumberL(), |
|
165 aEntry.RecurrenceIdL(), |
|
166 aEntry.RecurrenceRangeL() ); |
|
167 } |
|
168 else |
|
169 { |
|
170 copy = CCalEntry::NewL( aEntry.EntryTypeL(), |
|
171 uid, |
|
172 aMethod, |
|
173 aEntry.SequenceNumberL() ); |
|
174 } |
|
175 CleanupStack::Pop( uid ); // ownership transferred to the copy entry |
|
176 CleanupStack::PushL( copy ); |
|
177 |
|
178 CopyFieldsL( aEntry, *copy, aCopyType ); |
|
179 copy->SetLastModifiedDateL(); |
|
180 |
|
181 return copy; |
|
182 } |
|
183 |
|
184 // ---------------------------------------------------------------------------- |
|
185 // ESMRHelper::CopyFieldsL |
|
186 // ---------------------------------------------------------------------------- |
|
187 // |
|
188 EXPORT_C void ESMRHelper::CopyFieldsL( |
|
189 const CCalEntry& aSource, |
|
190 CCalEntry& aTarget, |
|
191 TCopyFields aCopyType ) |
|
192 { |
|
193 FUNC_LOG; |
|
194 if ( aCopyType == ECopyFull ) |
|
195 { |
|
196 CCalEntry::TMethod tmpMethod( aTarget.MethodL() ); |
|
197 aTarget.CopyFromL( aSource ); |
|
198 // We must re-set the method to the original value |
|
199 aTarget.SetMethodL( tmpMethod ); |
|
200 |
|
201 if ( Time::NullTTime() == aTarget.DTStampL().TimeUtcL() ) |
|
202 { |
|
203 TCalTime dtStamp( aSource.DTStampL() ); |
|
204 if ( Time::NullTTime() == dtStamp.TimeUtcL() ) |
|
205 { |
|
206 TTime now; now.UniversalTime(); |
|
207 dtStamp.SetTimeUtcL( now ); |
|
208 } |
|
209 aTarget.SetDTStampL( dtStamp ); |
|
210 } |
|
211 } |
|
212 else |
|
213 { |
|
214 if ( aCopyType == ECopyOrganizer ) |
|
215 { |
|
216 __ASSERT_DEBUG( aSource.OrganizerL(), Panic( EPanicNoOrganizer ) ); |
|
217 CCalUser* organizer = CopyUserLC( *( aSource.OrganizerL() ) ); |
|
218 aTarget.SetOrganizerL( organizer ); |
|
219 CleanupStack::Pop( organizer ); // ownership transferred |
|
220 } |
|
221 |
|
222 // these are required for entries (start and end time actually not |
|
223 // for cancels and responses, but won't do any harm either): |
|
224 aTarget.SetStartAndEndTimeL( aSource.StartTimeL(), aSource.EndTimeL() ); |
|
225 aTarget.SetDTStampL( aSource.DTStampL() ); |
|
226 } |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // ESMRHelper::AddressWithoutMailtoPrefix |
|
231 // ---------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C TPtrC ESMRHelper::AddressWithoutMailtoPrefix( const TDesC& aAddress ) |
|
234 { |
|
235 FUNC_LOG; |
|
236 TPtrC addrWithoutPrefix( aAddress ); |
|
237 TInt pos = KErrNotFound; |
|
238 |
|
239 do |
|
240 { |
|
241 pos = addrWithoutPrefix.MatchF( KMailtoMatchPattern ); |
|
242 if ( pos != KErrNotFound ) |
|
243 { |
|
244 addrWithoutPrefix.Set( addrWithoutPrefix.Mid( KMailtoLength ) ); |
|
245 } |
|
246 } |
|
247 while ( pos != KErrNotFound ); |
|
248 |
|
249 return addrWithoutPrefix; |
|
250 } |
|
251 |
|
252 // ---------------------------------------------------------------------------- |
|
253 // ESMRHelper::GetCorrectDllDriveL |
|
254 // ---------------------------------------------------------------------------- |
|
255 // |
|
256 EXPORT_C void ESMRHelper::GetCorrectDllDriveL( TFileName& aDriveName ) |
|
257 { |
|
258 FUNC_LOG; |
|
259 TParse parse; |
|
260 Dll::FileName( aDriveName ); |
|
261 User::LeaveIfError( parse.Set( aDriveName, NULL, NULL ) ); |
|
262 aDriveName = parse.Drive(); // contains drive, e.g. "c:" |
|
263 } |
|
264 |
|
265 // ---------------------------------------------------------------------------- |
|
266 // ESMRHelper::LoadResourceL |
|
267 // ---------------------------------------------------------------------------- |
|
268 // |
|
269 EXPORT_C TInt ESMRHelper::LoadResourceL( // codescanner::intleaves |
|
270 const TDesC& aResourceFile, |
|
271 const TDesC& aResourcePath ) |
|
272 { |
|
273 FUNC_LOG; |
|
274 TFileName pathAndFile; |
|
275 // contains drive, e.g. "c:" |
|
276 ESMRHelper::GetCorrectDllDriveL( pathAndFile ); |
|
277 // e.g. "c:MyResource.rsc" |
|
278 pathAndFile.Append( aResourceFile ); |
|
279 |
|
280 TParse parse; |
|
281 parse.Set( pathAndFile, &aResourcePath, NULL ); |
|
282 pathAndFile = parse.FullName(); // now we have full (unlocalized) file name |
|
283 |
|
284 // Find the resource file for the nearest language |
|
285 BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), |
|
286 pathAndFile ); |
|
287 TInt offset = CCoeEnv::Static()->AddResourceFileL( pathAndFile ); |
|
288 return offset; |
|
289 } |
|
290 |
|
291 // ---------------------------------------------------------------------------- |
|
292 // ESMRHelper::CorrespondingSmtpServiceL |
|
293 // ---------------------------------------------------------------------------- |
|
294 // |
|
295 EXPORT_C TMsvId ESMRHelper::CorrespondingSmtpServiceL( |
|
296 TMsvId aRelatedService, |
|
297 CMsvSession& aMsvSession ) |
|
298 { |
|
299 FUNC_LOG; |
|
300 TMsvEntry entry; |
|
301 TMsvId dummyService; |
|
302 |
|
303 User::LeaveIfError( aMsvSession.GetEntry( aRelatedService, |
|
304 dummyService, |
|
305 entry ) ); |
|
306 TMsvId smtpId( KMsvNullIndexEntryId ); |
|
307 |
|
308 switch ( entry.iMtm.iUid ) |
|
309 { |
|
310 case KSenduiMtmImap4UidValue: // flow through |
|
311 case KSenduiMtmPop3UidValue: |
|
312 { |
|
313 // In these cases smtp entry is available in iRelatedId: |
|
314 smtpId = entry.iRelatedId; |
|
315 break; |
|
316 } |
|
317 case KSenduiMtmSmtpUidValue: |
|
318 case KSenduiMtmSyncMLEmailUidValue: |
|
319 { |
|
320 // In these cases we already know the msvid for the smtp settings |
|
321 // (for syncml there is also smtp settings): |
|
322 smtpId = aRelatedService; |
|
323 break; |
|
324 } |
|
325 default: |
|
326 { |
|
327 User::Leave( KErrNotSupported ); |
|
328 break; |
|
329 } |
|
330 } |
|
331 |
|
332 return smtpId; |
|
333 } |
|
334 |
|
335 // ---------------------------------------------------------------------------- |
|
336 // ESMRHelper::PopulateChildFromParentL |
|
337 // ---------------------------------------------------------------------------- |
|
338 // |
|
339 EXPORT_C void ESMRHelper::PopulateChildFromParentL ( |
|
340 CCalEntry &aChild, |
|
341 const CCalEntry &aParent) |
|
342 { |
|
343 FUNC_LOG; |
|
344 if ( aChild.DescriptionL() == KNullDesC ) |
|
345 { |
|
346 aChild.SetDescriptionL( aParent.DescriptionL() ); |
|
347 } |
|
348 if ( aChild.LocationL() == KNullDesC ) |
|
349 { |
|
350 aChild.SetLocationL( aParent.LocationL() ); |
|
351 } |
|
352 if ( aChild.PriorityL() == 0 ) |
|
353 { |
|
354 // zero is undefined priority according to iCal spec. |
|
355 aChild.SetPriorityL( aParent.PriorityL() ); |
|
356 } |
|
357 if ( aChild.SummaryL() == KNullDesC ) |
|
358 { |
|
359 aChild.SetSummaryL( aParent.SummaryL() ); |
|
360 } |
|
361 if ( aChild.StatusL() == CCalEntry::ENullStatus ) |
|
362 { |
|
363 aChild.SetStatusL( aParent.StatusL() ); |
|
364 } |
|
365 if (aChild.ReplicationStatusL() != aParent.ReplicationStatusL()) |
|
366 { |
|
367 aChild.SetReplicationStatusL(aParent.ReplicationStatusL()); |
|
368 } |
|
369 if (aChild.MethodL() == CCalEntry::EMethodNone) |
|
370 { |
|
371 aChild.SetMethodL(aParent.MethodL()); |
|
372 } |
|
373 |
|
374 CCalAlarm* childAlarm = aChild.AlarmL(); |
|
375 CleanupStack::PushL( childAlarm ); |
|
376 CCalAlarm* parentAlarm = aChild.AlarmL(); |
|
377 CleanupStack::PushL( parentAlarm ); |
|
378 |
|
379 if( !childAlarm && parentAlarm ) |
|
380 { |
|
381 aChild.SetAlarmL( parentAlarm ); |
|
382 } |
|
383 CleanupStack::PopAndDestroy( parentAlarm ); |
|
384 CleanupStack::PopAndDestroy( childAlarm ); |
|
385 |
|
386 // Organizer |
|
387 if ( !aChild.OrganizerL() && aParent.OrganizerL() ) |
|
388 { |
|
389 CCalUser* owner = |
|
390 ESMRHelper::CopyUserLC( *( aParent.OrganizerL() ) ); |
|
391 aChild.SetOrganizerL( owner ); |
|
392 CleanupStack::Pop(owner); // ownership transferred |
|
393 } |
|
394 |
|
395 // Attendees |
|
396 RPointerArray<CCalAttendee>& childAtt = aChild.AttendeesL(); |
|
397 RPointerArray<CCalAttendee>& parentAtt = aParent.AttendeesL(); |
|
398 |
|
399 CCalUser *po = NULL; |
|
400 if ( !aChild.PhoneOwnerL() ) |
|
401 { // Phone owner is internal data, not part of ical protocol, it's |
|
402 // benefit is to avoid heavy "who am I" resolving operation |
|
403 po = aParent.PhoneOwnerL(); |
|
404 } |
|
405 TInt parentAttCount( parentAtt.Count() ); |
|
406 if ( childAtt.Count() == 0 && parentAttCount > 0 ) |
|
407 { |
|
408 for ( TInt i( 0 ); i < parentAttCount; ++i ) |
|
409 { |
|
410 CCalAttendee* copy = |
|
411 ESMRHelper::CopyAttendeeLC( *( parentAtt[i] ) ); |
|
412 aChild.AddAttendeeL( copy ); |
|
413 CleanupStack::Pop(copy); // ownership transferred |
|
414 if(po == parentAtt[i]) |
|
415 { |
|
416 aChild.SetPhoneOwnerL(copy); |
|
417 } |
|
418 } |
|
419 } |
|
420 } |
|
421 |
|
422 // ---------------------------------------------------------------------------- |
|
423 // ESMRHelper::LocateResourceFile |
|
424 // ---------------------------------------------------------------------------- |
|
425 // |
|
426 EXPORT_C TInt ESMRHelper::LocateResourceFile( |
|
427 const TDesC& aResource, |
|
428 const TDesC& aPath, |
|
429 TFileName &aResourceFile, |
|
430 RFs* aFs ) |
|
431 { |
|
432 FUNC_LOG; |
|
433 RFs* fsSession; |
|
434 if ( aFs ) |
|
435 { |
|
436 fsSession = aFs; |
|
437 } |
|
438 else |
|
439 { |
|
440 fsSession=&CCoeEnv::Static()->FsSession();//codescanner::eikonenvstatic |
|
441 } |
|
442 |
|
443 TFindFile resourceFile( *fsSession ); |
|
444 TInt err = resourceFile.FindByDir( |
|
445 aResource, |
|
446 aPath ); |
|
447 |
|
448 if ( KErrNone == err ) |
|
449 { |
|
450 aResourceFile.Copy( resourceFile.File() ); |
|
451 } |
|
452 else |
|
453 { |
|
454 const TChar KFileFormatDelim( '.' ); |
|
455 TFileName locResourceFile; |
|
456 |
|
457 |
|
458 TInt pos = aResource.LocateReverse( KFileFormatDelim ); |
|
459 if ( pos != KErrNotFound ) |
|
460 { |
|
461 locResourceFile.Copy( aResource.Mid(0, pos + 1) ); |
|
462 |
|
463 TInt language( User::Language() ); |
|
464 if (language < KMinTwoDigitLanguageCode ) |
|
465 { |
|
466 locResourceFile.AppendFormat( KResourceFileLocFormat1, language ); |
|
467 } |
|
468 else |
|
469 { |
|
470 locResourceFile.AppendFormat( KResourceFileLocFormat2, language ); |
|
471 } |
|
472 |
|
473 TFindFile resourceFile( *fsSession ); |
|
474 err = resourceFile.FindByDir( |
|
475 locResourceFile, |
|
476 aPath ); |
|
477 |
|
478 if ( KErrNone == err ) |
|
479 { |
|
480 TFileName tempName; |
|
481 tempName.Copy( resourceFile.File() ); |
|
482 TInt dotpos= tempName.LocateReverse(KFileFormatDelim); |
|
483 aResourceFile.Copy(tempName.Mid(0,dotpos+1) ); |
|
484 aResourceFile.Append(KResourceFormat); |
|
485 } |
|
486 } |
|
487 } |
|
488 |
|
489 |
|
490 if ( KErrNone != err ) |
|
491 { |
|
492 } |
|
493 return err; |
|
494 } |
|
495 |
|
496 //<cmail> |
|
497 // ---------------------------------------------------------------------------- |
|
498 // ESMRHelper::CreateAndAppendPrivateDirToFileName |
|
499 // ---------------------------------------------------------------------------- |
|
500 // |
|
501 EXPORT_C TInt ESMRHelper::CreateAndAppendPrivateDirToFileName(TFileName& aFileName) |
|
502 { |
|
503 TFileName KPath; |
|
504 RFs fsSession; |
|
505 TInt result = fsSession.Connect(); |
|
506 if(result==KErrNone) |
|
507 { |
|
508 fsSession.PrivatePath(KPath); |
|
509 TFindFile findFile(fsSession); |
|
510 |
|
511 result = findFile.FindByDir(KPath, KNullDesC); |
|
512 if (result != KErrNone) //create path if doesn't exists |
|
513 { |
|
514 fsSession.CreatePrivatePath(TDriveUnit(PathInfo::PhoneMemoryRootPath())); |
|
515 result = findFile.FindByDir(KPath, KNullDesC); |
|
516 } |
|
517 KPath = findFile.File(); |
|
518 aFileName.Insert(0,KPath); |
|
519 fsSession.MkDirAll(aFileName); |
|
520 fsSession.Close(); |
|
521 } |
|
522 return result; |
|
523 } |
|
524 //</cmail> |
|
525 |
|
526 // EOF |