ncdengine/provider/server/src/ncdpreviewdownloadhandler.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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <f32file.h>
       
    20 
       
    21 #include "ncdnode.h"
       
    22 #include "catalogshttpoperation.h"
       
    23 #include "catalogshttpconfig.h"
       
    24 #include "catalogshttpsession.h"
       
    25 #include "catalogsdebug.h"
       
    26 #include "ncdpreviewdownloadhandler.h"
       
    27 #include "ncdnodepreviewimpl.h"
       
    28 #include "ncdnodemetadataimpl.h"
       
    29 #include "ncdfilehandler.h"
       
    30 #include "ncdpanics.h"
       
    31 #include "ncdproviderutils.h"
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // NewL
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CNcdPreviewDownloadHandler* CNcdPreviewDownloadHandler::NewL( 
       
    40     const CNcdNodeIdentifier& aNodeId,
       
    41     CNcdNodeManager& aNodeManager,
       
    42     MCatalogsHttpSession& aHttpSession )
       
    43     {
       
    44     CNcdPreviewDownloadHandler* self = new( ELeave ) 
       
    45         CNcdPreviewDownloadHandler( aNodeManager, aHttpSession );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL( aNodeId );
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51     
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Destructor
       
    55 // ---------------------------------------------------------------------------
       
    56 //    
       
    57 CNcdPreviewDownloadHandler::~CNcdPreviewDownloadHandler()
       
    58     {
       
    59     }
       
    60 
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // DownloadL
       
    65 // ---------------------------------------------------------------------------
       
    66 //    
       
    67 MCatalogsHttpOperation* CNcdPreviewDownloadHandler::DownloadL()
       
    68     {
       
    69     DLTRACEIN(( "" ));
       
    70     
       
    71     CNcdNode& node( NodeL() );
       
    72     CNcdNodeMetaData& metadata( node.NodeMetaDataL() );
       
    73     CNcdNodePreview& preview( metadata.PreviewL() );
       
    74 
       
    75     NCD_ASSERT_ALWAYS( CurrentDownload() < preview.UriCount(),
       
    76         ENcdPanicIndexOutOfRange ); 
       
    77                 
       
    78 
       
    79     DLTRACE(( _L("Create preview download, URI: %S"),
       
    80         &preview.Uri( CurrentDownload() ) ));        
       
    81         
       
    82     MCatalogsHttpOperation* dl = HttpSession().CreateDownloadL( 
       
    83         preview.Uri( CurrentDownload() ),
       
    84         EFalse );
       
    85     CleanupReleasePushL( *dl );
       
    86 
       
    87     HBufC* tempPath = CNcdProviderUtils::TempPathLC( 
       
    88         NodeId().ClientUid().Name() );
       
    89     
       
    90     // Use provider's temp path    
       
    91     dl->Config().SetDirectoryL( 
       
    92         *tempPath );
       
    93     CleanupStack::PopAndDestroy( tempPath );
       
    94 
       
    95     dl->SetHeaderMode( ECatalogsHttpHeaderModeForceHead );
       
    96     
       
    97     SetCurrentDownload( CurrentDownload() + 1 );
       
    98     CleanupStack::Pop( dl );
       
    99     DLTRACEOUT( ( "" ) );
       
   100     return dl;
       
   101     }
       
   102     
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // FinishDownloadL
       
   106 // ---------------------------------------------------------------------------
       
   107 //    
       
   108 void CNcdPreviewDownloadHandler::FinishDownloadL( 
       
   109     MCatalogsHttpOperation& aDownload, 
       
   110     MNcdFileHandler* /* aFileHandler */)
       
   111     {
       
   112     DLTRACEIN( ( "" ) );
       
   113     HBufC* filename = aDownload.Config().FullPathLC();
       
   114     
       
   115     DLTRACE(("Call preview handler"));
       
   116     
       
   117     // CurrentDownload-1 since it was increased after the download was
       
   118     // created
       
   119     DASSERT( CurrentDownload() - 1 >= 0 );
       
   120     HBufC* mime = Des8ToDes16LC( aDownload.ContentType() );
       
   121     //        
       
   122     NodeManager().PreviewHandlerL( 
       
   123         NodeId(), 
       
   124         *filename, 
       
   125         CurrentDownload() - 1,
       
   126         *mime );
       
   127         
       
   128     CleanupStack::PopAndDestroy( 2, filename );  // mime, filename
       
   129     DLTRACEOUT( ( "" ) );
       
   130     }
       
   131 
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // Constructor
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 CNcdPreviewDownloadHandler::CNcdPreviewDownloadHandler( 
       
   138     CNcdNodeManager& aNodeManager,
       
   139     MCatalogsHttpSession& aHttpSession ) :
       
   140     CNcdBaseDownloadHandler( aNodeManager, aHttpSession )
       
   141     {
       
   142     }