psln/Src/PslnGeneralThemeContainer.cpp
branchRCL_3
changeset 56 d48ab3b357f1
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
       
     1 /*
       
     2 * Copyright (c) 2005-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:  General theme view's container.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 // General
       
    21 #include <aknlists.h>
       
    22 #include <eikclbd.h>
       
    23 #include <StringLoader.h>
       
    24 #include <AknGlobalNote.h>
       
    25 
       
    26 #include <aknlistloadertfx.h>
       
    27 
       
    28 #include <aknnotewrappers.h> 
       
    29 
       
    30 // Resources.
       
    31 #include <psln.rsg>
       
    32 
       
    33 // Constants.
       
    34 #include "PslnConst.h"
       
    35 
       
    36 // Help context.
       
    37 #include <csxhelp/skins.hlp.hrh>
       
    38 
       
    39 // HAL
       
    40 #include <hal.h>
       
    41 
       
    42 // General - psln specific.
       
    43 #include "PslnGeneralThemeContainer.h"
       
    44 #include "PslnFeatures.h"
       
    45 #include "PslnModel.h"
       
    46 #include "PslnDebug.h"
       
    47 #include "PslnSkinEntry.h"
       
    48 #include "PslnUi.h"
       
    49 
       
    50 // Central Repository and Publish&Subscribe keys.
       
    51 #include <centralrepository.h>
       
    52 #include "pslninternalcrkeys.h"
       
    53 
       
    54 
       
    55 // Framework
       
    56 #include <pslnfwiconhelper.h>
       
    57 #include <mpslnfwmsklabelobserver.h>
       
    58 
       
    59 // ============================ MEMBER FUNCTIONS ===============================
       
    60 // -----------------------------------------------------------------------------
       
    61 // C++ default constructor can NOT contain any code, that might leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CPslnGeneralThemeContainer::CPslnGeneralThemeContainer()
       
    65     {
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // Symbian 2nd phase constructor can leave.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CPslnGeneralThemeContainer::ConstructL( const TRect& aRect )
       
    73     {
       
    74     iListBox = new (ELeave) CAknSingleGraphicStyleListBox;
       
    75     BaseConstructL( aRect, R_PSLN_SKIN_LIST_VIEW_TITLE, KPslnNoResource );
       
    76     iOldSkinNum = iModel->NumberOfSkins();
       
    77     }
       
    78 
       
    79 // Destructor
       
    80 CPslnGeneralThemeContainer::~CPslnGeneralThemeContainer()
       
    81     {
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Checks if embedded browser is supported.
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 TBool CPslnGeneralThemeContainer::IsEmbeddedLinkVisible() const
       
    89     {
       
    90     return PslnFeatures::IsEnhancedEmbeddedLinksSupported();
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // Updates skin item list.
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CPslnGeneralThemeContainer::UpdateSkinListItemsL( const TInt& aNewIndex )
       
    98 {
       
    99     // This is needed to make the list effects update
       
   100     CAknListLoader::InvalidateAll();
       
   101 
       
   102     PSLN_TRACE_DEBUG("CPslnGeneralThemeContainer::UpdateSkinListItemsL");
       
   103     // Update skins.
       
   104     iItemArray->Reset();
       
   105     iToBeUsedIndex = KErrNotFound;
       
   106     if ( aNewIndex != KErrNotFound )
       
   107         {
       
   108         iToBeUsedIndex = aNewIndex;
       
   109         }
       
   110     CreateListBoxItemsL();
       
   111     
       
   112     // Create pre- and post-text icons.
       
   113     CPslnFWIconHelper* iconHelper = CPslnFWIconHelper::NewL();
       
   114     CleanupStack::PushL( iconHelper );
       
   115     iconHelper->AddIconsToSettingItemsL(
       
   116         ETrue,
       
   117         KErrNotFound, // not used since we are adding all
       
   118         iListBox );
       
   119     CleanupStack::PopAndDestroy( iconHelper );
       
   120     
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // Creates listbox.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CPslnGeneralThemeContainer::ConstructListBoxL( TInt /*aResLbxId*/ )
       
   128     {
       
   129     UpdateSkinListItemsL( KErrNotFound );
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // Empty implementation of inherited method.
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CPslnGeneralThemeContainer::CreateListBoxItemsL()
       
   137     {
       
   138     PSLN_TRACE_DEBUG("CPslnGeneralThemeContainer::CreateListBoxItemsL BEGIN");
       
   139     TInt downloadAdded = 0;
       
   140     if ( IsEmbeddedLinkVisible() )
       
   141         {
       
   142         HBufC* text = StringLoader::LoadLC(
       
   143             R_PSLN_QTN_SKINS_DOWNLOAD_SKINS, iEikonEnv );
       
   144         // Reallocating invalidates original text, so it is required that
       
   145         // original text is popped from cleanupstack, then reassigned to
       
   146         // reallocated value and finally pushed back to cleanupstack.
       
   147         HBufC* reallocText = text->ReAllocL( text->Length() + KPslnIconSize );
       
   148         CleanupStack::Pop( text );
       
   149         text = reallocText;
       
   150         CleanupStack::PushL( text );
       
   151         // Do not use reallocated string after assigning it to the original.
       
   152         reallocText = NULL;
       
   153         TPtr textPtr = text->Des();
       
   154 
       
   155         textPtr.Insert( 0, KPslnFWEmbeddedLinkListItemFormat );
       
   156         iItemArray->InsertL( 0, textPtr );
       
   157         downloadAdded = 1;
       
   158         CleanupStack::PopAndDestroy( text );
       
   159         }
       
   160 
       
   161     TInt maxSkinIndex = 0;
       
   162     if ( iModel )
       
   163         {
       
   164         // If current skin is not found => update from server.
       
   165         if ( iModel->ActiveSkinIndex() == KErrNotFound )
       
   166             {
       
   167             iModel->PerformCompleteUpdateL();
       
   168             }
       
   169         maxSkinIndex = iModel->NumberOfSkins();
       
   170         }
       
   171 
       
   172     HBufC* skinName = HBufC::NewLC( KMaxName );
       
   173     TInt currentlyActiveSkinIndex = KErrNotFound;
       
   174     static_cast<CPslnUi*>( ControlEnv()->AppUi() )->
       
   175         SetDRMProtectedSkinInSkinList( EFalse );
       
   176 
       
   177     for ( TInt skinIndex = KPslnSeries60SkinIndex;
       
   178           skinIndex < maxSkinIndex; skinIndex++ )
       
   179         {
       
   180         PSLN_TRACE_DEBUG("CPslnGeneralThemeContainer::CreateListBoxItemsL 3");
       
   181         TPtr skinNamePtr = skinName->Des();
       
   182         iModel->GetSkinNameByIndex(
       
   183             skinIndex,
       
   184             skinNamePtr,
       
   185             EPslnSkinNameTypeList );
       
   186 
       
   187         // Add pre-text icon.
       
   188         if ( iModel->IsActiveSkinSelected( skinIndex  ) )
       
   189             {
       
   190             skinNamePtr.Insert( 0, KPslnFWActiveListItemFormat );
       
   191             currentlyActiveSkinIndex = skinIndex;
       
   192             }
       
   193         else
       
   194             {
       
   195             skinNamePtr.Insert( 0, KPslnFWNonActiveListItemFormat );
       
   196             }
       
   197 
       
   198         if( iModel->IsActiveSkinSelected( skinIndex  ) && iToBeUsedIndex == KErrNotFound )
       
   199             {
       
   200             iModel->SetCurrentSelectedSkinIndex (skinIndex);
       
   201             iToBeUsedIndex = skinIndex + downloadAdded;
       
   202             }
       
   203 
       
   204         // Add post-text icon(s).
       
   205 #ifndef RD_MULTIPLE_DRIVE
       
   206         if( iModel->LocationOfSkin( skinIndex ) == EAknsSrvMMC )
       
   207             {
       
   208             skinNamePtr.Append( KPslnFWListItemFormatMMCSuffix );
       
   209             }
       
   210 #else
       
   211         if( iModel->IsThemeOnMemoryCard( skinIndex ) )
       
   212             {
       
   213             skinNamePtr.Append( KPslnFWListItemFormatMMCSuffix );
       
   214             }
       
   215         else if( iModel->IsThemeOnMassDrive( skinIndex ) )
       
   216             {
       
   217             skinNamePtr.Append( KPslnFWListItemFormatMassDriveSuffix );
       
   218             }
       
   219 #endif // RD_MULTIPLE_DRIVE
       
   220 
       
   221         switch( iModel->ProtectionOfSkin( skinIndex ) )
       
   222             {
       
   223             case EAknsSrvProtected:
       
   224                 skinNamePtr.Append( KPslnFWListItemFormatDRMProtectedSuffix );
       
   225                 static_cast<CPslnUi*>( ControlEnv()->AppUi() )->
       
   226                     SetDRMProtectedSkinInSkinList( ETrue );
       
   227                 break;
       
   228             case EAknsSrvNoRights:
       
   229             case EAknsSrvCountBased:
       
   230             case EAknsSrvFutureRights:
       
   231             case EAknsSrvExpiredRights:
       
   232                 skinNamePtr.Append( KPslnFWListItemFormatDRMExpiredSuffix );
       
   233                 static_cast<CPslnUi*>( ControlEnv()->AppUi() )->
       
   234                     SetDRMProtectedSkinInSkinList( ETrue );
       
   235                 break;
       
   236             case EAknsSrvNoProtection:
       
   237             default:
       
   238                 // Do nothing
       
   239                 break;
       
   240             }
       
   241         PSLN_TRACE_DEBUG1("CPslnGeneralThemeContainer::CreateListBoxItemsL postfix icon: %d", iModel->ProtectionOfSkin( skinIndex ) );
       
   242         iItemArray->InsertL( ( skinIndex + downloadAdded ), skinNamePtr );
       
   243         skinNamePtr.Zero();
       
   244         }
       
   245     CleanupStack::PopAndDestroy( skinName );
       
   246     
       
   247     iActiveSkinItemIndex = currentlyActiveSkinIndex + downloadAdded;
       
   248     if ( iOldSkinNum != maxSkinIndex )
       
   249         {
       
   250         iToBeUsedIndex = currentlyActiveSkinIndex + downloadAdded;
       
   251         }
       
   252     if ( ( iToBeUsedIndex >= ( 0 + downloadAdded ) ) &&
       
   253          ( iToBeUsedIndex <= ( maxSkinIndex + downloadAdded ) ) )
       
   254         {
       
   255         SetCurrentItemIndex( iToBeUsedIndex );
       
   256         }
       
   257     else
       
   258         {    
       
   259         SetCurrentItemIndex( currentlyActiveSkinIndex + downloadAdded );
       
   260         }
       
   261     iListBox->HandleItemAdditionL();
       
   262     if ( iOldSkinNum != maxSkinIndex )
       
   263         {
       
   264         iOldSkinNum = maxSkinIndex;
       
   265         }
       
   266     PSLN_TRACE_DEBUG("CPslnGeneralThemeContainer::CreateListBoxItemsL END");
       
   267     }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // Updates D column icons.
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 void CPslnGeneralThemeContainer::UpdateSkinListItemsDColumnOnlyL()
       
   274     {
       
   275     // Create pre- and post-text icons.
       
   276     CPslnFWIconHelper* iconHelper = CPslnFWIconHelper::NewL();
       
   277     CleanupStack::PushL( iconHelper );
       
   278     iconHelper->AddIconsToSettingItemsL(
       
   279         ETrue,
       
   280         KErrNotFound, // not used since we are adding all
       
   281         iListBox );
       
   282     CleanupStack::PopAndDestroy( iconHelper );
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // Gets help context for Help application.
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 void CPslnGeneralThemeContainer::GetHelpContext(
       
   290     TCoeHelpContext& aContext ) const
       
   291     {
       
   292     aContext.iMajor = KUidPsln;
       
   293     aContext.iContext = KSKINS_HLP_LIST;
       
   294     }
       
   295 
       
   296 //  End of File