svgtviewer/SvgtViewerPlugin/SvgtFileViewDetailsSrc/svgtfileviewdetails.cpp
changeset 12 2b69f8f46e4a
parent 1 ec62f27282ac
equal deleted inserted replaced
1:ec62f27282ac 12:2b69f8f46e4a
     1 /*
       
     2 * Copyright (c) 2006 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 CSvgtFileViewDetailsDialog.
       
    15 *
       
    16 */
       
    17 
       
    18     
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "svgtfileviewdetails.h"
       
    22 
       
    23 #include <aknlists.h>
       
    24 #include <bautils.h>
       
    25 #include <StringLoader.h>
       
    26 #include <e32base.h>
       
    27 #include <apmstd.h> // KMaxDataTypeLength
       
    28 #include <DRMHelper.h> 
       
    29 #include <caf/content.h>
       
    30 #include <caf/attribute.h>
       
    31 #include <data_caging_path_literals.hrh>
       
    32 #include <tz.h>
       
    33 #include <tzconverter.h>
       
    34 
       
    35 #include <svgtfileviewdetails.rsg>
       
    36 
       
    37 _LIT(KResourceFileName,"svgtfileviewdetails.rsc");
       
    38 
       
    39 const TInt KSizeStringLengthSix = 6;
       
    40 const TInt KSizeStringLengthFive = 5;
       
    41 const TInt KSizeStringLengthFour = 4;
       
    42 const TInt KSizeStringLengthThree = 3;
       
    43 
       
    44 const TInt KValBufferLength = 512;
       
    45 const TInt KTimeCount = 2;
       
    46 const TInt KArrayGranularity = 2; 
       
    47 const TInt KDecimalCount = 2;
       
    48 
       
    49 const TInt KOneDigit1 = 1;
       
    50 const TInt KOneDigit5 = 5;
       
    51 const TInt KOneDigit9 = 9;
       
    52 const TInt KTwoDigit11 = 11;
       
    53 const TInt KTwoDigit14 = 14;
       
    54 
       
    55 
       
    56 // ============================ MEMBER FUNCTIONS ===============================
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CSvgtFileDetails::CSvgtFileDetails
       
    60 // C++ default constructor can NOT contain any code, that
       
    61 // might leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CSvgtFileDetails::CSvgtFileDetails() 
       
    65     :   iUrl(NULL), iFormat(NULL), 
       
    66         iDRMExpireConstraint( ESVGTNone )   //Initialize with no constraints
       
    67     {
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CSvgtFileDetails::~CSvgtFileDetails   
       
    72 // Destructor
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CSvgtFileDetails::~CSvgtFileDetails()
       
    76     {
       
    77     delete iUrl;    
       
    78     delete iFormat; 
       
    79     }
       
    80 
       
    81 
       
    82 // CONSTANTS
       
    83 
       
    84 
       
    85 _LIT(KDataTypeSvgt,"svg"); 
       
    86 
       
    87 const TInt KFileSizeOneKilobyte = 1024;
       
    88 const TInt KThousandNotKilobyte = 1000;
       
    89 const TInt KMaxTimeLength = 36;
       
    90 
       
    91 // For meta data 
       
    92 _LIT( KSpace, " ");
       
    93 
       
    94 // Language specific time format
       
    95 const TInt KOneDigit = 10;
       
    96 const TInt KTwoDigits = 100;
       
    97 
       
    98 
       
    99 // ============================ MEMBER FUNCTIONS ===============================
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CSvgtFileViewDetailsDialog::CSvgtFileViewDetailsDialog
       
   103 // C++ default constructor can NOT contain any code, that
       
   104 // might leave.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 CSvgtFileViewDetailsDialog::CSvgtFileViewDetailsDialog() 
       
   108     {
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CSvgtFileViewDetailsDialog::ConstructL
       
   113 // Symbian 2nd phase constructor can leave.
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CSvgtFileViewDetailsDialog::ConstructL()
       
   117     {
       
   118     iListBox = new (ELeave) CAknDoublePopupMenuStyleListBox();
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CSvgtFileViewDetailsDialog::NewL
       
   123 // Two-phased constructor.
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 EXPORT_C CSvgtFileViewDetailsDialog* CSvgtFileViewDetailsDialog::NewL()
       
   127     {
       
   128     CSvgtFileViewDetailsDialog* self = new( ELeave ) CSvgtFileViewDetailsDialog;
       
   129     CleanupStack::PushL( self );
       
   130     self->ConstructL();
       
   131     CleanupStack::Pop( self );
       
   132     return self;
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CSvgtFileViewDetailsDialog::~CSvgtFileViewDetailsDialog   
       
   137 // Destructor
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 CSvgtFileViewDetailsDialog::~CSvgtFileViewDetailsDialog()
       
   141     {
       
   142     delete iListBox;
       
   143     iEnv->DeleteResourceFile( iResOffset );  //removing the resource file for enviornment
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CSvgtFileViewDetailsDialog::ExecuteLD
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 EXPORT_C void CSvgtFileViewDetailsDialog::ExecuteLD( RFile& aFileHandle )     
       
   151     {
       
   152     CleanupStack::PushL( this );
       
   153     CSvgtFileDetails* fileDetails = new (ELeave) CSvgtFileDetails();
       
   154     CleanupStack::PushL( fileDetails );
       
   155 
       
   156     AddResourceFileToEnvL();
       
   157 
       
   158    // Creates a handle to content handled via CAF
       
   159     CContent *content = CContent::NewLC( aFileHandle ); 
       
   160     content->GetAttribute( EIsProtected, fileDetails->iDrmProtected );
       
   161     CleanupStack::PopAndDestroy( content );
       
   162   
       
   163     if ( fileDetails->iDrmProtected )
       
   164         {
       
   165         // drm data
       
   166         FetchDrmDataL( aFileHandle, fileDetails );        
       
   167         }
       
   168     
       
   169     // recognize file and get format
       
   170     TBuf<KMaxDataTypeLength> format(KDataTypeSvgt);
       
   171     fileDetails->iFormat = format.AllocL();
       
   172     
       
   173     // creation time
       
   174     aFileHandle.Modified(fileDetails->iTime);
       
   175    
       
   176     // Convert from UTC to local time
       
   177     RTz lTz;
       
   178     // Connect to TimeZone Server
       
   179     User::LeaveIfError( lTz.Connect() );
       
   180     CleanupClosePushL( lTz );
       
   181     
       
   182     // Create Util Class
       
   183     CTzConverter* lTzConverterPtr = CTzConverter::NewL( lTz );
       
   184     
       
   185     CleanupStack::PushL( lTzConverterPtr );
       
   186     // Perform conversion to local time
       
   187     User::LeaveIfError( lTzConverterPtr->ConvertToLocalTime( fileDetails->iTime ) );
       
   188 
       
   189     CleanupStack::PopAndDestroy( 2 ); // lTzConverterPtr, lTz
       
   190 
       
   191     // file size
       
   192     aFileHandle.Size(fileDetails->iSize);
       
   193     
       
   194     // Show File Details Dialog
       
   195     DoLaunchDialogL( fileDetails );
       
   196 
       
   197     CleanupStack::PopAndDestroy( fileDetails ); 
       
   198     CleanupStack::PopAndDestroy( this ); 
       
   199     
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CSvgtFileViewDetailsDialog::DoLaunchDialog
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CSvgtFileViewDetailsDialog::DoLaunchDialogL(const CSvgtFileDetails* aFileDetails )
       
   207     {
       
   208     CAknPopupList* popupList = CAknPopupList::NewL(iListBox,
       
   209             R_AVKON_SOFTKEYS_OK_EMPTY__OK, 
       
   210             AknPopupLayouts::EMenuDoubleWindow);
       
   211     CleanupStack::PushL(popupList);
       
   212     
       
   213     iListBox->ConstructL(popupList, EAknListBoxViewerFlags);
       
   214     iListBox->CreateScrollBarFrameL(ETrue);   
       
   215     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   216                     CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   217     
       
   218     SetTitleL(popupList);
       
   219     FillListBoxL(aFileDetails);
       
   220 
       
   221     CleanupStack::Pop( popupList );
       
   222     popupList->ExecuteLD();
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CSvgtFileViewDetailsDialog::SetTitleL
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CSvgtFileViewDetailsDialog::SetTitleL(CAknPopupList* aPopupList) const
       
   230     {
       
   231     HBufC* title = StringLoader::LoadLC(R_FILE_DETAILS);
       
   232     if( aPopupList )
       
   233        {
       
   234        aPopupList->SetTitleL(*title);   
       
   235        }    
       
   236     CleanupStack::PopAndDestroy( title ); 
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CSvgtFileViewDetailsDialog::FillListBoxL
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void CSvgtFileViewDetailsDialog::FillListBoxL(const CSvgtFileDetails* aFileDetails)
       
   244     {
       
   245     CDesCArray* itemArray = 
       
   246             static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
       
   247     
       
   248     if( aFileDetails )
       
   249         {
       
   250         if ( aFileDetails->iDrmProtected )
       
   251             {
       
   252             MakeDrmItemsL(itemArray,aFileDetails);
       
   253             }    
       
   254            
       
   255         MakeUrlItemL(itemArray,aFileDetails);
       
   256         MakeFormatItemL(itemArray,aFileDetails);
       
   257         MakeDateItemL(itemArray,aFileDetails);
       
   258         MakeTimeItemL(itemArray,aFileDetails);
       
   259         MakeSizeItemL(itemArray,aFileDetails);
       
   260         }
       
   261         
       
   262     iListBox->HandleItemAdditionL();
       
   263     iListBox->SetCurrentItemIndex(0);
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CSvgtFileViewDetailsDialog::AddItemToListBoxL
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 void CSvgtFileViewDetailsDialog::AddItemToListBoxL(const TDesC& aHeading,
       
   271                                              const TDesC& aValue, 
       
   272                                              CDesCArray* aItemArray) const
       
   273     {
       
   274     CDesCArrayFlat* items = new (ELeave) CDesCArrayFlat( KArrayGranularity );
       
   275     CleanupStack::PushL(items);
       
   276     items->AppendL(aHeading); //First string (heading)
       
   277     items->AppendL(aValue);   //Second string (value)
       
   278     HBufC* headingAndValue = 
       
   279             StringLoader::LoadLC( R_FILE_DETAILS_ROW_FORMAT, *items );
       
   280     if( aItemArray )        
       
   281         {
       
   282         aItemArray->AppendL(*headingAndValue);  
       
   283         }    
       
   284 
       
   285         CleanupStack::PopAndDestroy( headingAndValue ); // headingAndValue 
       
   286         CleanupStack::PopAndDestroy( items ); // items 
       
   287     }
       
   288 
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // CSvgtFileViewDetailsDialog::MakeUrlItemL
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 void CSvgtFileViewDetailsDialog::MakeUrlItemL(CDesCArray* aItemArray,
       
   295                                   const CSvgtFileDetails* aFileDetails) const
       
   296     {
       
   297     
       
   298     if ( aFileDetails && aFileDetails->iUrl )
       
   299         {
       
   300         HBufC* heading = StringLoader::LoadLC(R_FILE_URL_HEADING);
       
   301         AddItemToListBoxL(*heading,*aFileDetails->iUrl,aItemArray);
       
   302         CleanupStack::PopAndDestroy( heading ); 
       
   303         }
       
   304     }
       
   305 
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // CSvgtFileViewDetailsDialog::MakeFormatItemL
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 void CSvgtFileViewDetailsDialog::MakeFormatItemL(CDesCArray* aItemArray,
       
   312                                      const CSvgtFileDetails* aFileDetails) const
       
   313     {
       
   314     if ( aFileDetails && aFileDetails->iFormat )
       
   315         {
       
   316         HBufC* heading = StringLoader::LoadLC(R_FILE_FORMAT_HEADING);
       
   317         AddItemToListBoxL(*heading,*aFileDetails->iFormat,aItemArray);
       
   318         CleanupStack::PopAndDestroy( heading );
       
   319         }
       
   320     }
       
   321 
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CSvgtFileViewDetailsDialog::MakeSizeItemL
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CSvgtFileViewDetailsDialog::MakeSizeItemL(CDesCArray* aItemArray,
       
   328                                    const  CSvgtFileDetails* aFileDetails) const
       
   329     {
       
   330 
       
   331     if ( aFileDetails && aFileDetails->iSize )
       
   332         {   
       
   333         TRealFormat format = TRealFormat(KMaxFileName, KDecimalCount);
       
   334         TBuf<KMaxFileName> sizeString;
       
   335         HBufC* value = NULL;
       
   336         HBufC* heading = StringLoader::LoadLC(R_FILE_SIZE_HEADING);
       
   337         TReal size = aFileDetails->iSize;
       
   338         
       
   339         // Show bytes with 3 digits. If more digits needed, 
       
   340         // show size in kilobytes.
       
   341         if ( size < KThousandNotKilobyte )
       
   342             {
       
   343             sizeString.Num(size,format);
       
   344             switch (sizeString.Length())
       
   345                 {
       
   346                 case KSizeStringLengthSix:
       
   347                     sizeString = sizeString.Left( KSizeStringLengthThree );
       
   348                     break;
       
   349                 case KSizeStringLengthFive:
       
   350                     sizeString = sizeString.Left( KSizeStringLengthFour );
       
   351                     break;
       
   352                 default:
       
   353                     break;
       
   354                 }
       
   355             value = StringLoader::LoadLC(R_FILE_SIZE_B,sizeString);
       
   356             }
       
   357         else
       
   358             {
       
   359             size = size/KFileSizeOneKilobyte;
       
   360             sizeString.Num(size,format);
       
   361             switch (sizeString.Length())
       
   362                 {
       
   363                 case KSizeStringLengthSix:
       
   364                     sizeString = sizeString.Left( KSizeStringLengthThree );
       
   365                     break;
       
   366                 case KSizeStringLengthFive:
       
   367                     sizeString = sizeString.Left( KSizeStringLengthFour );
       
   368                     break;
       
   369                 default:
       
   370                     break;
       
   371                 }
       
   372             value = StringLoader::LoadLC(R_FILE_SIZE_KB,sizeString);
       
   373             }
       
   374         TPtr textPtr = value->Des();
       
   375         LanguageSpecificNumberConversion( textPtr );
       
   376         AddItemToListBoxL(*heading,*value,aItemArray);
       
   377         CleanupStack::PopAndDestroy( value ); 
       
   378         CleanupStack::PopAndDestroy( heading ); // heading & value
       
   379         }
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CSvgtFileViewDetailsDialog::MakeDateItemL
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 void CSvgtFileViewDetailsDialog::MakeDateItemL(CDesCArray* aItemArray,
       
   387                                     const CSvgtFileDetails* aFileDetails) const
       
   388     {
       
   389 
       
   390     if ( ( aFileDetails ) && ( aFileDetails->iTime > TTime(0) ))
       
   391         {
       
   392         HBufC* heading = StringLoader::LoadLC(R_FILE_DATE_HEADING);
       
   393         HBufC* dateFormatString = 
       
   394                 StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO );
       
   395         TBuf<KMaxTimeLength> date;
       
   396         aFileDetails->iTime.FormatL(date,*dateFormatString);
       
   397         LanguageSpecificNumberConversion( date );
       
   398         AddItemToListBoxL(*heading,date,aItemArray);
       
   399         CleanupStack::PopAndDestroy( dateFormatString ); 
       
   400         CleanupStack::PopAndDestroy( heading ); // heading & dateFormatString
       
   401         }
       
   402 
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CSvgtFileViewDetailsDialog::MakeTimeItemL
       
   407 // -----------------------------------------------------------------------------
       
   408 //
       
   409 void CSvgtFileViewDetailsDialog::MakeTimeItemL(CDesCArray* aItemArray,
       
   410                                   const CSvgtFileDetails* aFileDetails) const
       
   411     {
       
   412     if ( ( aFileDetails ) && ( aFileDetails->iTime > TTime(0)))
       
   413         {
       
   414         HBufC* heading = StringLoader::LoadLC( R_FILE_TIME_HEADING );
       
   415         HBufC* timeFormatString = 
       
   416                 StringLoader::LoadLC( R_QTN_TIME_USUAL_WITH_ZERO );
       
   417         TBuf<KMaxTimeLength> time;
       
   418         aFileDetails->iTime.FormatL(time,*timeFormatString);
       
   419         LanguageSpecificNumberConversion( time );
       
   420         AddItemToListBoxL(*heading,time,aItemArray);
       
   421         CleanupStack::PopAndDestroy( timeFormatString ); 
       
   422         CleanupStack::PopAndDestroy( heading ); // heading & timeFormatString
       
   423         }
       
   424     }
       
   425 
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // CSvgtFileViewDetailsDialog::MakeDrmItemsL
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 void CSvgtFileViewDetailsDialog::MakeDrmItemsL(CDesCArray* aItemArray,
       
   432                                        const CSvgtFileDetails* aFileDetails) const
       
   433     {
       
   434 
       
   435     HBufC* rights = StringLoader::LoadLC(R_FILE_DRM_DISPLAY);
       
   436     HBufC* heading = NULL;
       
   437     HBufC* value = NULL;
       
   438     
       
   439     if ( aFileDetails )
       
   440         {
       
   441         switch (aFileDetails->iDRMRightsStatus)
       
   442             {
       
   443             case ESVGTFull:
       
   444                 // status
       
   445                 heading = StringLoader::LoadLC(R_FILE_DRM_STAT);
       
   446                 value = StringLoader::LoadLC(R_FILE_DRM_VALID);
       
   447                 AddItemToListBoxL(*heading,*value,aItemArray);
       
   448                 CleanupStack::PopAndDestroy( value ); 
       
   449                 CleanupStack::PopAndDestroy( heading ); // heading && value
       
   450                 // full rights
       
   451                 heading = StringLoader::LoadLC(R_FILE_DRM_FULL,*rights);
       
   452                 value = StringLoader::LoadLC(R_FILE_DRM_UNLIMITED);
       
   453                 AddItemToListBoxL(*heading,*value,aItemArray);
       
   454                 CleanupStack::PopAndDestroy( value ); 
       
   455                 CleanupStack::PopAndDestroy( heading ); // heading && value
       
   456                 break;
       
   457             case ESVGTRestricted:
       
   458             case ESVGTPreview:
       
   459                 // status
       
   460                 heading = StringLoader::LoadLC(R_FILE_DRM_STAT);
       
   461                 value = StringLoader::LoadLC(R_FILE_DRM_VALID);
       
   462                 AddItemToListBoxL(*heading,*value,aItemArray);
       
   463                 CleanupStack::PopAndDestroy( value ); 
       
   464                 CleanupStack::PopAndDestroy( heading ); // heading && value
       
   465                 // make rest of the drm items
       
   466                 MakeRestrictedDrmItemsL(rights,aItemArray,aFileDetails);          
       
   467                 break;
       
   468             case ESVGTMissing:
       
   469                 // status
       
   470                 heading = StringLoader::LoadLC(R_FILE_DRM_STAT);
       
   471                 value = StringLoader::LoadLC(R_FILE_DRM_EXP);
       
   472                 AddItemToListBoxL(*heading,*value,aItemArray);
       
   473                 CleanupStack::PopAndDestroy( value ); 
       
   474                 CleanupStack::PopAndDestroy( heading ); // heading && value
       
   475                 break;
       
   476             case ESVGTExpired:
       
   477                 // status
       
   478                 heading = StringLoader::LoadLC(R_FILE_DRM_STAT);
       
   479                 value = StringLoader::LoadLC(R_FILE_DRM_EXP);
       
   480                 AddItemToListBoxL(*heading,*value,aItemArray);
       
   481                 CleanupStack::PopAndDestroy( value ); 
       
   482                 CleanupStack::PopAndDestroy( heading ); // heading && value
       
   483                 // make rest of the drm items
       
   484                 MakeRestrictedDrmItemsL(rights,aItemArray,aFileDetails);          
       
   485                 break;
       
   486             default:
       
   487                 break;
       
   488             }
       
   489         }
       
   490     
       
   491     heading = NULL;
       
   492     value = NULL;
       
   493     
       
   494     // sending
       
   495     heading = StringLoader::LoadLC(R_FILE_DRM_CS);
       
   496     if ( aFileDetails && aFileDetails->iDRMForwardLocked )
       
   497         {
       
   498         value = StringLoader::LoadLC(R_FILE_DRM_FORBID);
       
   499         }
       
   500     else
       
   501         {
       
   502         value = StringLoader::LoadLC(R_FILE_DRM_ALLOWED);
       
   503         }
       
   504     AddItemToListBoxL(*heading,*value,aItemArray); 
       
   505     CleanupStack::PopAndDestroy( value ); 
       
   506     CleanupStack::PopAndDestroy( heading ); 
       
   507     CleanupStack::PopAndDestroy( rights ); // heading, value, rights
       
   508     }
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CSvgtFileViewDetailsDialog::MakeDrmItemsL
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 void CSvgtFileViewDetailsDialog::MakeRestrictedDrmItemsL(
       
   515         const HBufC* aRights, CDesCArray* aItemArray, 
       
   516         const CSvgtFileDetails* aFileDetails ) const
       
   517     {
       
   518 
       
   519     HBufC* heading = NULL;
       
   520     HBufC* value = NULL;
       
   521     
       
   522     if ( !aRights || !aItemArray )
       
   523         {
       
   524         return;
       
   525         }
       
   526         
       
   527     // count
       
   528     if ( ( aFileDetails ) && ( aFileDetails->iDRMExpireConstraint == ESVGTCount 
       
   529     || aFileDetails->iDRMExpireConstraint == ESVGTCountAndTime ))
       
   530         {
       
   531         heading = StringLoader::LoadLC(R_FILE_DRM_UTL,*aRights);
       
   532         
       
   533         TInt counts = aFileDetails->iDRMCountsLeft;
       
   534         
       
   535         if (counts == 1)
       
   536             {
       
   537             value = StringLoader::LoadLC(R_FILE_DRM_1_COUNT);
       
   538             }
       
   539         else
       
   540             {
       
   541             value = StringLoader::LoadLC(R_FILE_DRM_N_COUNTS,counts);
       
   542             }
       
   543         TPtr textPtr = value->Des();
       
   544         LanguageSpecificNumberConversion( textPtr );
       
   545         AddItemToListBoxL(*heading,*value,aItemArray);
       
   546         CleanupStack::PopAndDestroy( value ); 
       
   547         CleanupStack::PopAndDestroy( heading ); // heading && value
       
   548         }
       
   549 
       
   550     if ( ( aFileDetails ) && ( aFileDetails->iDRMExpireConstraint == ESVGTTime ||
       
   551         aFileDetails->iDRMExpireConstraint == ESVGTCountAndTime ||
       
   552         ( aFileDetails->iDRMFileHasInterval && 
       
   553         aFileDetails->iDRMIntervalActive )))
       
   554         {
       
   555         HBufC* dateFormatString = StringLoader::LoadLC( 
       
   556                 R_QTN_DATE_USUAL_WITH_ZERO );
       
   557         HBufC* timeFormatString = StringLoader::LoadLC( R_QTN_TIME_USUAL );
       
   558         
       
   559         TTime from = aFileDetails->iDRMValidFrom;
       
   560         TTime until = aFileDetails->iDRMValidUntil;
       
   561 
       
   562         // from
       
   563         heading = StringLoader::LoadLC(R_FILE_DRM_VALID_FROM,*aRights);
       
   564         HBufC* datePointer = HBufC::NewLC( KMaxLongDateFormatSpec );
       
   565         TPtr date = datePointer->Des();
       
   566         from.FormatL( date, *dateFormatString );
       
   567         TBuf<KMaxTimeLength> time;
       
   568         from.FormatL( time, *timeFormatString );
       
   569         date.Append( KSpace );
       
   570         date.Append( time );
       
   571         LanguageSpecificNumberConversion( date );
       
   572         AddItemToListBoxL( *heading, date, aItemArray );
       
   573         CleanupStack::PopAndDestroy( datePointer ); 
       
   574         CleanupStack::PopAndDestroy( heading ); // datePointer, heading 
       
   575 
       
   576         // until
       
   577         heading = StringLoader::LoadLC(R_FILE_DRM_VALID_TO,*aRights);
       
   578         HBufC* dateToPntr = HBufC::NewLC( KMaxLongDateFormatSpec );
       
   579         TPtr dateTo = dateToPntr->Des();
       
   580         until.FormatL( dateTo, *dateFormatString );
       
   581         TBuf<KMaxTimeLength> timeTo;
       
   582         until.FormatL( timeTo, *timeFormatString );
       
   583         dateTo.Append( KSpace );
       
   584         dateTo.Append( timeTo );
       
   585         LanguageSpecificNumberConversion( dateTo );
       
   586         AddItemToListBoxL( *heading, dateTo, aItemArray );
       
   587 
       
   588         // destroying dateFormatString, timeFormatString, heading, dateToPntr 
       
   589         CleanupStack::PopAndDestroy( dateToPntr ); 
       
   590         CleanupStack::PopAndDestroy( heading ); 
       
   591         CleanupStack::PopAndDestroy( timeFormatString ); 
       
   592         CleanupStack::PopAndDestroy( dateFormatString ); 
       
   593         }
       
   594     // interval
       
   595     else 
       
   596         {
       
   597         if ( ( aFileDetails ) && ( aFileDetails->iDRMFileHasInterval && 
       
   598              !aFileDetails->iDRMIntervalActive ))
       
   599             {
       
   600             // times not activated
       
   601             heading = StringLoader::LoadLC(R_FILE_DRM_UTS,*aRights);
       
   602             value  = StringLoader::LoadLC(R_FILE_DRM_NOT_ACT);
       
   603             AddItemToListBoxL(*heading,*value,aItemArray);
       
   604             CleanupStack::PopAndDestroy( value ); // heading && value
       
   605             CleanupStack::PopAndDestroy( heading );
       
   606 
       
   607             // query what the current time is
       
   608             TTime currentTime;
       
   609             currentTime.HomeTime();
       
   610             // calculate rights end time
       
   611             TTime endTime = currentTime + aFileDetails->iDRMInterval;
       
   612 
       
   613             HBufC* lVal = HBufC::NewLC( KValBufferLength );
       
   614             TPtr valPtr(lVal->Des());
       
   615             
       
   616             TInt count = 0;
       
   617 
       
   618             // years
       
   619             TTimeIntervalYears years = endTime.YearsFrom(currentTime);
       
   620             if (years.Int())
       
   621                 {
       
   622                 AddSinglePartOfTimeL( years.Int(), 
       
   623                                   R_FILE_DRM_NBR_OF_YEARS_ONE,
       
   624                                   R_FILE_DRM_NBR_OF_YEARS_ONE_FINAL,
       
   625                                   R_FILE_DRM_NBR_OF_YEARS_TWO_FOUR,
       
   626                                   R_FILE_DRM_NBR_OF_YEARS_FIVE_ZERO,
       
   627                                   value );
       
   628                 count++;
       
   629                 valPtr.Append(*value);
       
   630                 endTime -= years; 
       
   631                 CleanupStack::PopAndDestroy( value ); 
       
   632                 }
       
   633             
       
   634             // months
       
   635             TTimeIntervalMonths months = endTime.MonthsFrom(currentTime);
       
   636             if (months.Int())
       
   637                 {
       
   638                 AddSinglePartOfTimeL( months.Int(), 
       
   639                                   R_FILE_DRM_NBR_OF_MONTHS_ONE,
       
   640                                   0,                                  
       
   641                                   R_FILE_DRM_NBR_OF_MONTHS_TWO_FOUR, 
       
   642                                   R_FILE_DRM_NBR_OF_MONTHS_FIVE_ZERO, 
       
   643                                   value );
       
   644                  if (count)
       
   645                     {
       
   646                     valPtr.Append( KSpace );
       
   647                     }
       
   648 
       
   649                 count++;
       
   650                 valPtr.Append(*value);
       
   651                 endTime -= months;
       
   652                 CleanupStack::PopAndDestroy( value );
       
   653                 }
       
   654        
       
   655             // days
       
   656             TTimeIntervalDays days = endTime.DaysFrom(currentTime);
       
   657             if (days.Int() && count < KTimeCount)
       
   658                 {
       
   659                 AddSinglePartOfTimeL( days.Int(), 
       
   660                                   R_FILE_DRM_NBR_OF_DAYS_ONE,
       
   661                                   R_FILE_DRM_NBR_OF_DAYS_ONE_FINAL,
       
   662                                   R_FILE_DRM_NBR_OF_DAYS_TWO_FOUR, 
       
   663                                   R_FILE_DRM_NBR_OF_DAYS_FIVE_ZERO, 
       
   664                                   value );
       
   665                 if (count)
       
   666                     {
       
   667                     valPtr.Append( KSpace );
       
   668                     }
       
   669 
       
   670                 valPtr.Append(*value);
       
   671                 endTime -= days; 
       
   672                 CleanupStack::PopAndDestroy( value ); 
       
   673                 count++;
       
   674                 }
       
   675        
       
   676             // hours
       
   677             TTimeIntervalHours hours;
       
   678             TInt ret = endTime.HoursFrom(currentTime,hours);
       
   679             if (ret == KErrNone && count < KTimeCount && hours.Int())
       
   680                 {
       
   681                 AddSinglePartOfTimeL( hours.Int(), 
       
   682                                   R_FILE_DRM_NBR_OF_HOURS_ONE, 
       
   683                                   R_FILE_DRM_NBR_OF_HOURS_ONE_FINAL,
       
   684                                   R_FILE_DRM_NBR_OF_HOURS_TWO_FOUR, 
       
   685                                   R_FILE_DRM_NBR_OF_HOURS_FIVE_ZERO, 
       
   686                                   value );
       
   687                 if (count)
       
   688                     {
       
   689                     valPtr.Append( KSpace );
       
   690                     }
       
   691 
       
   692                 valPtr.Append(*value);
       
   693                 endTime -= hours; 
       
   694                 CleanupStack::PopAndDestroy( value ); 
       
   695                 count++;
       
   696                 }
       
   697 
       
   698             // mins
       
   699             TTimeIntervalMinutes minutes;
       
   700             ret = endTime.MinutesFrom(currentTime,minutes);
       
   701             if (ret == KErrNone && count < KTimeCount && minutes.Int())
       
   702                 {
       
   703                 AddSinglePartOfTimeL( minutes.Int(), 
       
   704                                   R_FILE_DRM_NBR_OF_MINS_ONE,
       
   705                                   R_FILE_DRM_NBR_OF_MINS_ONE_FINAL,
       
   706                                   R_FILE_DRM_NBR_OF_MINS_TWO_FOUR, 
       
   707                                   R_FILE_DRM_NBR_OF_MINS_FIVE_ZERO, 
       
   708                                   value );
       
   709                 if (count)
       
   710                     {
       
   711                     valPtr.Append( KSpace );
       
   712                     }
       
   713 
       
   714                 valPtr.Append(*value);
       
   715                 endTime -= minutes; 
       
   716                 CleanupStack::PopAndDestroy( value );
       
   717                 count++;
       
   718                 }
       
   719             
       
   720             // seconds
       
   721             TTimeIntervalSeconds seconds;
       
   722             ret = endTime.SecondsFrom(currentTime,seconds);
       
   723             if (ret == KErrNone && count < KTimeCount && seconds.Int())
       
   724                 {
       
   725                 AddSinglePartOfTimeL( seconds.Int(), 
       
   726                                   R_FILE_DRM_NBR_OF_SECS_ONE, 
       
   727                                   R_FILE_DRM_NBR_OF_SECS_ONE_FINAL,
       
   728                                   R_FILE_DRM_NBR_OF_SECS_TWO_FOUR, 
       
   729                                   R_FILE_DRM_NBR_OF_SECS_FIVE_ZERO, 
       
   730                                   value );
       
   731 
       
   732                 if (count)
       
   733                     {
       
   734                     valPtr.Append( KSpace );
       
   735                     }
       
   736 
       
   737                 valPtr.Append(*value);
       
   738                 CleanupStack::PopAndDestroy( value ); 
       
   739                 count++;
       
   740                 }
       
   741            
       
   742             heading = StringLoader::LoadLC(R_FILE_DRM_UDL,*aRights);
       
   743             LanguageSpecificNumberConversion(valPtr);
       
   744             AddItemToListBoxL(*heading,valPtr,aItemArray);
       
   745             CleanupStack::PopAndDestroy( lVal ); 
       
   746             CleanupStack::PopAndDestroy( heading ); 
       
   747             }
       
   748             
       
   749         }
       
   750       
       
   751     }
       
   752 
       
   753 // -----------------------------------------------------------------------------
       
   754 // CSvgtFileViewDetailsDialog::LanguageSpecificNumberConversion
       
   755 // -----------------------------------------------------------------------------
       
   756 //
       
   757 void CSvgtFileViewDetailsDialog::LanguageSpecificNumberConversion( TDes& aText ) const
       
   758     {
       
   759     if ( AknTextUtils::DigitModeQuery( AknTextUtils::EDigitModeShownToUser ) )
       
   760         {
       
   761         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( aText );
       
   762         }
       
   763     }
       
   764 
       
   765 // -----------------------------------------------------------------------------
       
   766 // CSvgtFileViewDetailsDialog::FetchDrmDataL
       
   767 // -----------------------------------------------------------------------------
       
   768 //
       
   769 void CSvgtFileViewDetailsDialog::FetchDrmDataL( RFile& aFileHandle, 
       
   770                                           CSvgtFileDetails* aFileDetails ) const
       
   771     {
       
   772    
       
   773     CSVGTDrmHelper* myHelper = CSVGTDrmHelper::NewLC();
       
   774     
       
   775     myHelper->LoadUsageRigthsInfoL(aFileHandle);
       
   776 
       
   777     if ( aFileDetails )
       
   778         {
       
   779         myHelper->GetUsageRightsStatus(aFileDetails->iDRMRightsStatus);
       
   780       
       
   781         // sending
       
   782         aFileDetails->iDRMForwardLocked = !myHelper->SendingAllowed();
       
   783             
       
   784         if (aFileDetails->iDRMRightsStatus == ESVGTRestricted ||
       
   785             aFileDetails->iDRMRightsStatus == ESVGTPreview ||
       
   786             aFileDetails->iDRMRightsStatus == ESVGTExpired)
       
   787             {    
       
   788             // counts
       
   789             TInt retCount = myHelper->GetCount(aFileDetails->iDRMCountsLeft);
       
   790 
       
   791             if (retCount == KErrNone)
       
   792                 {
       
   793                 aFileDetails->iDRMExpireConstraint = ESVGTCount;
       
   794                 }
       
   795             
       
   796             // time
       
   797             TInt retTime = myHelper->GetStartTime(aFileDetails->iDRMValidFrom); 
       
   798             retTime = myHelper->GetEndTime(aFileDetails->iDRMValidUntil); 
       
   799 
       
   800             if (retTime == KErrNone && retCount == KErrNone)
       
   801                 {
       
   802                 aFileDetails->iDRMExpireConstraint = ESVGTCountAndTime;
       
   803                 }
       
   804             else 
       
   805                 {
       
   806                 if (retTime == KErrNone)
       
   807                     {
       
   808                     aFileDetails->iDRMExpireConstraint = ESVGTTime;
       
   809                     }
       
   810                 }
       
   811       
       
   812              // interval    
       
   813             if (myHelper->GetInterval(aFileDetails->iDRMInterval) == KErrNone)
       
   814                 {
       
   815                 aFileDetails->iDRMFileHasInterval = ETrue;
       
   816                 TTime from;
       
   817                 if (myHelper->GetIntervalStart(from) == KErrNone)
       
   818                     {
       
   819                     aFileDetails->iDRMIntervalActive = ETrue;
       
   820                     // active from
       
   821                     aFileDetails->iDRMValidFrom = from;
       
   822                     // calculate rights end time
       
   823                     aFileDetails->iDRMValidUntil = 
       
   824                         aFileDetails->iDRMValidFrom + aFileDetails->iDRMInterval;
       
   825                     }
       
   826                 else
       
   827                     {
       
   828                     aFileDetails->iDRMIntervalActive = EFalse;
       
   829                     }
       
   830                 }
       
   831             else
       
   832                 {
       
   833                 aFileDetails->iDRMFileHasInterval = EFalse;
       
   834                 aFileDetails->iDRMIntervalActive = EFalse;
       
   835                 }
       
   836             }        
       
   837         }
       
   838     
       
   839     // cleanup
       
   840     CleanupStack::PopAndDestroy( myHelper );
       
   841     }
       
   842 
       
   843 // -----------------------------------------------------------------------------
       
   844 // CSvgtFileViewDetailsDialog::AddSinglePartOfTimeL
       
   845 // -----------------------------------------------------------------------------
       
   846 //
       
   847 void CSvgtFileViewDetailsDialog::AddSinglePartOfTimeL( TInt aNumOfElements,
       
   848                                                  TInt aResourceIdSingle,
       
   849                                                  TInt aResourceIdOneFinal, 
       
   850                                                  TInt aResourceIdTwoFour,
       
   851                                                  TInt aResourceIdFiveZero, 
       
   852                                                  HBufC*& aStrings ) const
       
   853     {
       
   854     TInt finalOneDigit = aNumOfElements % KOneDigit;
       
   855     TInt finalTwoDigits = aNumOfElements % KTwoDigits;
       
   856 
       
   857     if ( aNumOfElements == 1 )
       
   858         {
       
   859         aStrings = StringLoader::LoadLC( aResourceIdSingle);
       
   860         }
       
   861     else if ( finalOneDigit == KOneDigit1 && finalTwoDigits != KTwoDigit11 )
       
   862         {
       
   863         // Used for period of years ending with 1 from 21 (21, 31, 41, etc.)
       
   864         aStrings = StringLoader::LoadLC( aResourceIdOneFinal, aNumOfElements );
       
   865         }
       
   866     else if ( finalOneDigit == 0 || 
       
   867             ( finalOneDigit >= KOneDigit5 && finalOneDigit <= KOneDigit9 ) ||
       
   868             ( finalTwoDigits >= KTwoDigit11 && finalTwoDigits <= KTwoDigit14 ) )
       
   869         {
       
   870         // Used for period of minutes ending from 5 to 0 plus range between 11 
       
   871         // and 14 (5-20, 25-30, 35-40, 45-50, 53-59)
       
   872         aStrings = StringLoader::LoadLC( aResourceIdFiveZero, aNumOfElements );
       
   873         }
       
   874     else
       
   875         {
       
   876         // Used for period of minutes ending from 2 to 4, excluded 12-14 (2-4,
       
   877         // 22-24, 32-34, 42-44, 52-54)        
       
   878         aStrings = StringLoader::LoadLC( aResourceIdTwoFour, aNumOfElements );
       
   879         }     
       
   880     }
       
   881 
       
   882 void CSvgtFileViewDetailsDialog::AddResourceFileToEnvL() 
       
   883     {
       
   884     TFileName resFileName;
       
   885     Dll::FileName( resFileName ); // get dll path
       
   886     TDriveName drive( TParsePtrC( resFileName ).Drive( ) ); // solve drive
       
   887     resFileName.Zero();
       
   888     resFileName.Append( drive );
       
   889     resFileName.Append( KDC_RESOURCE_FILES_DIR );
       
   890     resFileName.Append( KResourceFileName );
       
   891 
       
   892     iEnv = CEikonEnv::Static();
       
   893     BaflUtils::NearestLanguageFile(iEnv->FsSession(), resFileName); //for localization
       
   894     iEnv->AddResourceFileL(resFileName);
       
   895     RResourceFile resFile;
       
   896     CleanupClosePushL(resFile);
       
   897     resFile.OpenL(iEnv->FsSession(), resFileName);
       
   898     resFile.ConfirmSignatureL();
       
   899     iResOffset = resFile.Offset();
       
   900     CleanupStack::PopAndDestroy(&resFile); //resFile
       
   901     }
       
   902 
       
   903     
       
   904 //  End of File