homesync/contentmanager/mediaservant/src/msitembrowser.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2009 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:  CMSItemBrowser class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <AknIconArray.h>
       
    21 #include <mediaservant.rsg>
       
    22 #include <mediaservant.mbg>
       
    23 #include <avkon.mbg>
       
    24 #include <aknnotedialog.h>
       
    25 #include <StringLoader.h>
       
    26 #include <e32math.h>
       
    27 
       
    28 #include "cmbaselistitem.h"
       
    29 #include "msappui.h"
       
    30 #include "msitembrowser.h"
       
    31 #include "msengine.h"
       
    32 #include "msconstants.h"
       
    33 #include "msdebug.h"
       
    34 
       
    35 
       
    36 // --------------------------------------------------------------------------
       
    37 // CMSItemBrowser::ConstructL()
       
    38 // --------------------------------------------------------------------------
       
    39 //
       
    40 void CMSItemBrowser::ConstructL( TRect aRect )
       
    41     {
       
    42     LOG(_L("[MediaServant]\t CMSItemBrowser::ConstructL"));    
       
    43 
       
    44     GetBrowseDataL();
       
    45 
       
    46     CreateWindowL();
       
    47 
       
    48     iListBox = new (ELeave) CAknDoubleGraphicStyleListBox;
       
    49 
       
    50     SetListBoxFromResourceL(iListBox, R_BROWSE_VIEW_LISTBOX);
       
    51 
       
    52     // Create icons
       
    53     CAknIconArray* icons = new (ELeave) CAknIconArray( EIconCount );
       
    54     CleanupStack::PushL( icons );
       
    55     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
    56 
       
    57     // mark icon
       
    58     AppendIconToArrayL( icons, skin,
       
    59                         KAvkonMifFileName,
       
    60                         KAknsIIDDefault,
       
    61                         EMbmAvkonQgn_indi_marked_add,
       
    62                         EMbmAvkonQgn_indi_marked_add_mask );
       
    63 
       
    64     // image icon
       
    65     AppendIconToArrayL( icons, skin,
       
    66                         KMSMifFileName,
       
    67                         KAknsIIDDefault,
       
    68                         EMbmMediaservantQgn_prop_file_image,
       
    69                         EMbmMediaservantQgn_prop_file_image_mask );
       
    70     // audio icon
       
    71     AppendIconToArrayL( icons, skin,
       
    72                         KMSMifFileName,
       
    73                         KAknsIIDDefault,
       
    74                         EMbmMediaservantQgn_prop_file_audio,
       
    75                         EMbmMediaservantQgn_prop_file_audio_mask );
       
    76     // video icon
       
    77     AppendIconToArrayL( icons, skin,
       
    78                         KMSMifFileName,
       
    79                         KAknsIIDDefault,
       
    80                         EMbmMediaservantQgn_prop_file_video,
       
    81                         EMbmMediaservantQgn_prop_file_video_mask );
       
    82 
       
    83 
       
    84     iListBox->ItemDrawer()->FormattedCellData()->SetIconArray(icons);
       
    85     CleanupStack::Pop(icons);
       
    86 
       
    87     // Container is listbox observer
       
    88     iListBox->SetListBoxObserver( this );
       
    89 
       
    90     SetRect(aRect);
       
    91 
       
    92     // Add data to listbox
       
    93     UpdateListBoxDataL();
       
    94 
       
    95     ActivateL(); // Activates window. ( Ready to draw )
       
    96     }
       
    97 
       
    98 // --------------------------------------------------------------------------
       
    99 // CMSItemBrowser::~CMSItemBrowser
       
   100 // --------------------------------------------------------------------------
       
   101 CMSItemBrowser::~CMSItemBrowser()
       
   102     {
       
   103     if ( iItemArray )
       
   104         {
       
   105         iItemArray->ResetAndDestroy();
       
   106         iItemArray->Close();
       
   107         delete iItemArray;
       
   108         }
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CMSItemBrowser::CountComponentControls()
       
   113 // Returns number of components.
       
   114 // --------------------------------------------------------------------------
       
   115 //
       
   116 TInt CMSItemBrowser::CountComponentControls() const
       
   117     {
       
   118     return 1; // return number of controls inside this container
       
   119     }
       
   120 
       
   121 // --------------------------------------------------------------------------
       
   122 // CMSItemBrowser::ComponentControl()
       
   123 // Returns pointer to particular component.
       
   124 // --------------------------------------------------------------------------
       
   125 //
       
   126 CCoeControl* CMSItemBrowser::ComponentControl( TInt /*aIndex*/) const
       
   127 
       
   128     {
       
   129     return iListBox; // return a pointer to the listbox
       
   130     }
       
   131 
       
   132 // --------------------------------------------------------------------------
       
   133 // CMSItemBrowser::OfferKeyEventL()
       
   134 // Handles the key events.
       
   135 // --------------------------------------------------------------------------
       
   136 //
       
   137 TKeyResponse CMSItemBrowser::OfferKeyEventL(
       
   138     const TKeyEvent& aKeyEvent,
       
   139     TEventCode aType )
       
   140     {
       
   141     LOG(_L("[MediaServant]\t CMSItemBrowser::OfferKeyEventL"));
       
   142 
       
   143     TKeyResponse response = EKeyWasNotConsumed;
       
   144 
       
   145     if ( aType != EEventKey )
       
   146         {
       
   147         response =  EKeyWasNotConsumed;
       
   148         }
       
   149 
       
   150     if ( iListBox )
       
   151         {
       
   152         response = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   153         }
       
   154 
       
   155     return response;
       
   156     }
       
   157 
       
   158 // --------------------------------------------------------------------------
       
   159 // CMSItemBrowser::HandleListBoxEventL()
       
   160 // Handles listbox event.
       
   161 // --------------------------------------------------------------------------
       
   162 void CMSItemBrowser::HandleListBoxEventL(
       
   163     CEikListBox* /*aListBox*/,
       
   164     TListBoxEvent /*aEventType*/ )
       
   165     {
       
   166     LOG(_L("[MediaServant]\t CMSItemBrowser::HandleListBoxEventL"));
       
   167     }
       
   168 
       
   169 // --------------------------------------------------------------------------
       
   170 // CMSItemBrowser::ReadDataFromEngineL()
       
   171 // Reads data items from engine
       
   172 // --------------------------------------------------------------------------
       
   173 //
       
   174 void CMSItemBrowser::UpdateListBoxDataL()
       
   175     {
       
   176     LOG(_L("[MediaServant]\t CMSItemBrowser::UpdateListBoxDataL"));
       
   177 
       
   178     // Listbox items
       
   179     CDesCArray* itemArray = static_cast<CDesCArray*>
       
   180                                    (iListBox->Model()->ItemTextArray());
       
   181     // Clear list
       
   182     itemArray->Reset();
       
   183 
       
   184     TInt count = iItemArray->Count();
       
   185 
       
   186     for (TInt index = 0; index < count; index++)
       
   187         {
       
   188         TInt iconType;
       
   189         CCmBaseListItem* item = (*iItemArray)[index];
       
   190         TUint32 fileSize = item->Size();
       
   191         HBufC* fileSizeStr = NULL;
       
   192         HBufC* primaryText = HBufC::NewLC( KMaxDataTypeLength );
       
   193         HBufC* secondaryText = HBufC::NewLC( KMaxDataTypeLength );
       
   194 
       
   195         switch ( iMediaType )
       
   196             {
       
   197             case ECmVideo:
       
   198             // fall through
       
   199             case ECmOtherVideo:
       
   200                 {
       
   201                 iconType = EIconVideo;
       
   202                 break;
       
   203                 }
       
   204             case ECmImage:
       
   205             // fall through
       
   206             case ECmOtherImage:
       
   207                 {
       
   208                 iconType = EIconImage;
       
   209                 break;
       
   210                 }
       
   211             case ECmAudio:
       
   212                 {
       
   213                 iconType = EIconAudio;
       
   214 
       
   215                 secondaryText->Des().Copy( item->SecondaryText() );
       
   216                 break;
       
   217                 }
       
   218             default:
       
   219                 {
       
   220                 iconType = EIconVideo;
       
   221                 break;
       
   222                 }
       
   223             }
       
   224 
       
   225         // Set item secondary text
       
   226         if ( fileSize < KMega )
       
   227             {
       
   228             if ( secondaryText->Length() )
       
   229                 {
       
   230                 secondaryText->Des().Append( KDelimiter);
       
   231                 }
       
   232 
       
   233             fileSizeStr = StringLoader::LoadLC(
       
   234                                   R_MS_FILE_SIZE_KB, fileSize / KKilo );
       
   235             }
       
   236         else
       
   237             {
       
   238             if ( secondaryText->Length() )
       
   239                 {
       
   240                 secondaryText->Des().Append( KDelimiter );
       
   241                 }
       
   242 
       
   243             TReal size( 0 );
       
   244             Math::Round( size, TReal( fileSize ) / KMega, 0 );
       
   245             fileSizeStr = StringLoader::LoadLC(
       
   246                                   R_MS_FILE_SIZE_MB, size );
       
   247             }
       
   248 
       
   249         secondaryText->Des().Append( *fileSizeStr );
       
   250         if ( fileSizeStr )
       
   251             {
       
   252             CleanupStack::PopAndDestroy( fileSizeStr );
       
   253             }
       
   254 
       
   255         // do number conversion
       
   256         TPtr ptr = secondaryText->Des();
       
   257         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   258 
       
   259         // add item
       
   260         AppendItemToListBoxArrayL(
       
   261                             iListBox,
       
   262                             iListBox->Model(),
       
   263                             iconType, // default icon
       
   264                             (*iItemArray)[index]->PrimaryText(),
       
   265                             *secondaryText );
       
   266         CleanupStack::PopAndDestroy( secondaryText );
       
   267         CleanupStack::PopAndDestroy( primaryText );
       
   268         }
       
   269     }
       
   270 
       
   271 // --------------------------------------------------------------------------
       
   272 // CMSItemBrowser::SetCurrentFileStatus
       
   273 // --------------------------------------------------------------------------
       
   274 //
       
   275 void CMSItemBrowser::SetFileStatus( TInt aIndex,
       
   276                                            TCmListItemStatus aStatus )
       
   277     {
       
   278     LOG(_L("[MediaServant]\t CMSItemBrowser::SetFileStatus"));
       
   279 
       
   280     (*iItemArray)[aIndex]->SetStatus( aStatus );
       
   281     }
       
   282 
       
   283 // --------------------------------------------------------------------------
       
   284 // CMSItemBrowser::GetCurrentFileStatus
       
   285 // --------------------------------------------------------------------------
       
   286 //
       
   287 TCmListItemStatus CMSItemBrowser::FileStatus( TInt aIndex )
       
   288     {
       
   289     LOG(_L("[MediaServant]\t CMSItemBrowser::FileStatus"));
       
   290 
       
   291     return (*iItemArray)[ aIndex ]->Status();
       
   292     }
       
   293 
       
   294 // --------------------------------------------------------------------------
       
   295 // CMSItemBrowser::ListBox()
       
   296 // Returns listbox
       
   297 // --------------------------------------------------------------------------
       
   298 //
       
   299 CEikListBox* CMSItemBrowser::ListBox()
       
   300     {
       
   301     return iListBox;
       
   302     }
       
   303 
       
   304 // --------------------------------------------------------------------------
       
   305 // CMSItemBrowser::SizeChanged()
       
   306 // Called by framework when the view size is changed.
       
   307 // --------------------------------------------------------------------------
       
   308 //
       
   309 void CMSItemBrowser::SizeChanged()
       
   310     {
       
   311     // container control resize code.
       
   312     if ( iListBox )
       
   313         {
       
   314         iListBox->SetRect( Rect() ); // Set rectangle of listbox.
       
   315         }
       
   316     }