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