pushmtm/MtmUtilSrc/PushMtmUtil.cpp
changeset 32 92a061761a7b
parent 0 84ad3b177aa3
equal deleted inserted replaced
31:868cceedabd3 32:92a061761a7b
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 
    21 
    22 #include "PushMtmUtil.h"
    22 #include "PushMtmUtil.h"
    23 #include "PushMtmUtilPanic.h"
    23 #include "PushMtmUtilPanic.h"
    24 #include "PushMtmLog.h"
    24 #include "PushMtmLog.h"
    25 #include <CSIPushMsgEntry.h>
    25 #include <push/CSIPushMsgEntry.h>
    26 #include <CSLPushMsgEntry.h>
    26 #include <push/CSLPushMsgEntry.h>
    27 #include <msvids.h>
    27 #include <msvids.h>
    28 #include <msvuids.h>
    28 #include <msvuids.h>
    29 #include <msvapi.h>
    29 #include <msvapi.h>
    30 #include <Uri16.h>
    30 #include <Uri16.h>
    31 #include <UriUtils.h>
    31 #include <UriUtils.h>
    55 
    55 
    56 // ---------------------------------------------------------
    56 // ---------------------------------------------------------
    57 // CPushMtmUtil::MarkServiceUnreadL
    57 // CPushMtmUtil::MarkServiceUnreadL
    58 // ---------------------------------------------------------
    58 // ---------------------------------------------------------
    59 //
    59 //
    60 EXPORT_C void CPushMtmUtil::MarkServiceUnreadL( TMsvId aEntryId, 
    60 EXPORT_C void CPushMtmUtil::MarkServiceUnreadL( TMsvId aEntryId,
    61                                                 TBool aUnread )
    61                                                 TBool aUnread )
    62     {
    62     {
    63     PUSHLOG_ENTERFN("CPushMtmUtil::MarkServiceUnreadL")
    63     PUSHLOG_ENTERFN("CPushMtmUtil::MarkServiceUnreadL")
    64 
    64 
    65     CMsvEntry* cEntry = iMsvSession.GetEntryL( aEntryId );
    65     CMsvEntry* cEntry = iMsvSession.GetEntryL( aEntryId );
    82 // ---------------------------------------------------------
    82 // ---------------------------------------------------------
    83 // CPushMtmUtil::FindMessagesL
    83 // CPushMtmUtil::FindMessagesL
    84 // ---------------------------------------------------------
    84 // ---------------------------------------------------------
    85 //
    85 //
    86 EXPORT_C CMsvEntrySelection* CPushMtmUtil::FindMessagesL
    86 EXPORT_C CMsvEntrySelection* CPushMtmUtil::FindMessagesL
    87                                                ( TMsvId aFolderId, 
    87                                                ( TMsvId aFolderId,
    88                                                  TUid aMsgType, 
    88                                                  TUid aMsgType,
    89                                                  TBool aRecursive )
    89                                                  TBool aRecursive )
    90     {
    90     {
    91     CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection;
    91     CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection;
    92     CleanupStack::PushL( sel );
    92     CleanupStack::PushL( sel );
    93 
    93 
   136 // CPushMtmUtil::FindPushFoldersL
   136 // CPushMtmUtil::FindPushFoldersL
   137 // ---------------------------------------------------------
   137 // ---------------------------------------------------------
   138 //
   138 //
   139 EXPORT_C CMsvEntrySelection* CPushMtmUtil::FindPushFoldersL()
   139 EXPORT_C CMsvEntrySelection* CPushMtmUtil::FindPushFoldersL()
   140     {
   140     {
   141     // Only the Inbox, the Documents folder and the user 
   141     // Only the Inbox, the Documents folder and the user
   142     // defined folders can contain push messages.
   142     // defined folders can contain push messages.
   143     // The user defined folders can only be in the Documents folder.
   143     // The user defined folders can only be in the Documents folder.
   144     // (See the definition of CMsgFolderSelectionListArray::ConstructL 
   144     // (See the definition of CMsgFolderSelectionListArray::ConstructL
   145     // in msgavkon for more details.)
   145     // in msgavkon for more details.)
   146     CMsvEntrySelection* pushFolders = new (ELeave) CMsvEntrySelection;
   146     CMsvEntrySelection* pushFolders = new (ELeave) CMsvEntrySelection;
   147     CleanupStack::PushL( pushFolders );
   147     CleanupStack::PushL( pushFolders );
   148 
   148 
   149     // Check if Inbox folder exists.
   149     // Check if Inbox folder exists.
   170             ( KMsvGroupByType, EMsvSortByDescription, ETrue );
   170             ( KMsvGroupByType, EMsvSortByDescription, ETrue );
   171         CMsvEntry* documentsFolder = CMsvEntry::NewL
   171         CMsvEntry* documentsFolder = CMsvEntry::NewL
   172             ( iMsvSession, KDocumentsIndexEntryId, selOrd );
   172             ( iMsvSession, KDocumentsIndexEntryId, selOrd );
   173         CleanupStack::PushL( documentsFolder );
   173         CleanupStack::PushL( documentsFolder );
   174 
   174 
   175         CMsvEntrySelection* userDefFolders = 
   175         CMsvEntrySelection* userDefFolders =
   176             documentsFolder->ChildrenWithTypeL( KUidMsvFolderEntry );
   176             documentsFolder->ChildrenWithTypeL( KUidMsvFolderEntry );
   177         CleanupStack::PopAndDestroy(); // documentsFolder
   177         CleanupStack::PopAndDestroy(); // documentsFolder
   178         CleanupStack::PushL( userDefFolders );
   178         CleanupStack::PushL( userDefFolders );
   179 
   179 
   180         const TMsvId KTemplatesIndexEntryId( 0x1009 );
   180         const TMsvId KTemplatesIndexEntryId( 0x1009 );
   181         const TInt count( userDefFolders->Count() );
   181         const TInt count( userDefFolders->Count() );
   182         for ( TInt i = 0; i < count; ++i )
   182         for ( TInt i = 0; i < count; ++i )
   183             {
   183             {
   184             // However Templates folder is in Documents, no messages 
   184             // However Templates folder is in Documents, no messages
   185             // can be moved there - it cannot contain push messages.
   185             // can be moved there - it cannot contain push messages.
   186             if ( userDefFolders->At( i ) != KTemplatesIndexEntryId )
   186             if ( userDefFolders->At( i ) != KTemplatesIndexEntryId )
   187                 {
   187                 {
   188                 pushFolders->AppendL( userDefFolders->At( i ) );
   188                 pushFolders->AppendL( userDefFolders->At( i ) );
   189                 }
   189                 }
   202 //
   202 //
   203 EXPORT_C CMsvEntrySelection* CPushMtmUtil::FindSiIdLC( const TDesC& aSiId )
   203 EXPORT_C CMsvEntrySelection* CPushMtmUtil::FindSiIdLC( const TDesC& aSiId )
   204     {
   204     {
   205 	CMsvEntrySelection* matching = new (ELeave) CMsvEntrySelection;
   205 	CMsvEntrySelection* matching = new (ELeave) CMsvEntrySelection;
   206 	CleanupStack::PushL( matching );
   206 	CleanupStack::PushL( matching );
   207 	
   207 
   208 	CSIPushMsgEntry* siEntry = CSIPushMsgEntry::NewL();
   208 	CSIPushMsgEntry* siEntry = CSIPushMsgEntry::NewL();
   209 	CleanupStack::PushL( siEntry );
   209 	CleanupStack::PushL( siEntry );
   210 
   210 
   211     CMsvEntrySelection* allSi = FindMessagesL( KUidWapPushMsgSI );
   211     CMsvEntrySelection* allSi = FindMessagesL( KUidWapPushMsgSI );
   212     CleanupStack::PushL( allSi );
   212     CleanupStack::PushL( allSi );
   229 
   229 
   230 // ---------------------------------------------------------
   230 // ---------------------------------------------------------
   231 // CPushMtmUtil::FindUrlLC
   231 // CPushMtmUtil::FindUrlLC
   232 // ---------------------------------------------------------
   232 // ---------------------------------------------------------
   233 //
   233 //
   234 EXPORT_C CMsvEntrySelection* CPushMtmUtil::FindUrlLC( const TDesC& aUrl, 
   234 EXPORT_C CMsvEntrySelection* CPushMtmUtil::FindUrlLC( const TDesC& aUrl,
   235                                                       TUid aPushType )
   235                                                       TUid aPushType )
   236 	{
   236 	{
   237     __ASSERT_ALWAYS( aPushType == KUidWapPushMsgSI || 
   237     __ASSERT_ALWAYS( aPushType == KUidWapPushMsgSI ||
   238                      aPushType == KUidWapPushMsgSL, 
   238                      aPushType == KUidWapPushMsgSL,
   239                      UtilPanic( EPushMtmUtilPanBadBioType ) );
   239                      UtilPanic( EPushMtmUtilPanBadBioType ) );
   240 
   240 
   241 	CMsvEntrySelection* matching = new (ELeave) CMsvEntrySelection;
   241 	CMsvEntrySelection* matching = new (ELeave) CMsvEntrySelection;
   242 	CleanupStack::PushL( matching );
   242 	CleanupStack::PushL( matching );
   243 	
   243 
   244     CMsvEntrySelection* all = FindMessagesL( aPushType );
   244     CMsvEntrySelection* all = FindMessagesL( aPushType );
   245     CleanupStack::PushL( all );
   245     CleanupStack::PushL( all );
   246 
   246 
   247 	// loop until we find a match or reach the end of the SI entries
   247 	// loop until we find a match or reach the end of the SI entries
   248     const TInt numEntries( all->Count() );
   248     const TInt numEntries( all->Count() );
   330 // CPushMtmUtil::SetAttrs
   330 // CPushMtmUtil::SetAttrs
   331 // ---------------------------------------------------------
   331 // ---------------------------------------------------------
   332 //
   332 //
   333 EXPORT_C void CPushMtmUtil::SetAttrs( TMsvEntry& aContext, TUint32 aAttrs )
   333 EXPORT_C void CPushMtmUtil::SetAttrs( TMsvEntry& aContext, TUint32 aAttrs )
   334     {
   334     {
   335     aContext.iMtmData2 = aContext.iMtmData2 | 
   335     aContext.iMtmData2 = aContext.iMtmData2 |
   336                          (aAttrs<<KPushMtmShiftOnlyAttrs);
   336                          (aAttrs<<KPushMtmShiftOnlyAttrs);
   337     }
   337     }
   338 
   338 
   339 // ---------------------------------------------------------
   339 // ---------------------------------------------------------
   340 // CPushMtmUtil::ResetAttrs
   340 // CPushMtmUtil::ResetAttrs
   341 // ---------------------------------------------------------
   341 // ---------------------------------------------------------
   342 //
   342 //
   343 EXPORT_C void CPushMtmUtil::ResetAttrs( TMsvEntry& aContext, TUint32 aAttrs )
   343 EXPORT_C void CPushMtmUtil::ResetAttrs( TMsvEntry& aContext, TUint32 aAttrs )
   344     {
   344     {
   345     aContext.iMtmData2 = aContext.iMtmData2 & 
   345     aContext.iMtmData2 = aContext.iMtmData2 &
   346                          ~(aAttrs<<KPushMtmShiftOnlyAttrs);
   346                          ~(aAttrs<<KPushMtmShiftOnlyAttrs);
   347     }
   347     }
   348 
   348 
   349 // ---------------------------------------------------------
   349 // ---------------------------------------------------------
   350 // CPushMtmUtil::Attrs
   350 // CPushMtmUtil::Attrs
   351 // ---------------------------------------------------------
   351 // ---------------------------------------------------------
   352 //
   352 //
   353 EXPORT_C TUint32 CPushMtmUtil::Attrs( const TMsvEntry& aContext )
   353 EXPORT_C TUint32 CPushMtmUtil::Attrs( const TMsvEntry& aContext )
   354     {
   354     {
   355     return (aContext.iMtmData2 >> KPushMtmShiftOnlyAttrs) & 
   355     return (aContext.iMtmData2 >> KPushMtmShiftOnlyAttrs) &
   356            KPushMtmMaskOnlyAttrs;
   356            KPushMtmMaskOnlyAttrs;
   357     }
   357     }
   358 
   358 
   359 // ---------------------------------------------------------
   359 // ---------------------------------------------------------
   360 // CPushMtmUtil::ConvertUriToDisplayFormL
   360 // CPushMtmUtil::ConvertUriToDisplayFormL
   376 
   376 
   377 // ---------------------------------------------------------
   377 // ---------------------------------------------------------
   378 // CPushMtmUtil::CPushMtmUtil
   378 // CPushMtmUtil::CPushMtmUtil
   379 // ---------------------------------------------------------
   379 // ---------------------------------------------------------
   380 //
   380 //
   381 CPushMtmUtil::CPushMtmUtil( CMsvSession& aMsvSession ) 
   381 CPushMtmUtil::CPushMtmUtil( CMsvSession& aMsvSession )
   382 : iMsvSession( aMsvSession )
   382 : iMsvSession( aMsvSession )
   383     {
   383     {
   384     }
   384     }
   385 
   385 
   386 // ---------------------------------------------------------
   386 // ---------------------------------------------------------
   393 
   393 
   394 // ---------------------------------------------------------
   394 // ---------------------------------------------------------
   395 // CPushMtmUtil::FindMessagesL
   395 // CPushMtmUtil::FindMessagesL
   396 // ---------------------------------------------------------
   396 // ---------------------------------------------------------
   397 //
   397 //
   398 void CPushMtmUtil::FindMessagesL( TMsvId aFolderId, 
   398 void CPushMtmUtil::FindMessagesL( TMsvId aFolderId,
   399                                   TUid aMsgType, 
   399                                   TUid aMsgType,
   400                                   TBool aRecursive, 
   400                                   TBool aRecursive,
   401                                   CMsvEntrySelection& aResult )
   401                                   CMsvEntrySelection& aResult )
   402     {
   402     {
   403     // Find the push entries of the specified type in the specified folder.
   403     // Find the push entries of the specified type in the specified folder.
   404     CMsvEntry* thisFolder = iMsvSession.GetEntryL( aFolderId );
   404     CMsvEntry* thisFolder = iMsvSession.GetEntryL( aFolderId );
   405     CleanupStack::PushL( thisFolder );
   405     CleanupStack::PushL( thisFolder );
   440     CleanupStack::PopAndDestroy( msgSel ); // msgSel
   440     CleanupStack::PopAndDestroy( msgSel ); // msgSel
   441 
   441 
   442     // Find messages in the subfolders if required.
   442     // Find messages in the subfolders if required.
   443     if ( aRecursive )
   443     if ( aRecursive )
   444         {
   444         {
   445         CMsvEntrySelection* subFolders = 
   445         CMsvEntrySelection* subFolders =
   446             thisFolder->ChildrenWithTypeL( KUidMsvFolderEntry );
   446             thisFolder->ChildrenWithTypeL( KUidMsvFolderEntry );
   447         CleanupStack::PushL( subFolders );
   447         CleanupStack::PushL( subFolders );
   448 
   448 
   449         const TInt count( subFolders->Count() );
   449         const TInt count( subFolders->Count() );
   450         for ( TInt i = 0; i < count; ++i )
   450         for ( TInt i = 0; i < count; ++i )