camerauis/cameraapp/generic/src/CamCaptureSetupMenuListBoxModel.cpp
branchRCL_3
changeset 54 bac7acad7cb3
parent 0 1ddebce53859
equal deleted inserted replaced
53:61bc0f252b2b 54:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 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:  Model class of capture setup menu list box.*
       
    15 */
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <barsread.h>
       
    20 #include <eikenv.h>
       
    21 #include "CamCaptureSetupMenuListBoxModel.h"
       
    22 #include "CamAppController.h"
       
    23 #include "CamCaptureSetupMenuListItem.h"
       
    24 #include "CamPanic.h"
       
    25 #include "camlogging.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // ---------------------------------------------------------
       
    30 // CCamCaptureSetupMenuListBoxModel::NewLC
       
    31 // Returns CCamCaptureSetupMenuListBoxModel*: Pointer to the created model.
       
    32 // ---------------------------------------------------------
       
    33 //
       
    34 CCamCaptureSetupMenuListBoxModel* CCamCaptureSetupMenuListBoxModel::NewLC(
       
    35     CCamAppController& aController,
       
    36     TResourceReader& aReader )  
       
    37     {
       
    38     CCamCaptureSetupMenuListBoxModel* self = 
       
    39         new( ELeave ) CCamCaptureSetupMenuListBoxModel( aController );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructFromResourceL( aReader );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // Destructor
       
    47 // ---------------------------------------------------------
       
    48 //
       
    49 CCamCaptureSetupMenuListBoxModel::~CCamCaptureSetupMenuListBoxModel()
       
    50   {
       
    51   PRINT( _L("Camera => ~CCamCaptureSetupMenuListBoxModel") );
       
    52   iListItemPtrArray.ResetAndDestroy();
       
    53   iListItemPtrArray.Close();
       
    54   PRINT( _L("Camera <= ~CCamCaptureSetupMenuListBoxModel") );
       
    55   }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // ItemHasIconText
       
    59 // Returns whether the current item has icon text.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 TBool CCamCaptureSetupMenuListBoxModel::ItemHasIconText( TInt aItemIndex ) const
       
    63 	{
       
    64 	const TInt settingVal = iController.IntegerSettingValue( 
       
    65                 iListItemPtrArray[aItemIndex]->SettingsModelItemId() );
       
    66 	return iListItemPtrArray[aItemIndex]->IconText( settingVal ).Length() > 0;
       
    67 	}
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // CCamCaptureSetupMenuListBoxModel::BitmapForItem()
       
    71 // Returns a pointer to the bitmap associated with a specific list item.
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 CFbsBitmap* CCamCaptureSetupMenuListBoxModel::BitmapForItem( 
       
    75   TInt aItemIndex, TBool aMask )
       
    76     {
       
    77     // If the value in the settings model for this list item has changed
       
    78     // since the last time we asked for a bitmap, then let list item know
       
    79     // what it has changed to.
       
    80     TInt itemCurrentValue = iListItemPtrArray[aItemIndex]->CurrentValue();
       
    81     TInt itemSettingsModelItemId = 
       
    82         iListItemPtrArray[aItemIndex]->SettingsModelItemId();
       
    83     TInt itemNewValue = iController.IntegerSettingValue( 
       
    84                                         itemSettingsModelItemId );
       
    85     if ( itemCurrentValue != itemNewValue )
       
    86         {
       
    87         iListItemPtrArray[aItemIndex]->SetValueTo( itemNewValue );
       
    88         }
       
    89     // Return the bitmap that represents the list item value.
       
    90     if ( aMask )
       
    91         {
       
    92         return iListItemPtrArray[aItemIndex]->Mask();
       
    93         }
       
    94     else
       
    95         {
       
    96         return iListItemPtrArray[aItemIndex]->Bitmap();
       
    97         }
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CCamCaptureSetupMenuListBoxModel::TextForItem() const
       
   102 // Returns the text associated with a specific list item.
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 const TDesC& CCamCaptureSetupMenuListBoxModel::TextForItem( 
       
   106     TInt aItemIndex ) const
       
   107     {
       
   108     return iListItemPtrArray[aItemIndex]->Text();
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------
       
   112 // CCamCaptureSetupMenuListBoxModel::IconTextForItem() const
       
   113 // Returns the text to be used in place of an icon for a particular list item.
       
   114 // ---------------------------------------------------------
       
   115 //
       
   116 const TDesC& CCamCaptureSetupMenuListBoxModel::IconTextForItem( 
       
   117     TInt aItemIndex ) const
       
   118     {
       
   119 	const TInt settingVal = iController.IntegerSettingValue( 
       
   120             iListItemPtrArray[aItemIndex]->SettingsModelItemId() );
       
   121     return iListItemPtrArray[aItemIndex]->IconText( settingVal );
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CCamCaptureSetupMenuListBoxModel::SettingsModelIdAssociatedWithItem() const
       
   126 // Returns the settings model id associated with a particular list item.
       
   127 // ---------------------------------------------------------
       
   128 //
       
   129 TInt CCamCaptureSetupMenuListBoxModel::SettingsModelIdAssociatedWithItem
       
   130 ( TInt aItemIndex ) const
       
   131     {
       
   132     return iListItemPtrArray[aItemIndex]->SettingsModelItemId();
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CCamCaptureSetupMenuListBoxModel::NumberOfItems() const
       
   137 // Returns number of items that are in array
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 TInt CCamCaptureSetupMenuListBoxModel::NumberOfItems() const
       
   141     {
       
   142     return iListItemPtrArray.Count();
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // CCamCaptureSetupMenuListBoxModel::MatchableTextArray() const
       
   147 // Returns pointer to MDesCArray
       
   148 // ---------------------------------------------------------
       
   149 //
       
   150 const MDesCArray* CCamCaptureSetupMenuListBoxModel::MatchableTextArray() const
       
   151     {
       
   152     return iMatchableTextArray;
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------
       
   156 // Constructor
       
   157 // ---------------------------------------------------------
       
   158 //
       
   159 CCamCaptureSetupMenuListBoxModel::CCamCaptureSetupMenuListBoxModel
       
   160 ( CCamAppController& aController ) 
       
   161 : iController( aController )
       
   162     {
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------
       
   166 // CCamCaptureSetupMenuListBoxModel::ConstructFromResourceL()
       
   167 // 2nd phase constructor.
       
   168 // ---------------------------------------------------------
       
   169 //
       
   170 void CCamCaptureSetupMenuListBoxModel::ConstructFromResourceL( 
       
   171     TResourceReader& aReader ) 
       
   172     {
       
   173     // Create all list items from the resource reader.
       
   174     TInt itemCount = aReader.ReadInt16();
       
   175     TInt i;
       
   176     for ( i = 0; i < itemCount; ++i )
       
   177         {
       
   178         // Create a list item from the resource at current reading position.
       
   179         CCamCaptureSetupMenuListItem* newListItem = 
       
   180             CCamCaptureSetupMenuListItem::NewL( aReader );
       
   181 
       
   182         // Add it to the array of list items.
       
   183         CleanupStack::PushL( newListItem );
       
   184         User::LeaveIfError( iListItemPtrArray.Append( newListItem ) );
       
   185         CleanupStack::Pop( newListItem );
       
   186         }
       
   187     }
       
   188 
       
   189 
       
   190 //  End of File  
       
   191