Nokia N97 SDK
Example Applications Guide

CCEMusicContainer.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : CCEMusicContainer.cpp
00004 *  Part of     : Content Listing Framework Sample Application
00005 *  Interface   :
00006 *  Description :
00007 *  Version     :
00008 *
00009 *  Copyright (c) 2006 Nokia Corporation.
00010 *  This material, including documentation and any related
00011 *  computer programs, is protected by copyright controlled by
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 
00017 // INCLUDE FILES
00018 #include "CCEMusicContainer.h"
00019 
00020 #include "CCEMusicView.h"
00021 #include "CLFExample.hrh"
00022 #include "CLFExampleConsts.h"
00023 
00024 #include <aknlists.h>
00025 #include <barsread.h>
00026 #include <stringloader.h>
00027 #include <CLFExample.rsg>
00028 
00029 // ============================ MEMBER FUNCTIONS ===============================
00030 
00031 // -----------------------------------------------------------------------------
00032 // CCEMusicContainer::CCEMusicContainer
00033 // C++ default constructor can NOT contain any code, that
00034 // might leave.
00035 // -----------------------------------------------------------------------------
00036 //
00037 CCEMusicContainer::CCEMusicContainer( CAknView* aParent )
00038     : iParent( aParent )
00039     {
00040     }
00041 
00042 // -----------------------------------------------------------------------------
00043 // CCEMusicContainer::ConstructL
00044 // Symbian 2nd phase constructor can leave.
00045 // -----------------------------------------------------------------------------
00046 //
00047 void CCEMusicContainer::ConstructL()
00048     {
00049     // Create a window for the music view
00050     CreateWindowL();
00051 
00052     // Create a list box for the music files listing
00053     iListBox = new (ELeave) CAknDoubleStyleListBox;
00054     iListBox->MakeVisible( EFalse );
00055     iListBox->SetContainerWindowL( *this );
00056     iListBox->ConstructL( this, NULL );
00057     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
00058     iListBox->CreateScrollBarFrameL( ETrue );
00059     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
00060         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
00061 
00062     // Create text array for items of the list box
00063     iItemList = new (ELeave) CDesCArraySeg( KCEArrayGranularity );
00064     iListBox->Model()->SetItemTextArray( iItemList );
00065     iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
00066 
00067     // Set size of the window and activate it
00068     SetRect( iAvkonAppUi->ClientRect() );
00069     ActivateL();
00070     }
00071 
00072 // Destructor
00073 CCEMusicContainer::~CCEMusicContainer()
00074     {
00075     delete iItemList;
00076     delete iListBox;
00077     }
00078 
00079 // -----------------------------------------------------------------------------
00080 // CCEMusicContainer::AppendListBoxItemL
00081 // Append a new item with song name and artist to list box of group listing.
00082 // -----------------------------------------------------------------------------
00083 //
00084 void CCEMusicContainer::AppendListBoxItemL( CDesCArray* aTextItems )
00085     {
00086     HBufC* listItem;
00087 
00088     // Load the string from the resource. The string will be used to
00089     // generate a new item to the list box. There are different strings
00090     // for items that have an album tag and items that does not
00091     // have album, title or artist tag.
00092 
00093     // If song name and artist tags are present this string will be used.
00094     // It is also used to view file name if name or artist tag is missing.
00095     if( aTextItems->Count() == 2 )
00096         {
00097         listItem = StringLoader::LoadLC(
00098             R_CE_MUSIC_LIST_2_ITEM, *aTextItems, iEikonEnv );
00099         }
00100 
00101     // If song name, artist and album tags are all found
00102     else if ( aTextItems->Count() == 3 )
00103         {
00104         listItem = StringLoader::LoadLC(
00105             R_CE_MUSIC_LIST_3_ITEM, *aTextItems, iEikonEnv );
00106         }
00107 
00108     // If this else is reached, the function has not been used properly
00109     else
00110         {
00111         return;
00112         }
00113 
00114     // Append the new item to the list box and refresh it
00115     iItemList->AppendL( *listItem );
00116     iListBox->HandleItemAdditionL();
00117 
00118     CleanupStack::PopAndDestroy( listItem );
00119 
00120     // Make the list box visible, if needed
00121     if( !iListBox->IsVisible() )
00122         {
00123         iListBox->MakeVisible( ETrue );
00124         }
00125     }
00126 
00127 // -----------------------------------------------------------------------------
00128 // CCEMusicContainer::ResetListBoxL
00129 // Reset the list box of group listing.
00130 // -----------------------------------------------------------------------------
00131 //
00132 void CCEMusicContainer::ResetListBoxL()
00133     {
00134     // Clear the list box
00135     iItemList->Reset();
00136     iListBox->HandleItemRemovalL();
00137     iListBox->MakeVisible( EFalse );
00138     }
00139 
00140 // -----------------------------------------------------------------------------
00141 // CCEMusicContainer::CurrentItemIndex
00142 // Get index of the item that is currently selected in the list box.
00143 // -----------------------------------------------------------------------------
00144 //
00145 TInt CCEMusicContainer::CurrentItemIndex()
00146         {
00147         return iListBox->CurrentItemIndex();
00148         }
00149 
00150 // -----------------------------------------------------------------------------
00151 // CCEMusicContainer::SetCurrentItemIndex
00152 // Selects specified item of the list box.
00153 // -----------------------------------------------------------------------------
00154 //
00155 void CCEMusicContainer::SetCurrentItemIndex( TInt aIndex )
00156         {
00157     iListBox->SetCurrentItemIndexAndDraw( aIndex );
00158         }
00159 
00160 // -----------------------------------------------------------------------------
00161 // CCEMusicContainer::Draw
00162 // Draw the screen.
00163 // -----------------------------------------------------------------------------
00164 //
00165 void CCEMusicContainer::Draw( const TRect& aRect ) const
00166     {
00167     // Get the graphics content and clear the screen
00168     CWindowGc& gc = SystemGc();
00169     gc.Clear( aRect );
00170     }
00171 
00172 // -----------------------------------------------------------------------------
00173 // CCEMusicContainer::OfferKeyEventL
00174 // Handle user's key events.
00175 // -----------------------------------------------------------------------------
00176 //
00177 TKeyResponse CCEMusicContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
00178         {
00179         if( aType == EEventKey )
00180                 {
00181                 switch( aKeyEvent.iScanCode )
00182                         {
00183                         case EStdKeyUpArrow:
00184                         case EStdKeyDownArrow:
00185                                 {
00186                 // Send arrow key events to the list box for moving the focus
00187                                 iListBox->OfferKeyEventL( aKeyEvent, aType );
00188                                 return EKeyWasConsumed;
00189                                 }
00190 
00191                         case EStdKeyDevice3:
00192                                 {
00193                 // Send selection event to parent view
00194                                 iParent->HandleCommandL( ECECmdSelect );
00195                                 return EKeyWasConsumed;
00196                                 }
00197 
00198                         default:
00199                                 {
00200                                 break;
00201                                 }
00202                         }
00203                 }
00204         return EKeyWasNotConsumed;
00205         }
00206 
00207 // -----------------------------------------------------------------------------
00208 // CCEMusicContainer::CountComponentControls
00209 // Get count of component controls in the container.
00210 // -----------------------------------------------------------------------------
00211 //
00212 TInt CCEMusicContainer::CountComponentControls() const
00213     {
00214     return KCENumberOfComponentsInMusicContainer;
00215     }
00216 
00217 // -----------------------------------------------------------------------------
00218 // CCEMusicContainer::ComponentControl
00219 // Get component control by its index.
00220 // -----------------------------------------------------------------------------
00221 //
00222 CCoeControl* CCEMusicContainer::ComponentControl(TInt aIndex) const
00223     {
00224     switch( aIndex )
00225         {
00226         case 0:
00227             {
00228                 return iListBox;
00229                     }
00230         default:
00231             {
00232                 return NULL;
00233                 }
00234         }
00235     }
00236 
00237 // -----------------------------------------------------------------------------
00238 // CCEMusicContainer::HandleResourceChange
00239 // Handle change of the screen resolution.
00240 // -----------------------------------------------------------------------------
00241 //
00242 void CCEMusicContainer::HandleResourceChange( TInt aType )
00243     {
00244     if ( aType == KEikDynamicLayoutVariantSwitch )
00245         {
00246         ( static_cast <CCEMusicView *> ( iParent ) )->HandleClientRectChange();
00247         }
00248     }
00249 
00250 
00251 // -----------------------------------------------------------------------------
00252 // CCEMusicContainer::SizeChanged
00253 // Responds to size changes to sets the size and position of the contents of
00254 // this control.
00255 // -----------------------------------------------------------------------------
00256 //
00257 void CCEMusicContainer::SizeChanged()
00258         {
00259         iListBox->SetRect( Rect() );
00260         }
00261 
00262 // End of File

© Nokia 2009

Back to top