profilesservices/ProfileEngine/WrapperSrc/CProEngProfileNameImpl.cpp
changeset 0 8c5d936e5675
child 8 f62c3a3d66b8
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Implementation of CProEngProfileNameImpl.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CProEngProfileNameImpl.h"
       
    22 #include    <MProfileName.h>
       
    23 #include    <MProEngProfileNameArray.h>
       
    24 #include    "MProfileSetName.h"
       
    25 #include    "CProEngEngineImpl.h"
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CProEngProfileNameImpl::CProEngProfileNameImpl
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CProEngProfileNameImpl::CProEngProfileNameImpl(
       
    34         const MProfileName& aProfileName,
       
    35         MProfileSetName& aProfileSetName,
       
    36         CProEngEngineImpl& aEngine,
       
    37         TBool aModifiable )
       
    38     : iProfileName( aProfileName ), iProfileSetName( aProfileSetName ),
       
    39       iEngine( aEngine), iModifiable( aModifiable )
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CProEngProfileNameImpl::NewL
       
    45 // Two-phased constructor.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CProEngProfileNameImpl* CProEngProfileNameImpl::NewL(
       
    49         const MProfileName& aProfileName,
       
    50         MProfileSetName& aProfileSetName,
       
    51         CProEngEngineImpl& aEngine,
       
    52         TBool aModifiable )
       
    53     {
       
    54     return new ( ELeave ) CProEngProfileNameImpl(
       
    55             aProfileName, aProfileSetName, aEngine, aModifiable );
       
    56     }
       
    57 
       
    58 // Destructor
       
    59 CProEngProfileNameImpl::~CProEngProfileNameImpl()
       
    60     {
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CProEngProfileNameImpl::Id
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 TInt CProEngProfileNameImpl::Id() const
       
    68     {
       
    69     return iProfileName.Id();
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CProEngProfileNameImpl::Name
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 const TDesC& CProEngProfileNameImpl::Name() const
       
    77     {
       
    78     return iProfileName.Name();
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CProEngProfileNameImpl::SetNameL
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 TInt CProEngProfileNameImpl::SetNameL( const TDesC& aName )
       
    86     {
       
    87     if( !iModifiable )
       
    88         {
       
    89         return KErrAccessDenied;
       
    90         }
       
    91 
       
    92     if( AlreadyExistsL( aName ) )
       
    93         {
       
    94         return KErrAlreadyExists;
       
    95         }
       
    96 
       
    97     iProfileSetName.SetNameL( aName );
       
    98 
       
    99     return KErrNone;
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CProEngProfileNameImpl::AlreadyExistsL
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 TBool CProEngProfileNameImpl::AlreadyExistsL( const TDesC& aName )
       
   107     {
       
   108     MProEngProfileNameArray* existingNames( iEngine.ProfileNameArrayLC() );
       
   109     TInt result( existingNames->FindByName( aName ) );
       
   110     TInt resId( existingNames->ProfileId( result ) );
       
   111     CleanupStack::PopAndDestroy(); // existingNames
       
   112 
       
   113     return ( ( result != KErrNotFound ) && ( resId != Id() ) );
       
   114     }
       
   115 
       
   116 //  End of File
       
   117