|
1 // Copyright (c) 2000-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 // source file for CWapPushServiceFinder - basic function is to locate a service Id, and if none exists |
|
15 // then find one. |
|
16 // |
|
17 // |
|
18 |
|
19 #include <msvids.h> |
|
20 #include <msvuids.h> |
|
21 #include <MmsUtils.h> |
|
22 #include <MmsSettings.h> |
|
23 |
|
24 |
|
25 #include <pushentry.h> |
|
26 #include "WPushUtils.h" |
|
27 #include "t_serviceutils.h" |
|
28 |
|
29 |
|
30 |
|
31 CWapPushTestMsgUtils* CWapPushTestMsgUtils::NewL() |
|
32 { |
|
33 CWapPushTestMsgUtils* self = new (ELeave) CWapPushTestMsgUtils(); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CWapPushTestMsgUtils::~CWapPushTestMsgUtils() |
|
41 { |
|
42 delete iMsvEntry; |
|
43 delete iMsvSession; |
|
44 } |
|
45 |
|
46 void CWapPushTestMsgUtils::ConstructL() |
|
47 { |
|
48 iMsvSession = CMsvSession::OpenSyncL(*this); |
|
49 iMsvEntry = iMsvSession->GetEntryL(KMsvRootIndexEntryId); |
|
50 } |
|
51 |
|
52 |
|
53 void CWapPushTestMsgUtils::PushServiceIdL(TMsvId& rFirstId, CMsvEntrySelection* rServiceIds) |
|
54 { |
|
55 //Returns the Service IDs of MTM aMtm, or Null value if none exist |
|
56 |
|
57 rFirstId = KMsvNullIndexEntryId; |
|
58 |
|
59 iMsvEntry->SetEntryL(KMsvRootIndexEntryId); |
|
60 |
|
61 TMsvSelectionOrdering order; |
|
62 order.SetShowInvisibleEntries(ETrue); |
|
63 iMsvEntry->SetSortTypeL(order); |
|
64 |
|
65 //Get the children on the Root Index Entry |
|
66 CMsvEntrySelection* selection = iMsvEntry->ChildrenWithTypeL(KUidMsvServiceEntry); |
|
67 CleanupStack::PushL(selection); |
|
68 |
|
69 TInt count = selection->Count(); |
|
70 |
|
71 //Find an entry for MTM aMtm |
|
72 for (TInt curChild = 0; curChild < count && (rFirstId == KMsvNullIndexEntryId || rServiceIds); curChild++) |
|
73 { |
|
74 iMsvEntry->SetEntryL(selection->At(curChild)); |
|
75 |
|
76 if (iMsvEntry->Entry().iMtm == KUidMtmWapPush) |
|
77 { |
|
78 TMsvId id = iMsvEntry->Entry().Id(); |
|
79 |
|
80 if (rFirstId == KMsvNullIndexEntryId) |
|
81 rFirstId = id; |
|
82 |
|
83 if (rServiceIds) |
|
84 rServiceIds->AppendL(id); |
|
85 } |
|
86 } |
|
87 |
|
88 CleanupStack::Pop(); //selection |
|
89 delete selection; |
|
90 } |
|
91 |
|
92 |
|
93 |
|
94 void CWapPushTestMsgUtils::InstallMtmGroupL(const TDesC& aDatFile) |
|
95 { |
|
96 TInt err = KErrNone; |
|
97 err = iMsvSession->InstallMtmGroup(aDatFile); |
|
98 if (err != KErrAlreadyExists) |
|
99 User::LeaveIfError(err); |
|
100 } |
|
101 |
|
102 |
|
103 |
|
104 void CWapPushTestMsgUtils::RemoveServiceEntryChildrenL(TMsvId aServiceId) |
|
105 { |
|
106 CMsvEntrySelection* inboxMessageSel; |
|
107 |
|
108 TMsvSelectionOrdering sort; |
|
109 sort.SetShowInvisibleEntries(ETrue); |
|
110 iMsvEntry->SetSortTypeL(sort); |
|
111 |
|
112 iMsvEntry->SetEntryL(aServiceId); |
|
113 inboxMessageSel = iMsvEntry->ChildrenL(); |
|
114 CleanupStack::PushL(inboxMessageSel); |
|
115 |
|
116 DeleteEntriesSychronouslyL(inboxMessageSel); |
|
117 |
|
118 CleanupStack::PopAndDestroy(); // inboxMessageSel |
|
119 |
|
120 iMsvEntry->SetEntryL(KMsvRootIndexEntryId); |
|
121 |
|
122 } |
|
123 |
|
124 |
|
125 // Cleans the message folder of all entries with the specified Mtm Type. Get the Inbox Entry, and then all the |
|
126 // children of this entry.Then iterate through the selection deleting each entry with chosesn Mtm Uid. |
|
127 void CWapPushTestMsgUtils::RemoveEntriesFromLocalServiceFolderL(TMsvId aPushFolderId, TUid aMtm) |
|
128 { |
|
129 CMsvEntrySelection* inboxMessageSel; |
|
130 |
|
131 TMsvSelectionOrdering sort; |
|
132 sort.SetShowInvisibleEntries(ETrue); |
|
133 iMsvEntry->SetSortTypeL(sort); |
|
134 |
|
135 iMsvEntry->SetEntryL(aPushFolderId); |
|
136 __ASSERT_ALWAYS(iMsvEntry->Entry().iType == KUidMsvFolderEntry, |
|
137 User::Panic(_L("CWapPushTestMsgUtils"), 0)); |
|
138 inboxMessageSel = iMsvEntry->ChildrenWithMtmL(aMtm); |
|
139 CleanupStack::PushL(inboxMessageSel); |
|
140 |
|
141 for (TInt count =0; count < inboxMessageSel->Count(); count++) |
|
142 { |
|
143 iMsvEntry->DeleteL(inboxMessageSel->At(count)); |
|
144 } |
|
145 |
|
146 iMsvEntry->SetEntryL(KMsvRootIndexEntryId); |
|
147 CleanupStack::PopAndDestroy(); // inboxMessageSel |
|
148 } |
|
149 |
|
150 |
|
151 |
|
152 void CWapPushTestMsgUtils::DeleteEntriesSychronouslyL(CMsvEntrySelection* aSelection) |
|
153 { |
|
154 if (aSelection->Count() != 0) |
|
155 { |
|
156 // iMsvEntry should be set to the parent of the entries to delete, otherwise delete leaves |
|
157 iMsvEntry->SetEntryL(aSelection->At(0)); |
|
158 iMsvEntry->SetEntryL(iMsvEntry->Entry().Parent()); |
|
159 CMsvOperationWait* wait=CMsvOperationWait::NewLC(CActive::EPriorityStandard); |
|
160 CMsvOperation* op=iMsvEntry->DeleteL(*aSelection, wait->iStatus); |
|
161 CleanupStack::PushL(op); |
|
162 wait->Start(); |
|
163 CActiveScheduler::Start(); |
|
164 |
|
165 const TInt err=op->iStatus.Int(); |
|
166 TPushMTMProgressBuf progressBuf; |
|
167 progressBuf.Copy(op->ProgressL()); |
|
168 TPushMTMProgress progress = progressBuf(); |
|
169 CleanupStack::PopAndDestroy(2); // op, wait |
|
170 |
|
171 User::LeaveIfError(err); |
|
172 User::LeaveIfError(progress.iError); |
|
173 } |
|
174 } |
|
175 |
|
176 TMsvId CWapPushTestMsgUtils::CreateServiceL() |
|
177 { |
|
178 _LIT(KServicedescription, "WAP Push Service Entry"); |
|
179 TMsvId id = 0; |
|
180 TMsvEntry entry; |
|
181 entry.iMtm = KUidMtmWapPush; |
|
182 entry.iType = KUidMsvServiceEntry; |
|
183 entry.SetReadOnly(ETrue); |
|
184 entry.SetVisible(ETrue); |
|
185 entry.iDetails.Set(KServicedescription); |
|
186 |
|
187 iMsvEntry->SetEntryL(KMsvRootIndexEntryId); |
|
188 iMsvEntry->CreateL(entry); |
|
189 id = entry.Id(); |
|
190 iMsvEntry->SetEntryL(id); |
|
191 return id; |
|
192 } |
|
193 |
|
194 |
|
195 TMsvId CWapPushTestMsgUtils::CreateMmsServiceL() |
|
196 { |
|
197 TMsvId id = KMsvNullIndexEntryId; |
|
198 |
|
199 // Check if there is one |
|
200 iMsvEntry->SetEntryL(KMsvRootIndexEntryId); |
|
201 |
|
202 //Get the children on the Root Index Entry |
|
203 CMsvEntrySelection* selection = iMsvEntry->ChildrenWithTypeL(KUidMsvServiceEntry); |
|
204 CleanupStack::PushL(selection); |
|
205 |
|
206 TInt count = selection->Count(); |
|
207 |
|
208 //Find an entry for MTM aMtm |
|
209 for (TInt curChild = 0; curChild < count && (id == KMsvNullIndexEntryId); curChild++) |
|
210 { |
|
211 iMsvEntry->SetEntryL(selection->At(curChild)); |
|
212 |
|
213 if (iMsvEntry->Entry().iMtm == KUidMsgTypeMMS) |
|
214 id = iMsvEntry->Entry().Id(); |
|
215 } |
|
216 |
|
217 CleanupStack::PopAndDestroy(); //selection |
|
218 |
|
219 if (id == KMsvNullIndexEntryId) |
|
220 { |
|
221 TMsvEntry entry; |
|
222 entry.iMtm = KUidMsgTypeMMS; |
|
223 entry.iType = KUidMsvServiceEntry; |
|
224 |
|
225 iMsvEntry->SetEntryL(KMsvRootIndexEntryId); |
|
226 iMsvEntry->CreateL(entry); |
|
227 id = entry.Id(); |
|
228 iMsvEntry->SetEntryL(id); |
|
229 } |
|
230 |
|
231 SetMmsSettings(id); |
|
232 |
|
233 return id; |
|
234 } |
|
235 |
|
236 void CWapPushTestMsgUtils::SetMmsSettingsL(TMsvId aId) |
|
237 { |
|
238 CMmsSettings* settings = CMmsSettings::NewLC(); |
|
239 settings->SetAutomaticFetch(EFalse); |
|
240 iMsvEntry->SetEntryL(aId); |
|
241 CMsvStore* store = iMsvEntry->EditStoreL(); |
|
242 CleanupStack::PushL(store); |
|
243 settings->StoreL(*store); |
|
244 store->CommitL(); |
|
245 CleanupStack::PopAndDestroy(2); // store1,settings1 |
|
246 } |
|
247 |
|
248 |
|
249 void CWapPushTestMsgUtils::PushFolderIdL(TMsvId& rFirstFolderId, CMsvEntrySelection* rFolderIds) |
|
250 { |
|
251 //Returns the Service IDs of MTM aMtm, or Null value if none exist |
|
252 |
|
253 rFirstFolderId = KMsvNullIndexEntryId; |
|
254 |
|
255 iMsvEntry->SetEntryL(KMsvLocalServiceIndexEntryId); |
|
256 |
|
257 TMsvSelectionOrdering order; |
|
258 order.SetShowInvisibleEntries(ETrue); |
|
259 iMsvEntry->SetSortTypeL(order); |
|
260 |
|
261 //Get the children on the Root Index Entry |
|
262 CMsvEntrySelection* selection = iMsvEntry->ChildrenWithTypeL(KUidMsvFolderEntry); |
|
263 CleanupStack::PushL(selection); |
|
264 |
|
265 TInt count = selection->Count(); |
|
266 |
|
267 //Find an entry for Push MTM |
|
268 for (TInt curChild = 0; curChild < count ; curChild++) |
|
269 { |
|
270 iMsvEntry->SetEntryL(selection->At(curChild)); |
|
271 |
|
272 if (iMsvEntry->Entry().iMtm == KUidMtmWapPush) |
|
273 { |
|
274 TMsvId id = iMsvEntry->Entry().Id(); |
|
275 |
|
276 if (rFirstFolderId == KMsvNullIndexEntryId) |
|
277 rFirstFolderId = id; |
|
278 |
|
279 if (rFolderIds) |
|
280 rFolderIds->AppendL(id); |
|
281 } |
|
282 } |
|
283 |
|
284 CleanupStack::Pop(); //selection |
|
285 delete selection; |
|
286 |
|
287 |
|
288 |
|
289 } |
|
290 |
|
291 TMsvId CWapPushTestMsgUtils::CreatePushMsgFolderL() |
|
292 { |
|
293 TMsvId id = 0; |
|
294 TMsvEntry entry; |
|
295 entry.iServiceId = KMsvLocalServiceIndexEntryId; |
|
296 entry.iMtm = KUidMtmWapPush; |
|
297 entry.iType = KUidMsvFolderEntry; |
|
298 entry.SetReadOnly(ETrue); |
|
299 entry.SetVisible(EFalse); |
|
300 entry.iDetails.Set(KPushFolderDescription); |
|
301 |
|
302 iMsvEntry->SetEntryL(KMsvLocalServiceIndexEntryId); |
|
303 iMsvEntry->CreateL(entry); |
|
304 id = entry.Id(); |
|
305 iMsvEntry->SetEntryL(id); |
|
306 return id; |
|
307 } |
|
308 |
|
309 |
|
310 // Clears any existing Push Service entries - test if creation works |
|
311 void CWapPushTestMsgUtils::RemoveAllPushServiceEntriesL() |
|
312 { |
|
313 iMsvEntry->SetEntryL(KMsvRootIndexEntryId); |
|
314 |
|
315 TMsvSelectionOrdering order; |
|
316 order.SetShowInvisibleEntries(ETrue); |
|
317 iMsvEntry->SetSortTypeL(order); |
|
318 |
|
319 CMsvEntrySelection* selection = iMsvEntry->ChildrenWithTypeL(KUidMsvServiceEntry); |
|
320 CleanupStack::PushL(selection); |
|
321 |
|
322 TInt count = selection->Count(); |
|
323 TMsvEntry entry; |
|
324 |
|
325 for (TInt currentEntry = 0; currentEntry < count; currentEntry++) |
|
326 { |
|
327 iMsvEntry->SetEntryL(selection->At(currentEntry)); |
|
328 entry = iMsvEntry->Entry(); |
|
329 if (entry.iMtm == KUidMtmWapPush && entry.iType == KUidMsvServiceEntry) |
|
330 { |
|
331 iMsvEntry->SetEntryL(KMsvRootIndexEntryId); |
|
332 iMsvEntry->DeleteL(entry.Id()); |
|
333 } |
|
334 } |
|
335 CleanupStack::PopAndDestroy();//selection |
|
336 } |
|
337 |
|
338 |
|
339 void CWapPushTestMsgUtils::RemoveAllPushFolderEntriesL() |
|
340 { |
|
341 iMsvEntry->SetEntryL(KMsvLocalServiceIndexEntryId); |
|
342 |
|
343 TMsvSelectionOrdering order; |
|
344 order.SetShowInvisibleEntries(ETrue); |
|
345 iMsvEntry->SetSortTypeL(order); |
|
346 |
|
347 CMsvEntrySelection* selection = iMsvEntry->ChildrenWithTypeL(KUidMsvFolderEntry); |
|
348 CleanupStack::PushL(selection); |
|
349 |
|
350 TInt count = selection->Count(); |
|
351 TMsvEntry folderEntry; |
|
352 |
|
353 for (TInt current = 0; current <count; current++) |
|
354 { |
|
355 iMsvEntry->SetEntryL(selection->At(current)); |
|
356 folderEntry = iMsvEntry->Entry(); |
|
357 |
|
358 if (folderEntry.iMtm == KUidMtmWapPush && folderEntry.iType == KUidMsvFolderEntry) |
|
359 { |
|
360 // if (iMsvEntry->Entry().ReadOnly()) |
|
361 // { |
|
362 // iMsvEntry->Entry().SetReadOnly(False); |
|
363 // iMsvEntry->ChangeL(iMsvEntry->Entry().Id()); |
|
364 // } |
|
365 iMsvEntry->SetEntryL(KMsvLocalServiceIndexEntryId); |
|
366 iMsvEntry->DeleteL(folderEntry.Id()); |
|
367 } |
|
368 } |
|
369 CleanupStack::PopAndDestroy(); |
|
370 } |