phonebookui/Phonebook2/UIExtensionManager/src/CPbk2UIExtensionConfigurationObserver.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  A store configuration observer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbk2UIExtensionConfigurationObserver.h"
       
    22 
       
    23 #include "CPbk2UIExtensionLoader.h"
       
    24 #include "CPbk2UIExtensionInformation.h"
       
    25 #include "CPbk2UIExtensionPlugin.h"
       
    26 
       
    27 #include <CPbk2StorePropertyArray.h>
       
    28 #include <CPbk2StoreConfiguration.h>
       
    29 #include <barsread.h>
       
    30 #include <coemain.h>
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CPbk2UIExtensionConfigurationObserver::CPbk2UIExtensionConfigurationObserver
       
    36 // C++ default constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CPbk2UIExtensionConfigurationObserver::CPbk2UIExtensionConfigurationObserver(
       
    41         CPbk2StorePropertyArray& aPropertyArray, 
       
    42         CPbk2UIExtensionLoader& aExtensionLoader,
       
    43         CPbk2StoreConfiguration& aStoreConfiguration) :   
       
    44     iPropertyArray(aPropertyArray),
       
    45     iExtensionLoader(aExtensionLoader),
       
    46     iStoreConfiguration(aStoreConfiguration)
       
    47     {
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CPbk2UIExtensionConfigurationObserver::ConstructL
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void CPbk2UIExtensionConfigurationObserver::ConstructL() 
       
    55     {
       
    56     AddPropertiesFromExtensionsL();
       
    57     iStoreConfiguration.AddObserverL(*this);
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CPbk2UIExtensionConfigurationObserver::NewL
       
    62 // -----------------------------------------------------------------------------
       
    63 //    
       
    64 CPbk2UIExtensionConfigurationObserver* 
       
    65         CPbk2UIExtensionConfigurationObserver::NewL(
       
    66             CPbk2StorePropertyArray& aPropertyArray,
       
    67             CPbk2UIExtensionLoader& aExtensionLoader,
       
    68             CPbk2StoreConfiguration& aStoreConfiguration)
       
    69     {
       
    70     CPbk2UIExtensionConfigurationObserver* self = 
       
    71         new( ELeave ) CPbk2UIExtensionConfigurationObserver(aPropertyArray, 
       
    72             aExtensionLoader, aStoreConfiguration);
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop( self );
       
    76     return self;
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CPbk2UIExtensionConfigurationObserver::~CPbk2UIExtensionConfigurationObserver
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CPbk2UIExtensionConfigurationObserver::~CPbk2UIExtensionConfigurationObserver()
       
    84     {
       
    85     iStoreConfiguration.RemoveObserver(*this);
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CPbk2UIExtensionConfigurationObserver::ConfigurationChanged
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CPbk2UIExtensionConfigurationObserver::ConfigurationChanged()
       
    93     {
       
    94 	// Update array from extensions
       
    95 	TRAPD(res, AddPropertiesFromExtensionsL());
       
    96 	if (res != KErrNone)
       
    97 	    {
       
    98 	    CCoeEnv::Static()->HandleError(res);
       
    99 	    }
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CPbk2UIExtensionConfigurationObserver::ConfigurationChangedComplete
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CPbk2UIExtensionConfigurationObserver::ConfigurationChangedComplete()
       
   107 	{
       
   108 	// Do nothing
       
   109 	}
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CPbk2UIExtensionConfigurationObserver::AddPropertiesFromExtensionsL
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CPbk2UIExtensionConfigurationObserver::AddPropertiesFromExtensionsL()
       
   116     {
       
   117     TArray<CPbk2UIExtensionInformation*> info = 
       
   118         iExtensionLoader.PluginInformation();
       
   119     const TInt count = info.Count();
       
   120     for (TInt i = 0; i < count; ++i)
       
   121         {
       
   122         if (info[i]->HasStorePropertyArray())
       
   123             {
       
   124             // Extension defines store properties in resource
       
   125             TResourceReader reader;
       
   126             info[i]->CreateStorePropertyArrayReaderLC(reader);
       
   127             iPropertyArray.AppendFromResourceL(reader);
       
   128             CleanupStack::PopAndDestroy();
       
   129             }
       
   130             
       
   131         TUid uid(info[i]->ImplementationUid());
       
   132         // Called only for loaded extensions
       
   133         if (iExtensionLoader.IsLoaded(uid))
       
   134             {
       
   135             iExtensionLoader.LoadedPlugin(uid)->UpdateStorePropertiesL(iPropertyArray);
       
   136             }
       
   137         }
       
   138     }
       
   139 //  End of File