profilesservices/ProfileEngine/WrapperSrc/CProEngProfileImpl.cpp
changeset 0 8c5d936e5675
child 8 f62c3a3d66b8
child 18 e3554c9069b6
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 CProEngProfileImpl.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CProEngProfileImpl.h"
       
    22 #include    "CProEngProfileNameImpl.h"
       
    23 #include    "CProEngTonesImpl.h"
       
    24 #include    "CProEngToneSettingsImpl.h"
       
    25 #include    "CProEngEngineImpl.h"
       
    26 #include    "MProfileExtended.h"
       
    27 #include    "MProfileEngineExtended.h"
       
    28 #include    "MProfileSetTones.h"
       
    29 #include    "MProfileExtended.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CProEngProfileImpl::CProEngProfileImpl
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CProEngProfileImpl::CProEngProfileImpl( CProEngEngineImpl& aProfileEngine,
       
    38                                         MProfileExtended* aProfile )
       
    39     : iProfileEngine( aProfileEngine ), iProfile( aProfile )
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CProEngProfileImpl::ConstructL
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 void CProEngProfileImpl::ConstructL()
       
    48     {
       
    49     TUint32 flags = iProfile->ModifiableFlags();
       
    50     iProfileName = CProEngProfileNameImpl::NewL(
       
    51             iProfile->ProfileName(),
       
    52             iProfile->ProfileSetName(),
       
    53             iProfileEngine,
       
    54             flags & EProfileFlagProfileName );
       
    55     iTones = CProEngTonesImpl::NewL( 
       
    56             iProfile->ProfileTones(),
       
    57             iProfile->ProfileSetTones(),
       
    58             iProfile->ProfileExtraTones(),
       
    59             iProfile->ProfileSetExtraTones(),
       
    60             flags );
       
    61     iToneSettings = CProEngToneSettingsImpl::NewL(
       
    62             iProfile->ProfileSetTones().SetToneSettings(),
       
    63             flags );
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CProEngProfileImpl::NewL
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CProEngProfileImpl* CProEngProfileImpl::NewL(
       
    72         CProEngEngineImpl& aProfileEngine,
       
    73         MProfileExtended* aProfile )
       
    74     {
       
    75     CProEngProfileImpl* self = new ( ELeave ) CProEngProfileImpl(
       
    76             aProfileEngine, aProfile );
       
    77 
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL();
       
    80     CleanupStack::Pop( self );
       
    81 
       
    82     return self;
       
    83     }
       
    84 
       
    85 // Destructor
       
    86 CProEngProfileImpl::~CProEngProfileImpl()
       
    87     {
       
    88     delete iToneSettings;
       
    89     delete iTones;
       
    90     delete iProfileName;
       
    91     if( iProfile )
       
    92         {
       
    93         iProfile->Release();
       
    94         }
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CProEngProfileImpl::Release
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CProEngProfileImpl::Release()
       
   102     {
       
   103     delete this;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CProEngProfileImpl::AlertForL
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 const TArray<TContactItemId> CProEngProfileImpl::AlertForL()
       
   111     {
       
   112     return iProfile->AlertForL();
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CProEngProfileImpl::SetAlertForL
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TInt CProEngProfileImpl::SetAlertForL( const TArray<TContactItemId>& aAlertFor )
       
   120     {
       
   121     TRAPD( err, iProfile->SetAlertForL( aAlertFor ) );
       
   122     if( err == KErrArgument )
       
   123         {
       
   124         return err;
       
   125         }
       
   126 
       
   127     User::LeaveIfError( err );
       
   128 
       
   129     return KErrNone;
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CProEngProfileImpl::IsSilent
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 TBool CProEngProfileImpl::IsSilent() const
       
   137     {
       
   138     return iProfile->IsSilent();
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CProEngProfileImpl::ProfileName
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 MProEngProfileName& CProEngProfileImpl::ProfileName() const
       
   146     {
       
   147     return *iProfileName;
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CProEngProfileImpl::ProfileTones
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 MProEngTones& CProEngProfileImpl::ProfileTones() const
       
   155     {
       
   156     return *iTones;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CProEngProfileImpl::ToneSettings
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 MProEngToneSettings& CProEngProfileImpl::ToneSettings() const
       
   164     {
       
   165     return *iToneSettings;
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CProEngProfileImpl::CommitChangeL
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CProEngProfileImpl::CommitChangeL()
       
   173     {
       
   174     if( iProfileName->AlreadyExistsL( iProfileName->Name() ) )
       
   175         {
       
   176         User::Leave( KErrAlreadyExists );
       
   177         }
       
   178 
       
   179     User::LeaveIfError( iTones->CheckTonesL( iProfileEngine.ToneHandler() ) );
       
   180 
       
   181     // Read the current tones of this profile for automated content removal
       
   182     CProEngProfileImpl* current =
       
   183         iProfileEngine.ProfilePrivateLC( iProfileName->Id() );
       
   184 
       
   185     // Read the current settings (as internal interface) for roll back in case
       
   186     // HandleAutomatedContentL() fails:
       
   187     MProfileExtended* currentInternal =
       
   188         iProfileEngine.ProfileEngineExtended().ProfileLC( iProfileName->Id() );
       
   189 
       
   190     iProfileEngine.ProfileEngineExtended().CommitChangeL( *iProfile );
       
   191 
       
   192     TInt err( iTones->HandleAutomatedContent( iProfileEngine.ToneHandler(),
       
   193                                               *( current->iTones ) ) );
       
   194     if( err )
       
   195         { // Roll back the original settings:
       
   196         iProfileEngine.ProfileEngineExtended().CommitChangeL(
       
   197                 *currentInternal );
       
   198         }
       
   199 
       
   200     CleanupStack::PopAndDestroy( 2 ); // currentInternal, current
       
   201     }
       
   202 
       
   203 //  End of File
       
   204