|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation for meeting request utils ui services |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // ---------------------------------------------------------------------------- |
|
21 // INCLUDE FILES |
|
22 // ---------------------------------------------------------------------------- |
|
23 // |
|
24 #include "CMRUtilsUiServices.h" |
|
25 #include "CMRUtilsInternal.h" |
|
26 #include "CMREditBeforeSendingViewForm.h" |
|
27 #include "CMRUtilsCalDbBase.h" |
|
28 #include "MREntryConsultant.h" |
|
29 #include "meetingrequestutils.hrh" |
|
30 #include "MRUtilsFactory.h" |
|
31 #include "CMRUtilsEmailSender.h" |
|
32 #include <CalSession.h> |
|
33 #include <CalEntry.h> |
|
34 #include <CalInstance.h> |
|
35 #include <CalInstanceView.h> |
|
36 #include <CalCommon.h> |
|
37 #include <CalUser.h> |
|
38 #include <avkon.hrh> |
|
39 #include <aknlistquerydialog.h> |
|
40 #include <meetingrequestutilsuires.rsg> |
|
41 #include <stringloader.h> |
|
42 #include <aknnotewrappers.h> |
|
43 #include <data_caging_path_literals.hrh> |
|
44 #include <cmrmailboxutils.h> |
|
45 #include <msvstd.h> |
|
46 #include <SendUiConsts.h> |
|
47 #include "ICalUILog.h" |
|
48 |
|
49 // CONSTANTS |
|
50 /// Unnamed namespace for local definitions |
|
51 namespace { |
|
52 |
|
53 const TInt KDescriptionLength = 700; |
|
54 |
|
55 _LIT( KResourceFile,"meetingrequestutilsuires.rsc" ); |
|
56 |
|
57 enum TPanicCode |
|
58 { |
|
59 EPanicEmptyArray = 1, |
|
60 }; |
|
61 |
|
62 _LIT( KPanicMsg, "CMRUtilsUiServices" ); |
|
63 |
|
64 void Panic( TPanicCode aReason ) |
|
65 { |
|
66 User::Panic( KPanicMsg, aReason ); |
|
67 } |
|
68 |
|
69 const TInt KResourcePathMaxLen = 30; |
|
70 |
|
71 } // namespace |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // MEMBER FUNCTIONS |
|
75 // ---------------------------------------------------------------------------- |
|
76 // |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // CMRUtilsUiServices::NewL |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 CMRUtilsUiServices* CMRUtilsUiServices::NewL( |
|
83 CMRUtilsInternal& aMRUtils, |
|
84 CCalSession& aCalSession, |
|
85 CMsvSession* aMsvSession, |
|
86 CMRMailboxUtils& aMRMailboxUtils ) |
|
87 { |
|
88 |
|
89 LOG("CMRUtilsUiServices NewL"); |
|
90 CMRUtilsUiServices* self = |
|
91 new( ELeave ) CMRUtilsUiServices( aMRUtils, |
|
92 aMsvSession, |
|
93 aMRMailboxUtils ); |
|
94 CleanupStack::PushL( self ); |
|
95 self->ConstructL( aCalSession ); |
|
96 CleanupStack::Pop(); |
|
97 return self; |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // CMRUtilsUiServices::CMRUtilsUiServices |
|
102 // |
|
103 // Constructor. |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 CMRUtilsUiServices::CMRUtilsUiServices( |
|
107 CMRUtilsInternal& aMRUtils, |
|
108 CMsvSession* aMsvSession, |
|
109 CMRMailboxUtils& aMRMailboxUtils ) |
|
110 : iOwnMsvSession( aMsvSession ? EFalse : ETrue ), |
|
111 iMRUtils( aMRUtils ), |
|
112 iMRMailboxUtils( aMRMailboxUtils ), |
|
113 iMsvSession( aMsvSession ) |
|
114 { |
|
115 } |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // CMRUtilsUiServices::~CMRUtilsUiServices |
|
119 // |
|
120 // Destructor. |
|
121 // ---------------------------------------------------------------------------- |
|
122 // |
|
123 CMRUtilsUiServices::~CMRUtilsUiServices() |
|
124 { |
|
125 delete iEmailSender; |
|
126 |
|
127 if ( iOwnMsvSession ) |
|
128 { |
|
129 delete iMsvSession; |
|
130 } |
|
131 |
|
132 if ( iResourceFileOffset ) |
|
133 { |
|
134 CCoeEnv::Static()->DeleteResourceFile( iResourceFileOffset ); |
|
135 } |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------------------------------- |
|
139 // CMRUtilsUiServices::ConstructL |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 void CMRUtilsUiServices::ConstructL( CCalSession& aCalSession ) |
|
143 { |
|
144 LOG("CMRUtilsUiServices ConstructL: loading resopurces"); |
|
145 iResourceFileOffset = MRHelpers::LoadResourceL( KResourceFile, |
|
146 KDC_RESOURCE_FILES_DIR ); |
|
147 LOG("CMRUtilsUiServices ConstructL: creating emailsender"); |
|
148 iEmailSender = MRUtilsFactory::CreateEmailSenderL( aCalSession ); |
|
149 |
|
150 if ( iMsvSession ) |
|
151 { // if existing session was given as construction parameter, |
|
152 // then add observer manually |
|
153 iMsvSession->AddObserverL( *this ); |
|
154 } |
|
155 |
|
156 LOG("CMRUtilsUiServices ConstructL finished"); |
|
157 } |
|
158 |
|
159 // ---------------------------------------------------------------------------- |
|
160 // CMRUtilsUiServices::ReplyToL |
|
161 // ---------------------------------------------------------------------------- |
|
162 // |
|
163 void CMRUtilsUiServices::ReplyToL( |
|
164 CMRUtilsInternal::TMailRecipients aRecipients, |
|
165 const CCalEntry& aCalEntry, |
|
166 const TDesC& aSenderAddr, |
|
167 TMsvId aMailbox ) |
|
168 { |
|
169 iEmailSender->ReplyToL( aRecipients, aCalEntry, aMailbox, aSenderAddr ); |
|
170 } |
|
171 |
|
172 // ---------------------------------------------------------------------------- |
|
173 // CMRUtilsUiServices::SendL |
|
174 // ---------------------------------------------------------------------------- |
|
175 // |
|
176 void CMRUtilsUiServices::SendL( |
|
177 const CCalEntry& aCalEntry, |
|
178 TMsvId aMailbox ) |
|
179 { |
|
180 iEmailSender->SendL( aCalEntry, CorrespondingSmtpServiceL( aMailbox) ); |
|
181 } |
|
182 |
|
183 // ---------------------------------------------------------------------------- |
|
184 // CMRUtilsUiServices::DeleteWithUiL |
|
185 // ---------------------------------------------------------------------------- |
|
186 // |
|
187 TInt CMRUtilsUiServices::DeleteWithUiL( |
|
188 const CCalEntry& aEntry, |
|
189 TMsvId aMailbox ) |
|
190 { |
|
191 TInt retVal( KErrNone ); |
|
192 // try to cancel/respond if necessary, don't care if fails since deletion |
|
193 // is the important part of this method |
|
194 TRAP_IGNORE( PerformDeleteSubOpL( aEntry, NULL, aMailbox ) ); |
|
195 // if entry is originating, then also modifying entries will get deleted: |
|
196 iMRUtils.DeleteL( aEntry ); |
|
197 return retVal; |
|
198 } |
|
199 |
|
200 // ---------------------------------------------------------------------------- |
|
201 // CMRUtilsUiServices::DeleteWithUiL |
|
202 // ---------------------------------------------------------------------------- |
|
203 // |
|
204 TInt CMRUtilsUiServices::DeleteWithUiL( |
|
205 CCalInstance* aInstance, |
|
206 TMsvId aMailbox ) |
|
207 { |
|
208 TInt retVal( KErrNone ); |
|
209 |
|
210 if ( !aInstance ) |
|
211 { |
|
212 User::Leave( KErrArgument ); |
|
213 } |
|
214 // try to cancel/respond if necessary, don't care if fails since deletion |
|
215 // is the important part of this method |
|
216 TRAP_IGNORE( PerformDeleteSubOpL( aInstance->Entry(), |
|
217 aInstance, |
|
218 aMailbox ) ); |
|
219 // delete instance |
|
220 iMRUtils.InstanceView()->DeleteL( aInstance, CalCommon::EThisOnly ); |
|
221 return retVal; |
|
222 } |
|
223 |
|
224 // ---------------------------------------------------------------------------- |
|
225 // CMRUtilsUiServices::PerformDeleteSubOpL |
|
226 // ---------------------------------------------------------------------------- |
|
227 // |
|
228 void CMRUtilsUiServices::PerformDeleteSubOpL( |
|
229 const CCalEntry& aEntry, |
|
230 const CCalInstance* aInstance, |
|
231 TMsvId aMailbox ) |
|
232 { |
|
233 // create arrays since QueryAndSendL needs them |
|
234 RPointerArray<CCalEntry> entryInArray( 1 ); |
|
235 CleanupClosePushL( entryInArray ); // does not own |
|
236 entryInArray.AppendL( &aEntry ); |
|
237 RArray<TInt> subOpIndexes( 1 ); |
|
238 CleanupClosePushL( subOpIndexes ); |
|
239 |
|
240 if ( IsValidForCancelL( aEntry ) ) |
|
241 { // cancellation can be sent |
|
242 subOpIndexes.AppendL( 0 ); |
|
243 QueryAndSendL( entryInArray, |
|
244 subOpIndexes, |
|
245 aInstance, |
|
246 aMailbox, |
|
247 ETrue ); |
|
248 } |
|
249 else if ( IsValidForResponseL( aEntry ) ) |
|
250 { // response with declined status can be sent |
|
251 subOpIndexes.AppendL( 0 ); |
|
252 QueryAndSendL( entryInArray, |
|
253 subOpIndexes, |
|
254 aInstance, |
|
255 aMailbox, |
|
256 EFalse, |
|
257 CCalAttendee::EDeclined ); |
|
258 } |
|
259 CleanupStack::PopAndDestroy( 2 ); // subOpIndexes, entryInArray |
|
260 } |
|
261 |
|
262 // ---------------------------------------------------------------------------- |
|
263 // CMRUtilsUiServices::CancelWithUiL |
|
264 // ---------------------------------------------------------------------------- |
|
265 // |
|
266 TInt CMRUtilsUiServices::CancelWithUiL( |
|
267 const RPointerArray<CCalEntry>& aEntries, |
|
268 TMsvId aMailbox ) |
|
269 { |
|
270 TInt retVal( KErrNone ); |
|
271 TInt count( aEntries.Count() ); |
|
272 RArray<TInt> cancelIndexes( count+1 ); // +1 to tolerate count == 0 case |
|
273 CleanupClosePushL( cancelIndexes ); |
|
274 |
|
275 // evaluate which entries can be cancelled, update status in database |
|
276 EvaluateAndUpdateL( aEntries, cancelIndexes, ETrue ); |
|
277 |
|
278 TInt cancelCount( cancelIndexes.Count() ); |
|
279 if ( cancelCount == 0 ) |
|
280 { // If there are no entries to cancel to we can return |
|
281 retVal = KErrArgument; |
|
282 } |
|
283 else |
|
284 { // query user for sending options and send if user wants |
|
285 retVal = QueryAndSendL( aEntries, |
|
286 cancelIndexes, |
|
287 NULL, |
|
288 aMailbox, |
|
289 ETrue ); |
|
290 } |
|
291 CleanupStack::PopAndDestroy(); // cancelIndexes |
|
292 return retVal; |
|
293 } |
|
294 |
|
295 // ---------------------------------------------------------------------------- |
|
296 // CMRUtilsUiServices::RespondWithUiL |
|
297 // ---------------------------------------------------------------------------- |
|
298 // |
|
299 TInt CMRUtilsUiServices::RespondWithUiL( |
|
300 const RPointerArray<CCalEntry>& aEntries, |
|
301 CCalAttendee::TCalStatus aStatus, |
|
302 TMsvId aMailbox ) |
|
303 { |
|
304 TInt retVal( KErrNone ); |
|
305 TInt count( aEntries.Count() ); |
|
306 RArray<TInt> respondIndexes( count+1 ); // +1 to tolerate count == 0 case |
|
307 CleanupClosePushL( respondIndexes ); |
|
308 |
|
309 // evaluate which entries can be responded to, update status in database |
|
310 EvaluateAndUpdateL( aEntries, respondIndexes, EFalse, aStatus ); |
|
311 |
|
312 TInt respondCount( respondIndexes.Count() ); |
|
313 if ( respondCount == 0 ) |
|
314 { // If there are no entries to respond to to we can return |
|
315 retVal = KErrArgument; |
|
316 } |
|
317 else |
|
318 { // query user for sending options and send if user wants |
|
319 retVal = QueryAndSendL( aEntries, |
|
320 respondIndexes, |
|
321 NULL, |
|
322 aMailbox, |
|
323 EFalse, |
|
324 aStatus ); |
|
325 } |
|
326 CleanupStack::PopAndDestroy(); // respondIndexes |
|
327 return retVal; |
|
328 } |
|
329 |
|
330 // ---------------------------------------------------------------------------- |
|
331 // CMRUtilsUiServices::EvaluateAndUpdateL |
|
332 // ---------------------------------------------------------------------------- |
|
333 // |
|
334 void CMRUtilsUiServices::EvaluateAndUpdateL( |
|
335 const RPointerArray<CCalEntry>& aEntries, |
|
336 RArray<TInt>& aValidIndexes, |
|
337 TBool aIsCancellation, |
|
338 CCalAttendee::TCalStatus aStatus ) |
|
339 { |
|
340 TInt count( aEntries.Count() ); |
|
341 // Go through all entries in the array, and update status of those requests |
|
342 // that we should cancel/respond. Store indexes of those requests. |
|
343 for ( TInt i( 0 ); i < count; ++i ) |
|
344 { |
|
345 CCalEntry& entry = *( aEntries[i] ); |
|
346 TBool isValid = aIsCancellation ? IsValidForCancelL( entry ) : |
|
347 IsValidForResponseL( entry ); |
|
348 if ( isValid ) |
|
349 { |
|
350 UpdateDbStatusL( entry, aIsCancellation, aStatus ); |
|
351 aValidIndexes.AppendL( i ); |
|
352 } |
|
353 } |
|
354 } |
|
355 |
|
356 // ---------------------------------------------------------------------------- |
|
357 // CMRUtilsUiServices::IsValidForCancelL |
|
358 // ---------------------------------------------------------------------------- |
|
359 // |
|
360 TBool CMRUtilsUiServices::IsValidForCancelL( const CCalEntry& aEntry ) |
|
361 { |
|
362 // entry must have been sent, otherwise cancellation won't be sent |
|
363 return ( IsValidRequestL( aEntry ) && |
|
364 iMRMailboxUtils.IsOrganizerL( aEntry ) && |
|
365 MREntryConsultant::IsSentL( aEntry ) ); |
|
366 |
|
367 } |
|
368 |
|
369 // ---------------------------------------------------------------------------- |
|
370 // CMRUtilsUiServices::IsValidForResponseL |
|
371 // ---------------------------------------------------------------------------- |
|
372 // |
|
373 TBool CMRUtilsUiServices::IsValidForResponseL( const CCalEntry& aEntry ) |
|
374 { |
|
375 CCalAttendee* thisAttendee = iMRMailboxUtils.ThisAttendeeL( aEntry ); |
|
376 return ( IsValidRequestL( aEntry ) && thisAttendee ); |
|
377 } |
|
378 |
|
379 // ---------------------------------------------------------------------------- |
|
380 // CMRUtilsUiServices::IsValidRequestL |
|
381 // ---------------------------------------------------------------------------- |
|
382 // |
|
383 TBool CMRUtilsUiServices::IsValidRequestL( |
|
384 const CCalEntry& aEntry ) const |
|
385 { |
|
386 TBool retVal( EFalse ); |
|
387 if ( !MREntryConsultant::IsCancelledL( aEntry, iMRMailboxUtils ) && |
|
388 !MREntryConsultant::IsEntryOutOfDateL( aEntry ) ) |
|
389 { |
|
390 retVal= ETrue; |
|
391 } |
|
392 return retVal; |
|
393 } |
|
394 |
|
395 // ---------------------------------------------------------------------------- |
|
396 // CMRUtilsUiServices::UpdateDbStatusL |
|
397 // ---------------------------------------------------------------------------- |
|
398 // |
|
399 void CMRUtilsUiServices::UpdateDbStatusL( |
|
400 const CCalEntry& aEntry, |
|
401 TBool aIsCancellation, |
|
402 CCalAttendee::TCalStatus aStatus ) const |
|
403 { |
|
404 CCalEntry* dbEntry = iMRUtils.FetchEntryL( aEntry.UidL(), |
|
405 aEntry.RecurrenceIdL() ); |
|
406 if ( dbEntry ) |
|
407 { |
|
408 CleanupStack::PushL( dbEntry ); |
|
409 if ( aIsCancellation ) |
|
410 { // we have already in evaluation phase ensured that phone |
|
411 // owner is organizer |
|
412 dbEntry->SetStatusL( CCalEntry::ECancelled ); |
|
413 iMRUtils.UpdateEntryL( *dbEntry ); |
|
414 } |
|
415 else |
|
416 { |
|
417 CCalAttendee* thisAttendee = |
|
418 iMRMailboxUtils.ThisAttendeeL( *dbEntry ); |
|
419 if ( thisAttendee ) |
|
420 { // this should be found since we found it in evaluation phase |
|
421 thisAttendee->SetStatusL( aStatus ); |
|
422 iMRUtils.UpdateEntryL( *dbEntry ); |
|
423 } |
|
424 else |
|
425 { // bad entry given |
|
426 User::Leave( KErrArgument ); |
|
427 } |
|
428 } |
|
429 CleanupStack::PopAndDestroy( dbEntry ); |
|
430 } |
|
431 else |
|
432 { // database entry not found |
|
433 User::Leave( KErrNotFound ); |
|
434 } |
|
435 } |
|
436 |
|
437 // ---------------------------------------------------------------------------- |
|
438 // CMRUtilsUiServices::QueryAndSendL |
|
439 // ---------------------------------------------------------------------------- |
|
440 // |
|
441 TInt CMRUtilsUiServices::QueryAndSendL( |
|
442 const RPointerArray<CCalEntry>& aEntries, |
|
443 const RArray<TInt>& aValidIndexes, |
|
444 const CCalInstance* aInstance, |
|
445 TMsvId aMailbox, |
|
446 TBool aIsCancellation, |
|
447 CCalAttendee::TCalStatus aStatus ) |
|
448 { |
|
449 // caller should ensure that there is at least one entry in array |
|
450 __ASSERT_DEBUG( aValidIndexes.Count() > 0, Panic( EPanicEmptyArray ) ); |
|
451 |
|
452 TInt retVal( KErrNone ); |
|
453 |
|
454 // we will use the first entry in the array of entries to be cancelled |
|
455 // or responded as a base entry (it doesn't really matter which one). |
|
456 const CCalEntry& base = *( aEntries[aValidIndexes[0]] ); |
|
457 |
|
458 TInt sendChoice( QuerySendChoiceL( base, aIsCancellation, aStatus ) ); |
|
459 HBufC* description = HBufC::NewLC( KDescriptionLength ); |
|
460 |
|
461 if ( sendChoice == EEditAndSendChoice ) |
|
462 { |
|
463 CEditBeforeSendingViewForm::TMode mode = aIsCancellation ? |
|
464 CEditBeforeSendingViewForm::EEditCancellation : |
|
465 CEditBeforeSendingViewForm::EEditResponse; |
|
466 TPtr descriptionPtr( description->Des() ); |
|
467 CEditBeforeSendingViewForm* editorForm = |
|
468 CEditBeforeSendingViewForm::NewL( mode, base, descriptionPtr ); |
|
469 TInt buttonID = editorForm->ExecuteLD( |
|
470 R_EDIT_BEFORE_SENDING_VIEW_FORM_DIALOG ); |
|
471 if ( buttonID == EEikCmdCanceled ) |
|
472 { |
|
473 retVal = KErrCancel; |
|
474 } |
|
475 } |
|
476 |
|
477 if ( retVal == KErrNone && sendChoice != EDoNotSendChoice ) |
|
478 { |
|
479 TInt count( aValidIndexes.Count() ); |
|
480 for ( TInt i( 0 ); i < count; ++i ) |
|
481 { |
|
482 const CCalEntry& entry = *( aEntries[aValidIndexes[i]] ); |
|
483 CCalEntry* respOrCancel = CreateToBeSentLC( entry, |
|
484 aInstance, |
|
485 *description, |
|
486 aIsCancellation ); |
|
487 SendL( *respOrCancel, aMailbox ); |
|
488 CleanupStack::PopAndDestroy( respOrCancel ); |
|
489 } |
|
490 } |
|
491 CleanupStack::PopAndDestroy( description ); |
|
492 return retVal; |
|
493 } |
|
494 |
|
495 // ---------------------------------------------------------------------------- |
|
496 // CMRUtilsUiServices::QuerySendChoiceL |
|
497 // ---------------------------------------------------------------------------- |
|
498 // |
|
499 TInt CMRUtilsUiServices::QuerySendChoiceL( |
|
500 const CCalEntry& aBase, |
|
501 TBool aIsCancellation, |
|
502 CCalAttendee::TCalStatus aStatus ) const |
|
503 { |
|
504 TInt retVal( KErrNone ); |
|
505 HBufC* headerText; |
|
506 TInt resource( 0 ); |
|
507 if ( aIsCancellation ) |
|
508 { |
|
509 resource = R_QTN_CALE_MEETIN_REQUEST_CANCELLED; |
|
510 } |
|
511 else |
|
512 { |
|
513 switch( aStatus ) |
|
514 { |
|
515 case CCalAttendee::EAccepted: |
|
516 { |
|
517 resource = R_QTN_MAIL_MTG_SUB_ACCEPTED; |
|
518 break; |
|
519 } |
|
520 case CCalAttendee::ETentative: |
|
521 { |
|
522 resource = R_QTN_MAIL_MTG_SUB_TENTATIVE; |
|
523 break; |
|
524 } |
|
525 case CCalAttendee::EDeclined: |
|
526 { |
|
527 resource = R_QTN_MAIL_MTG_SUB_DECLINED; |
|
528 break; |
|
529 } |
|
530 default: |
|
531 { |
|
532 User::Leave( KErrNotSupported ); |
|
533 } |
|
534 } |
|
535 } |
|
536 headerText = StringLoader::LoadLC( resource, |
|
537 aBase.SummaryL(), |
|
538 CEikonEnv::Static() ); |
|
539 |
|
540 // show choice list for different alternatives |
|
541 CAknListQueryDialog* dlg = new( ELeave ) CAknListQueryDialog( &retVal ); |
|
542 |
|
543 if ( aIsCancellation ) |
|
544 { |
|
545 dlg->PrepareLC( R_CANCEL_LIST_QUERY ); |
|
546 } |
|
547 else |
|
548 { |
|
549 dlg->PrepareLC( R_SEND_RESPONSE_LIST_QUERY ); |
|
550 } |
|
551 |
|
552 CAknPopupHeadingPane* headingPane = dlg->QueryHeading(); |
|
553 headingPane->SetTextL( headerText->Des() ); |
|
554 |
|
555 if ( dlg->RunLD() == EEikCmdCanceled ) |
|
556 { |
|
557 retVal = KErrCancel; |
|
558 } |
|
559 CleanupStack::PopAndDestroy( headerText ); |
|
560 return retVal; |
|
561 } |
|
562 |
|
563 // ---------------------------------------------------------------------------- |
|
564 // CMRUtilsUiServices::CreateToBeSentLC |
|
565 // ---------------------------------------------------------------------------- |
|
566 // |
|
567 CCalEntry* CMRUtilsUiServices::CreateToBeSentLC( |
|
568 const CCalEntry& aBase, |
|
569 const CCalInstance* aInstance, |
|
570 const TDesC& aDescription, |
|
571 TBool aIsCancellation ) const |
|
572 { |
|
573 if ( aIsCancellation ) |
|
574 { |
|
575 return CreateCancelLC( aBase, aInstance, aDescription ); |
|
576 } |
|
577 else |
|
578 { |
|
579 return CreateResponseLC( aBase, aInstance, aDescription ); |
|
580 } |
|
581 } |
|
582 |
|
583 // ---------------------------------------------------------------------------- |
|
584 // CMRUtilsUiServices::CreateResponseL |
|
585 // ---------------------------------------------------------------------------- |
|
586 // |
|
587 CCalEntry* CMRUtilsUiServices::CreateResponseLC( |
|
588 const CCalEntry& aBase, |
|
589 const CCalInstance* aInstance, |
|
590 const TDesC& aDescription ) const |
|
591 { |
|
592 // use MRHelpers::ECopyOrganizer (attendee list is different than in base) |
|
593 CCalEntry* response = CreateFromLC( aBase, |
|
594 aInstance, |
|
595 CCalEntry::EMethodReply, |
|
596 aBase.SequenceNumberL(), |
|
597 MRHelpers::ECopyOrganizer ); |
|
598 |
|
599 response->SetDescriptionL( aDescription ); |
|
600 |
|
601 CCalAttendee* thisAttendee = iMRMailboxUtils.ThisAttendeeL( aBase ); |
|
602 if ( !thisAttendee ) |
|
603 { |
|
604 User::Leave( KErrNotFound ); |
|
605 } |
|
606 |
|
607 CCalAttendee* thisCopy = MRHelpers::CopyAttendeeLC( *thisAttendee ); |
|
608 response->AddAttendeeL( thisCopy ); |
|
609 CleanupStack::Pop(); // thisCopy, ownership was transferred |
|
610 return response; |
|
611 } |
|
612 |
|
613 // ---------------------------------------------------------------------------- |
|
614 // CMRUtilsUiServices::CreateCancelL |
|
615 // ---------------------------------------------------------------------------- |
|
616 // |
|
617 CCalEntry* CMRUtilsUiServices::CreateCancelLC( |
|
618 const CCalEntry& aBase, |
|
619 const CCalInstance* aInstance, |
|
620 const TDesC& aDescription ) const |
|
621 { |
|
622 // create a full copy of a base entry |
|
623 CCalEntry* cancellation = CreateFromLC( aBase, |
|
624 aInstance, |
|
625 CCalEntry::EMethodCancel, |
|
626 aBase.SequenceNumberL() + 1, |
|
627 MRHelpers::ECopyFull ); |
|
628 |
|
629 cancellation->SetDescriptionL( aDescription ); |
|
630 |
|
631 return cancellation; |
|
632 } |
|
633 |
|
634 // ---------------------------------------------------------------------------- |
|
635 // CMRUtilsUiServices::CreateFromLC |
|
636 // ---------------------------------------------------------------------------- |
|
637 // |
|
638 CCalEntry* CMRUtilsUiServices::CreateFromLC( |
|
639 const CCalEntry& aBase, |
|
640 const CCalInstance* aInstance, |
|
641 CCalEntry::TMethod aMethod, |
|
642 TInt aSequenceNumber, |
|
643 MRHelpers::TCopyFields aCopyType ) const |
|
644 { |
|
645 CCalEntry* entry = NULL; |
|
646 |
|
647 if ( aInstance ) |
|
648 { // create entry representing instance, instance also has a base |
|
649 // entry, but it may be common for entire series or a range |
|
650 HBufC8* calUid = aBase.UidL().AllocLC(); |
|
651 entry = CCalEntry::NewL( CCalEntry::EAppt, |
|
652 calUid, |
|
653 aMethod, |
|
654 aSequenceNumber, |
|
655 aInstance->StartTimeL(), |
|
656 CalCommon::EThisOnly ); |
|
657 CleanupStack::Pop( calUid ); // ownership transferred |
|
658 CleanupStack::PushL( entry ); |
|
659 |
|
660 MRHelpers::CopyFieldsL( aBase, *entry, aCopyType ); |
|
661 } |
|
662 else |
|
663 { // usual case - create a copy of base entry |
|
664 entry = MRHelpers::CopyEntryLC( aBase, aMethod, aCopyType ); |
|
665 } |
|
666 |
|
667 entry->SetSequenceNumberL( aSequenceNumber ); |
|
668 return entry; |
|
669 } |
|
670 |
|
671 // ---------------------------------------------------------------------------- |
|
672 // CMRUtilsUiServices::CorrespondingSmtpServiceL |
|
673 // ---------------------------------------------------------------------------- |
|
674 // |
|
675 TMsvId CMRUtilsUiServices::CorrespondingSmtpServiceL( TMsvId aRelatedService ) |
|
676 { |
|
677 TMsvEntry entry; |
|
678 TMsvId dummyService; |
|
679 EnsureMsvSessionExistsL(); |
|
680 User::LeaveIfError( iMsvSession->GetEntry( aRelatedService, |
|
681 dummyService, |
|
682 entry ) ); |
|
683 TMsvId smtpId( KMsvNullIndexEntryId ); |
|
684 |
|
685 switch ( entry.iMtm.iUid ) |
|
686 { |
|
687 case KSenduiMtmImap4UidValue: // flow through |
|
688 case KSenduiMtmPop3UidValue: |
|
689 { |
|
690 // In these cases smtp entry is available in iRelatedId: |
|
691 smtpId = entry.iRelatedId; |
|
692 break; |
|
693 } |
|
694 case KSenduiMtmSmtpUidValue: |
|
695 case KSenduiMtmSyncMLEmailUidValue: |
|
696 { |
|
697 // In these cases we already know the msvid for the smtp settings |
|
698 // (for syncml there is also smtp settings!): |
|
699 smtpId = aRelatedService; |
|
700 break; |
|
701 } |
|
702 default: |
|
703 { |
|
704 User::Leave( KErrNotSupported ); |
|
705 break; |
|
706 } |
|
707 } |
|
708 |
|
709 return smtpId; |
|
710 } |
|
711 |
|
712 |
|
713 |
|
714 // ---------------------------------------------------------------------------- |
|
715 // CMRUtilsUiServices::EnsureMsvSessionExistsL |
|
716 // ---------------------------------------------------------------------------- |
|
717 // |
|
718 void CMRUtilsUiServices::EnsureMsvSessionExistsL() |
|
719 { |
|
720 if ( !iMsvSession ) |
|
721 { // Lazy instantiation of iMsvSession |
|
722 iMsvSession = CMsvSession::OpenSyncL( *this ); |
|
723 iOwnMsvSession = ETrue; |
|
724 } |
|
725 } |
|
726 |
|
727 // ---------------------------------------------------------------------------- |
|
728 // CMRUtilsUiServices::HandleSessionEventL |
|
729 // ---------------------------------------------------------------------------- |
|
730 // |
|
731 void CMRUtilsUiServices::HandleSessionEventL( |
|
732 TMsvSessionEvent aEvent, |
|
733 TAny* /*aArg1*/, |
|
734 TAny* /*aArg2*/, |
|
735 TAny* /*aArg3*/ ) |
|
736 { |
|
737 switch ( aEvent ) |
|
738 { |
|
739 case EMsvCloseSession: |
|
740 case EMsvServerTerminated: |
|
741 { |
|
742 if ( iOwnMsvSession ) |
|
743 { |
|
744 delete iMsvSession; |
|
745 } |
|
746 iMsvSession = NULL; // New session constructed lazily only if needed |
|
747 break; |
|
748 } |
|
749 default: |
|
750 { |
|
751 // ignore other events |
|
752 break; |
|
753 } |
|
754 } |
|
755 } |
|
756 |
|
757 // End of file |