phoneuis/BubbleManager/Src/BMCustomManager.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Customization manager
       
    15 *
       
    16 */
       
    17 
       
    18 #include "BMCustomManager.h"
       
    19 #include "BMDefaultManager.h"
       
    20 #include "BMBubbleHeader.h"
       
    21 #include "BMPanic.h"
       
    22 
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // TArrayItem class
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 class TArrayItem
       
    29     {
       
    30 public:
       
    31     TArrayItem( 
       
    32         CTelBubbleCustomElement* aElement,
       
    33         TInt aPriority ): 
       
    34             iElement( *aElement ),
       
    35             iPriority( aPriority ) {};
       
    36         
       
    37     static TInt Compare( const TArrayItem& aFirst, const TArrayItem& aSecond )
       
    38         {
       
    39         if( aFirst.iPriority > aSecond.iPriority )
       
    40             {
       
    41             return 1;
       
    42             }
       
    43         else if( aFirst.iPriority < aSecond.iPriority )
       
    44             {
       
    45             return -1;
       
    46             }
       
    47         else
       
    48             {
       
    49             return 0;
       
    50             }
       
    51         }
       
    52 
       
    53     CTelBubbleCustomElement* Item() { return &iElement; }
       
    54 private:
       
    55     CTelBubbleCustomElement& iElement;
       
    56     TInt iPriority;
       
    57     };
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // C++ constructor
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CBubbleCustomManager::CBubbleCustomManager( CBubbleManager& aBubbleManager ) :
       
    64     iBubbleManager( aBubbleManager )
       
    65     {
       
    66     }
       
    67 
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // ConstructL
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CBubbleCustomManager::ConstructL()
       
    74     {
       
    75     // create default implementations
       
    76     iDefaultManager = CBubbleDefaultManager::NewL( iBubbleManager );
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // NewL
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 CBubbleCustomManager* CBubbleCustomManager::NewL(
       
    84     CBubbleManager& aBubbleManager )
       
    85     {
       
    86     CBubbleCustomManager* self = 
       
    87         new( ELeave ) CBubbleCustomManager( aBubbleManager );
       
    88     CleanupStack::PushL( self );
       
    89     self->ConstructL();
       
    90     CleanupStack::Pop( self );
       
    91     return self;
       
    92     }
       
    93 
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // Destructor
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 CBubbleCustomManager::~CBubbleCustomManager()
       
   100     {
       
   101     for( TInt i = 0; i < iCustomizations.Count(); i++)
       
   102         {
       
   103         for( TInt j = 0; j < iCustomizations[j].Count(); j++ )
       
   104             {
       
   105             iCustomizations[i][j].Reset();
       
   106             iCustomizations[i][j].Close();
       
   107             }
       
   108         }
       
   109     
       
   110     delete iDefaultManager;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // AddCustomElement
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CBubbleCustomManager::AddCustomElement( 
       
   118     const CBubbleManager::TBubbleId& aBubbleId,
       
   119     CTelBubbleCustomElement* aElement,
       
   120     TInt aPriority )
       
   121     {
       
   122     __ASSERT_DEBUG( aElement->Control(), Panic( EBMPanicCustomization ) ) ;
       
   123     TRAPD( err, aElement->Control()->SetContainerWindowL( iBubbleManager ) );
       
   124     
       
   125     if ( !err )
       
   126         {
       
   127         TArrayItem item( aElement, aPriority );
       
   128         iCustomizations[aBubbleId]
       
   129                        [aElement->ElementType()].InsertInOrderAllowRepeats(
       
   130             item, TLinearOrder<TArrayItem>(TArrayItem::Compare) );    
       
   131         }
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // RemoveCustomElement
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CBubbleCustomManager::RemoveCustomElement(
       
   139     const CBubbleManager::TBubbleId& aBubbleId,
       
   140     CTelBubbleCustomElement* aElement )
       
   141     {
       
   142     RArray<TArrayItem>& array = 
       
   143         iCustomizations[aBubbleId][aElement->ElementType()];
       
   144     
       
   145     for( TInt j = 0; j < array.Count(); j++ )
       
   146         {
       
   147         if( array[j].Item() == aElement )
       
   148             {
       
   149             array.Remove(j);
       
   150             return;
       
   151             }
       
   152         }
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // RemoveCustomElements
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CBubbleCustomManager::RemoveCustomElements( 
       
   160     const CBubbleManager::TBubbleId& aBubbleId )
       
   161     {
       
   162     for( TInt i = 0; i < iCustomizations[aBubbleId].Count(); i++ )
       
   163         {
       
   164         iCustomizations[aBubbleId][i].Reset();
       
   165         }
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // ReserveCustomElement
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 CTelBubbleCustomElement* CBubbleCustomManager::ReserveCustomElement( 
       
   173     const CBubbleHeader& aBubbleHeader,
       
   174     CTelBubbleCustomElement::TElementType aElement )
       
   175     {
       
   176     TBool isDefault;
       
   177     return ReserveCustomElement( aBubbleHeader, aElement, isDefault );
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // ReserveCustomElement
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 CTelBubbleCustomElement* CBubbleCustomManager::ReserveCustomElement( 
       
   185     const CBubbleHeader& aBubbleHeader,
       
   186     CTelBubbleCustomElement::TElementType aElement,
       
   187     TBool& aIsDefault )
       
   188     {
       
   189     const CBubbleManager::TBubbleId bubbleId = aBubbleHeader.BubbleId();
       
   190     CTelBubbleCustomElement* customElement = NULL;
       
   191     aIsDefault = EFalse;
       
   192     
       
   193     if( bubbleId != KBubbleConferenceId &&
       
   194         iCustomizations[bubbleId][aElement].Count() )
       
   195         {
       
   196         // Get custom implmentation.
       
   197         customElement = 
       
   198             iCustomizations[aBubbleHeader.BubbleId()][aElement][0].Item();
       
   199         customElement->Control()->MakeVisible( ETrue );
       
   200         }
       
   201     
       
   202     if ( !customElement )
       
   203         {
       
   204         // Get default implementation, if exists.
       
   205         customElement = DefaultElement( aBubbleHeader, aElement );
       
   206         if ( customElement )
       
   207             {
       
   208             aIsDefault = ETrue;
       
   209             }
       
   210         }
       
   211     
       
   212     return customElement;
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // ReleaseCustomElement
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CBubbleCustomManager::ReleaseCustomElement( 
       
   220     CTelBubbleCustomElement*& aCustomElement )
       
   221     {
       
   222     if ( aCustomElement )
       
   223         {
       
   224         aCustomElement->Control()->MakeVisible( EFalse );
       
   225         iDefaultManager->ReleaseElement( aCustomElement );
       
   226         aCustomElement = NULL;
       
   227         }
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // DefaultElement
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 CTelBubbleCustomElement* CBubbleCustomManager::DefaultElement( 
       
   235     const CBubbleHeader& aBubbleHeader,
       
   236     CTelBubbleCustomElement::TElementType aElement )
       
   237     {
       
   238     CTelBubbleCustomElement* element = NULL;
       
   239     
       
   240     switch( aElement )
       
   241         {
       
   242         case CTelBubbleCustomElement::EBigCallIndicator:
       
   243             {
       
   244             element = iDefaultManager->ReserveBigCallIndicatorElement(
       
   245                 aBubbleHeader );
       
   246             }
       
   247             break;
       
   248         case CTelBubbleCustomElement::ENumberTypeIcon:
       
   249             {
       
   250             element = iDefaultManager->ReserveNumberTypeIconElement(
       
   251                 aBubbleHeader );
       
   252             }
       
   253             break;
       
   254         case CTelBubbleCustomElement::ESmallCallIndicator:
       
   255             {
       
   256             element = iDefaultManager->ReserveSmallCallIndicatorElement(
       
   257                 aBubbleHeader );
       
   258             }
       
   259             break;
       
   260         case CTelBubbleCustomElement::ECallImage:
       
   261             {
       
   262             element = iDefaultManager->ReserveCallImageElement(
       
   263                 aBubbleHeader );
       
   264             }
       
   265             break;
       
   266         default:
       
   267             // NULL
       
   268             break;
       
   269         }
       
   270     
       
   271     if ( element )
       
   272         {
       
   273         // Make found element visible
       
   274         element->Control()->MakeVisible( ETrue );
       
   275         }
       
   276     
       
   277     return element;
       
   278     }
       
   279