filemanager/View/src/CFileManagerFullOmaDrmInfo.cpp
branchRCL_3
changeset 20 491b3ed49290
parent 19 95243422089a
child 21 65326cf895ed
equal deleted inserted replaced
19:95243422089a 20:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2005-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:  Gets the item DRM information
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <coemain.h>
       
    21 #include <StringLoader.h>
       
    22 #include <DRMHelper.h>
       
    23 #include <DRMRights.h>
       
    24 #include <AknUtils.h>
       
    25 #include <filemanagerview.rsg>
       
    26 #include <FileManagerDebug.h>
       
    27 #include <drmuihandling.h>
       
    28 #include "CFileManagerFullOmaDrmInfo.h"
       
    29 
       
    30 // CONSTANTS
       
    31 _LIT( KSeparator, "\t" );
       
    32 #ifndef RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
    33 _LIT( KDateFormat1, "%1" );
       
    34 _LIT( KDateFormat2, "%2" );
       
    35 _LIT( KDateFormat3, "%3" );
       
    36 _LIT( KTimeFormatBefore, " %-B %J:%T" );
       
    37 _LIT( KTimeFormatAfter, " %J:%T %+B" );
       
    38 _LIT( KEmptyChar, " " );
       
    39 const TInt KDateStringLen = 20;
       
    40 
       
    41 const TUint KSecondSeparator = 1;
       
    42 const TUint KThirdSeparator = 2;
       
    43 
       
    44 
       
    45 const TInt KPlayRights = 0;
       
    46 const TInt KDisplayRights = 1;
       
    47 const TInt KExecuteRights = 2;
       
    48 const TInt KPrintRights = 3;
       
    49 #endif // RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
    50 
       
    51 
       
    52 // ============================ LOCAL FUNCTIONS ================================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // AppendLabelAndDataToArrayL
       
    56 // -----------------------------------------------------------------------------
       
    57 static void AppendLabelAndDataToArrayL( CDesCArray& aArray,
       
    58                                  const TDesC& aLabel,
       
    59                                  const TDesC& aData )
       
    60     {
       
    61     HBufC* dataStr = HBufC::NewLC( aLabel.Length() +
       
    62                                    KSeparator().Length() +
       
    63                                    aData.Length() );
       
    64 
       
    65     TPtr dataPtr( dataStr->Des() );
       
    66     dataPtr.Append( aLabel );
       
    67     dataPtr.Append( KSeparator );
       
    68     dataPtr.Append( aData );
       
    69 
       
    70     AknTextUtils::LanguageSpecificNumberConversion( dataPtr );
       
    71 
       
    72     aArray.AppendL( dataPtr );
       
    73 
       
    74     CleanupStack::PopAndDestroy( dataStr );
       
    75     }
       
    76     
       
    77 #ifndef RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
    78 // -----------------------------------------------------------------------------
       
    79 // ResetAndDestroy
       
    80 // -----------------------------------------------------------------------------
       
    81 static void ResetAndDestroy( TAny* aPtr )
       
    82     {
       
    83     RPointerArray< CDRMHelperRightsConstraints >* array =
       
    84         static_cast< RPointerArray<CDRMHelperRightsConstraints>* >( aPtr );
       
    85     array->ResetAndDestroy();
       
    86     array->Close();
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // IsFutureRights
       
    91 // -----------------------------------------------------------------------------
       
    92 static TBool IsFutureRights(
       
    93         RPointerArray<CDRMRightsConstraints>& aRightsArray )
       
    94     {
       
    95     TBool ret( EFalse );
       
    96     const TInt count( aRightsArray.Count() );
       
    97     for( TInt i = 0 ; i < count ; ++i )
       
    98         {
       
    99         CDRMRightsConstraints* rights = aRightsArray[i];
       
   100         TUint32 expiration( 0 );
       
   101         TUint32 constType( 0 );
       
   102         TInt topPriorityValue( CDRMRights::EInvalidRights );
       
   103         if( rights )
       
   104             {
       
   105             TInt currentPriorityValue( rights->GetConstraintInfo( expiration, constType ) );
       
   106             if( currentPriorityValue > topPriorityValue )
       
   107                 {
       
   108                 // priority is higher than previous rigths
       
   109                 topPriorityValue = currentPriorityValue;
       
   110                 if( CDRMRights::EFutureRights == expiration )
       
   111                     {
       
   112                     ret = ETrue;
       
   113                     }
       
   114                 else
       
   115                     {
       
   116                     // no future rights
       
   117                     ret = EFalse;
       
   118                     }
       
   119                 }
       
   120             }
       
   121         }
       
   122     return ret;
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // DateTimeStringLC
       
   127 // -----------------------------------------------------------------------------
       
   128 static HBufC* DateTimeStringLC( const TTime& aTime )
       
   129     {
       
   130     TBuf<KDateStringLen> dateStr;
       
   131     TBuf<KDateStringLen> timeStr;
       
   132     TBuf<KDateStringLen> dateStrFormat;
       
   133 
       
   134     // Localized date separator form
       
   135     TLocale local;
       
   136     dateStrFormat.Append( KDateFormat1 );
       
   137     dateStrFormat.Append( local.DateSeparator( KSecondSeparator ) );
       
   138     dateStrFormat.Append( KDateFormat2 );
       
   139     dateStrFormat.Append( local.DateSeparator( KThirdSeparator ) );
       
   140     dateStrFormat.Append( KDateFormat3 );
       
   141     aTime.FormatL( dateStr, dateStrFormat );
       
   142 
       
   143     if ( local.AmPmSymbolPosition() == ELocaleBefore )
       
   144         {
       
   145         aTime.FormatL( timeStr, KTimeFormatBefore );
       
   146         }
       
   147     else
       
   148         {
       
   149         aTime.FormatL( timeStr, KTimeFormatAfter );
       
   150         }
       
   151 
       
   152     HBufC* buf = HBufC::NewLC( dateStr.Length() +
       
   153                                KEmptyChar().Length() +
       
   154                                timeStr.Length() );
       
   155     TPtr ptrBuffer( buf->Des() );
       
   156     ptrBuffer.Append( dateStr );
       
   157     ptrBuffer.Append( KEmptyChar );
       
   158     ptrBuffer.Append( timeStr );
       
   159 
       
   160     return buf;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // DateTimeL
       
   165 // -----------------------------------------------------------------------------
       
   166 static void DateTimeL( CDesCArray& aArray,
       
   167                 const TTime& aTime,
       
   168                 TInt aResourceId,
       
   169                 const TDesC& aType )
       
   170     {
       
   171     HBufC* label = StringLoader::LoadLC( aResourceId, aType );
       
   172     HBufC* dateTime = DateTimeStringLC( aTime );
       
   173 
       
   174     AppendLabelAndDataToArrayL( aArray, *label, *dateTime );
       
   175 
       
   176     CleanupStack::PopAndDestroy( dateTime );
       
   177     CleanupStack::PopAndDestroy( label );
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // FillCounterInfoL
       
   182 // -----------------------------------------------------------------------------
       
   183 static void FillCounterInfoL( CDesCArray& aArray,
       
   184                        CDRMHelperRightsConstraints& aRights,
       
   185                        const TDesC& aType )
       
   186     {
       
   187     TUint32 count( 0 );
       
   188     TUint32 timedCount( 0 );
       
   189     TUint32 ignore1( 0 );
       
   190     TUint32 ignore2( 0 );
       
   191     TTimeIntervalSeconds ignore3( 0 );
       
   192     TInt err( KErrNone );
       
   193 
       
   194     TRAPD( errCount, aRights.GetCountersL( count, ignore1 ) );
       
   195     TRAPD( errTimedCount, aRights.GetTimedCountL( timedCount, ignore2,
       
   196         ignore3 ) );
       
   197 
       
   198     if ( errCount == KErrNone && errTimedCount == KErrNone )
       
   199         {
       
   200         // Both counts present, use minimum
       
   201         count = Min( count, timedCount );
       
   202         err = KErrNone;
       
   203         }
       
   204     else if ( errCount == KErrNone )
       
   205         {
       
   206         // Use count
       
   207         err = KErrNone;
       
   208         }
       
   209     else if ( errTimedCount == KErrNone )
       
   210         {
       
   211         // Use timed count
       
   212         count = timedCount;
       
   213         err = KErrNone;
       
   214         }
       
   215     else
       
   216         {
       
   217         // Neither regular nor timed count constraint
       
   218         // present, return error
       
   219         err = KErrNotFound;
       
   220         }
       
   221 
       
   222     if ( err == KErrNone )
       
   223         {
       
   224         // "Times left (%U)"
       
   225         HBufC* label =
       
   226                 StringLoader::LoadLC( R_QTN_DRM_MGR_DET_UTL_X, aType );
       
   227 
       
   228         HBufC* data = NULL;
       
   229 
       
   230         if ( count == 1 )
       
   231             {
       
   232             // "1 count"
       
   233             data = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_1_COUNT );
       
   234             }
       
   235         else
       
   236             {
       
   237             // "%N counts"
       
   238             data = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_N_COUNTS, count );
       
   239             }
       
   240 
       
   241         AppendLabelAndDataToArrayL( aArray, *label, *data );
       
   242 
       
   243         CleanupStack::PopAndDestroy( data );
       
   244         CleanupStack::PopAndDestroy( label );
       
   245         }
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // SplitTime
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 static void SplitTime( const TTimeIntervalSeconds& aInterval,
       
   253         TInt& aIntYrs, TInt& aIntMon, TInt& aIntDay,
       
   254         TInt& aIntHrs, TInt& aIntMin, TInt& aIntSec )
       
   255     {
       
   256     const TInt KSecsInMin( 60 );
       
   257     const TInt KSecsInHour( KSecsInMin * 60 );
       
   258     const TInt KSecsInDay( KSecsInHour * 24 );
       
   259 
       
   260     // includes leap year day
       
   261     const TInt KLastMonthIndex = 11;
       
   262     const TInt KMaxDaysInMonths[] = {
       
   263             31,  62,  92, 123, 153, 184,
       
   264             215, 245, 276, 306, 337, 366 };
       
   265 
       
   266     // calculate full days
       
   267     TInt temp( aInterval.Int() / KSecsInDay );
       
   268 
       
   269     // calculate full years, calculate without leap year for user to get the 
       
   270     // longest time possible
       
   271     aIntYrs = temp / ( KMaxDaysInMonths[KLastMonthIndex] - 1 );
       
   272 
       
   273     // calc remainder days
       
   274     temp = temp % ( KMaxDaysInMonths[KLastMonthIndex] - 1 );
       
   275 
       
   276     aIntMon = 0;
       
   277 
       
   278     TInt i( 0 );
       
   279     if ( temp >= KMaxDaysInMonths[0] )
       
   280         {
       
   281         for ( i = 0; i < KLastMonthIndex; i++ )
       
   282             {
       
   283             // found correct amount of months
       
   284             if ( temp >= KMaxDaysInMonths[i] && temp < KMaxDaysInMonths[i+1] )
       
   285                 {
       
   286                 // i now contains amount of full months (+1 because of table index)
       
   287                 aIntMon = i + 1;
       
   288                 break;
       
   289                 }
       
   290             }
       
   291         }
       
   292 
       
   293     // calc remainder days = allSecs - secsInFullYears - secsInFullMonts
       
   294     if( temp >= KMaxDaysInMonths[i] )
       
   295         {
       
   296         aIntDay = temp - KMaxDaysInMonths[i];
       
   297         }
       
   298     else
       
   299         {
       
   300         aIntDay = temp;
       
   301         }
       
   302 
       
   303     // calculate remainder secs
       
   304     temp = aInterval.Int() % KSecsInDay;
       
   305 
       
   306     aIntHrs = temp / KSecsInHour;
       
   307 
       
   308     // calculate remainder secs
       
   309     temp = temp % KSecsInHour;
       
   310 
       
   311     aIntMin = temp / KSecsInMin;
       
   312 
       
   313     // calculate remainder secs
       
   314     aIntSec = temp % KSecsInMin;
       
   315     }
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // AddSinglePartOfTimeL
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 static void AddSinglePartOfTimeL( TInt aNumOfElements,
       
   322         TInt aResourceIdSingle,
       
   323         TInt aResourceIdOneFinal, 
       
   324         TInt aResourceIdTwoFour,
       
   325         TInt aResourceIdFiveZero, 
       
   326         CDesCArrayFlat* aStrings )
       
   327     {
       
   328     const TInt KDigitFive = 5;
       
   329     const TInt KDigitNine = 9;
       
   330     const TInt KDigitTen = 10;
       
   331     const TInt KDigitEleven = 11;
       
   332     const TInt KDigitFourTeen = 14;
       
   333     const TInt KDigitHundred = 100;
       
   334     HBufC* stringHolder = NULL;
       
   335     TInt finalOneDigit( aNumOfElements % KDigitTen );
       
   336     TInt finalTwoDigits( aNumOfElements % KDigitHundred );
       
   337 
       
   338     if ( aNumOfElements == 1 )
       
   339         {
       
   340         stringHolder = StringLoader::LoadLC( aResourceIdSingle );
       
   341         }
       
   342     else if ( finalOneDigit == 1 && finalTwoDigits != KDigitEleven )
       
   343         {
       
   344         stringHolder = StringLoader::LoadLC( aResourceIdOneFinal, 
       
   345             aNumOfElements );
       
   346         }
       
   347     else if ( finalOneDigit == 0 || 
       
   348              ( finalOneDigit >= KDigitFive && finalOneDigit <= KDigitNine ) ||
       
   349              ( finalTwoDigits >= KDigitEleven && finalTwoDigits <= KDigitFourTeen ) )
       
   350         {
       
   351         stringHolder = StringLoader::LoadLC( aResourceIdFiveZero,
       
   352             aNumOfElements );
       
   353         }
       
   354     else
       
   355         {
       
   356         stringHolder = StringLoader::LoadLC( aResourceIdTwoFour,
       
   357             aNumOfElements );
       
   358         }
       
   359 
       
   360     if ( aStrings )
       
   361         {
       
   362         aStrings->AppendL( *stringHolder );
       
   363         }
       
   364 
       
   365     CleanupStack::PopAndDestroy ( stringHolder );
       
   366     }
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // AddPartsOfTimeLC
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 static HBufC* AddPartsOfTimeLC( TInt aIntYrs, TInt aIntMon, TInt aIntDay, 
       
   373                          TInt aIntHrs, TInt aIntMin, TInt aIntSec )
       
   374     {
       
   375     // Only the two most meaningful data will be showed
       
   376     TInt numOfData( 0 );
       
   377     const TInt KMaxDataItems = 2;
       
   378 
       
   379     CDesCArrayFlat* strings = new ( ELeave ) CDesCArrayFlat( KMaxDataItems );
       
   380     CleanupStack::PushL( strings );
       
   381 
       
   382     if ( aIntYrs > 0 )
       
   383         {
       
   384         AddSinglePartOfTimeL( aIntYrs, 
       
   385             R_QTN_DRM_NBR_OF_YEARS_ONE,
       
   386             R_QTN_DRM_NBR_OF_YEARS_ONE_FINAL,
       
   387             R_QTN_DRM_NBR_OF_YEARS_TWO_FOUR,
       
   388             R_QTN_DRM_NBR_OF_YEARS_FIVE_ZERO,
       
   389             strings );
       
   390         numOfData++;
       
   391         }
       
   392 
       
   393     if ( aIntMon > 0 )
       
   394         {
       
   395         //  Second type not provided because 11 is the maximum
       
   396         AddSinglePartOfTimeL( aIntMon, 
       
   397             R_QTN_DRM_NBR_OF_MONTHS_ONE,
       
   398             0,       
       
   399             R_QTN_DRM_NBR_OF_MONTHS_TWO_FOUR, 
       
   400             R_QTN_DRM_NBR_OF_MONTHS_FIVE_ZERO, 
       
   401             strings );
       
   402         numOfData++;
       
   403         }
       
   404 
       
   405     // Only if years or months were missing
       
   406     if ( aIntDay > 0 && numOfData < KMaxDataItems )
       
   407         {
       
   408         AddSinglePartOfTimeL( aIntDay, 
       
   409             R_QTN_DRM_NBR_OF_DAYS_ONE,
       
   410             R_QTN_DRM_NBR_OF_DAYS_ONE_FINAL,
       
   411             R_QTN_DRM_NBR_OF_DAYS_TWO_FOUR, 
       
   412             R_QTN_DRM_NBR_OF_DAYS_FIVE_ZERO, 
       
   413             strings );
       
   414         numOfData++;
       
   415         }
       
   416 
       
   417     if ( aIntHrs > 0 && numOfData < KMaxDataItems )
       
   418         {
       
   419         AddSinglePartOfTimeL( aIntHrs, 
       
   420             R_QTN_DRM_NBR_OF_HOURS_ONE, 
       
   421             R_QTN_DRM_NBR_OF_HOURS_ONE_FINAL,
       
   422             R_QTN_DRM_NBR_OF_HOURS_TWO_FOUR, 
       
   423             R_QTN_DRM_NBR_OF_HOURS_FIVE_ZERO, 
       
   424             strings );
       
   425         numOfData++;
       
   426         }
       
   427 
       
   428     if ( aIntMin > 0 && numOfData < KMaxDataItems )
       
   429         {
       
   430         AddSinglePartOfTimeL( aIntMin, 
       
   431             R_QTN_DRM_NBR_OF_MINS_ONE,
       
   432             R_QTN_DRM_NBR_OF_MINS_ONE_FINAL,
       
   433             R_QTN_DRM_NBR_OF_MINS_TWO_FOUR, 
       
   434             R_QTN_DRM_NBR_OF_MINS_FIVE_ZERO, 
       
   435             strings );
       
   436         numOfData++;
       
   437         }
       
   438 
       
   439     // If interval is 0, then it shows "0 seconds" anyway
       
   440     if ( ( aIntSec > 0 && numOfData < KMaxDataItems ) || numOfData == 0 )
       
   441         {
       
   442         AddSinglePartOfTimeL( aIntSec, 
       
   443             R_QTN_DRM_NBR_OF_SECS_ONE, 
       
   444             R_QTN_DRM_NBR_OF_SECS_ONE_FINAL,
       
   445             R_QTN_DRM_NBR_OF_SECS_TWO_FOUR, 
       
   446             R_QTN_DRM_NBR_OF_SECS_FIVE_ZERO, 
       
   447             strings );
       
   448         numOfData++;
       
   449         }
       
   450 
       
   451     HBufC* stringHolder = NULL;
       
   452     if ( numOfData == 1 )
       
   453         {
       
   454         stringHolder = StringLoader::LoadL( R_QTN_DRM_MGR_DET_INTER,
       
   455             strings->MdcaPoint(0) );
       
   456         }
       
   457     else
       
   458         {
       
   459         stringHolder = StringLoader::LoadL( R_QTN_DRM_MGR_DET_INTER_TWO,
       
   460             *strings );
       
   461         }
       
   462 
       
   463     CleanupStack::PopAndDestroy( strings );
       
   464     
       
   465     CleanupStack::PushL( stringHolder );
       
   466 
       
   467     return stringHolder;
       
   468     }
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // FillUsageTimeLeftInfoL
       
   472 // -----------------------------------------------------------------------------
       
   473 static void FillUsageTimeLeftInfoL( CDesCArray& aArray,
       
   474                              const TTimeIntervalSeconds& aInterval,
       
   475                              const TDesC& aType,
       
   476                              TBool aIsAccumulatedTime )
       
   477     {
       
   478     TInt years( 0 );
       
   479     TInt months( 0 );
       
   480     TInt days( 0 );
       
   481     TInt hours( 0 );
       
   482     TInt minutes( 0 );
       
   483     TInt seconds( 0 );
       
   484     HBufC* label = NULL;
       
   485     HBufC* data = NULL;
       
   486 
       
   487     if ( aIsAccumulatedTime )
       
   488         {
       
   489         // "Usage time left"
       
   490         label = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_ACCUM_TIME_LEFT  );
       
   491         }
       
   492     else
       
   493         {
       
   494         // "Time left (%U)"
       
   495         label = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_UDL_X, aType );
       
   496         }
       
   497 
       
   498     SplitTime( aInterval, years, months, days, hours, minutes, seconds );
       
   499     data = AddPartsOfTimeLC( years, months, days, hours, minutes, seconds );
       
   500 
       
   501     AppendLabelAndDataToArrayL( aArray, *label, *data );
       
   502 
       
   503     CleanupStack::PopAndDestroy( data );
       
   504     CleanupStack::PopAndDestroy( label );
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // FillIntervalInfoL
       
   509 // -----------------------------------------------------------------------------
       
   510 static void FillIntervalInfoL( CDesCArray& aArray,
       
   511                         CDRMHelperRightsConstraints& aRights,
       
   512                         const TDesC& aType )
       
   513     {
       
   514     TTimeIntervalSeconds intervalSeconds( 0 );
       
   515 
       
   516     TRAPD( err, aRights.GetIntervalL( intervalSeconds ) );
       
   517 
       
   518     if ( err != KErrNotFound && err != KErrNone )
       
   519         {
       
   520         User::Leave( err );
       
   521         }
       
   522 
       
   523     if ( err == KErrNone )
       
   524         {
       
   525         TTime intervalStartTime( 0 );
       
   526 
       
   527         TRAP( err, aRights.GetIntervalStartL( intervalStartTime ) );
       
   528 
       
   529         if ( ( err != KErrNotFound ) && ( err != KErrNone ) )
       
   530             {
       
   531             User::Leave( err );
       
   532             }
       
   533 
       
   534         if ( err == KErrNotFound )
       
   535             {
       
   536             // "Times status (%U)"
       
   537             HBufC* label =
       
   538                 StringLoader::LoadLC( R_QTN_DRM_MGR_DET_UTS_X, aType );
       
   539 
       
   540             // "Not activated"
       
   541             HBufC* data = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_NOT_ACT );
       
   542 
       
   543             AppendLabelAndDataToArrayL( aArray, *label, *data );
       
   544 
       
   545             CleanupStack::PopAndDestroy( data );
       
   546             CleanupStack::PopAndDestroy( label );
       
   547 
       
   548             // "Time left (%U)"
       
   549             FillUsageTimeLeftInfoL( aArray, intervalSeconds, aType, EFalse );
       
   550             }
       
   551         else
       
   552             {
       
   553             TTime endTime( intervalStartTime );
       
   554             endTime += intervalSeconds;
       
   555 
       
   556             // "Valid from (%U)"
       
   557             DateTimeL( aArray, intervalStartTime,
       
   558                                         R_QTN_DRM_MGR_DET_RVF_X, aType );
       
   559 
       
   560             // "Valid until (%U)"
       
   561             DateTimeL( aArray, endTime, R_QTN_DRM_MGR_DET_RVT_X, aType );
       
   562             }
       
   563         }
       
   564     }
       
   565 
       
   566 // -----------------------------------------------------------------------------
       
   567 // FillTimeInfoL
       
   568 // -----------------------------------------------------------------------------
       
   569 static void FillTimeInfoL( CDesCArray& aArray,
       
   570                     CDRMHelperRightsConstraints& aRights,
       
   571                     const TDesC& aType )
       
   572     {
       
   573     TTime startTime;
       
   574     TRAPD( err, aRights.GetStartTimeL( startTime ) );
       
   575     if ( err != KErrNotFound && err != KErrNone )
       
   576         {
       
   577         User::Leave( err );
       
   578         }
       
   579     if ( err == KErrNone )
       
   580         {
       
   581         // "Valid from (%U)"
       
   582         DateTimeL( aArray, startTime, R_QTN_DRM_MGR_DET_RVF_X, aType );
       
   583         }
       
   584 
       
   585     TTime endTime;
       
   586     TRAP( err, aRights.GetEndTimeL( endTime ) );
       
   587     if ( err != KErrNotFound && err != KErrNone )
       
   588         {
       
   589         User::Leave( err );
       
   590         }
       
   591     if ( err == KErrNone )
       
   592         {
       
   593         // "Valid until (%U)"
       
   594         DateTimeL( aArray, endTime, R_QTN_DRM_MGR_DET_RVT_X, aType );
       
   595         }
       
   596     }
       
   597 
       
   598 // -----------------------------------------------------------------------------
       
   599 // FillAccumulatedTimeInfoL
       
   600 // -----------------------------------------------------------------------------
       
   601 static void FillAccumulatedTimeInfoL( CDesCArray& aArray,
       
   602                                CDRMHelperRightsConstraints& aRights,
       
   603                                const TDesC& aType )
       
   604     {
       
   605     TTimeIntervalSeconds accumSeconds( 0 );
       
   606     TRAPD( err, aRights.GetAccumulatedTimeL( accumSeconds ));
       
   607     if ( err != KErrNotFound && err != KErrNone )
       
   608         {
       
   609         User::Leave( err );
       
   610         }
       
   611     if ( err == KErrNone )
       
   612         {
       
   613         // "Usage time left"
       
   614         FillUsageTimeLeftInfoL( aArray, accumSeconds, aType, ETrue );
       
   615         }
       
   616     }
       
   617 
       
   618 // -----------------------------------------------------------------------------
       
   619 // FillDrmInfoL
       
   620 // -----------------------------------------------------------------------------
       
   621 static void FillDrmInfoL( CDesCArray& aArray,
       
   622                    CDRMHelperRightsConstraints* aRights,
       
   623                    TInt aResourceId )
       
   624     {
       
   625     // Check if no rights at all
       
   626     if ( !aRights )
       
   627         {
       
   628         return;
       
   629         }
       
   630 
       
   631     // Rights type is either "Play", "Display", "Execute" or "Print"
       
   632     HBufC* type = StringLoader::LoadLC( aResourceId );
       
   633 
       
   634     // Check if full rights
       
   635     if ( aRights->FullRights() )
       
   636         {
       
   637         // "Rights (%U)"
       
   638         HBufC* label =
       
   639                 StringLoader::LoadLC( R_QTN_DRM_MGR_DET_FULL_X, *type );
       
   640 
       
   641         // "Unlimited"
       
   642         HBufC* data = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_UNLIMITED );
       
   643 
       
   644         AppendLabelAndDataToArrayL( aArray, *label, *data );
       
   645 
       
   646         CleanupStack::PopAndDestroy( data );
       
   647         CleanupStack::PopAndDestroy( label );
       
   648         CleanupStack::PopAndDestroy( type );
       
   649         return;                           // full rights -> return
       
   650         }
       
   651 
       
   652     // Get detailed counter constraint information
       
   653     FillCounterInfoL( aArray, *aRights, *type );
       
   654 
       
   655     // Get detailed interval constraint information (start time + duration)
       
   656     FillIntervalInfoL( aArray, *aRights, *type );
       
   657 
       
   658     // Get detailed time constraint information (start time + end time)
       
   659     FillTimeInfoL( aArray, *aRights, *type );
       
   660 
       
   661     // Get detailed accumulated time constraint information (duration)
       
   662     FillAccumulatedTimeInfoL( aArray, *aRights, *type );
       
   663 
       
   664     CleanupStack::PopAndDestroy( type );
       
   665     }
       
   666 
       
   667 #endif // RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
   668 
       
   669 
       
   670 // ============================ MEMBER FUNCTIONS ===============================
       
   671 
       
   672 // -----------------------------------------------------------------------------
       
   673 // CFileManagerFullOmaDrmInfo
       
   674 // C++ default constructor.
       
   675 // -----------------------------------------------------------------------------
       
   676 //
       
   677 CFileManagerFullOmaDrmInfo::CFileManagerFullOmaDrmInfo()
       
   678     {
       
   679     }
       
   680 
       
   681 // -----------------------------------------------------------------------------
       
   682 // CFileManagerFullOmaDrmInfo::NewL
       
   683 // Two-phased constructor.
       
   684 // -----------------------------------------------------------------------------
       
   685 //
       
   686 CFileManagerFullOmaDrmInfo* CFileManagerFullOmaDrmInfo::NewL( CDesCArray& aArray, 
       
   687                                                          const TDesC& aFullPath,
       
   688                                                          CCoeEnv& aCoeEnv )
       
   689     {
       
   690     CFileManagerFullOmaDrmInfo* self = NewLC( aArray, aFullPath, aCoeEnv );
       
   691     CleanupStack::Pop( self );
       
   692 
       
   693     return self;
       
   694     }
       
   695 
       
   696 // -----------------------------------------------------------------------------
       
   697 // CFileManagerFullOmaDrmInfo::NewLC
       
   698 // Two-phased constructor.
       
   699 // -----------------------------------------------------------------------------
       
   700 //
       
   701 CFileManagerFullOmaDrmInfo* CFileManagerFullOmaDrmInfo::NewLC( CDesCArray& aArray, 
       
   702                                                           const TDesC& aFullPath,
       
   703                                                           CCoeEnv& aCoeEnv )
       
   704     {
       
   705     CFileManagerFullOmaDrmInfo* self = new( ELeave ) CFileManagerFullOmaDrmInfo();
       
   706  
       
   707     CleanupStack::PushL( self );
       
   708     self->ConstructL( aArray, aFullPath, aCoeEnv );
       
   709 
       
   710     return self;
       
   711     }
       
   712     
       
   713 // -----------------------------------------------------------------------------
       
   714 // CFileManagerFullOmaDrmInfo::~CFileManagerFullOmaDrmInfo
       
   715 // Destructor
       
   716 // -----------------------------------------------------------------------------
       
   717 // 
       
   718 CFileManagerFullOmaDrmInfo::~CFileManagerFullOmaDrmInfo()
       
   719     {
       
   720     }
       
   721 
       
   722 #ifndef RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
   723 
       
   724 // -----------------------------------------------------------------------------
       
   725 // CImageInfoPopupList::ConstructL
       
   726 // -----------------------------------------------------------------------------
       
   727 //
       
   728 void CFileManagerFullOmaDrmInfo::ConstructL( CDesCArray& aItemArray,
       
   729                                           const TDesC& aFileName,
       
   730                                           CCoeEnv& aCoeEnv )
       
   731     {
       
   732     TBool expired ( EFalse );
       
   733     TBool sendingAllowed( EFalse );
       
   734     RPointerArray<CDRMHelperRightsConstraints> tempArr;
       
   735     TCleanupItem cleanupItem( ResetAndDestroy, &tempArr );
       
   736     CleanupStack::PushL( cleanupItem );
       
   737     tempArr.AppendL( NULL ); // Play
       
   738     tempArr.AppendL( NULL ); // Display
       
   739     tempArr.AppendL( NULL ); // Execute
       
   740     tempArr.AppendL( NULL ); // Print
       
   741 
       
   742     CDRMHelper* drmHelper = CDRMHelper::NewLC( aCoeEnv );
       
   743 
       
   744     TRAPD( err, drmHelper->GetRightsDetailsL(
       
   745                     aFileName,
       
   746                     0, // Details for everything
       
   747                     expired,
       
   748                     sendingAllowed,
       
   749                     tempArr[KPlayRights],
       
   750                     tempArr[KDisplayRights],
       
   751                     tempArr[KExecuteRights],
       
   752                     tempArr[KPrintRights] ) );
       
   753     TBool future( EFalse );
       
   754     if( expired || err == CDRMRights::ENoRights )
       
   755         {
       
   756         // Check future rights
       
   757         RPointerArray<CDRMRightsConstraints> fArr;
       
   758         TCleanupItem cleanupItem( ResetAndDestroy, &fArr );
       
   759         CleanupStack::PushL( cleanupItem );
       
   760         fArr.AppendL( NULL ); // Play
       
   761         fArr.AppendL( NULL ); // Display
       
   762         fArr.AppendL( NULL ); // Execute
       
   763         fArr.AppendL( NULL ); // Print
       
   764 
       
   765         TBool tmp( EFalse );
       
   766         TBool tmp2( EFalse );
       
   767         TRAP( err, drmHelper->GetRightsDetailsL( aFileName,
       
   768                                  0,
       
   769                                  tmp,
       
   770                                  tmp2,
       
   771                                  fArr[KPlayRights],
       
   772                                  fArr[KDisplayRights],
       
   773                                  fArr[KExecuteRights],
       
   774                                  fArr[KPrintRights] ) );
       
   775 
       
   776         if( err == KErrNone || err == CDRMRights::ENoRights )
       
   777             {
       
   778             future = IsFutureRights( fArr );
       
   779             }
       
   780         CleanupStack::PopAndDestroy( &fArr );
       
   781 
       
   782         ERROR_LOG2( "CFileManagerFullOmaDrmInfo::ConstructL-err:%d,future:%d",
       
   783             err, future )
       
   784         }
       
   785     CleanupStack::PopAndDestroy( drmHelper );
       
   786 
       
   787     ERROR_LOG3( "CFileManagerFullOmaDrmInfo::ConstructL-err:%d,expired:%d,sendingAllowed:%d",
       
   788         err, expired, sendingAllowed )
       
   789 
       
   790     // Check if the rights are valid or expired
       
   791     // Should probably be able to append this information also when the
       
   792     // rights have expired.
       
   793     // "Status"
       
   794     HBufC* label = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_STAT );
       
   795     HBufC* data = NULL;
       
   796     // "Valid" or "Expired" or "Not valid yet"
       
   797     TInt resId( R_QTN_DRM_MGR_DET_VALID );
       
   798     if( future )
       
   799         {
       
   800         resId = R_QTN_DRM_MGR_DET_NOT_VALID_YET;
       
   801         }
       
   802     else if ( expired || err == CDRMRights::ENoRights )
       
   803         {
       
   804         resId = R_QTN_DRM_MGR_DET_EXP;
       
   805         }
       
   806     data = StringLoader::LoadLC( resId );
       
   807     AppendLabelAndDataToArrayL( aItemArray, *label, *data );
       
   808     CleanupStack::PopAndDestroy( data );
       
   809     CleanupStack::PopAndDestroy( label );
       
   810 
       
   811     // "Play"
       
   812     FillDrmInfoL( aItemArray, tempArr[KPlayRights], R_QTN_DRM_MGR_DET2_PLAY );
       
   813 
       
   814     // "Display"
       
   815     FillDrmInfoL( aItemArray, tempArr[KDisplayRights], R_QTN_DRM_MGR_DET2_DISPLAY );
       
   816 
       
   817     // "Execute"
       
   818     FillDrmInfoL( aItemArray, tempArr[KExecuteRights], R_QTN_DRM_MGR_DET2_EXECUTE );
       
   819 
       
   820     // "Print"
       
   821     FillDrmInfoL( aItemArray, tempArr[KPrintRights], R_QTN_DRM_MGR_DET2_PRINT );
       
   822 
       
   823     CleanupStack::PopAndDestroy( &tempArr );
       
   824 
       
   825     // Check whether sending is allowed or not
       
   826 
       
   827     // "Sending"
       
   828     label = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_CS );
       
   829     data = NULL;
       
   830     // "Allowed" or "Forbidden"
       
   831     resId = ( sendingAllowed ? R_QTN_DRM_MGR_DET_ALLOWED
       
   832                              : R_QTN_DRM_MGR_DET_FORBID );
       
   833     data = StringLoader::LoadLC( resId );
       
   834     AppendLabelAndDataToArrayL( aItemArray, *label, *data );
       
   835     CleanupStack::PopAndDestroy( data );
       
   836     CleanupStack::PopAndDestroy( label );
       
   837     }
       
   838 
       
   839 #else // RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
   840 
       
   841 // -----------------------------------------------------------------------------
       
   842 // CImageInfoPopupList::ConstructL
       
   843 // -----------------------------------------------------------------------------
       
   844 //
       
   845 void CFileManagerFullOmaDrmInfo::ConstructL( CDesCArray& aItemArray,
       
   846                                           const TDesC& /*aFileName*/,
       
   847                                           CCoeEnv& /*aCoeEnv*/ )
       
   848     {
       
   849     /*
       
   850     TBool expired ( EFalse );
       
   851     TBool sendingAllowed( EFalse );
       
   852     RPointerArray<CDRMHelperRightsConstraints> tempArr;
       
   853     TCleanupItem cleanupItem( ResetAndDestroy, &tempArr );
       
   854     CleanupStack::PushL( cleanupItem );
       
   855     tempArr.AppendL( NULL ); // Play
       
   856     tempArr.AppendL( NULL ); // Display
       
   857     tempArr.AppendL( NULL ); // Execute
       
   858     tempArr.AppendL( NULL ); // Print
       
   859 
       
   860     CDRMHelper* drmHelper = CDRMHelper::NewLC( aCoeEnv );
       
   861 
       
   862     TRAPD( err, drmHelper->GetRightsDetailsL(
       
   863                     aFileName,
       
   864                     0, // Details for everything
       
   865                     expired,
       
   866                     sendingAllowed,
       
   867                     tempArr[KPlayRights],
       
   868                     tempArr[KDisplayRights],
       
   869                     tempArr[KExecuteRights],
       
   870                     tempArr[KPrintRights] ) );
       
   871     TBool future( EFalse );
       
   872     if( expired || err == CDRMRights::ENoRights )
       
   873         {
       
   874         // Check future rights
       
   875         RPointerArray<CDRMRightsConstraints> fArr;
       
   876         TCleanupItem cleanupItem( ResetAndDestroy, &fArr );
       
   877         CleanupStack::PushL( cleanupItem );
       
   878         fArr.AppendL( NULL ); // Play
       
   879         fArr.AppendL( NULL ); // Display
       
   880         fArr.AppendL( NULL ); // Execute
       
   881         fArr.AppendL( NULL ); // Print
       
   882 
       
   883         TBool tmp( EFalse );
       
   884         TBool tmp2( EFalse );
       
   885         TRAP( err, drmHelper->GetRightsDetailsL( aFileName,
       
   886                                  0,
       
   887                                  tmp,
       
   888                                  tmp2,
       
   889                                  fArr[KPlayRights],
       
   890                                  fArr[KDisplayRights],
       
   891                                  fArr[KExecuteRights],
       
   892                                  fArr[KPrintRights] ) );
       
   893 
       
   894         if( err == KErrNone || err == CDRMRights::ENoRights )
       
   895             {
       
   896             future = IsFutureRights( fArr );
       
   897             }
       
   898         CleanupStack::PopAndDestroy( &fArr );
       
   899 
       
   900         ERROR_LOG2( "CFileManagerFullOmaDrmInfo::ConstructL-err:%d,future:%d",
       
   901             err, future )
       
   902         }
       
   903     CleanupStack::PopAndDestroy( drmHelper );
       
   904 
       
   905     ERROR_LOG3( "CFileManagerFullOmaDrmInfo::ConstructL-err:%d,expired:%d,sendingAllowed:%d",
       
   906         err, expired, sendingAllowed )
       
   907 
       
   908     if ( tempArr[KPlayRights] ||
       
   909         tempArr[KDisplayRights] ||
       
   910         tempArr[KExecuteRights] ||
       
   911         tempArr[KPrintRights] )
       
   912         {
       
   913     */
       
   914         // Add link to display rights details
       
   915     _LIT( KLinkTagStart, "<AknMessageQuery Link>" );
       
   916     _LIT( KLinkTagEnd, "</AknMessageQuery Link>" );
       
   917 
       
   918     HBufC* linkTitle = StringLoader::LoadLC( R_QTN_FMGR_DRM_DET_LINK );
       
   919     HBufC* linkText = StringLoader::LoadLC( R_QTN_FMGR_DRM_DET_LINK_VIEW );
       
   920     HBufC* dataStr = HBufC::NewLC( KLinkTagStart().Length() +
       
   921                                    linkText->Length() +
       
   922                                    KLinkTagEnd().Length() );
       
   923     TPtr dataPtr( dataStr->Des() );
       
   924     dataPtr.Append( KLinkTagStart );
       
   925     dataPtr.Append( *linkText );
       
   926     dataPtr.Append( KLinkTagEnd );
       
   927     AppendLabelAndDataToArrayL( aItemArray, *linkTitle, *dataStr );
       
   928     CleanupStack::PopAndDestroy( dataStr );
       
   929     CleanupStack::PopAndDestroy( linkText );
       
   930     CleanupStack::PopAndDestroy( linkTitle );
       
   931     /*
       
   932         }
       
   933     else
       
   934         {
       
   935         // Add forward-lock details
       
   936         // "Status"
       
   937         HBufC* label = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_STAT );
       
   938         HBufC* data = NULL;
       
   939         // "Valid" or "Expired" or "Not valid yet"
       
   940         TInt resId( R_QTN_DRM_MGR_DET_VALID );
       
   941         if( future )
       
   942             {
       
   943             resId = R_QTN_DRM_MGR_DET_NOT_VALID_YET;
       
   944             }
       
   945         else if ( expired || err == CDRMRights::ENoRights )
       
   946             {
       
   947             resId = R_QTN_DRM_MGR_DET_EXP;
       
   948             }
       
   949         data = StringLoader::LoadLC( resId );
       
   950         AppendLabelAndDataToArrayL( aItemArray, *label, *data );
       
   951         CleanupStack::PopAndDestroy( data );
       
   952         CleanupStack::PopAndDestroy( label );
       
   953 
       
   954         // "Sending"
       
   955         label = StringLoader::LoadLC( R_QTN_DRM_MGR_DET_CS );
       
   956         data = NULL;
       
   957         // "Allowed" or "Forbidden"
       
   958         resId = ( sendingAllowed ? R_QTN_DRM_MGR_DET_ALLOWED
       
   959                                  : R_QTN_DRM_MGR_DET_FORBID );
       
   960         data = StringLoader::LoadLC( resId );
       
   961         AppendLabelAndDataToArrayL( aItemArray, *label, *data );
       
   962         CleanupStack::PopAndDestroy( data );
       
   963         CleanupStack::PopAndDestroy( label );
       
   964         }
       
   965 
       
   966     CleanupStack::PopAndDestroy( &tempArr );
       
   967     */
       
   968     }
       
   969 
       
   970 // -----------------------------------------------------------------------------
       
   971 // CImageInfoPopupList::ViewDetailsL
       
   972 // -----------------------------------------------------------------------------
       
   973 //
       
   974 void CFileManagerFullOmaDrmInfo::ViewDetailsL(
       
   975         const TDesC& aFileName,
       
   976         DRM::CDrmUiHandling* aUiHandling )
       
   977     {
       
   978     RFs fs;
       
   979     User::LeaveIfError( fs.Connect() );
       
   980     CleanupClosePushL( fs );
       
   981     
       
   982     RFile64 drmFile;
       
   983     User::LeaveIfError( drmFile.Open( 
       
   984             fs, aFileName, EFileRead | EFileShareReadersOrWriters ) );
       
   985     
       
   986     CleanupClosePushL( drmFile );
       
   987     
       
   988     TRAPD( err, aUiHandling->ShowDetailsViewL( drmFile ) );
       
   989     
       
   990     CleanupStack::PopAndDestroy( &drmFile );
       
   991     CleanupStack::PopAndDestroy( &fs );
       
   992     
       
   993     }
       
   994 
       
   995 #endif // RD_DRM_COMMON_INTERFACE_FOR_OMA_AND_WMDRM
       
   996 
       
   997 // End of file