ncdengine/provider/server/src/ncdfileinfo.cpp
changeset 4 32704c33136d
equal deleted inserted replaced
-1:000000000000 4:32704c33136d
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   CNcdFileInfo implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdfileinfo.h"
       
    20 #include "catalogsdebug.h"
       
    21 #include "catalogsutils.h"
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // 
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 CNcdFileInfo* CNcdFileInfo::NewLC( 
       
    28     const TDesC& aFilePath,
       
    29     const TDesC& aMimeType, 
       
    30     TNcdItemPurpose aPurpose )
       
    31     {
       
    32     CNcdFileInfo* self = new(ELeave) CNcdFileInfo( aPurpose );
       
    33     CleanupStack::PushL( self );  
       
    34     self->ConstructL( aFilePath, aMimeType );
       
    35     return self;
       
    36     }
       
    37     
       
    38     
       
    39 // ---------------------------------------------------------------------------
       
    40 // 
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CNcdFileInfo* CNcdFileInfo::NewLC( RReadStream& aStream )
       
    44     {
       
    45     CNcdFileInfo* self = new(ELeave) CNcdFileInfo( 
       
    46         ENcdItemPurposeUnknown );
       
    47     CleanupStack::PushL( self );  
       
    48     self->InternalizeL( aStream );
       
    49     return self;
       
    50     }
       
    51     
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // 
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CNcdFileInfo::~CNcdFileInfo()
       
    58     {
       
    59     DLTRACEIN((""));
       
    60     delete iFilePath;
       
    61     delete iMimeType;
       
    62     delete iData;
       
    63     DLTRACEOUT((""));
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // 
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 const TDesC& CNcdFileInfo::FilePath() const
       
    71     {
       
    72     return *iFilePath;
       
    73     }
       
    74     
       
    75     
       
    76 // ---------------------------------------------------------------------------
       
    77 // 
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 const TDesC& CNcdFileInfo::MimeType() const
       
    81     {
       
    82     return *iMimeType;
       
    83     }
       
    84     
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // 
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void CNcdFileInfo::SetMimeTypeL( const TDesC& aMime )
       
    91     {
       
    92     delete iMimeType;
       
    93     iMimeType = NULL;
       
    94     iMimeType = aMime.AllocL();
       
    95     }
       
    96     
       
    97 // ---------------------------------------------------------------------------
       
    98 // 
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 TNcdItemPurpose CNcdFileInfo::Purpose() const
       
   102     {
       
   103     return iPurpose;
       
   104     }
       
   105 
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // 
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CNcdFileInfo::SetDataL( HBufC8* aData )
       
   112     {
       
   113     delete iData;
       
   114     iData = aData;
       
   115     if ( !iData ) 
       
   116         {
       
   117         iData = KNullDesC8().AllocL();
       
   118         }
       
   119     }
       
   120 
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // 
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 const TDesC8& CNcdFileInfo::Data() const
       
   127     {    
       
   128     return *iData;
       
   129     }
       
   130         
       
   131     
       
   132 // ---------------------------------------------------------------------------
       
   133 // 
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CNcdFileInfo::ExternalizeL( RWriteStream& aStream ) const
       
   137     {
       
   138     DLTRACEIN((""));
       
   139     
       
   140     DLINFO(( "Purpose: %d", iPurpose ));
       
   141     DLINFO(( _L("Filepath: %S"), iFilePath ));
       
   142     DLINFO(( _L("Mimetype: %S"), iMimeType));
       
   143     aStream.WriteInt32L( iPurpose );
       
   144     ExternalizeDesL( *iFilePath, aStream );
       
   145     ExternalizeDesL( *iMimeType, aStream );
       
   146     ExternalizeDesL( *iData, aStream );
       
   147     DLTRACEOUT((""));
       
   148     }
       
   149 
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // 
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CNcdFileInfo::ExternalizeWithoutFilenamesL( 
       
   156     RWriteStream& aStream ) const
       
   157     {
       
   158     DLTRACEIN((""));
       
   159     aStream.WriteInt32L( iPurpose );
       
   160     ExternalizeDesL( KNullDesC, aStream );
       
   161     ExternalizeDesL( *iMimeType, aStream );
       
   162     ExternalizeDesL( KNullDesC8, aStream );
       
   163     DLTRACEOUT((""));
       
   164     }
       
   165 
       
   166 
       
   167 
       
   168     
       
   169 // ---------------------------------------------------------------------------
       
   170 // 
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void CNcdFileInfo::InternalizeL( RReadStream& aStream )
       
   174     {
       
   175     DLTRACEIN((""));
       
   176     iPurpose = static_cast<TNcdItemPurpose>( aStream.ReadInt32L() );
       
   177     InternalizeDesL( iFilePath, aStream );
       
   178     InternalizeDesL( iMimeType, aStream );
       
   179     InternalizeDesL( iData, aStream );
       
   180 
       
   181     DLINFO(( "Purpose: %d", iPurpose ));
       
   182     DLINFO(( _L("Filepath: %S"), iFilePath ));
       
   183     DLINFO(( _L("Mimetype: %S"), iMimeType));
       
   184 
       
   185     DLTRACEOUT((""));
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // 
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 CNcdFileInfo::CNcdFileInfo( TNcdItemPurpose aPurpose ) :
       
   193     iPurpose( aPurpose )
       
   194     {
       
   195     }
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // 
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 void CNcdFileInfo::ConstructL( const TDesC& aFilePath,
       
   203     const TDesC& aMimeType )
       
   204     {
       
   205     iFilePath = aFilePath.AllocL();
       
   206     iMimeType = aMimeType.AllocL();
       
   207     iData = KNullDesC8().AllocL();
       
   208     }