filemanager/View/src/CFileManagerInfoPopup.cpp
branchRCL_3
changeset 21 65326cf895ed
equal deleted inserted replaced
20:491b3ed49290 21:65326cf895ed
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Popup to show the item information, view info
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <aknlists.h>
       
    22 #include <StringLoader.h>
       
    23 #include <cmemstatepopup.h>
       
    24 #include <filemanagerview.rsg>
       
    25 #include <CFileManagerItemProperties.h>
       
    26 #include <CFileManagerFeatureManager.h>
       
    27 #include <drmuihandling.h>
       
    28 #include "CFileManagerInfoPopup.h"
       
    29 #include "CFileManagerFullOmaDrmInfo.h"
       
    30 
       
    31 // CONSTANTS
       
    32 _LIT( KDateFormat1, "%1" );
       
    33 _LIT( KDateFormat2, "%2" );
       
    34 _LIT( KDateFormat3, "%3" );
       
    35 _LIT( KTimeFormatBefore, "%-B" );
       
    36 _LIT( KTimeFormatAfter, "%+B" );
       
    37 _LIT( KTimeFormatHour, "%J" );
       
    38 _LIT( KTimeFormatMinutes, "%T" );
       
    39 _LIT( KTimeFormatSpace, " ");
       
    40 
       
    41 _LIT( KNumberFormat, "%d" );
       
    42 _LIT( KSeparator, "\t" );
       
    43 const TUint KDefaultItemCount = 3;
       
    44 const TUint KMaxInfoPopupWidth = 16; // From AVKON LAF document
       
    45 const TUint KSecondSeparator = 1;
       
    46 const TUint KThirdSeparator = 2;
       
    47 const TInt KNumBufLen = 24;
       
    48 _LIT( KNumBufFormatString, "%d" );
       
    49 _LIT( KNumBufSpaceString, " " );
       
    50 
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CFileManagerInfoPopup::CFileManagerInfoPopup
       
    56 // C++ default constructor can NOT contain any code, that
       
    57 // might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CFileManagerInfoPopup::CFileManagerInfoPopup(
       
    61         CFileManagerItemProperties& aProperties,
       
    62         const CFileManagerFeatureManager& aFeatureManager ) :
       
    63     iProperties( aProperties ),
       
    64     iFeatureManager( aFeatureManager ),
       
    65     iUiHandling( NULL )
       
    66     {
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CFileManagerInfoPopup::ConstructDataArrayL
       
    71 // 
       
    72 // -----------------------------------------------------------------------------
       
    73 // 
       
    74 MDesCArray* CFileManagerInfoPopup::ConstructDataArrayL()
       
    75     {
       
    76     // Get unit utility instance
       
    77     CMemStatePopup::GetUtilL( iUtil );
       
    78 
       
    79     CDesCArray* array = new( ELeave ) CDesCArrayFlat( KDefaultItemCount );
       
    80     CleanupStack::PushL( array );
       
    81 
       
    82     HBufC* title = NULL;
       
    83     TUint32 itemType( iProperties.TypeL() );
       
    84     if( itemType & CFileManagerItemProperties::EFolder )
       
    85         {
       
    86         title = StringLoader::LoadLC( R_QTN_FMGR_INFO_HEADING_FLDR );
       
    87         }
       
    88     else if( itemType & CFileManagerItemProperties::ELink )
       
    89         {
       
    90         title = StringLoader::LoadLC( R_QTN_FMGR_INFO_HEADING_LINK );
       
    91         }
       
    92     else
       
    93         {
       
    94         title = StringLoader::LoadLC( R_QTN_FMGR_INFO_HEADING_FILE );
       
    95         }
       
    96     SetTitleL( *title );
       
    97     CleanupStack::PopAndDestroy( title );
       
    98 
       
    99     if ( ( itemType & CFileManagerItemProperties::EDrmProtected ) &&
       
   100          iFeatureManager.IsDrmFullSupported() )
       
   101         {
       
   102         CFileManagerFullOmaDrmInfo* drmInfo = 
       
   103             CFileManagerFullOmaDrmInfo::NewLC( *array, iProperties.FullPath(), *iCoeEnv );  
       
   104         CleanupStack::PopAndDestroy( drmInfo );
       
   105         }
       
   106 
       
   107     // Name of the file/folder
       
   108     HBufC* nameEntry = NameEntryLC();
       
   109     array->AppendL( *nameEntry );
       
   110     CleanupStack::PopAndDestroy( nameEntry );
       
   111 
       
   112     if( itemType & CFileManagerItemProperties::EFile )
       
   113         {
       
   114         // Type of the file 
       
   115         HBufC* type = TypeEntryLC();
       
   116         array->AppendL( *type );
       
   117         CleanupStack::PopAndDestroy( type );
       
   118         }
       
   119 
       
   120     // Modification date
       
   121     HBufC* date = DateEntryLC();
       
   122     array->AppendL( *date );
       
   123     CleanupStack::PopAndDestroy( date ); 
       
   124 
       
   125     // Modification time
       
   126     HBufC* time = TimeEntryLC();
       
   127     array->AppendL( *time );
       
   128     CleanupStack::PopAndDestroy( time ); 
       
   129 
       
   130     // Size of file/folder
       
   131     HBufC* size = SizeEntryLC();
       
   132     array->AppendL( *size );
       
   133     CleanupStack::PopAndDestroy( size );
       
   134 
       
   135     TUint32 defaultFolderMask = CFileManagerItemProperties::EFolder |
       
   136                                 CFileManagerItemProperties::EDefault;
       
   137     if( ( itemType & defaultFolderMask ) == defaultFolderMask )
       
   138         {
       
   139         HBufC* str = DefaultFolderEntryLC();
       
   140         array->AppendL( *str );
       
   141         CleanupStack::PopAndDestroy( str );
       
   142         }
       
   143 
       
   144     if( itemType & CFileManagerItemProperties::EFolder )
       
   145         {
       
   146         HBufC* folders = ResourceStringValueLC( 
       
   147             R_QTN_FMGR_INFO_CONTAIN_FLDR, 
       
   148             iProperties.FoldersContainedL() );
       
   149         array->AppendL( *folders );
       
   150         CleanupStack::PopAndDestroy( folders );
       
   151 
       
   152         HBufC* files = ResourceStringValueLC( 
       
   153             R_QTN_FMGR_INFO_CONTAIN_FILE, 
       
   154             iProperties.FilesContainedL()  );
       
   155         array->AppendL( *files );
       
   156         CleanupStack::PopAndDestroy( files );
       
   157         }
       
   158 
       
   159     CleanupStack::Pop( array ); 
       
   160     return array;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CFileManagerInfoPopup::NewL
       
   165 // Two-phased constructor.
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 CFileManagerInfoPopup* CFileManagerInfoPopup::NewL(
       
   169         CFileManagerItemProperties& aProperties,
       
   170         const CFileManagerFeatureManager& aFeatureManager )
       
   171     {
       
   172     CFileManagerInfoPopup* self = new( ELeave ) CFileManagerInfoPopup(
       
   173         aProperties, aFeatureManager );
       
   174     
       
   175     CleanupStack::PushL( self );
       
   176     self->ConstructL();
       
   177     CleanupStack::Pop( self );
       
   178 
       
   179     return self;
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CFileManagerInfoPopup::ConstructL
       
   184 // Symbian 2nd phase constructor can leave.
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CFileManagerInfoPopup::ConstructL()
       
   188     {
       
   189     iUiHandling = DRM::CDrmUiHandling::NewL();
       
   190     
       
   191     CFileManagerPopupBase::ConstructL();
       
   192     }
       
   193     
       
   194 // -----------------------------------------------------------------------------
       
   195 // CFileManagerInfoPopup::~CFileManagerInfoPopup
       
   196 // Destructor
       
   197 // -----------------------------------------------------------------------------
       
   198 // 
       
   199 CFileManagerInfoPopup::~CFileManagerInfoPopup()
       
   200     {
       
   201     delete iUtil;
       
   202     
       
   203     delete iUiHandling;
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CFileManagerInfoPopup::NameEntryLC
       
   208 // 
       
   209 // -----------------------------------------------------------------------------
       
   210 // 
       
   211 HBufC* CFileManagerInfoPopup::NameEntryLC()
       
   212     {
       
   213     HBufC* name = StringLoader::LoadLC( R_QTN_SWINS_LSH2_APPS_NAME );
       
   214     HBufC* dataStr = HBufC::NewLC(
       
   215         name->Length() + 1 + iProperties.LocalizedName().Length() );
       
   216     TPtr dataPtr( dataStr->Des() );
       
   217     dataPtr.Append( *name );
       
   218     dataPtr.Append( KSeparator );
       
   219     HBufC* itemNameBuf = NULL;
       
   220     if ( iProperties.TypeL() & CFileManagerItemProperties::EFolder )
       
   221         {
       
   222         const TPtrC ptr( iProperties.LocalizedName() );
       
   223         itemNameBuf = ptr.AllocLC();
       
   224         }
       
   225     else
       
   226         {
       
   227         const TPtrC ptr( iProperties.Name() );
       
   228         itemNameBuf = ptr.AllocLC();
       
   229         }
       
   230     // Remove all possible tabs in the name so listbox won't get broken
       
   231     TPtr itemNamePtr = itemNameBuf->Des();
       
   232     AknTextUtils::StripCharacters( itemNamePtr, KSeparator );
       
   233     dataPtr.Append( itemNamePtr );
       
   234     CleanupStack::PopAndDestroy( itemNameBuf );
       
   235     CleanupStack::Pop( dataStr );
       
   236     CleanupStack::PopAndDestroy( name );
       
   237     CleanupStack::PushL( dataStr );
       
   238 
       
   239     return dataStr;
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CFileManagerInfoPopup::TypeEntryLC
       
   244 // 
       
   245 // -----------------------------------------------------------------------------
       
   246 // 
       
   247 HBufC* CFileManagerInfoPopup::TypeEntryLC()
       
   248     {
       
   249     HBufC* type = StringLoader::LoadLC( R_QTN_SWINS_LSH2_APPS_TYPE );
       
   250     HBufC* dataStr = HBufC::NewL( type->Length() + 1 + iProperties.Ext().Length() );
       
   251     TPtr dataPtr( dataStr->Des() );
       
   252     dataPtr.Append( *type );
       
   253     dataPtr.Append( KSeparator );
       
   254     const TPtrC ptr( iProperties.Ext() );
       
   255     HBufC* extBuf = ptr.AllocLC();
       
   256     // Remove all possible tabs in the name so listbox won't get broken
       
   257     TPtr extPtr = extBuf->Des();
       
   258     AknTextUtils::StripCharacters( extPtr, KSeparator );
       
   259     dataPtr.Append( extPtr );
       
   260     CleanupStack::PopAndDestroy( extBuf );
       
   261     CleanupStack::PopAndDestroy( type );
       
   262     CleanupStack::PushL( dataStr );
       
   263 
       
   264     return dataStr;
       
   265     }
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CFileManagerInfoPopup::DateEntryLC
       
   269 // 
       
   270 // -----------------------------------------------------------------------------
       
   271 // 
       
   272 HBufC* CFileManagerInfoPopup::DateEntryLC()
       
   273     {
       
   274     HBufC* date = StringLoader::LoadLC( R_QTN_ALBUM_DATIM_DATE );
       
   275     TBuf<KMaxInfoPopupWidth> dateStr;
       
   276     TBuf<KMaxInfoPopupWidth> dateStrFormat;
       
   277     // Localized date separator form
       
   278     TLocale local;
       
   279     TTime localTime;
       
   280     User::LeaveIfError( iProperties.ModifiedLocalDate( localTime ) );
       
   281     dateStrFormat.Append( KDateFormat1 );
       
   282     dateStrFormat.Append( local.DateSeparator( KSecondSeparator ) );
       
   283     dateStrFormat.Append( KDateFormat2 );
       
   284     dateStrFormat.Append( local.DateSeparator( KThirdSeparator ) );
       
   285     dateStrFormat.Append( KDateFormat3 );
       
   286     localTime.FormatL( dateStr, dateStrFormat );
       
   287     HBufC* dataStr = HBufC::NewL( date->Length() + 1 + dateStr.Length() );
       
   288     TPtr dataPtr( dataStr->Des() );
       
   289     dataPtr.Append( *date );
       
   290     dataPtr.Append( KSeparator );
       
   291     dataPtr.Append( dateStr );
       
   292 
       
   293     CleanupStack::PopAndDestroy( date );
       
   294     CleanupStack::PushL( dataStr );
       
   295 
       
   296     AknTextUtils::LanguageSpecificNumberConversion( dataPtr );
       
   297 
       
   298     return dataStr;
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CFileManagerInfoPopup::TimeEntryLC
       
   303 // 
       
   304 // -----------------------------------------------------------------------------
       
   305 // 
       
   306 HBufC* CFileManagerInfoPopup::TimeEntryLC()
       
   307     {
       
   308     HBufC* time = StringLoader::LoadLC( R_QTN_ALBUM_DATIM_TIME );
       
   309     TBuf<KMaxInfoPopupWidth> timeStr;
       
   310     TBuf<KMaxInfoPopupWidth> timeStrFormat;
       
   311     TLocale local;
       
   312     TTime localTime;
       
   313     User::LeaveIfError( iProperties.ModifiedLocalDate( localTime ) );
       
   314 
       
   315     if( local.AmPmSymbolPosition() == ELocaleBefore )
       
   316         {
       
   317         timeStrFormat.Append( KTimeFormatBefore );
       
   318         timeStrFormat.Append( KTimeFormatSpace );
       
   319         timeStrFormat.Append( KTimeFormatHour );
       
   320         timeStrFormat.Append( local.TimeSeparator( KSecondSeparator ) );
       
   321         timeStrFormat.Append( KTimeFormatMinutes );
       
   322 
       
   323         localTime.FormatL( timeStr, timeStrFormat );
       
   324         }
       
   325     else
       
   326         {
       
   327         timeStrFormat.Append( KTimeFormatHour );
       
   328         timeStrFormat.Append( local.TimeSeparator( KSecondSeparator ) );
       
   329         timeStrFormat.Append( KTimeFormatMinutes );
       
   330         timeStrFormat.Append( KTimeFormatSpace );
       
   331         timeStrFormat.Append( KTimeFormatAfter );
       
   332 
       
   333         localTime.FormatL( timeStr, timeStrFormat );
       
   334         }
       
   335 
       
   336     HBufC* dataStr = HBufC::NewL( time->Length() + 1 + timeStr.Length() );
       
   337     TPtr dataPtr( dataStr->Des() );
       
   338     dataPtr.Append( *time );
       
   339     dataPtr.Append( KSeparator );
       
   340     dataPtr.Append( timeStr );
       
   341 
       
   342     CleanupStack::PopAndDestroy( time );
       
   343     CleanupStack::PushL( dataStr );
       
   344 
       
   345     AknTextUtils::LanguageSpecificNumberConversion( dataPtr );
       
   346 
       
   347     return dataStr;
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CFileManagerInfoPopup::SizeEntryLC
       
   352 // 
       
   353 // -----------------------------------------------------------------------------
       
   354 // 
       
   355 HBufC* CFileManagerInfoPopup::SizeEntryLC()
       
   356     {
       
   357     TInt64 sizeInBytes( iProperties.SizeL() );
       
   358     TPtrC unit( iUtil->SolveUnitAndSize( sizeInBytes ) );
       
   359     TBuf< KNumBufLen > numBuf;
       
   360     numBuf.Format( KNumBufFormatString, I64INT( sizeInBytes ) );
       
   361 
       
   362     HBufC* header = StringLoader::LoadLC( R_QTN_ALBUM_LITXT_SIZE );
       
   363     HBufC* dataStr = HBufC::NewL(
       
   364         header->Length() + 1 +
       
   365         numBuf.Length() + 
       
   366         KNumBufSpaceString().Length() +
       
   367         unit.Length() );
       
   368     TPtr dataPtr( dataStr->Des() );
       
   369 
       
   370     dataPtr.Append( *header );
       
   371     dataPtr.Append( KSeparator );
       
   372     dataPtr.Append( numBuf );
       
   373     dataPtr.Append( KNumBufSpaceString );
       
   374     dataPtr.Append( unit );
       
   375 
       
   376     CleanupStack::PopAndDestroy( header );
       
   377     CleanupStack::PushL( dataStr );
       
   378 
       
   379     AknTextUtils::LanguageSpecificNumberConversion( dataPtr );
       
   380     return dataStr;
       
   381     }
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // CFileManagerInfoPopup::DefaultFolderEntryLC
       
   385 // 
       
   386 // -----------------------------------------------------------------------------
       
   387 // 
       
   388 HBufC* CFileManagerInfoPopup::DefaultFolderEntryLC()
       
   389     {
       
   390     HBufC* header = StringLoader::LoadLC( R_QTN_FMGR_INFO_FLDR_DEFAULT );
       
   391     HBufC* data = StringLoader::LoadLC( R_QTN_FMGR_INFO_DEF_FLDR_TEXT );
       
   392     HBufC* dataStr = HBufC::NewL( header->Length() + 1 + data->Length() );
       
   393     TPtr dataPtr( dataStr->Des() );
       
   394     dataPtr.Append( *header );
       
   395     dataPtr.Append( KSeparator );
       
   396     dataPtr.Append( *data );
       
   397 
       
   398     CleanupStack::PopAndDestroy( data );
       
   399     CleanupStack::PopAndDestroy( header );
       
   400     CleanupStack::PushL( dataStr );
       
   401 
       
   402     return dataStr;
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CFileManagerInfoPopup::ResourceStringValueLC
       
   407 // 
       
   408 // -----------------------------------------------------------------------------
       
   409 // 
       
   410 HBufC* CFileManagerInfoPopup::ResourceStringValueLC( TInt aResId, TInt aValue )
       
   411     {
       
   412     HBufC* string = StringLoader::LoadLC( aResId );
       
   413     TBuf<KMaxInfoPopupWidth> infoStr;
       
   414     infoStr.Format( KNumberFormat, aValue );
       
   415     HBufC* dataStr = HBufC::NewL( string->Length() + 1 + infoStr.Length() );
       
   416     TPtr dataPtr( dataStr->Des() );
       
   417     dataPtr.Append( *string );
       
   418     dataPtr.Append( KSeparator );
       
   419     dataPtr.Append( infoStr );
       
   420 
       
   421     CleanupStack::PopAndDestroy( string );
       
   422     CleanupStack::PushL( dataStr );
       
   423 
       
   424     AknTextUtils::LanguageSpecificNumberConversion( dataPtr );
       
   425 
       
   426     return dataStr;
       
   427     }
       
   428 
       
   429 #ifdef RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
   430 // -----------------------------------------------------------------------------
       
   431 // CFileManagerInfoPopup::ActivateLinkL
       
   432 // 
       
   433 // -----------------------------------------------------------------------------
       
   434 //
       
   435 void CFileManagerInfoPopup::ActivateLinkL()
       
   436     {
       
   437     CFileManagerFullOmaDrmInfo::ViewDetailsL(
       
   438         iProperties.FullPath(),
       
   439         iUiHandling );
       
   440     }
       
   441 #endif //RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
   442 
       
   443 //  End of File