ximpfw/core/srcdatamodel/ximpconfigurationitembase.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 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:  Configuration item base for configuration items.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ximpconfigurationitembase.h"
       
    20 #include "ximpitemparent.h"
       
    21 
       
    22 // ---------------------------------------------------------------------------
       
    23 // CXIMPConfigurationItemBase::OrderOfItems()
       
    24 // ---------------------------------------------------------------------------
       
    25 //
       
    26 TInt CXIMPConfigurationItemBase::OrderOfItems( const CXIMPConfigurationItemBase& aFirst, 
       
    27                                                const CXIMPConfigurationItemBase& aSecond )
       
    28     {
       
    29     if( &aFirst < &aSecond )
       
    30         {
       
    31         return -1;
       
    32         }
       
    33     else if( &aFirst == &aSecond )
       
    34         {
       
    35         return 0;
       
    36         }
       
    37     else
       
    38         {
       
    39         return 1;
       
    40         }
       
    41     }    
       
    42 
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CXIMPConfigurationItemBase::CXIMPConfigurationItemBase()
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C CXIMPConfigurationItemBase::CXIMPConfigurationItemBase( MXIMPItemParentBase& aParent )
       
    49 : CXIMPSubscriptionItemBase( aParent )
       
    50     {
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CXIMPConfigurationItemBase::BaseConstructL()
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C void CXIMPConfigurationItemBase::BaseConstructL()
       
    58     {
       
    59     CXIMPSubscriptionItemBase::BaseConstructL();
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CXIMPConfigurationItemBase::~CXIMPConfigurationItemBase()
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CXIMPConfigurationItemBase::~CXIMPConfigurationItemBase()
       
    67     {
       
    68     iConfigContexts.Close();
       
    69     iConfigItems.Close();
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CXIMPConfigurationItemBase::ConfigurationStatus()
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 EXPORT_C CXIMPConfigurationItemBase::TConfigurationStatus 
       
    77            CXIMPConfigurationItemBase::ConfigurationStatus( MXIMPPscContext* aContext )
       
    78     {
       
    79     // Calculate situation
       
    80     TInt count = iConfigContexts.Count() + iConfigItems.Count();
       
    81     TBool contextFound = IsContext( aContext );
       
    82     if( count == 0 )
       
    83         {
       
    84         return ENotConfiguredAtAll;
       
    85         }
       
    86     else if( contextFound )
       
    87         {
       
    88         if( count == 1 )
       
    89             {
       
    90             return EConfiguredForCtxOnly;
       
    91             }
       
    92         return EConfiguredForCtxAndOthers;
       
    93         }
       
    94     return EConfiguredForOtherCtxOnly;
       
    95     }
       
    96     
       
    97 // ---------------------------------------------------------------------------
       
    98 // CXIMPConfigurationItemBase::AddConfiguratorL()
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C void CXIMPConfigurationItemBase::AddConfiguratorL( MXIMPPscContext* aContext )
       
   102     {
       
   103     TLinearOrder< MXIMPPscContext > order( OrderOfContexts );
       
   104     if( IsContext( aContext ) )
       
   105         {
       
   106         User::Leave( KErrAlreadyExists );
       
   107         }    
       
   108     iConfigContexts.InsertInOrderL( aContext, order );
       
   109     User::LeaveIfError( Open() );
       
   110     }
       
   111     
       
   112 // ---------------------------------------------------------------------------
       
   113 // CXIMPConfigurationItemBase::RemoveConfigurator()
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 EXPORT_C void CXIMPConfigurationItemBase::RemoveConfigurator( MXIMPPscContext* aContext )
       
   117     {
       
   118     TLinearOrder< MXIMPPscContext > order( OrderOfContexts );
       
   119     TInt index = iConfigContexts.FindInOrder( aContext, order );
       
   120     if( index >= 0 )
       
   121         {
       
   122         iConfigContexts.Remove( index );
       
   123         Close();
       
   124         }
       
   125     else
       
   126         {
       
   127         iParent.UnregisterExpiringItem( this );
       
   128         }
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CXIMPConfigurationItemBase::AddConfiguratorL()
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 EXPORT_C void CXIMPConfigurationItemBase::AddConfiguratorL( CXIMPConfigurationItemBase* aItem )
       
   136     {
       
   137     TLinearOrder< CXIMPConfigurationItemBase > order( OrderOfItems );
       
   138     TInt index = iConfigItems.FindInOrder( aItem, order );    
       
   139     if( index != KErrNotFound )
       
   140         {
       
   141         return;
       
   142         }
       
   143     
       
   144     iConfigItems.InsertInOrderL( aItem, order );
       
   145     User::LeaveIfError( Open() );
       
   146     }
       
   147     
       
   148 // ---------------------------------------------------------------------------
       
   149 // CXIMPConfigurationItemBase::RemoveConfigurator()
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 EXPORT_C void CXIMPConfigurationItemBase::RemoveConfigurator( CXIMPConfigurationItemBase* aItem )
       
   153     {
       
   154     TLinearOrder< CXIMPConfigurationItemBase > order( OrderOfItems );
       
   155     TInt index = iConfigItems.FindInOrder( aItem, order );
       
   156     if( index >= 0 )
       
   157         {
       
   158         iConfigItems.Remove( index );
       
   159         Close();
       
   160         }
       
   161     else
       
   162         {
       
   163         iParent.UnregisterExpiringItem( this );
       
   164         }
       
   165     }    
       
   166     
       
   167 // ---------------------------------------------------------------------------
       
   168 // CXIMPConfigurationItemBase::IsContext()
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 EXPORT_C TBool CXIMPConfigurationItemBase::IsContext( MXIMPPscContext* aContext ) const
       
   172     {
       
   173     TLinearOrder< MXIMPPscContext > order( OrderOfContexts );    
       
   174     return iConfigContexts.FindInOrder( aContext, order ) != KErrNotFound;
       
   175     }
       
   176     
       
   177 // ---------------------------------------------------------------------------
       
   178 // CXIMPConfigurationItemBase::ForceClose()
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 EXPORT_C void CXIMPConfigurationItemBase::ForceClose()
       
   182     {
       
   183     CXIMPSubscriptionItemBase::ForceClose();
       
   184     TInt count = iConfigContexts.Count();
       
   185     for( TInt a = 0; a < count; ++a )
       
   186         {
       
   187         // RemoveSubscriber removes first one every time.
       
   188         RemoveConfigurator( iConfigContexts[ 0 ] );
       
   189         }
       
   190     count = iConfigItems.Count();
       
   191     for( TInt a = 0; a < count; ++a )
       
   192         {
       
   193         RemoveConfigurator( iConfigItems[ 0 ] );
       
   194         }
       
   195     }    
       
   196 // End of file