mmsengine/mmsserversettings/src/mmsmessagestoreutils.cpp
changeset 0 72b543305e3a
child 23 238255e8b033
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2004-2006 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:  mmsmessagestoreutils implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19    
       
    20 // INCLUDE FILES   
       
    21 #include <msvids.h>
       
    22 #include <msvapi.h>
       
    23 
       
    24 // USERINCLUDE FILES
       
    25 #include "mmsmessagestoreutils.h"
       
    26 #include "mmsdebuglogging.h"
       
    27 
       
    28 // EXTERNAL DATA STRUCTURES
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 // MACROS
       
    35 
       
    36 // LOCAL CONSTANTS AND MACROS
       
    37 
       
    38 // MODULE DATA STRUCTURES
       
    39 
       
    40 // LOCAL FUNCTION PROTOTYPES
       
    41 
       
    42 // ============================== LOCAL FUNCTIONS ==============================
       
    43 
       
    44 // ============================== MEMBER FUNCTIONS =============================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CMmsMessageStoreUtils::CMmsMessageStoreUtils
       
    48 // C++ default constructor can NOT contain any code, that
       
    49 // might leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CMmsMessageStoreUtils::CMmsMessageStoreUtils()   
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CMmsMessageStoreUtils::ConstructL
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CMmsMessageStoreUtils::ConstructL( CMsvSession& aSession )
       
    62     {
       
    63     LOG(_L("CMmsMessageStoreUtils::ConstructL"));
       
    64     iSession = &aSession;
       
    65     iParentEntry = iSession->GetEntryL( KMsvRootIndexEntryId );
       
    66     iMmsEntry = iSession->GetEntryL( KMsvRootIndexEntryId );
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CMmsMessageStoreUtils::NewL
       
    71 // Two-phased constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C CMmsMessageStoreUtils* CMmsMessageStoreUtils::NewL( CMsvSession& aSession )
       
    75     {
       
    76     CMmsMessageStoreUtils* self = new ( ELeave ) CMmsMessageStoreUtils;
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL( aSession );
       
    79     CleanupStack::Pop( self );
       
    80     return self;
       
    81     }
       
    82     
       
    83 // -----------------------------------------------------------------------------
       
    84 // Destructor
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CMmsMessageStoreUtils::~CMmsMessageStoreUtils()
       
    88     {
       
    89     LOG(_L("~CMmsMessageStoreUtils"));
       
    90     // iSession is not owned by CMmsMessageStoreUtils
       
    91     delete iParentEntry;
       
    92     delete iMmsEntry;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CreateServiceEntryL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 TMsvId CMmsMessageStoreUtils::CreateServiceEntryL()
       
   100     {
       
   101     LOG(_L("CMmsMessageStoreUtils::CreateServiceEntryL"));
       
   102 
       
   103     //
       
   104     // Find old MMS entries
       
   105     //
       
   106     iParentEntry->SetEntryL( KMsvRootIndexEntryId );
       
   107     // Find also invisible entries
       
   108     iParentEntry->SetSortTypeL( TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) );
       
   109     CMsvEntrySelection* selection = iParentEntry->ChildrenWithMtmL( KUidMsgTypeMultimedia );
       
   110     CleanupStack::PushL( selection ); // ***
       
   111     TInt count = selection->Count();
       
   112     LOG2(_L("- found %d MMS entries"), count );
       
   113 
       
   114     //
       
   115     // Concentrate on service entries
       
   116     //
       
   117     TMsvEntry tEntry;
       
   118     for( TInt index = count-1; index >= 0; index-- )
       
   119         {
       
   120         iMmsEntry->SetEntryL( selection->At( index ) );
       
   121         tEntry = iMmsEntry->Entry();
       
   122         if( tEntry.iType != KUidMsvServiceEntry )
       
   123             {
       
   124             // Take out from selection
       
   125             selection->Delete( index );
       
   126             }
       
   127         }
       
   128     count = selection->Count();
       
   129     LOG2(_L("- found %d MMS service entries"), count );
       
   130     
       
   131     //
       
   132     // Handle entry depending on number of already existing entries
       
   133     //
       
   134     TMsvId id = KMsvNullIndexEntryId;
       
   135     if( count == 0 ) // no service before
       
   136         {
       
   137         tEntry.iType = KUidMsvServiceEntry;
       
   138         tEntry.iMtm = KUidMsgTypeMultimedia;
       
   139         tEntry.iDetails.Set( KMmsDefaultServiceName ); 
       
   140         tEntry.SetVisible( EFalse );
       
   141         tEntry.SetInPreparation( EFalse );
       
   142         iParentEntry->CreateL( tEntry );
       
   143         id = tEntry.Id();        
       
   144         } 
       
   145     else // At least one service found
       
   146         {
       
   147         for( TInt index = 1; index < count; index++ )
       
   148             {
       
   149             // More than 1 service found -> delete them
       
   150             // The error must be ignored because there is nothing we can do
       
   151             // if we can't delete the extra services
       
   152 #ifdef _DEBUG
       
   153             TRAPD( error, iParentEntry->DeleteL( selection->At( index ) ) );
       
   154             LOG3(_L("- deletion of service %d returned error %d "), selection->At( index ), error );
       
   155 #else
       
   156             TRAP_IGNORE( iParentEntry->DeleteL( selection->At( index ) ) );
       
   157 #endif            
       
   158             }
       
   159         id = selection->At( 0 );
       
   160         }
       
   161         
       
   162     //
       
   163     // Return new service entry id
       
   164     //
       
   165     CleanupStack::PopAndDestroy( selection );
       
   166     return id;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CreateFolderEntryL
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TMsvId CMmsMessageStoreUtils::CreateFolderEntryL( const TDesC& aFolderName )
       
   174     {
       
   175     LOG(_L("CMmsMessageStoreUtils::CreateFolderEntryL"));
       
   176 
       
   177     //
       
   178     // Find old MMS entries
       
   179     //
       
   180     iParentEntry->SetEntryL( KMsvLocalServiceIndexEntryId );
       
   181     // Find also invisible entries
       
   182     iParentEntry->SetSortTypeL( TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) );
       
   183     CMsvEntrySelection* selection = iParentEntry->ChildrenWithTypeL( KUidMsvFolderEntry );
       
   184     CleanupStack::PushL( selection ); // ***
       
   185     TInt count = selection->Count();
       
   186     LOG2(_L("- found %d folder entries under localservice"), count );
       
   187 
       
   188     //
       
   189     // Concentrate on folders that have name 'aFolderName'
       
   190     //
       
   191     TMsvEntry tEntry;
       
   192     for( TInt index = count-1; index >= 0; index-- )
       
   193         {
       
   194         iMmsEntry->SetEntryL( selection->At( index ) );
       
   195         tEntry = iMmsEntry->Entry();
       
   196         if( tEntry.iDetails.Compare( aFolderName ) != 0 )
       
   197             {
       
   198             // Take out from selection
       
   199             selection->Delete( index );            
       
   200             }
       
   201         }
       
   202     count = selection->Count();
       
   203     LOG2(_L("- found %d folders with matching iDetails"), count );
       
   204     
       
   205     //
       
   206     // Handle entry depending on number of already existing entries
       
   207     //
       
   208     TMsvId id = KMsvNullIndexEntryId;
       
   209     if( count == 0 ) // no folder before
       
   210         {
       
   211         tEntry.iType = KUidMsvFolderEntry;
       
   212         tEntry.iMtm = KUidMsvLocalServiceMtm;
       
   213         tEntry.iDetails.Set( aFolderName );
       
   214         tEntry.SetVisible( EFalse );
       
   215         tEntry.SetInPreparation( EFalse );
       
   216         tEntry.iServiceId = KMsvLocalServiceIndexEntryId;
       
   217         iParentEntry->CreateL( tEntry );
       
   218         id = tEntry.Id();        
       
   219         } 
       
   220     else // At least one folder found
       
   221         {
       
   222         for( TInt index = 1; index < count; index++ )
       
   223             {
       
   224             // More than 1 folder found -> delete them
       
   225             // The error must be ignored because there is nothing we can do
       
   226             // if we can't delete the extra folders
       
   227 #ifdef _DEBUG
       
   228             TRAPD( error, iParentEntry->DeleteL( selection->At( index ) ) );
       
   229             LOG3(_L("- deletion of folder %d returned error %d "), selection->At( index ), error );
       
   230 #else
       
   231             TRAP_IGNORE( iParentEntry->DeleteL( selection->At( index ) ) );
       
   232 #endif            
       
   233             }
       
   234         id = selection->At( 0 );
       
   235         }
       
   236         
       
   237     //
       
   238     // Return new service entry id
       
   239     //
       
   240     CleanupStack::PopAndDestroy( selection );
       
   241     return id;
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CreateFolderEntryL
       
   246 //
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 TInt CMmsMessageStoreUtils::CreateFolderEntryL(
       
   250     TMsvId aParentFolder, const TDesC& aFolderName, TMsvId& aFolderId )
       
   251     {
       
   252     
       
   253     // Check if the folder already exists under parent folder.
       
   254     aFolderId = FolderEntryL( aParentFolder, aFolderName );    
       
   255     if ( aFolderId != KMsvNullIndexEntryId )
       
   256         {
       
   257          return KErrAlreadyExists;   
       
   258         }
       
   259       
       
   260     // Create a new folder.
       
   261     iMmsEntry->SetEntryL( aParentFolder );
       
   262 
       
   263     TMsvEntry entry;
       
   264     entry.iType = KUidMsvFolderEntry;
       
   265     entry.iMtm = KUidMsvLocalServiceMtm;
       
   266     entry.iDetails.Set( aFolderName );
       
   267     entry.SetVisible( EFalse );
       
   268     entry.SetInPreparation( EFalse );
       
   269     entry.iServiceId = KMsvLocalServiceIndexEntryId;
       
   270     iMmsEntry->CreateL( entry );    
       
   271     aFolderId = entry.Id();    
       
   272     return KErrNone;
       
   273        
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // FolderEntryL
       
   278 //
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 TMsvId CMmsMessageStoreUtils::FolderEntryL( TMsvId aParentFolder, const TDesC& aFolderName )
       
   282     {
       
   283     
       
   284     TMsvId folderId = KMsvNullIndexEntryId;
       
   285      
       
   286     iMmsEntry->SetEntryL( aParentFolder );
       
   287 
       
   288     // Show invisible entries
       
   289     iMmsEntry->SetSortTypeL( TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByIdReverse, ETrue ) );
       
   290     CMsvEntrySelection* selection = iMmsEntry->ChildrenWithTypeL( KUidMsvFolderEntry );
       
   291     CleanupStack::PushL( selection );
       
   292 
       
   293     // If selection contains folders, check if the folder is found.
       
   294     TInt count = selection->Count();
       
   295     for ( TInt i = 0; i < count && folderId == KMsvNullIndexEntryId; i++ )
       
   296         {
       
   297         iMmsEntry->SetEntryL( selection->At( i ) );
       
   298         // must be exact match
       
   299         if ( iMmsEntry->Entry().iDetails.Compare( aFolderName ) == 0 )
       
   300             {
       
   301             folderId = selection->At( i );
       
   302             }
       
   303         }
       
   304     CleanupStack::PopAndDestroy( selection );
       
   305     
       
   306     return folderId;
       
   307        
       
   308     }
       
   309         
       
   310 
       
   311 // =========================== OTHER EXPORTED FUNCTIONS ========================
       
   312 
       
   313 //  End of File