|
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: Active object for wiping messages, called by lawmomessagingplugin. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <msvids.h> |
|
19 #include <f32file.h> |
|
20 #include <e32base.h> |
|
21 #include "lawmomessagingasyncwipe.h" |
|
22 #include "fdebug.h" |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 // CActiveWipeObject::CActiveWipeObject |
|
26 // Description: CActiveWipeObject constructer . Initializes datamember of MLawmoPluginWipeObserver |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 CActiveWipeObject::CActiveWipeObject(MLawmoPluginWipeObserver* aObserver) : |
|
30 CActive(EPriorityStandard), iObserver(aObserver), iSession(NULL) |
|
31 { |
|
32 FLOG( |
|
33 _L(" Messaging: CActiveWipeObject::CActiveWipeObject(MLawmoPluginWipeObserver* aObserver) >>")); |
|
34 // See ConstructL() for initialisation completion. |
|
35 FLOG( |
|
36 _L(" Messaging: CActiveWipeObject::CActiveWipeObject(MLawmoPluginWipeObserver* aObserver) <<")); |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CActiveWipeObject::NewL |
|
41 // Description: CActiveWipeObject constructer |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CActiveWipeObject* CActiveWipeObject::NewL(MLawmoPluginWipeObserver* aObserver) |
|
45 { |
|
46 FLOG(_L(" Messaging: CActiveWipeObject* CActiveWipeObject::NewL(MLawmoPluginWipeObserver* aObserver) >>")); |
|
47 CActiveWipeObject* self=new(ELeave) CActiveWipeObject(aObserver); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop(); |
|
51 FLOG(_L(" Messaging: CActiveWipeObject* CActiveWipeObject::NewL(MLawmoPluginWipeObserver* aObserver) <<")); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------------------- |
|
56 // CActiveWipeObject::ConstructL |
|
57 // ---------------------------------------------------------------------------------------- |
|
58 void CActiveWipeObject::ConstructL() |
|
59 { |
|
60 FLOG(_L(" Messaging: CActiveWipeObject::ConstructL() >>")); |
|
61 |
|
62 iTimer.CreateLocal(); |
|
63 User::LeaveIfError(iWs.Connect()); |
|
64 CActiveScheduler::Add(this); // Add to scheduler |
|
65 iDummyObserver = new CDummyObserver(); |
|
66 FLOG(_L(" Messaging: CActiveWipeObject::ConstructL() <<")); |
|
67 } |
|
68 |
|
69 void CActiveWipeObject::Close() |
|
70 { |
|
71 FLOG(_L(" Messaging: void CActiveWipeObject::Close() >>")); |
|
72 if (iSession) |
|
73 { |
|
74 FLOG(_L(" delete iSession;")); |
|
75 delete iSession; |
|
76 iSession = NULL; |
|
77 } |
|
78 FLOG(_L(" Messaging: void CActiveWipeObject::Close() <<")); |
|
79 } |
|
80 |
|
81 // |
|
82 //----------------------------------------------------------------------------- |
|
83 // CActiveWipeObject:: CActiveWipeObject |
|
84 // Description: CActiveWipeObject Destructer |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CActiveWipeObject::~CActiveWipeObject() |
|
88 { |
|
89 FLOG(_L(" Messaging: CActiveWipeObject::~CActiveWipeObject() >>")); |
|
90 Close(); |
|
91 if (iDummyObserver) |
|
92 delete iDummyObserver; |
|
93 iWs.Close(); |
|
94 iTimer.Close(); |
|
95 FLOG(_L(" Messaging: CActiveWipeObject::~CActiveWipeObject() <<")); |
|
96 } |
|
97 |
|
98 // |
|
99 // Description: Deletes message entries one by one. If used by message application, force deletes. |
|
100 // |
|
101 void CActiveWipeObject::DoJobL(CMsvEntry* aContext) |
|
102 { |
|
103 FLOG(_L(" Messaging: void CLAWMOMessagingplugin::doJobL() >>")); |
|
104 |
|
105 TMsvId entryID; |
|
106 CMsvEntrySelection* entries; |
|
107 |
|
108 entries = aContext->ChildrenL(); |
|
109 CleanupStack::PushL(entries); |
|
110 |
|
111 TInt msgCount= entries->Count(); |
|
112 FLOG(_L(" msgCount= %d "), msgCount ); |
|
113 |
|
114 for (TInt i=msgCount-1; i>=0; i--) |
|
115 { |
|
116 entryID = entries->At(i); |
|
117 CMsvEntry* entry = iSession->GetEntryL(entryID); |
|
118 CleanupStack::PushL(entry); |
|
119 TRAPD(err, entry->DeleteL(entryID)); |
|
120 CleanupStack::PopAndDestroy(entry); |
|
121 if(err) |
|
122 { |
|
123 FLOG(_L(" Deleteing entry failed with err= %d "), err); |
|
124 // Force removal of the entry. If no any other way only. |
|
125 iSession->RemoveEntry(entryID); |
|
126 } |
|
127 } |
|
128 |
|
129 CleanupStack::PopAndDestroy(entries); |
|
130 FLOG(_L(" Messaging: void CLAWMOMessagingplugin::doJobL() <<")); |
|
131 } |
|
132 |
|
133 void CActiveWipeObject::InitializeL() |
|
134 { |
|
135 FLOG(_L(" Messaging: void CActiveWipeObject::InitializeL() >>")); |
|
136 iSession = CMsvSession::OpenSyncL(*iDummyObserver); |
|
137 FLOG(_L(" Messaging: void CActiveWipeObject::InitializeL() <<")); |
|
138 } |
|
139 |
|
140 // |
|
141 //----------------------------------------------------------------------------- |
|
142 // CActiveWipeObject::WipeAsyncL |
|
143 // Description: Wipes the logs |
|
144 // ---------------------------------------------------------------------------- |
|
145 // |
|
146 |
|
147 void CActiveWipeObject::WipeAsyncL() |
|
148 { |
|
149 FLOG(_L(" Messaging: void CActiveWipeObject::WipeAsyncL () >>")); |
|
150 |
|
151 if ( !WaitTillMessageAppKilled()) //Application is closed already |
|
152 { |
|
153 TRequestStatus* status = &iStatus; |
|
154 FLOG(_L(" SetActive()")); |
|
155 SetActive(); |
|
156 User::RequestComplete(status, KErrNone); |
|
157 } |
|
158 FLOG(_L(" Messaging: void CActiveWipeObject::WipeAsyncL () <<")); |
|
159 } |
|
160 |
|
161 // |
|
162 // Description: Wipes Inbox, Sent Items, Drafts, Outbox messages. |
|
163 // |
|
164 // |
|
165 void CActiveWipeObject::WipeAllL() |
|
166 { |
|
167 FLOG(_L(" Messaging: void CActiveWipeObject::wipeAll() >>")); |
|
168 |
|
169 CMsvEntry* context = NULL; |
|
170 TMsvSelectionOrdering sort; |
|
171 |
|
172 sort.SetShowInvisibleEntries(ETrue); // we want to handle also the invisible entries |
|
173 context = CMsvEntry::NewL(*iSession, KMsvGlobalInBoxIndexEntryId, sort); // Reading Messages from Inbox Folder |
|
174 DoJobL(context); |
|
175 delete context; |
|
176 |
|
177 context = CMsvEntry::NewL(*iSession, KMsvGlobalOutBoxIndexEntryId, sort); // Reading Messages from Outbox Folderif(KErrNone) |
|
178 DoJobL(context); |
|
179 delete context; |
|
180 |
|
181 context = CMsvEntry::NewL(*iSession, KMsvSentEntryId, sort); // Reading Messages from Sent Folder |
|
182 DoJobL(context); |
|
183 delete context; |
|
184 |
|
185 context = CMsvEntry::NewL(*iSession, KMsvDraftEntryId, sort); // Reading Messages from Draft Folder |
|
186 DoJobL(context); |
|
187 delete context; |
|
188 FLOG(_L(" Messaging: void CActiveWipeObject::wipeAll() <<")); |
|
189 } |
|
190 |
|
191 // |
|
192 //----------------------------------------------------------------------------- |
|
193 // CActiveWipeObject::RunError |
|
194 // Description: This returns error |
|
195 //----------------------------------------------------------------------------- |
|
196 // |
|
197 |
|
198 TInt CActiveWipeObject::RunError(TInt aError) |
|
199 { |
|
200 FLOG(_L(" Messaging: TInt CActiveWipeObject::RunError(TInt aError) >>")); |
|
201 |
|
202 FLOG(_L(" Messaging: RunError error %d"), aError); |
|
203 iObserver->HandleWipeCompleted(aError); |
|
204 |
|
205 FLOG(_L(" Messaging: TInt CActiveWipeObject::RunError(TInt aError) <<")); |
|
206 return KErrNone; |
|
207 } |
|
208 |
|
209 // |
|
210 //----------------------------------------------------------------------------- |
|
211 // CActiveWipeObject::DoCancel |
|
212 // Description: This calls CActive's Cancel |
|
213 //----------------------------------------------------------------------------- |
|
214 // |
|
215 void CActiveWipeObject::DoCancel() |
|
216 { |
|
217 FLOG(_L(" Messaging: void CActiveWipeObject::DoCancel() >>")); |
|
218 iTimer.Cancel(); |
|
219 FLOG(_L(" Messaging: void CActiveWipeObject::DoCancel() <<")); |
|
220 } |
|
221 |
|
222 // |
|
223 //----------------------------------------------------------------------------- |
|
224 // CActiveWipeObject::WaitTillMessageAppKilled |
|
225 // Description: This function checks for the Messaging applicaiton being run. If running then kill it. |
|
226 //----------------------------------------------------------------------------- |
|
227 |
|
228 TBool CActiveWipeObject::WaitTillMessageAppKilled() |
|
229 { |
|
230 FLOG(_L(" void CTTPAPITestAppUi::WaitTillMessageAppKilled() >>")); |
|
231 TBool ret(EFalse); |
|
232 TBool flag(ETrue); |
|
233 |
|
234 TApaTaskList list(iWs); |
|
235 TUid uid = |
|
236 { |
|
237 KMessagingAppUid |
|
238 }; |
|
239 |
|
240 while (flag) |
|
241 { |
|
242 TApaTask task( list.FindApp( uid ) ); |
|
243 if (task.Exists()) |
|
244 { |
|
245 FLOG(_L("Killing one instance...")); |
|
246 task.EndTask(); |
|
247 User::After(500000); |
|
248 ret = ETrue; |
|
249 } |
|
250 else |
|
251 { |
|
252 flag = EFalse; |
|
253 } |
|
254 } |
|
255 |
|
256 if (ret) |
|
257 { |
|
258 FLOG(_L(" WaitTillMessageAppKilled: iTimer.After(iStatus,2000); ")); |
|
259 iTimer.After(iStatus,2000); // 0.002 sec |
|
260 SetActive(); |
|
261 } |
|
262 |
|
263 FLOG(_L(" void CTTPAPITestAppUi::WaitTillMessageAppKilled(), ret = %d <<"), ret); |
|
264 return ret; |
|
265 } |
|
266 |
|
267 |
|
268 |
|
269 // |
|
270 //----------------------------------------------------------------------------- |
|
271 // CActiveWipeObject::RunL |
|
272 // Description: CActive::RunL implementation which will either stop the |
|
273 // Scheduler or increment the count |
|
274 //----------------------------------------------------------------------------- |
|
275 // |
|
276 void CActiveWipeObject::RunL() |
|
277 { |
|
278 FLOG(_L(" Messaging: void CActiveWipeObject::RunL() >>")); |
|
279 |
|
280 FLOG(_L("void CActiveWipeObject::RunL(): iStatus= %d "), iStatus.Int()); |
|
281 InitializeL(); |
|
282 WipeAllL(); |
|
283 iObserver->HandleWipeCompleted(KErrNone); |
|
284 FLOG(_L(" Messaging: void CActiveWipeObject::RunL() <<")); |
|
285 } |