|
1 /* |
|
2 * Copyright (c) 2006 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 * Used to reset a service's pre-created messages when the service changes |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <MTMStore.h> |
|
20 #include <mtmuibas.h> |
|
21 |
|
22 #include "SmtpResetPreCreationOp.h" |
|
23 #include "EmailPreCreation.h" |
|
24 #include "ImumMtmLogging.h" |
|
25 |
|
26 const TInt KResetCreateMsgPriority = CActive::EPriorityIdle - 10; |
|
27 |
|
28 |
|
29 CSmtpResetPreCreationOp* CSmtpResetPreCreationOp::NewL(CMsvSession& aMsvSession, |
|
30 TRequestStatus& aObserverRequestStatus, TMsvId aServiceId) |
|
31 { |
|
32 IMUM_STATIC_CONTEXT( CSmtpResetPreCreationOp::NewL, 0, mtm, KImumMtmLog ); |
|
33 IMUM_IN(); |
|
34 // static |
|
35 CSmtpResetPreCreationOp* op = new(ELeave) CSmtpResetPreCreationOp(aMsvSession, aObserverRequestStatus, aServiceId); |
|
36 CleanupStack::PushL(op); |
|
37 op->ConstructL(); |
|
38 CleanupStack::Pop(op); |
|
39 IMUM_OUT(); |
|
40 return op; |
|
41 } |
|
42 |
|
43 |
|
44 void CSmtpResetPreCreationOp::RunL() |
|
45 { |
|
46 IMUM_CONTEXT( CSmtpResetPreCreationOp::RunL, 0, KImumMtmLog ); |
|
47 IMUM_IN(); |
|
48 |
|
49 DoRunL(); |
|
50 |
|
51 IMUM_OUT(); |
|
52 } |
|
53 |
|
54 |
|
55 TInt CSmtpResetPreCreationOp::RunError(TInt __DEBUG_ONLY( aError ) ) |
|
56 { |
|
57 IMUM_CONTEXT( CSmtpResetPreCreationOp::RunError, 0, KImumMtmLog ); |
|
58 IMUM_IN(); |
|
59 |
|
60 IMUM1( 0, "RunL leaved with error code %d", aError ); |
|
61 |
|
62 iMtm = KUidMsvLocalServiceMtm; |
|
63 CompleteObserver(); |
|
64 |
|
65 IMUM_OUT(); |
|
66 |
|
67 return KErrNone; |
|
68 } |
|
69 |
|
70 void CSmtpResetPreCreationOp::DoRunL() |
|
71 { |
|
72 IMUM_CONTEXT( CSmtpResetPreCreationOp::DoRunL, 0, KImumMtmLog ); |
|
73 IMUM_IN(); |
|
74 |
|
75 TInt err = KErrNone; |
|
76 TPckgBuf<TMsvId> idbuf; |
|
77 if(iStatus.Int() != KErrNone) |
|
78 { |
|
79 err = iStatus.Int(); |
|
80 } |
|
81 else if(iOperation) |
|
82 { |
|
83 const TDesC8& prog = iOperation->ProgressL(); |
|
84 if(prog.Length()) |
|
85 { |
|
86 if(iState == EStateCreate) |
|
87 { |
|
88 idbuf.Copy(prog.Left(sizeof(TMsvId))); |
|
89 if(idbuf() == KMsvNullIndexEntryId) |
|
90 { |
|
91 err = KErrGeneral; |
|
92 } |
|
93 } |
|
94 else |
|
95 { |
|
96 const TUid uid(iOperation->Mtm()); |
|
97 if(uid == KUidMsvLocalServiceMtm) |
|
98 { |
|
99 err = McliUtils::GetLocalProgressL(*iOperation).iError; |
|
100 } |
|
101 else |
|
102 { |
|
103 TBuf<CBaseMtmUi::EProgressStringMaxLen> retString; |
|
104 TInt totalEntryCount = 0; |
|
105 TInt entriesDone = 0; |
|
106 TInt currentEntrySize = 0; |
|
107 TInt currentBytesTrans = 0; |
|
108 err = iMtmStore->ClaimMtmUiL(uid).GetProgress(prog, retString, totalEntryCount, entriesDone, currentEntrySize, currentBytesTrans); |
|
109 iMtmStore->ReleaseMtmUi(uid); |
|
110 } |
|
111 } |
|
112 } |
|
113 } |
|
114 if(iOperation) |
|
115 { |
|
116 delete iOperation; |
|
117 iOperation = NULL; |
|
118 } |
|
119 User::LeaveIfError(err); // Caught in RunL() |
|
120 |
|
121 switch(iState) |
|
122 { |
|
123 case EStateIdle: // should never occur... |
|
124 DeleteMessageL(); |
|
125 break; |
|
126 case EStateDelete: |
|
127 CreateMessageL(); |
|
128 break; |
|
129 case EStateCreate: |
|
130 CompleteObserver(); |
|
131 break; |
|
132 default: |
|
133 break; |
|
134 } |
|
135 iMtm = (iOperation) ? (iOperation->Mtm()) : (KUidMsvLocalServiceMtm); |
|
136 IMUM_OUT(); |
|
137 } |
|
138 |
|
139 |
|
140 CSmtpResetPreCreationOp::CSmtpResetPreCreationOp(CMsvSession& aMsvSession, TRequestStatus& aObserverRequestStatus, |
|
141 TMsvId aServiceId) |
|
142 : CSmtpPreCreationOpBase(aMsvSession, KResetCreateMsgPriority, aObserverRequestStatus) |
|
143 { |
|
144 IMUM_CONTEXT( CSmtpResetPreCreationOp::CSmtpResetPreCreationOp, 0, KImumMtmLog ); |
|
145 IMUM_IN(); |
|
146 |
|
147 iService = aServiceId; |
|
148 IMUM_OUT(); |
|
149 } |
|
150 |
|
151 |
|
152 CSmtpResetPreCreationOp::~CSmtpResetPreCreationOp() |
|
153 { |
|
154 IMUM_CONTEXT( CSmtpResetPreCreationOp::~CSmtpResetPreCreationOp, 0, KImumMtmLog ); |
|
155 IMUM_IN(); |
|
156 IMUM_OUT(); |
|
157 |
|
158 } |
|
159 |
|
160 |
|
161 void CSmtpResetPreCreationOp::ConstructL() |
|
162 { |
|
163 IMUM_CONTEXT( CSmtpResetPreCreationOp::ConstructL, 0, KImumMtmLog ); |
|
164 IMUM_IN(); |
|
165 |
|
166 CSmtpPreCreationOpBase::ConstructL(); |
|
167 |
|
168 // DeleteMessage operation must be run synchronously before Control is returned to the Active Scheduler |
|
169 // to ensure that an Email editor is not launched with a message which will be deleted by this operation. |
|
170 DeleteMessageL(); |
|
171 IMUM_OUT(); |
|
172 } |
|
173 |
|
174 |
|
175 void CSmtpResetPreCreationOp::DeleteMessageL() |
|
176 { |
|
177 IMUM_CONTEXT( CSmtpResetPreCreationOp::DeleteMessageL, 0, KImumMtmLog ); |
|
178 IMUM_IN(); |
|
179 |
|
180 iStatus = KRequestPending; |
|
181 iOperation = iPreCreate->DeleteAllPreCreatedEmailsL(iService, iStatus); |
|
182 SetActive(); |
|
183 iState = EStateDelete; |
|
184 if(!iOperation) // DeleteAllPreCreatedEmailsL() returns NULL if no messages to delete. |
|
185 { |
|
186 CompleteThis(); |
|
187 } |
|
188 IMUM_OUT(); |
|
189 } |
|
190 |
|
191 |
|
192 void CSmtpResetPreCreationOp::CreateMessageL() |
|
193 { |
|
194 IMUM_CONTEXT( CSmtpResetPreCreationOp::CreateMessageL, 0, KImumMtmLog ); |
|
195 IMUM_IN(); |
|
196 |
|
197 iStatus = KRequestPending; |
|
198 iOperation = iPreCreate->PreCreateBlankEmailL(iService, iStatus); |
|
199 SetActive(); |
|
200 iState = EStateCreate; |
|
201 IMUM_OUT(); |
|
202 } |
|
203 |
|
204 |