videofeeds/utils/src/iptvlastwatchedapi.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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 the License "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:    Interface for getting and setting the Video Center's last*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 #include <bautils.h>
       
    20 #include "IptvDebug.h"
       
    21 #include <s32file.h>
       
    22 #include "CIptvUtil.h"
       
    23 #include <sysutil.h>
       
    24 
       
    25 #include "iptvlastwatcheddata.h"
       
    26 #include "iptvlastwatchedapi.h"
       
    27 
       
    28 _LIT( KIptvLastWatchedFileName, "lastwatched.dat" );
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // 
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CIptvLastWatchedApi::CIptvLastWatchedApi()
       
    37     {
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // 
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 void CIptvLastWatchedApi::ConstructL()
       
    45     {
       
    46     User::LeaveIfError( iFsSession.Connect() );
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // 
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 EXPORT_C CIptvLastWatchedApi* CIptvLastWatchedApi::NewL()
       
    54     {
       
    55     CIptvLastWatchedApi* self = CIptvLastWatchedApi::NewLC();
       
    56     CleanupStack::Pop( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // 
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 EXPORT_C CIptvLastWatchedApi* CIptvLastWatchedApi::NewLC()
       
    65     {
       
    66     CIptvLastWatchedApi* self = new( ELeave ) CIptvLastWatchedApi;
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     return self;
       
    70     }
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CIptvLastWatchedApi::~CIptvLastWatchedApi()
       
    78     {
       
    79     iFsSession.Close();
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Write last watched data item to the file
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C TInt CIptvLastWatchedApi::SetLastWatchedDataL(
       
    87     CIptvLastWatchedData& aData )
       
    88     {
       
    89     IPTVLOGSTRING_HIGH_LEVEL( ">>>CIptvLastWatchedApi::SetLastWatchedDataL" );
       
    90 
       
    91     if ( ! CIptvUtil::LastPlaybackPositionFeatureSupported() )
       
    92         {
       
    93         aData.SetLastVideoPlayPoint( 0 );
       
    94         }    
       
    95     
       
    96     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFsSession,
       
    97             static_cast<TInt64>(aData.CountExternalizeSize()), EDriveC ) )
       
    98         {
       
    99     	IPTVLOGSTRING_HIGH_LEVEL(
       
   100     	    "<<<CIptvLastWatchedApi::SetLastWatchedDataL Disk full" );
       
   101         return KErrDiskFull;
       
   102         }
       
   103     else
       
   104         {
       
   105         TFileName fileName;
       
   106         CIptvUtil::GetPathL( iFsSession, EIptvPathEcg, fileName );
       
   107         fileName.Append( KIptvLastWatchedFileName );
       
   108 
       
   109         RFileWriteStream writeStream;
       
   110 
       
   111         TInt retVal = writeStream.Replace( iFsSession, fileName, EFileWrite );
       
   112 
       
   113         if ( retVal == KErrNone )
       
   114             {
       
   115             CleanupClosePushL( writeStream );
       
   116             aData.ExternalizeL( writeStream );
       
   117             CleanupStack::PopAndDestroy( &writeStream );
       
   118             }
       
   119 
       
   120     	IPTVLOGSTRING_HIGH_LEVEL(
       
   121     	    "<<<CIptvLastWatchedApi::SetLastWatchedDataL" );
       
   122         return retVal;
       
   123         }
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // Read last watched data item from the file
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 EXPORT_C TInt CIptvLastWatchedApi::GetLastWatchedDataL(
       
   131     CIptvLastWatchedData& aData )
       
   132     {
       
   133     IPTVLOGSTRING_HIGH_LEVEL( ">>>CIptvLastWatchedApi::GetLastWatchedDataL" );
       
   134 
       
   135     RFileReadStream readStream;
       
   136  
       
   137     TFileName fileName;
       
   138     CIptvUtil::GetPathL( iFsSession, EIptvPathEcg, fileName, EDriveC, EFalse );
       
   139     fileName.Append( KIptvLastWatchedFileName );
       
   140 
       
   141     TInt retVal = readStream.Open( iFsSession, fileName, EFileRead );
       
   142 
       
   143     if ( retVal == KErrNone )
       
   144         {
       
   145         CleanupClosePushL( readStream );
       
   146         aData.InternalizeL( readStream );
       
   147         CleanupStack::PopAndDestroy( &readStream );
       
   148         
       
   149         if ( ! CIptvUtil::LastPlaybackPositionFeatureSupported() )
       
   150             {
       
   151             aData.SetLastVideoPlayPoint( 0 );
       
   152             }
       
   153         }
       
   154     
       
   155 	IPTVLOGSTRING_HIGH_LEVEL( "<<<CIptvLastWatchedApi::GetLastWatchedDataL" );
       
   156 
       
   157     return retVal;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // Update last video play point
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 EXPORT_C TInt CIptvLastWatchedApi::UpdateLastVideoPlayPointL(
       
   165     const TUint32 aLastVideoPlayPoint )
       
   166     {
       
   167     IPTVLOGSTRING2_HIGH_LEVEL(
       
   168         ">>>CIptvLastWatchedApi::UpdateLastVideoPlayPointL( %u )",
       
   169         aLastVideoPlayPoint );
       
   170 
       
   171     TInt retVal( KErrNotFound );
       
   172     
       
   173     if ( CIptvUtil::LastPlaybackPositionFeatureSupported() )
       
   174         {
       
   175         // Create descriptor for last watched data.
       
   176         CIptvLastWatchedData* lwData = CIptvLastWatchedData::NewL();
       
   177         if ( lwData )
       
   178             {
       
   179             CleanupStack::PushL( lwData );
       
   180     
       
   181             // Create name for last watched data file.
       
   182             TFileName fileName;
       
   183             CIptvUtil::GetPathL( iFsSession, EIptvPathEcg, fileName, EDriveC, EFalse );
       
   184             fileName.Append( KIptvLastWatchedFileName );
       
   185 
       
   186             // Read original vales.
       
   187             RFileReadStream readStream;
       
   188             retVal = readStream.Open( iFsSession, fileName, EFileRead );
       
   189             if ( retVal == KErrNone )
       
   190                 {
       
   191                 CleanupClosePushL( readStream );
       
   192                 lwData->InternalizeL( readStream );
       
   193                 CleanupStack::PopAndDestroy( &readStream );
       
   194                    
       
   195                 // Update value.
       
   196                 lwData->SetLastVideoPlayPoint( aLastVideoPlayPoint );
       
   197 
       
   198                 // Replace data file with updated values.
       
   199                 RFileWriteStream writeStream;
       
   200                 retVal = writeStream.Replace( iFsSession, fileName, EFileWrite );
       
   201                 if ( retVal == KErrNone )
       
   202                     {
       
   203                     CleanupClosePushL( writeStream );
       
   204                     lwData->ExternalizeL( writeStream );
       
   205                     CleanupStack::PopAndDestroy( &writeStream );
       
   206                     }
       
   207                 }
       
   208             CleanupStack::PopAndDestroy( lwData );
       
   209             }
       
   210         }
       
   211     else
       
   212         {
       
   213         IPTVLOGSTRING_HIGH_LEVEL( "CIptvLastWatchedApi::UpdateLastVideoPlayPointL - Feature is not supported" );
       
   214         retVal = KErrNotSupported;
       
   215         }
       
   216 
       
   217 	IPTVLOGSTRING_HIGH_LEVEL( "<<<CIptvLastWatchedApi::UpdateLastVideoPlayPointL" );
       
   218 
       
   219     return retVal;
       
   220     }