phonesettings/pslncallimageplugin/src/PslnCallImagePluginContainer.cpp
branchRCL_3
changeset 62 5266b1f337bd
parent 0 5f000ab63145
equal deleted inserted replaced
61:41a7f70b3818 62:5266b1f337bd
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Container for the Data sub-folder
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 // From this plugin.
       
    22 #include "PslnCallImagePluginContainer.h"
       
    23 
       
    24 // From PSLN framework
       
    25 #include <pslnfwbaseview.h>
       
    26 #include <pslnfwiconhelper.h>
       
    27 #include <csxhelp/skins.hlp.hrh>
       
    28 
       
    29 // Resources
       
    30 #include <PslnCallImagePluginRsc.rsg>
       
    31 
       
    32 // General services
       
    33 #include <aknlists.h>
       
    34 #include <featmgr.h>
       
    35 #include <AknUtils.h>
       
    36 #include <pslninternalcrkeys.h>
       
    37 #include <bautils.h>
       
    38 
       
    39 // Logging
       
    40 #include "PslnCallImagePluginLogger.h"
       
    41 
       
    42 // CONSTANTS
       
    43 // Number of Call Image plugin items.
       
    44 const TInt KPslnCallImageItems = 3;
       
    45 
       
    46 // PSLN application UID.
       
    47 const TUid KUidPslnApp = { 0x10005A32 };
       
    48 
       
    49 // ========================= MEMBER FUNCTIONS ================================
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CPslnCallImagePluginContainer::ConstructL()
       
    53 // 
       
    54 // Symbian OS two phased constructor
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 void CPslnCallImagePluginContainer::ConstructL( const TRect& aRect )
       
    58     {
       
    59     __CALLLOGSTRING("CPslnCallImagePluginContainer::ConstructL -> START");
       
    60     iListBox = new( ELeave ) CAknSingleGraphicStyleListBox;
       
    61    					 
       
    62     BaseConstructL( aRect, 0, R_PSLN_CI_VIEW_LBX );
       
    63     __CALLLOGSTRING("CPslnCallImagePluginContainer::ConstructL -> COMPLETED");
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CPslnCallImagePluginContainer::~CPslnCallImagePluginContainer()
       
    68 // 
       
    69 // Destructor 
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CPslnCallImagePluginContainer::~CPslnCallImagePluginContainer()
       
    73     {
       
    74     __CALLLOGSTRING("CPslnCallImagePluginContainer::~CPslnCallImagePluginContainer -> START");
       
    75     delete iItemBuf;
       
    76     delete iItems;  
       
    77     __CALLLOGSTRING("CPslnCallImagePluginContainer::~CPslnCallImagePluginContainer -> COMPLETED");
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CPslnCallImagePluginContainer::UpdateListBoxL()
       
    82 // 
       
    83 // Update listbox item.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CPslnCallImagePluginContainer::UpdateListBoxL()
       
    87     {
       
    88     __CALLLOGSTRING("CPslnCallImagePluginContainer::UpdateListBoxL -> START");
       
    89     iItemArray->Reset();
       
    90     CreateListBoxItemsL();
       
    91     iListBox->HandleItemRemovalL();
       
    92     iListBox->DrawDeferred();
       
    93     __CALLLOGSTRING("CPslnCallImagePluginContainer::UpdateListBoxL -> COMPLETED");
       
    94     }
       
    95 // ---------------------------------------------------------------------------
       
    96 // CPslnCallImagePluginContainer::CurrentSelectionIndex
       
    97 // 
       
    98 // Sets tap for the selection.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 TInt CPslnCallImagePluginContainer::CurrentSelectionIndexL()
       
   102 	{
       
   103 	__CALLLOGSTRING("CPslnCallImagePluginContainer::CurrentSelectionIndexL-> START");
       
   104 	TInt itemIndex(KErrNotFound);
       
   105     TInt error(KErrNone);
       
   106     TInt currentSetting(0);
       
   107 
       
   108     CRepository* callImageSupp = CRepository::NewL ( KCRUidThemes ); 
       
   109 	CleanupStack::PushL( callImageSupp );     
       
   110 	error = callImageSupp->Get( KThemesCallImageSetting, currentSetting );
       
   111        
       
   112     // Verify that the image exists.
       
   113     TFileName callImagePath;
       
   114     error = callImageSupp->Get( KThemesCallImagePath, callImagePath );
       
   115     TBool imageExists = ( callImagePath.Length() && 
       
   116         BaflUtils::FileExists( CCoeEnv::Static()->FsSession(), 
       
   117         callImagePath ) ); 
       
   118     
       
   119     if( error != KErrNone ) 
       
   120     	{
       
   121         return error;
       
   122         }
       
   123         
       
   124     // Map CR value to list box index.
       
   125     switch ( currentSetting )
       
   126         {
       
   127         case EPlsnCRCallImageNone:
       
   128             itemIndex = EPlsnCallImageNone;
       
   129             break;
       
   130         case EPlsnCRUserDefinedImage:
       
   131             if ( !imageExists )
       
   132                 {
       
   133                 itemIndex = EPlsnCallImageNone;
       
   134                 }
       
   135             else
       
   136                 {
       
   137                 itemIndex = EPlsnCallImageUserDefinedImage;
       
   138                 }            
       
   139             break;
       
   140         case EPlsnCRThemeImage:
       
   141         default:
       
   142             itemIndex = EPlsnCallImageThemeImage;
       
   143             break;
       
   144         }
       
   145     CleanupStack::PopAndDestroy( callImageSupp );
       
   146     __CALLLOGSTRING("CPslnCallImagePluginContainer::CurrentSelectionIndexL -> COMPLETED");
       
   147     return itemIndex;
       
   148 	}
       
   149     
       
   150 // ---------------------------------------------------------------------------
       
   151 // CPslnCallImagePluginContainer::ConstructListBoxL()
       
   152 // 
       
   153 // Construct the listbox from resource array.
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CPslnCallImagePluginContainer::ConstructListBoxL( TInt aResLbxId )
       
   157     {
       
   158     __CALLLOGSTRING("CPslnCallImagePluginContainer::ConstructListBoxL-> START");
       
   159     iListBox->ConstructL( this, EAknListBoxSelectionList );
       
   160 
       
   161     iItemArray = static_cast<CDesCArray*>
       
   162         ( iListBox->Model()->ItemTextArray() );
       
   163         
       
   164     iItems = iCoeEnv->ReadDesC16ArrayResourceL( aResLbxId );
       
   165     
       
   166     CreateListBoxItemsL();  
       
   167     __CALLLOGSTRING("CPslnCallImagePluginContainer::ConstructListBoxL -> COMPLETED");
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // CPslnCallImagePluginContainer::CreateListBoxItemsL()
       
   172 // 
       
   173 // Create listbox items.
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CPslnCallImagePluginContainer::CreateListBoxItemsL()
       
   177     {
       
   178     __CALLLOGSTRING("CPslnCallImagePluginContainer::CreateListBoxItemsL -> START");
       
   179     TInt selectedItem = CurrentSelectionIndexL();
       
   180     if ( selectedItem < 0 )
       
   181         {
       
   182         selectedItem = 0;
       
   183         } 
       
   184         
       
   185         for( TInt i = 0; i < KPslnCallImageItems; i++ )
       
   186         {
       
   187         if ( i > iItems->Count() )
       
   188             {
       
   189             User::Leave( KErrOverflow );
       
   190             }
       
   191         iItemBuf = (*iItems)[i].AllocL();
       
   192         if ( iItemBuf )
       
   193             {            
       
   194             iItemBuf = iItemBuf->ReAllocL( iItemBuf->Length() + 4 );
       
   195             TPtr ptr = iItemBuf->Des();
       
   196             if ( selectedItem == i )
       
   197                 {
       
   198                 ptr.Insert( 0, KPslnFWActiveListItemFormat );
       
   199                 }
       
   200             else
       
   201                 {            
       
   202                 ptr.Insert( 0, KPslnFWNonActiveListItemFormat );
       
   203                 }
       
   204             iItemArray->InsertL( i, ptr );
       
   205             delete iItemBuf;
       
   206             iItemBuf = NULL;
       
   207             }
       
   208         }        
       
   209     // Create pre- and post-text icons.
       
   210     CPslnFWIconHelper* iconHelper = CPslnFWIconHelper::NewL();
       
   211     CleanupStack::PushL( iconHelper );   
       
   212     iconHelper->AddIconsToSettingItemsL( 
       
   213         ETrue, 
       
   214         1,
       
   215         iListBox );
       
   216     CleanupStack::PopAndDestroy( iconHelper );
       
   217     
       
   218     iListBox->HandleItemAdditionL();
       
   219     __CALLLOGSTRING("CCPslnCallImagePluginContainer::CreateListBoxItemsL -> COMPLETED");
       
   220     }
       
   221     
       
   222 // ---------------------------------------------------------------------------
       
   223 // CPslnCallImagePluginContainer::GetHelpContext()
       
   224 // 
       
   225 // Gets Help context.
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void CPslnCallImagePluginContainer::GetHelpContext(
       
   229     TCoeHelpContext& aContext ) const
       
   230     {
       
   231     aContext.iMajor = KUidPslnApp;
       
   232     aContext.iContext = KSKINS_HLP_CIMAGE_SETTINGS;
       
   233     }
       
   234 
       
   235 // End of File