omads/omadsextensions/adapters/mediads/src/snapshotitem.cpp
changeset 36 9ba7f05d28a5
equal deleted inserted replaced
35:0ca79e3612d9 36:9ba7f05d28a5
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Part of SyncML Data Synchronization Plug In Adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <S32STRM.h>
       
    21 
       
    22 #include "snapshotitem.h"
       
    23 
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // TSnapshotItem::TSnapshotItem
       
    27 // C++ default constructor can NOT contain any code, that might leave
       
    28 // -----------------------------------------------------------------------------
       
    29 TSnapshotItem::TSnapshotItem()
       
    30     {
       
    31     SetItemId( 0 );
       
    32     SetParentId( 0 );
       
    33     }
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // TSnapshotItem::TSnapshotItem
       
    37 // Constructor, takes item id as a parameter
       
    38 // -----------------------------------------------------------------------------
       
    39 TSnapshotItem::TSnapshotItem( const TSmlDbItemUid& aItemId,
       
    40     const TSmlDbItemUid& aParent )
       
    41     {
       
    42     SetItemId( aItemId );
       
    43     SetParentId( aParent );
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // TSnapshotItem::ExternalizeL
       
    48 // Writes the contents of this class to stream
       
    49 // -----------------------------------------------------------------------------
       
    50 void TSnapshotItem::ExternalizeL( RWriteStream& aStream ) const
       
    51     {
       
    52     aStream.WriteInt32L( iItemId );
       
    53     aStream.WriteInt32L( iParentId );
       
    54     
       
    55     TPckgBuf<THashValue> nameBuf(iHash);
       
    56     
       
    57     aStream << nameBuf;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // TSnapshotItem::InternalizeL
       
    62 // Reads the contents of this class from stream
       
    63 // -----------------------------------------------------------------------------
       
    64 void TSnapshotItem::InternalizeL( RReadStream& aStream )
       
    65     {
       
    66     iItemId = aStream.ReadInt32L();
       
    67     iParentId = aStream.ReadInt32L();
       
    68     
       
    69     TPckgBuf<THashValue> nameBuf;
       
    70 	aStream >> nameBuf;
       
    71 	iHash = nameBuf();
       
    72     }
       
    73 
       
    74 const TSmlDbItemUid& TSnapshotItem::ItemId() const
       
    75     {
       
    76     return iItemId;
       
    77     }
       
    78 
       
    79 void TSnapshotItem::SetItemId( const TSmlDbItemUid& aItemId )
       
    80     {
       
    81     iItemId = aItemId;
       
    82     }
       
    83 
       
    84 
       
    85 const TSmlDbItemUid& TSnapshotItem::ParentId() const
       
    86     {
       
    87     return iParentId;
       
    88     }
       
    89 
       
    90 void TSnapshotItem::SetParentId( const TSmlDbItemUid& aParentId )
       
    91     {
       
    92     iParentId = aParentId;
       
    93     }
       
    94 
       
    95 
       
    96 void TSnapshotItem::SetItemHash( const TDesC& aFolderName, CMD5& aHasher )
       
    97     {
       
    98     TPtrC8 narrowFolder;
       
    99     TInt narrowFolderLen = 0;
       
   100 
       
   101     narrowFolderLen = aFolderName.Length()*2;
       
   102     narrowFolder.Set((TUint8*)aFolderName.Ptr(), narrowFolderLen);
       
   103     
       
   104     aHasher.Reset();
       
   105     aHasher.Update( narrowFolder );
       
   106     
       
   107     iHash = aHasher.Final();
       
   108     
       
   109     }
       
   110 
       
   111 void TSnapshotItem::SetItemHash( const CSongItem& aSongItem, CMD5& aHasher )
       
   112     {
       
   113     TPtrC8 narrowData;
       
   114     TInt narrowDataLen = 0;
       
   115 
       
   116     
       
   117     aHasher.Reset();
       
   118     
       
   119     narrowDataLen = aSongItem.Uri().Length()*2;
       
   120     narrowData.Set((TUint8*)aSongItem.Uri().Ptr(), narrowDataLen);
       
   121     aHasher.Update( narrowData );
       
   122     
       
   123     narrowDataLen = aSongItem.Title().Length()*2;
       
   124     narrowData.Set((TUint8*)aSongItem.Title().Ptr(), narrowDataLen);
       
   125     aHasher.Update( narrowData );
       
   126     
       
   127     narrowDataLen = aSongItem.MimeType().Length()*2;
       
   128     narrowData.Set((TUint8*)aSongItem.MimeType().Ptr(), narrowDataLen);
       
   129     aHasher.Update( narrowData );
       
   130     
       
   131     narrowDataLen = aSongItem.Artist().Length()*2;
       
   132     narrowData.Set((TUint8*)aSongItem.Artist().Ptr(), narrowDataLen);
       
   133     aHasher.Update( narrowData );
       
   134     
       
   135     narrowDataLen = aSongItem.Album().Length()*2;
       
   136     narrowData.Set((TUint8*)aSongItem.Album().Ptr(), narrowDataLen);
       
   137     aHasher.Update( narrowData );
       
   138     
       
   139     narrowDataLen = aSongItem.Genre().Length()*2;
       
   140     narrowData.Set((TUint8*)aSongItem.Genre().Ptr(), narrowDataLen);
       
   141     aHasher.Update( narrowData );
       
   142     
       
   143     narrowDataLen = aSongItem.Comment().Length()*2;
       
   144     narrowData.Set((TUint8*)aSongItem.Comment().Ptr(), narrowDataLen);
       
   145     aHasher.Update( narrowData );
       
   146     
       
   147     narrowDataLen = aSongItem.Composer().Length()*2;
       
   148     narrowData.Set((TUint8*)aSongItem.Composer().Ptr(), narrowDataLen);
       
   149     aHasher.Update( narrowData );
       
   150     
       
   151     narrowDataLen = aSongItem.MimeType().Length()*2;
       
   152     narrowData.Set((TUint8*)aSongItem.MimeType().Ptr(), narrowDataLen);
       
   153     aHasher.Update( narrowData );
       
   154     
       
   155     const TInt KNumberMaxLength(11);
       
   156     TBuf8<KNumberMaxLength> temp;
       
   157     temp.Num( aSongItem.Year() );
       
   158     aHasher.Update( temp );
       
   159     
       
   160     temp.Num( aSongItem.AlbumTrack() );
       
   161     aHasher.Update( temp );
       
   162     
       
   163     temp.Num( aSongItem.Rating() );
       
   164     aHasher.Update( temp );   
       
   165     
       
   166     temp.Num( aSongItem.Duration() );
       
   167     aHasher.Update( temp );
       
   168     
       
   169     iHash.Copy( aHasher.Final() );
       
   170     
       
   171     }
       
   172 
       
   173 void TSnapshotItem::SetItemHash( const CPlaylistItem& aPlaylist, CMD5& aHasher )
       
   174     {
       
   175     TPtrC8 narrowData;
       
   176     TInt narrowDataLen = 0;
       
   177     
       
   178     aHasher.Reset();
       
   179     narrowDataLen = aPlaylist.Title().Length()*2;
       
   180     narrowData.Set((TUint8*)aPlaylist.Title().Ptr(), narrowDataLen);
       
   181     aHasher.Update( narrowData );
       
   182     
       
   183     narrowDataLen = aPlaylist.Url().Length()*2;
       
   184     narrowData.Set((TUint8*)aPlaylist.Url().Ptr(), narrowDataLen);
       
   185     aHasher.Update( narrowData );
       
   186     
       
   187     for (TInt i=0; i<aPlaylist.ItemCount(); i++ )
       
   188         {
       
   189         TPtrC16 song = aPlaylist.ItemAt(i);
       
   190         narrowDataLen = song.Length()*2;
       
   191         narrowData.Set((TUint8*)song.Ptr(), narrowDataLen);
       
   192         aHasher.Update( narrowData );
       
   193         }
       
   194     iHash.Copy( aHasher.Final() );
       
   195     }
       
   196 
       
   197 const TDesC8& TSnapshotItem::Hash() const
       
   198     {
       
   199     return iHash;
       
   200     }