|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32std.h> |
|
17 #include "PopsDele.h" |
|
18 #include "POPS.H" |
|
19 #include "POPSOP.H" // CImPop3Dele |
|
20 |
|
21 #include <msventry.h> |
|
22 #include <popsmtm.h> |
|
23 #include "POPSMBX.H" |
|
24 |
|
25 #include "POPS.PAN" // imrc's own panic codes |
|
26 |
|
27 #include "mobilitytestmtmapi.h" |
|
28 |
|
29 // Panic function |
|
30 GLREF_C void Panic(TPopsPanic aPanic); |
|
31 |
|
32 CImPop3Delete::CImPop3Delete(CMsvServerEntry& aRemoteEntry, CImPop3Session* aPop3Session, TMsvId aServiceId) |
|
33 : CMsgActive( KMsgPop3RefreshMailboxPriority ),iRemoteEntry(aRemoteEntry) ,iPopSession(aPop3Session), iServiceId(aServiceId) |
|
34 { |
|
35 __DECLARE_NAME(_S("CImPop3Delete")); |
|
36 } |
|
37 |
|
38 |
|
39 CImPop3Delete* CImPop3Delete::NewL(CMsvServerEntry& aRemoteEntry, const CMsvEntrySelection& aMsvSelection, CImPop3Session* aPop3Session, TMsvId aServiceId) |
|
40 { |
|
41 CImPop3Delete* self = new (ELeave) CImPop3Delete(aRemoteEntry, aPop3Session, aServiceId); |
|
42 |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(aMsvSelection); |
|
45 CleanupStack::Pop(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 void CImPop3Delete::ConstructL( const CMsvEntrySelection& aMsvSelection) |
|
51 { |
|
52 // make our copy of aMsvSelection |
|
53 iSource = aMsvSelection.CopyL(); |
|
54 |
|
55 iPopDelete=CImPop3Dele::NewL(iPopSession); |
|
56 CActiveScheduler::Add(this); // Add CImPop3Delete to scheduler's queue |
|
57 iCancelToMigrate = EFalse; |
|
58 } |
|
59 |
|
60 |
|
61 CImPop3Delete::~CImPop3Delete() |
|
62 { |
|
63 // delete everything here |
|
64 Cancel(); |
|
65 delete iSource; |
|
66 delete iPopDelete; |
|
67 } |
|
68 |
|
69 // |
|
70 // Cancel any current operation |
|
71 // |
|
72 void CImPop3Delete::DoCancel() |
|
73 { |
|
74 if (!iMigratingToNewBearer) |
|
75 { |
|
76 iPopSession->SetOpNotPending(); |
|
77 } |
|
78 |
|
79 iPopDelete->Cancel(); |
|
80 CMsgActive::DoCancel(); |
|
81 } |
|
82 |
|
83 // |
|
84 // Start me up |
|
85 // |
|
86 void CImPop3Delete::Start(TRequestStatus& aStatus) |
|
87 { |
|
88 iMsgCtr=0; |
|
89 iProgress.iTotalMsgs=iSource->Count(); |
|
90 iProgress.iMsgsToProcess=iProgress.iTotalMsgs; |
|
91 |
|
92 if(iSource->Count()) |
|
93 { |
|
94 DoDelete(); |
|
95 Queue(aStatus); |
|
96 } |
|
97 else |
|
98 { |
|
99 aStatus = KRequestPending; |
|
100 TRequestStatus* pS=&aStatus; |
|
101 User::RequestComplete(pS,KErrNone); |
|
102 } |
|
103 } |
|
104 |
|
105 // ****************************************************************************************** |
|
106 // Resume function called by the POP Server MTM, once it has completed Migrating to new bearer |
|
107 // |
|
108 // ****************************************************************************************** |
|
109 void CImPop3Delete::ResumeL(CImPop3Session* aPopSession, TRequestStatus& aStatus) |
|
110 { |
|
111 iMigratingToNewBearer = EFalse; |
|
112 iPopSession = aPopSession; |
|
113 |
|
114 delete iPopDelete; |
|
115 iPopDelete = NULL; |
|
116 iPopDelete = CImPop3Dele::NewL(iPopSession); |
|
117 |
|
118 if(iSource->Count()) |
|
119 { |
|
120 DoDelete(); |
|
121 Queue(aStatus); |
|
122 } |
|
123 else |
|
124 { |
|
125 aStatus = KRequestPending; |
|
126 TRequestStatus* pS = &aStatus; |
|
127 User::RequestComplete(pS,KErrNone); |
|
128 } |
|
129 } |
|
130 |
|
131 // |
|
132 // Result of last active call |
|
133 // |
|
134 void CImPop3Delete::DoRunL() |
|
135 { |
|
136 // No really good error handling can occur below. |
|
137 TInt err = iRemoteEntry.DeleteEntry(iSource->At(iMsgCtr)); |
|
138 //DMC __ASSERT_DEBUG(err == KErrNone, Panic(EPopFailedDebugAssert)); |
|
139 |
|
140 iMsgCtr++; |
|
141 iProgress.iMsgsToProcess--; |
|
142 |
|
143 // Decrement iMtmData3 attribute of the service entry - count of messages on POP3 server |
|
144 // NB our handle to the CMsvServerEntry must always be set to the service entry |
|
145 // prior to call to CImPop3Delete::NewL. |
|
146 TMsvEntry serviceEntry = iRemoteEntry.Entry(); |
|
147 serviceEntry.SetMtmData3(serviceEntry.MtmData3()-1); |
|
148 err = iRemoteEntry.ChangeEntry(serviceEntry); |
|
149 |
|
150 if(iMsgCtr<iSource->Count()) |
|
151 { |
|
152 // If we are migrating halt the operation here |
|
153 if (iMigratingToNewBearer) |
|
154 { |
|
155 // If we don't SetActive, the RunL will complete the request |
|
156 return; |
|
157 } |
|
158 else |
|
159 { |
|
160 DoDelete(); |
|
161 } |
|
162 } |
|
163 else |
|
164 { |
|
165 iProgress.iMsgsToProcess=0; |
|
166 } |
|
167 } |
|
168 |
|
169 // |
|
170 // Fire off the delete process |
|
171 // |
|
172 void CImPop3Delete::DoDelete() |
|
173 { |
|
174 TMsvId msgId=iSource->At(iMsgCtr); |
|
175 //DMC |
|
176 if (iPopDelete->SetMessage(msgId)) |
|
177 { |
|
178 iPopDelete->Start(iStatus); |
|
179 // activate ourselves |
|
180 SetActive(); |
|
181 MOBILITY_TEST_MTM_STATE(iServiceId, KMobilityTestMtmStatePopDeleting); |
|
182 } |
|
183 else |
|
184 { |
|
185 SetActive(); |
|
186 iStatus = KRequestPending; |
|
187 TRequestStatus* pS=&iStatus; |
|
188 User::RequestComplete(pS,KErrNone); |
|
189 } |
|
190 } |
|
191 |
|
192 // |
|
193 // Report the refreshing news back to the UI |
|
194 // |
|
195 TPop3Progress CImPop3Delete::Progress() |
|
196 { |
|
197 return iProgress; |
|
198 } |
|
199 |
|
200 // ****************************************************************************************** |
|
201 // This is called by the POP Server MTM when it starts Migrating Bearer |
|
202 // |
|
203 // ****************************************************************************************** |
|
204 void CImPop3Delete::Pause() |
|
205 { |
|
206 // Set the Migration flag |
|
207 iMigratingToNewBearer = ETrue; |
|
208 } |
|
209 |
|
210 // ****************************************************************************************** |
|
211 // This is called by the POP Server MTM when it starts Migrating Bearer |
|
212 // |
|
213 // ****************************************************************************************** |
|
214 void CImPop3Delete::CancelAllowResume() |
|
215 { |
|
216 iMigratingToNewBearer = ETrue; |
|
217 |
|
218 // Cancel the deletion of the current message and decrement counters |
|
219 // so we can restart from this message onwards when we have migrated. |
|
220 // Use the normal cancel, as we really need to cancel here. |
|
221 Cancel(); |
|
222 } |