messagingfw/wappushfw/PushMsgEntry/src/CWapPushMsgUtils.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     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 //
       
    15 
       
    16 #include <smut.h>
       
    17 #include <msvstd.h>
       
    18 #include <msventry.h>
       
    19 #include <msvids.h>
       
    20 #include <msvuids.h>
       
    21 #include <watcher.h>
       
    22 #include <pushentry.h>
       
    23 
       
    24 #include <push/pushlog.h>
       
    25 #include <push/cwappushmsgutils.h>
       
    26 
       
    27 EXPORT_C CWapPushMsgUtils* CWapPushMsgUtils::NewL()
       
    28 /**
       
    29 Allocates and constructs a new Wap Push Message Utility object.
       
    30 
       
    31 @return 
       
    32 New Wap Push Message Utility object.
       
    33 
       
    34 @leave CWapPushMsgUtils::ConstructL
       
    35 
       
    36 */
       
    37 	{
       
    38 	CWapPushMsgUtils* self = new (ELeave) CWapPushMsgUtils();
       
    39 	CleanupStack::PushL(self);
       
    40 	self->ConstructL();
       
    41 	CleanupStack::Pop();
       
    42 	return self;
       
    43 	}
       
    44 
       
    45 
       
    46 EXPORT_C CWapPushMsgUtils::CWapPushMsgUtils()
       
    47 	:iPushServiceId(KMsvNullIndexEntryId), iPushFolderId(KMsvNullIndexEntryId)
       
    48 /**
       
    49 Constructor.  
       
    50 */
       
    51 	{
       
    52 	}
       
    53 
       
    54 
       
    55 EXPORT_C void CWapPushMsgUtils::ConstructL()
       
    56 /**
       
    57 Second stage constructor. Creates CMsvSession and CMsvEntry.   
       
    58 
       
    59 @leave CMsvSession::OpenSyncL
       
    60 @leave CMsvSession::GetEntryL
       
    61 @leave CMsvSession::SetSortTypeL
       
    62 
       
    63 */
       
    64 	{
       
    65 	iMsvSession = CMsvSession::OpenSyncL(*this);
       
    66 	iMsvEntry = iMsvSession->GetEntryL(KMsvRootIndexEntryId);
       
    67 	
       
    68 	// Ensure that our CMsvEntry can always see invisible entries
       
    69 	TMsvSelectionOrdering sort;
       
    70 	sort.SetShowInvisibleEntries(ETrue);
       
    71 	iMsvEntry->SetSortTypeL(sort);
       
    72 	}
       
    73 
       
    74 
       
    75 EXPORT_C CWapPushMsgUtils::~CWapPushMsgUtils()
       
    76 /**
       
    77 Destructor.
       
    78 */
       
    79 	{
       
    80 	delete iMsvEntry;
       
    81 	delete iMsvSession;
       
    82 	}
       
    83 
       
    84 
       
    85 EXPORT_C void CWapPushMsgUtils::GetServiceIdL(TUid aMtm, TMsvId& aServiceId)
       
    86 /**
       
    87 Gets the Id of the Push Message Service Entry. 
       
    88 
       
    89 If there is no service entry then KMsvNullIndexEntry is returned. 
       
    90  
       
    91 @param aMtm 
       
    92 MTM type of the required service entry
       
    93 
       
    94 @param aServiceId 
       
    95 Id of the service entry
       
    96 */
       
    97 	{
       
    98 	//Returns the Service IDs of MTM aMtm
       
    99 	
       
   100 	if (iPushServiceId != KMsvNullIndexEntryId)
       
   101 		{
       
   102 		aServiceId = iPushServiceId;
       
   103 		return;
       
   104 		}
       
   105 
       
   106 	aServiceId = KMsvNullIndexEntryId;
       
   107 
       
   108 	iMsvEntry->SetEntryL(KMsvRootIndexEntryId);
       
   109 
       
   110 	//Get the children on the Root Index Entry
       
   111 	CMsvEntrySelection* selection = iMsvEntry->ChildrenWithTypeL(KUidMsvServiceEntry);
       
   112 	CleanupStack::PushL(selection);
       
   113 
       
   114 	TInt count = selection->Count();
       
   115 
       
   116 	//Find an entry for MTM aMtm
       
   117 	for (TInt curChild = 0; curChild < count && (aServiceId == KMsvNullIndexEntryId ); curChild++)
       
   118 		{
       
   119 		iMsvEntry->SetEntryL(selection->At(curChild));
       
   120 
       
   121 		if (iMsvEntry->Entry().iMtm == aMtm)
       
   122 			{
       
   123 			TMsvId id = iMsvEntry->Entry().Id();
       
   124 
       
   125 			if (aServiceId == KMsvNullIndexEntryId)
       
   126 				aServiceId = id;
       
   127 			}
       
   128 		}
       
   129 	iMsvEntry->SetEntryL(KMsvRootIndexEntryId);//Point our entry to something safe
       
   130 
       
   131 	//If the service Id is not set and we're not doing not self assignment store the ID
       
   132 	if (aServiceId != KMsvNullIndexEntryId && (&iPushServiceId != &aServiceId) ) 
       
   133 		iPushServiceId = aServiceId;  
       
   134 	CleanupStack::PopAndDestroy(); //selection
       
   135 	}
       
   136