videofeeds/utils/src/iptvlastwatcheddata.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:    Contains Video Center's last watched item's data.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 #include "IptvDebug.h"
       
    20 #include "CIptvUtil.h"
       
    21 #include <s32mem.h>
       
    22 
       
    23 #include "iptvlastwatcheddata.h"
       
    24 
       
    25 // ======== MEMBER FUNCTIONS ========
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CIptvLastWatchedData::CIptvLastWatchedData() :
       
    32     iServiceId( KIdUndefined ),
       
    33     iContentId( KIdUndefined ),
       
    34     iMpxId( KIdUndefined )
       
    35     {
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 EXPORT_C CIptvLastWatchedData* CIptvLastWatchedData::NewL()
       
    43     {
       
    44     return new( ELeave ) CIptvLastWatchedData;
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CIptvLastWatchedData::~CIptvLastWatchedData()
       
    52     {
       
    53     delete iName;
       
    54     delete iUri;
       
    55     delete iIconPath;
       
    56     delete iMimeType;
       
    57     delete iParameters;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // Construct class from binary stream
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 EXPORT_C void CIptvLastWatchedData::InternalizeL( RReadStream& aStream )
       
    65     {
       
    66     iAppUid.iUid      = aStream.ReadUint32L();
       
    67     iViewUid.iUid     = aStream.ReadUint32L();
       
    68     iParameterId.iUid = aStream.ReadUint32L();
       
    69 
       
    70     iLaunchType       = static_cast<TLaunchType>( aStream.ReadUint32L() );
       
    71 
       
    72     delete iName;
       
    73     iName = NULL;
       
    74     iName = HBufC::NewL( KIptvMyVideosVideoNameMaxLength );
       
    75     TPtr  pName       = iName->Des();
       
    76     CIptvUtil::ReadDesFromStreamL( pName, aStream );
       
    77     iName->ReAlloc( iName->Length() );
       
    78 
       
    79     delete iUri;
       
    80     iUri = NULL;
       
    81     iUri = HBufC::NewL( KIptvLastWatchedUriMaxLength );
       
    82     TPtr  pUri        = iUri->Des();
       
    83     CIptvUtil::ReadDesFromStreamL( pUri, aStream );
       
    84     iUri->ReAlloc( iUri->Length() );
       
    85 
       
    86     delete iIconPath;
       
    87     iIconPath = NULL;
       
    88     iIconPath = HBufC::NewL( KIptvMaxPath );
       
    89     TPtr  pIconPath   = iIconPath->Des();
       
    90     CIptvUtil::ReadDesFromStreamL( pIconPath, aStream );
       
    91     iIconPath->ReAlloc( iIconPath->Length() );
       
    92 
       
    93     delete iMimeType;
       
    94     iMimeType = NULL;
       
    95     iMimeType = HBufC::NewL( KIptvMaxPath );
       
    96     TPtr  pMimeType   = iMimeType->Des();
       
    97     CIptvUtil::ReadDesFromStreamL( pMimeType, aStream );
       
    98     iMimeType->ReAlloc( iMimeType->Length() );
       
    99 
       
   100     iServiceId        = aStream.ReadInt32L();
       
   101     iContentId        = aStream.ReadInt32L();
       
   102     iContentIndex     = aStream.ReadInt32L();
       
   103 
       
   104     iLastVideoPlayPoint = aStream.ReadUint32L();
       
   105     iParentalControl  = aStream.ReadUint32L();
       
   106 
       
   107     delete iParameters;
       
   108     iParameters       = NULL;
       
   109     iParameters       = HBufC8::NewL( KIptvLastWatchedStartparamMaxLength );
       
   110     TPtr8 pParameters = iParameters->Des();
       
   111     CIptvUtil::ReadDes8FromStreamL( pParameters, aStream );
       
   112     iParameters->ReAlloc( iParameters->Length() );
       
   113 
       
   114 #if !defined(__SERIES60_30__) && !defined(__SERIES60_31__) && !defined(__SERIES60_32__)
       
   115 
       
   116     TInt offset = aStream.Source()->TellL( MStreamBuf::ERead ).Offset();
       
   117     TInt size = aStream.Source()->SizeL();
       
   118 
       
   119     // Check if iContentType is in stream (file). If we are reading old file format,
       
   120     // we have already reached the EOF, but in new file format there's iContentType.
       
   121     if ( ( offset + 4 ) <= size )
       
   122         {
       
   123         iContentType = aStream.ReadInt32L();
       
   124         }
       
   125 
       
   126     offset = aStream.Source()->TellL( MStreamBuf::ERead ).Offset();
       
   127 
       
   128     // Check if iMpxId is in stream (file). If we are reading old file format,
       
   129     // we have already reached the EOF, but in new file format there's iMpxId.
       
   130     if ( ( offset + 4 ) <= size )
       
   131         {
       
   132         iMpxId = aStream.ReadInt32L();
       
   133         }
       
   134 
       
   135 #endif // !defined(__SERIES60_30__) && !defined(__SERIES60_31__) && !defined(__SERIES60_32__)    
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // Write class to binary stream
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C void CIptvLastWatchedData::ExternalizeL( RWriteStream& aStream )
       
   143     {
       
   144     aStream.WriteUint32L( iAppUid.iUid );
       
   145     aStream.WriteUint32L( iViewUid.iUid );
       
   146     aStream.WriteUint32L( iParameterId.iUid );
       
   147     aStream.WriteUint32L( iLaunchType );
       
   148 
       
   149     CIptvUtil::WriteDesToStreamL( Name(), aStream );
       
   150     CIptvUtil::WriteDesToStreamL( Uri(), aStream );
       
   151     CIptvUtil::WriteDesToStreamL( IconPath(), aStream );
       
   152     CIptvUtil::WriteDesToStreamL( MimeType(), aStream );
       
   153 
       
   154     aStream.WriteInt32L( iServiceId );
       
   155     aStream.WriteInt32L( iContentId );
       
   156     aStream.WriteInt32L( iContentIndex );
       
   157     aStream.WriteUint32L( iLastVideoPlayPoint );
       
   158     aStream.WriteUint32L( iParentalControl );
       
   159 
       
   160     CIptvUtil::WriteDes8ToStreamL( Parameters(), aStream );
       
   161 
       
   162 #if !defined(__SERIES60_30__) && !defined(__SERIES60_31__) && !defined(__SERIES60_32__)
       
   163 
       
   164     aStream.WriteInt32L( iContentType );
       
   165 
       
   166     aStream.WriteInt32L( iMpxId );
       
   167     
       
   168 #endif // !defined(__SERIES60_30__) && !defined(__SERIES60_31__) && !defined(__SERIES60_32__)
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // Setter
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C TInt CIptvLastWatchedData::SetNameL( const TDesC& aName )
       
   176     {
       
   177     if ( aName.Length() > KIptvMyVideosVideoNameMaxLength )
       
   178         {
       
   179         return KErrArgument;
       
   180         }
       
   181 
       
   182     delete iName;
       
   183     iName = NULL;
       
   184     iName = aName.AllocL();
       
   185 
       
   186     return KErrNone;
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // Setter
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 EXPORT_C TInt CIptvLastWatchedData::SetUriL( const TDesC& aUri )
       
   194     {
       
   195     if ( aUri.Length() > KIptvLastWatchedUriMaxLength )
       
   196         {
       
   197         return KErrArgument;
       
   198         }
       
   199 
       
   200     delete iUri;
       
   201     iUri = NULL;
       
   202     iUri = aUri.AllocL();
       
   203 
       
   204     return KErrNone;
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // Setter
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C TInt CIptvLastWatchedData::SetIconPathL( const TDesC& aIconPath )
       
   212     {
       
   213     if ( aIconPath.Length() > KIptvMaxPath )
       
   214         {
       
   215         return KErrArgument;
       
   216         }
       
   217 
       
   218     delete iIconPath;
       
   219     iIconPath = NULL;
       
   220     iIconPath = aIconPath.AllocL();
       
   221 
       
   222     return KErrNone;
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // Setter
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 EXPORT_C TInt CIptvLastWatchedData::SetMimeTypeL( const TDesC& aMimeType )
       
   230     {
       
   231     if ( aMimeType.Length() > KIptvMyVideosVideoMaxMimeTypeLength )
       
   232         {
       
   233         return KErrArgument;
       
   234         }
       
   235 
       
   236     delete iMimeType;
       
   237     iMimeType = NULL;
       
   238     iMimeType = aMimeType.AllocL();
       
   239 
       
   240     return KErrNone;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // Setter
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 EXPORT_C TInt CIptvLastWatchedData::SetServiceId(
       
   248     const TInt32 aServiceId )
       
   249     {
       
   250     iServiceId = aServiceId;
       
   251 
       
   252     return KErrNone;
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // Setter
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 EXPORT_C TInt CIptvLastWatchedData::SetContentId(
       
   260     const TIptvContentId aContentId )
       
   261     {
       
   262     iContentId = aContentId;
       
   263 
       
   264     return KErrNone;
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // Setter
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 EXPORT_C TInt CIptvLastWatchedData::SetContentIndex(
       
   272     const TInt32 aContentIndex )
       
   273     {
       
   274     iContentIndex = aContentIndex;
       
   275 
       
   276     return KErrNone;
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // Setter
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 EXPORT_C TInt CIptvLastWatchedData::SetLastVideoPlayPoint(
       
   284     const TUint32 aLastVideoPlayPoint )
       
   285     {
       
   286     iLastVideoPlayPoint = aLastVideoPlayPoint;
       
   287 
       
   288     return KErrNone;
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------------------------
       
   292 // Setter
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 EXPORT_C TInt CIptvLastWatchedData::SetParentalControl(
       
   296     const TUint32 aParentalControl )
       
   297     {
       
   298     iParentalControl = aParentalControl;
       
   299 
       
   300     return KErrNone;
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // Setter
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 EXPORT_C TInt CIptvLastWatchedData::SetParametersL( const TDesC8& aParameters )
       
   308     {
       
   309     if ( aParameters.Length() > KIptvLastWatchedStartparamMaxLength )
       
   310         {
       
   311         return KErrArgument;
       
   312         }
       
   313 
       
   314     delete iParameters;
       
   315     iParameters = NULL;
       
   316     iParameters = aParameters.AllocL();
       
   317 
       
   318     return KErrNone;
       
   319     }
       
   320 
       
   321 // ---------------------------------------------------------------------------
       
   322 // Setter
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 EXPORT_C void CIptvLastWatchedData::SetAppUid( const TUid& aAppUid )
       
   326     {
       
   327     iAppUid = aAppUid;
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // Setter
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 EXPORT_C void CIptvLastWatchedData::SetViewUid( const TUid& aViewUid )
       
   335     {
       
   336     iViewUid = aViewUid;
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // Setter
       
   341 // ---------------------------------------------------------------------------
       
   342 //
       
   343 EXPORT_C void CIptvLastWatchedData::SetParameterId( const TUid& aParameterId )
       
   344     {
       
   345     iParameterId = aParameterId;
       
   346     }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // Setter
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 EXPORT_C void CIptvLastWatchedData::SetLaunchType( TLaunchType aLaunchType )
       
   353     {
       
   354     iLaunchType = aLaunchType;
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------------------------
       
   358 // Getter
       
   359 // ---------------------------------------------------------------------------
       
   360 //
       
   361 EXPORT_C const TDesC& CIptvLastWatchedData::Name() const
       
   362     {
       
   363     if ( iName )
       
   364         {
       
   365         return *iName;
       
   366         }
       
   367     else
       
   368         {
       
   369         return KNullDesC();
       
   370         }
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // Getter
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 EXPORT_C const TDesC& CIptvLastWatchedData::Uri() const
       
   378     {
       
   379     if ( iUri )
       
   380         {
       
   381         return *iUri;
       
   382         }
       
   383     else
       
   384         {
       
   385         return KNullDesC();
       
   386         }
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // Getter
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 EXPORT_C const TDesC& CIptvLastWatchedData::IconPath() const
       
   394     {
       
   395     if ( iIconPath )
       
   396         {
       
   397         return *iIconPath;
       
   398         }
       
   399     else
       
   400         {
       
   401         return KNullDesC();
       
   402         }
       
   403     }
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // Getter
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 EXPORT_C const TDesC& CIptvLastWatchedData::MimeType() const
       
   410     {
       
   411     if ( iMimeType )
       
   412         {
       
   413         return *iMimeType;
       
   414         }
       
   415     else
       
   416         {
       
   417         return KNullDesC();
       
   418         }
       
   419     }
       
   420 
       
   421 // ---------------------------------------------------------------------------
       
   422 // Getter
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 EXPORT_C TInt32 CIptvLastWatchedData::ServiceId() const
       
   426     {
       
   427     return iServiceId;
       
   428     }
       
   429 
       
   430 // ---------------------------------------------------------------------------
       
   431 // Getter
       
   432 // ---------------------------------------------------------------------------
       
   433 //
       
   434 EXPORT_C TIptvContentId CIptvLastWatchedData::ContentId() const
       
   435     {
       
   436     return iContentId;
       
   437     }
       
   438 
       
   439 // ---------------------------------------------------------------------------
       
   440 // Getter
       
   441 // ---------------------------------------------------------------------------
       
   442 //
       
   443 EXPORT_C TInt32 CIptvLastWatchedData::ContentIndex() const
       
   444     {
       
   445     return iContentIndex;
       
   446     }
       
   447 
       
   448 // ---------------------------------------------------------------------------
       
   449 // Getter
       
   450 // ---------------------------------------------------------------------------
       
   451 //
       
   452 EXPORT_C TUint32 CIptvLastWatchedData::LastVideoPlayPoint() const
       
   453     {
       
   454     return iLastVideoPlayPoint;
       
   455     }
       
   456 
       
   457 // ---------------------------------------------------------------------------
       
   458 // Getter
       
   459 // ---------------------------------------------------------------------------
       
   460 //
       
   461 EXPORT_C TUint32 CIptvLastWatchedData::ParentalControl() const
       
   462     {
       
   463     return iParentalControl;
       
   464     }
       
   465 
       
   466 // ---------------------------------------------------------------------------
       
   467 // Getter
       
   468 // ---------------------------------------------------------------------------
       
   469 //
       
   470 EXPORT_C const TDesC8& CIptvLastWatchedData::Parameters() const
       
   471     {
       
   472     if ( iParameters )
       
   473         {
       
   474         return *iParameters;
       
   475         }
       
   476     else
       
   477         {
       
   478         return KNullDesC8();
       
   479         }
       
   480     }
       
   481 
       
   482 // ---------------------------------------------------------------------------
       
   483 // Getter
       
   484 // ---------------------------------------------------------------------------
       
   485 //
       
   486 EXPORT_C TUid CIptvLastWatchedData::AppUid() const
       
   487     {
       
   488     return iAppUid;
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // Getter
       
   493 // ---------------------------------------------------------------------------
       
   494 //
       
   495 EXPORT_C TUid CIptvLastWatchedData::ViewUid() const
       
   496     {
       
   497     return iViewUid;
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 // Getter
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 EXPORT_C TUid CIptvLastWatchedData::ParameterId() const
       
   505     {
       
   506     return iParameterId;
       
   507     }
       
   508 
       
   509 // ---------------------------------------------------------------------------
       
   510 // Getter
       
   511 // ---------------------------------------------------------------------------
       
   512 //
       
   513 EXPORT_C CIptvLastWatchedData::TLaunchType CIptvLastWatchedData::LaunchType()
       
   514     const
       
   515     {
       
   516     return iLaunchType;
       
   517     }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CIptvLastWatchedData::CountExternalizeSize()
       
   521 // Return externalize size in 8bit bytes.
       
   522 // -----------------------------------------------------------------------------
       
   523 //
       
   524 EXPORT_C TUint32 CIptvLastWatchedData::CountExternalizeSize() const
       
   525     {
       
   526     TUint32 size =
       
   527             2 +  ( Name().Length() * 2 ) +     // HBufC* iName
       
   528             2 +  ( Uri().Length() * 2 ) +      // HBufC* iUri
       
   529             2 +  ( IconPath().Length() * 2 ) + // HBufC* iIconPath
       
   530             2 +  ( MimeType().Length() * 2 ) + // HBufC* iMimeType
       
   531             4 +                                // TInt32 iServiceId;
       
   532             4 +                                // TIptvContentId iContentId;
       
   533             4 +                                // TInt32 ContentIndex;
       
   534             4 +                                // TUint32 iLastVideoPlayPoint;
       
   535             4 +                                // TUint32 iParentalControl;
       
   536             2 +  ( Parameters().Length() ) +   // HBufC8* iParameters
       
   537             4 +                                // TUid iAppUid
       
   538             4 +                                // TUid iViewUid
       
   539             4 +                                // TUid iParameterId
       
   540             4;                                 // TLaunchType iLaunchType
       
   541     
       
   542 #if !defined(__SERIES60_30__) && !defined(__SERIES60_31__) && !defined(__SERIES60_32__)
       
   543 
       
   544     size += 4;                                 // TUint32 iContentType
       
   545     size += 4;                                 // TUint32 iMpxId
       
   546     
       
   547 #endif // !defined(__SERIES60_30__) && !defined(__SERIES60_31__) && !defined(__SERIES60_32__)
       
   548     
       
   549     return size;
       
   550     }
       
   551 
       
   552 // -----------------------------------------------------------------------------
       
   553 // !defined(__SERIES60_30__) && !defined(__SERIES60_31__) && !defined(__SERIES60_32__)
       
   554 // -----------------------------------------------------------------------------
       
   555 //
       
   556 EXPORT_C TInt CIptvLastWatchedData::SetContentType( const TInt aContentType )    
       
   557     {
       
   558     iContentType = aContentType;
       
   559     return KErrNone;    
       
   560     }
       
   561 
       
   562 // -----------------------------------------------------------------------------
       
   563 // !defined(__SERIES60_30__) && !defined(__SERIES60_31__) && !defined(__SERIES60_32__)
       
   564 // -----------------------------------------------------------------------------
       
   565 //
       
   566 EXPORT_C TInt CIptvLastWatchedData::ContentType() const
       
   567     {
       
   568     return iContentType;
       
   569     }
       
   570 
       
   571 // -----------------------------------------------------------------------------
       
   572 // !defined(__SERIES60_30__) && !defined(__SERIES60_31__) && !defined(__SERIES60_32__)
       
   573 // -----------------------------------------------------------------------------
       
   574 //
       
   575 EXPORT_C TInt CIptvLastWatchedData::SetMpxId( const TInt aMpxId )    
       
   576     {
       
   577     iMpxId = aMpxId;
       
   578     return KErrNone;    
       
   579     }
       
   580 
       
   581 // -----------------------------------------------------------------------------
       
   582 // !defined(__SERIES60_30__) && !defined(__SERIES60_31__) && !defined(__SERIES60_32__)
       
   583 // -----------------------------------------------------------------------------
       
   584 //
       
   585 EXPORT_C TInt CIptvLastWatchedData::MpxId() const
       
   586     {
       
   587     return iMpxId;
       
   588     }