profilesservices/FileList/Src/CFLDSingleGraphicEntryFormatter.cpp
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     1 /*
       
     2 * Copyright (c) 2002 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: Implementation of the CFLDSingleGraphicEntryFormatter.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // CLASS HEADER
       
    21 #include "CFLDSingleGraphicEntryFormatter.h"
       
    22 
       
    23 // INTERNAL INCLUDES
       
    24 #include "CFLDEntryReference.h"
       
    25 
       
    26 // EXTERNAL INCLUDES
       
    27 #include <f32file.h>	// For TParsePtrC
       
    28 #include <AknUtils.h>	// For AknTextUtils
       
    29 #include <driveinfo.h>
       
    30 
       
    31 // CONSTANTS
       
    32 namespace
       
    33 	{
       
    34 	// Some helper literals
       
    35 	_LIT( KFLDTab, "\t" );
       
    36 	_LIT( KFLDIgnoredExt, ".rng" );
       
    37 
       
    38 	// these icon array indexes must match with the implementation
       
    39 	// of the function CFLDFileListContainer.cpp/PopulateIconArrayL
       
    40 	_LIT( KFLDZeroAndTab, "0\t" );
       
    41 	_LIT( KFLDSoundAndTab, "3\t" );
       
    42 	_LIT( KFLDVideoAndTab, "4\t" );
       
    43 	_LIT( KFLDMemoryCard, "2" );
       
    44 	_LIT( KFLDMassStorage, "5" );
       
    45 	
       
    46 	}
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CFLDSingleGraphicEntryFormatter::CFLDSingleGraphicEntryFormatter
       
    52 // C++ constructor can NOT contain any code, that might leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CFLDSingleGraphicEntryFormatter::CFLDSingleGraphicEntryFormatter()
       
    56 	{
       
    57 	
       
    58 	}
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CFLDSingleGraphicEntryFormatter::~CFLDSingleGraphicEntryFormatter()
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CFLDSingleGraphicEntryFormatter::~CFLDSingleGraphicEntryFormatter()
       
    65     {
       
    66     delete iDriveUtil;
       
    67     }
       
    68     
       
    69 // -----------------------------------------------------------------------------
       
    70 // CFLDSingleGraphicEntryFormatter::FormatL()
       
    71 // (other items were commented in a header).
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CFLDSingleGraphicEntryFormatter::FormatL( CFLDEntryReference& aEntry )
       
    75     {
       
    76     if ( !iDriveUtil )
       
    77         {
       
    78         iDriveUtil = CDriveUtil::NewL();
       
    79         }
       
    80         
       
    81 	HBufC* formattedName = NULL;
       
    82 	HBufC& pathAndMediaFileName = aEntry.PathAndMediaFileName();
       
    83     TParsePtrC parsedName( pathAndMediaFileName.Des() );
       
    84 
       
    85 #ifdef RD_VIDEO_AS_RINGING_TONE	    
       
    86 	TBool isFileVideo( EFalse );
       
    87 	if ( aEntry.MediaType() == ECLFMediaTypeVideo )
       
    88 		{
       
    89 		isFileVideo = ETrue;
       
    90 		}
       
    91   
       
    92     if( isFileVideo )
       
    93     	{
       
    94     	formattedName = HBufC::NewL( parsedName.NameAndExt().Length() + KFLDVideoAndTab().Length() * 2 );
       
    95     	}
       
    96     else
       
    97     	{
       
    98     	formattedName = HBufC::NewL( parsedName.NameAndExt().Length() + KFLDSoundAndTab().Length() * 2 );
       
    99     	}
       
   100 #else
       
   101    	formattedName = HBufC::NewL( parsedName.NameAndExt().Length() + KFLDZeroAndTab().Length() * 2 );
       
   102 #endif
       
   103 
       
   104 	aEntry.SetFormattedPresentation( formattedName );
       
   105 		
       
   106 	// Combine all the data to the formatted data descriptor:
       
   107 	TPtr des = formattedName->Des();
       
   108 
       
   109  	// RNG files are shown without the file extension
       
   110     TPtrC ext( parsedName.Ext() );
       
   111     if ( ext.CompareF( KFLDIgnoredExt ) == 0 )
       
   112         {
       
   113         des.Copy( parsedName.Name() );
       
   114         }
       
   115     else
       
   116         {
       
   117         des.Copy( parsedName.NameAndExt() );
       
   118         }
       
   119         
       
   120 	// Make sure that the file name does not contain tab characters
       
   121 	AknTextUtils::ReplaceCharacters( des, KAknReplaceListControlChars, TChar(' ') );        
       
   122 
       
   123 #ifdef RD_VIDEO_AS_RINGING_TONE	    
       
   124 	if( isFileVideo )
       
   125 		{
       
   126 		des.Insert( 0, KFLDVideoAndTab );
       
   127 		}
       
   128 	else
       
   129 		{
       
   130 		des.Insert( 0, KFLDSoundAndTab );
       
   131 		}
       
   132     
       
   133 #else
       
   134     des.Insert( 0, KFLDZeroAndTab );
       
   135 #endif    
       
   136 	des.Append( KFLDTab );
       
   137          
       
   138 	/*
       
   139 	TChar mmcDriveLetter( PathInfo::MemoryCardRootPath()[0] );
       
   140 	mmcDriveLetter.UpperCase();
       
   141 
       
   142     // Check if the entry is on MMC
       
   143     TChar entryDriveLetter( parsedName.Drive()[ 0 ] );
       
   144     entryDriveLetter.UpperCase();
       
   145 
       
   146     if ( entryDriveLetter == mmcDriveLetter )
       
   147         {
       
   148         des.Append( '2' ); // MMC icon index
       
   149         }
       
   150     */
       
   151     
       
   152     if ( iDriveUtil->IsMemoryCard( aEntry.PathAndMediaFileName() ) )
       
   153         {
       
   154         des.Append( KFLDMemoryCard );
       
   155         }
       
   156     else if ( iDriveUtil->IsMassStorage( aEntry.PathAndMediaFileName() ) )
       
   157         {
       
   158         des.Append( KFLDMassStorage );
       
   159         }
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CFLDSingleGraphicEntryFormatter::FormatTextLC()
       
   164 // (other items were commented in a header).
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 HBufC* CFLDSingleGraphicEntryFormatter::FormatTextLC( const TDesC& aText )
       
   168     {
       
   169     HBufC* text = NULL;
       
   170     if( aText.Find( KFLDTab ) == KErrNotFound )
       
   171         {
       
   172         text = HBufC::NewLC( aText.Length() + KFLDZeroAndTab().Length() );
       
   173         TPtr des( text->Des() );
       
   174         des.Copy( KFLDZeroAndTab );
       
   175         des.Append( aText );
       
   176         }
       
   177     else
       
   178         {
       
   179         text = aText.AllocLC();
       
   180         }
       
   181     return text;
       
   182     }
       
   183 
       
   184 
       
   185 
       
   186 
       
   187 /******************************************************************************
       
   188  * class CDriveUtil
       
   189  ******************************************************************************/
       
   190 
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CDriveUtil::NewL
       
   194 // 
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 CDriveUtil* CDriveUtil::NewL()
       
   198     {
       
   199     CDriveUtil* self = new (ELeave) CDriveUtil();
       
   200 	CleanupStack::PushL(self);
       
   201 	self->ConstructL();
       
   202 	CleanupStack::Pop(self);
       
   203 
       
   204     return self;
       
   205     }
       
   206 
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // Destructor
       
   210 // 
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 CDriveUtil::~CDriveUtil()
       
   214     {
       
   215 	iFsSession.Close();
       
   216     }
       
   217 
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CDriveUtil::CDriveUtil
       
   221 // 
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 CDriveUtil::CDriveUtil()
       
   225     {
       
   226     }
       
   227 
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CDriveUtil::ConstructL
       
   231 // 
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void CDriveUtil::ConstructL()
       
   235     {
       
   236     User::LeaveIfError( iFsSession.Connect() );
       
   237     }
       
   238 
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CDriveUtil::IsMassStorage
       
   242 // 
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 TBool CDriveUtil::IsMassStorage(const TDesC& aFullPath)
       
   246     {
       
   247     const TUint KMassStorageBits = DriveInfo::EDriveInternal |
       
   248                                    DriveInfo::EDriveExternallyMountable;
       
   249 
       
   250     TDriveUnit drive(aFullPath);
       
   251     TUint driveStatus(0);
       
   252     
       
   253     TInt err = DriveInfo::GetDriveStatus( iFsSession, drive, driveStatus );
       
   254     if ( err != KErrNone )
       
   255         {
       
   256         return EFalse;
       
   257         }
       
   258         
       
   259     if ( (driveStatus & KMassStorageBits) == KMassStorageBits )
       
   260         {
       
   261         return ETrue;
       
   262         }
       
   263         
       
   264     return EFalse;
       
   265     }
       
   266 
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CDriveUtil::IsMemoryCard
       
   270 // 
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 TBool CDriveUtil::IsMemoryCard(const TDesC& aFullPath)
       
   274     {
       
   275     const TUint KMemoryCardBits = DriveInfo::EDriveRemovable |
       
   276                                   DriveInfo::EDriveExternallyMountable;
       
   277 
       
   278     TDriveUnit drive(aFullPath);
       
   279     TUint driveStatus(0);
       
   280     
       
   281     TInt err = DriveInfo::GetDriveStatus( iFsSession, drive, driveStatus );
       
   282     if ( err != KErrNone )
       
   283         {
       
   284         return EFalse;
       
   285         }
       
   286         
       
   287     if ( (driveStatus & KMemoryCardBits) == KMemoryCardBits )
       
   288         {
       
   289         return ETrue;
       
   290         }
       
   291         
       
   292     return EFalse;
       
   293     }
       
   294 
       
   295 
       
   296 //  End of File