psln/Src/PslnMainViewContainer.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     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:  Container for Main View.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 // Psln specific.
       
    23 #include "PslnMainViewContainer.h"
       
    24 #include "PslnUi.h"
       
    25 #include "PslnDebug.h"
       
    26 #include "PslnConst.h"
       
    27 
       
    28 // Lists & Icons.
       
    29 #include <aknlists.h>
       
    30 #include <AknIconArray.h>
       
    31 #include <eikclbd.h>
       
    32 
       
    33 // Framework
       
    34 #include <pslnfwplugininterface.h>
       
    35 #include "PslnPluginHandler.h"
       
    36 
       
    37 // Resources
       
    38 #include <psln.rsg>
       
    39 #include <pslnicon.mbg>
       
    40 #include <data_caging_path_literals.hrh>
       
    41 
       
    42 // Help related.
       
    43 #include <csxhelp/skins.hlp.hrh>
       
    44 
       
    45 // CONSTANTS
       
    46 // Tab character.
       
    47 _LIT( KTab, "\t" );
       
    48 
       
    49 // Icon indexes for listbox.
       
    50 const TInt KPslnGeneralId          = 0;
       
    51 const TInt KPslnWallpaperId        = 1;
       
    52 const TInt KPslnScreenSaverId      = 2;
       
    53 // Container granularity.
       
    54 const TInt KPslnMainConGranularity = 6;
       
    55 // Max index of static (i.e. non-ECOM) folder when no plugins loaded.
       
    56 const TInt KPslnStaticFolderNum = 2;
       
    57 
       
    58 // Path to icon file.
       
    59 _LIT( KPslnIconFilename, "z:pslnicon.mbm" );
       
    60 
       
    61 // ============================ MEMBER FUNCTIONS ===============================
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // C++ constructor can NOT contain any code, that might leave.
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CPslnMainViewContainer::CPslnMainViewContainer( CPslnUi* aPslnUi )
       
    68     : iPslnUi( aPslnUi )
       
    69     {
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // Destructor.
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CPslnMainViewContainer::~CPslnMainViewContainer()
       
    77     {
       
    78     // iListBox is deleted in class CPslnBaseContainer.
       
    79     delete iItems;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Symbian 2nd phase constructor can leave.
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CPslnMainViewContainer::ConstructL( const TRect& aRect )
       
    87     {
       
    88     iListBox = new (ELeave) CAknSingleLargeStyleListBox;
       
    89 
       
    90     BaseConstructL(
       
    91         aRect,
       
    92         R_PSLN_SKIN_LIST_VIEW_TITLE,
       
    93         R_PSLN_MAIN_VIEW_LBX );
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Creates listbox.
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CPslnMainViewContainer::ConstructListBoxL( TInt aResLbxId )
       
   101     {
       
   102     iItems = iCoeEnv->ReadDesC16ArrayResourceL( aResLbxId );
       
   103     CreateListBoxItemsL();
       
   104     }
       
   105 
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // Creates listbox items.
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CPslnMainViewContainer::CreateListBoxItemsL()
       
   112     {
       
   113     PSLN_TRACE_DEBUG("CPslnMainViewContainer::CreateListBoxItemsL BEGIN");
       
   114     // Array for icons in the listbox. Owns the icons.
       
   115     CAknIconArray* iconList =
       
   116         new (ELeave) CAknIconArray( KPslnMainConGranularity );
       
   117     CleanupStack::PushL( iconList );
       
   118 
       
   119     // Find the resource file:
       
   120     HBufC* iconFile = HBufC::NewLC( KMaxFileName );
       
   121     TPtr fileNamePtr = iconFile->Des();
       
   122     GetIconFilePath( fileNamePtr );
       
   123 
       
   124     // Add non-plugin icons to icon group.
       
   125     // General icon.
       
   126     AddIconL(
       
   127         iconList,
       
   128         KAknsIIDQgnPropPslnGeneralSub,
       
   129         fileNamePtr,
       
   130         EMbmPslniconQgn_prop_psln_general_sub,
       
   131         EMbmPslniconQgn_prop_psln_general_sub_mask );
       
   132 
       
   133     // Wallpaper icon.
       
   134     AddIconL(
       
   135         iconList,
       
   136         KAknsIIDQgnPropPslnWpaperSub,
       
   137         fileNamePtr,
       
   138         EMbmPslniconQgn_prop_psln_wpaper_sub,
       
   139         EMbmPslniconQgn_prop_psln_wpaper_sub_mask );
       
   140 
       
   141     // Screensaver screensaver.
       
   142     AddIconL(
       
   143         iconList,
       
   144         KAknsIIDQgnPropPslnSsaverSub,
       
   145         fileNamePtr,
       
   146         EMbmPslniconQgn_prop_psln_ssaver_sub,
       
   147         EMbmPslniconQgn_prop_psln_ssaver_sub_mask );
       
   148 
       
   149     CleanupStack::PopAndDestroy( iconFile );
       
   150 
       
   151     // Add General Theme static view.
       
   152     // Icon location is ok - directly from resources.
       
   153     MakeItemL( KPslnGeneralId );
       
   154 
       
   155     // How many dynamic items have been added in-between.
       
   156     TInt offset = 0;
       
   157     iPluginArray = iPslnUi->PluginHandler()->GetPluginArray();
       
   158     // Create buffers.
       
   159     HBufC* buf = HBufC::NewLC( KPslnItemLength );
       
   160     TPtr ptrBuf = buf->Des();
       
   161     HBufC* item = HBufC::NewLC( KPslnItemLength );
       
   162     TPtr ptrItem = item->Des();
       
   163     // Add Active Idle (and Application Shell) plugin(s).
       
   164     if ( iPluginArray )
       
   165         {
       
   166         for ( TInt i = 0; i < iPluginArray->Count(); i++ )
       
   167             {
       
   168             CPslnFWPluginInterface* plugin = iPluginArray->operator[]( i );
       
   169             CleanupStack::PushL( plugin );
       
   170 
       
   171             // TRAP all but OOM, so that plugins cannot cause Psln to fail to
       
   172             // launch.
       
   173             TRAPD( err,
       
   174                 offset += MakePluginItemL( *plugin, *iconList, ptrBuf, ptrItem ) );
       
   175             if ( err == KErrNoMemory )
       
   176                 {
       
   177                 User::Leave( KErrNoMemory );
       
   178                 }
       
   179 
       
   180             // Initialize buffers.
       
   181             ptrBuf.Zero();
       
   182             ptrItem.Zero();
       
   183 
       
   184             // icon is now owned by icon array and plugin by plugin handler
       
   185             CleanupStack::Pop( plugin );
       
   186             plugin = NULL;
       
   187             }
       
   188         }
       
   189     CleanupStack::PopAndDestroy( 2, buf ); // buf, item
       
   190 
       
   191     // Add Screen Saver and Wallpaper static views.
       
   192     TBitFlags views = iPslnUi->ViewSupport();
       
   193     if ( views.IsSet( CPslnUi::EPslnWallpaperView ) )
       
   194         {
       
   195         MakeItemL( KPslnWallpaperId, offset );
       
   196         }
       
   197 
       
   198     if ( views.IsSet( CPslnUi::EPslnScreensaverView ) )
       
   199         {
       
   200         MakeItemL( KPslnScreenSaverId, offset );
       
   201         }
       
   202 
       
   203     iPslnUi->AllViewsDone();
       
   204 
       
   205     // Destroy the old icons because SetIconArray() does not destroy them.
       
   206     CEikColumnListBox* listbox = static_cast<CEikColumnListBox*> ( iListBox );
       
   207     CArrayPtr<CGulIcon>* oldIcons =
       
   208         listbox->ItemDrawer()->ColumnData()->IconArray();
       
   209     if( oldIcons )
       
   210         {
       
   211         oldIcons->ResetAndDestroy();
       
   212         delete oldIcons;
       
   213         }
       
   214 
       
   215     // Transfer ownership of icon array to the lbx.
       
   216     listbox->ItemDrawer()->ColumnData()->SetIconArray( iconList );
       
   217     CleanupStack::Pop( iconList );
       
   218 
       
   219     iListBox->HandleItemAdditionL();
       
   220     PSLN_TRACE_DEBUG("CPslnMainViewContainer::CreateListBoxItemsL END");
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // Creates a specific setting item.
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CPslnMainViewContainer::MakeItemL( const TInt aIndex, const TInt aOffset )
       
   228     {
       
   229     PSLN_TRACE_DEBUG("CPslnMainViewContainer::MakeItemL BEGIN");
       
   230     if ( aIndex > iItems->Count() )
       
   231         {
       
   232         User::Leave( KErrArgument );
       
   233         }
       
   234     HBufC* item = (*iItems)[aIndex].AllocLC();
       
   235     // Reallocating invalidates the original string.
       
   236     HBufC* reallocItem = item->ReAllocL( item->Length() + KPslnIconSize );
       
   237     CleanupStack::Pop( item );
       
   238     item = reallocItem;
       
   239     CleanupStack::PushL( item );
       
   240     reallocItem = NULL; // do not use anymore.
       
   241     TPtr ptr = item->Des();
       
   242     if ( aOffset != KErrNotFound )
       
   243         {
       
   244         iItemArray->InsertL( aIndex + aOffset, ptr );
       
   245         }
       
   246     else
       
   247         {
       
   248         iItemArray->InsertL( aIndex, ptr );
       
   249         }
       
   250     CleanupStack::PopAndDestroy( item );
       
   251     PSLN_TRACE_DEBUG("CPslnMainViewContainer::MakeItemL END");
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // Gets help context for Help application.
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CPslnMainViewContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   259     {
       
   260     aContext.iMajor = KUidPsln;
       
   261     aContext.iContext = KSKINS_HLP_APP_MAIN;
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // Creates a plugin item (with title and icon)
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 TInt CPslnMainViewContainer::MakePluginItemL(
       
   269     CPslnFWPluginInterface& aPlugin, CAknIconArray& aIconList,
       
   270     TPtr& aBufPtr, TPtr& aItemPtr  )
       
   271     {
       
   272     TInt offset = 0;
       
   273     // Adding icon.
       
   274     CGulIcon* icon = aPlugin.CreateIconL();
       
   275     CleanupStack::PushL( icon );
       
   276     PSLN_TRACE_DEBUG("CPslnMainViewContainer::MakePluginItemL BEGIN");
       
   277 
       
   278     aPlugin.GetCaptionL( aBufPtr );
       
   279     TInt location = KErrNotFound;
       
   280     CPslnFWPluginInterface::TPslnFWLocationType locType;
       
   281     aPlugin.GetLocationTypeAndIndex( locType, location );
       
   282 
       
   283     // If it is AS or AI plugin, add it.
       
   284     if ( aPlugin.Id().iUid == KPslnASPluginUid.iUid ||
       
   285          aPlugin.Id().iUid == KPslnAIPluginUid.iUid )
       
   286         {
       
   287         TInt upcomingPlace = location + KPslnStaticFolderNum;
       
   288         if ( upcomingPlace >= aIconList.Count() )
       
   289             {
       
   290             upcomingPlace = aIconList.Count();
       
   291             }
       
   292         aIconList.InsertL( upcomingPlace , icon );
       
   293 
       
   294         // Let's correct the icon index.
       
   295         upcomingPlace = location + KPslnStaticFolderNum;
       
   296         aItemPtr.AppendNum( upcomingPlace );
       
   297         aItemPtr.Append( KTab );
       
   298         aItemPtr.Append( aBufPtr );
       
   299         if ( location >= iItemArray->Count() )
       
   300             {
       
   301             location = iItemArray->Count();
       
   302             }
       
   303         iItemArray->InsertL( location , aItemPtr );
       
   304         offset++;
       
   305         }
       
   306     else
       
   307         {
       
   308         aIconList.AppendL( icon );
       
   309         // use icon list position as index
       
   310         // iconList->Count() is here always at least 1
       
   311         // we need to adjust the icon index based on loaded plugins
       
   312         // which are inserted between static views.
       
   313         aItemPtr.AppendNum( aIconList.Count() - 1 + iAIAdded + iASAdded );
       
   314         aItemPtr.Append( KTab );
       
   315         aItemPtr.Append( aBufPtr );
       
   316         iItemArray->AppendL( aItemPtr );
       
   317         }
       
   318 
       
   319     if ( aPlugin.Id().iUid == KPslnASPluginUid.iUid )
       
   320         {
       
   321         iASAdded = ETrue;
       
   322         }
       
   323 
       
   324     if ( aPlugin.Id().iUid == KPslnAIPluginUid.iUid )
       
   325         {
       
   326         iAIAdded = ETrue;
       
   327         }
       
   328 
       
   329     CleanupStack::Pop( icon );
       
   330     return offset;
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // Adds icon to icon array.
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 void CPslnMainViewContainer::AddIconL(
       
   338     CAknIconArray* aIcons,
       
   339     const TAknsItemID& aSkinId,
       
   340     const TDesC& aFileName,
       
   341     TInt aBitmapId,
       
   342     TInt aMaskId )
       
   343     {
       
   344     CFbsBitmap* bitmap = NULL;
       
   345     CFbsBitmap* mask = NULL;
       
   346     AknsUtils::CreateIconL(
       
   347         AknsUtils::SkinInstance(),
       
   348         aSkinId,
       
   349         bitmap,
       
   350         mask,
       
   351         aFileName,
       
   352         aBitmapId,
       
   353         aMaskId );
       
   354     CleanupStack::PushL( bitmap );
       
   355     CleanupStack::PushL( mask );
       
   356     CGulIcon* icon = CGulIcon::NewL( bitmap, mask );
       
   357     CleanupStack::Pop( 2, bitmap ); // bitmap, mask
       
   358     CleanupStack::PushL( icon );
       
   359     if ( aIcons )
       
   360         {
       
   361         aIcons->AppendL( icon );
       
   362         }
       
   363     CleanupStack::Pop( icon );
       
   364     }
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // Parses icon file path to given parameter.
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 void CPslnMainViewContainer::GetIconFilePath( TDes& aPath )
       
   371     {
       
   372     // Find the resource file:
       
   373     TParse parse;
       
   374     parse.Set( KPslnIconFilename, &KDC_APP_BITMAP_DIR, NULL );
       
   375     if ( aPath.MaxLength() >= parse.FullName().Length() )
       
   376         {
       
   377         aPath.Copy( parse.FullName() );
       
   378         }
       
   379     }
       
   380 
       
   381 //  End of File