ncdengine/provider/server/src/ncdscreenshotdownloadhandler.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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 "ncdscreenshotdownloadhandler.h"
       
    27 #include "ncdnodescreenshotimpl.h"
       
    28 #include "ncd_pp_download.h"
       
    29 #include "ncdproviderutils.h"
       
    30 #include "catalogsconstants.h"
       
    31 #include "ncdnodemetadataimpl.h"
       
    32 #include "ncdnodeidentifier.h"
       
    33 #include "ncdpanics.h"
       
    34 #include "ncdfilehandler.h"
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // NewL
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CNcdScreenshotDownloadHandler* CNcdScreenshotDownloadHandler::NewL( 
       
    43     const CNcdNodeIdentifier& aNodeId,
       
    44     CNcdNodeManager& aNodeManager,
       
    45     MCatalogsHttpSession& aHttpSession )
       
    46     {
       
    47     CNcdScreenshotDownloadHandler* self = new( ELeave ) 
       
    48         CNcdScreenshotDownloadHandler( aNodeManager, aHttpSession );
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL( aNodeId );
       
    51     CleanupStack::Pop( self );
       
    52     
       
    53     return self;
       
    54     }
       
    55     
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Destructor
       
    59 // ---------------------------------------------------------------------------
       
    60 //    
       
    61 CNcdScreenshotDownloadHandler::~CNcdScreenshotDownloadHandler()
       
    62     {
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // DownloadL
       
    68 // ---------------------------------------------------------------------------
       
    69 //    
       
    70 MCatalogsHttpOperation* CNcdScreenshotDownloadHandler::DownloadL()
       
    71     {
       
    72     DLTRACEIN(( "" ));
       
    73     
       
    74     CNcdNode& node( NodeL() );
       
    75     CNcdNodeMetaData& metadata( node.NodeMetaDataL() );
       
    76     const CNcdNodeScreenshot& screenshot( metadata.ScreenshotL() );
       
    77 
       
    78     NCD_ASSERT_ALWAYS( CurrentDownload() < 
       
    79         screenshot.ScreenshotDownloadCount(), ENcdPanicNoData );
       
    80 
       
    81     // Update total download count
       
    82     SetTotalDownloads( screenshot.ScreenshotDownloadCount() );
       
    83 
       
    84     const TDesC& uri( 
       
    85         screenshot.ScreenshotDownloadUri( CurrentDownload() ) );   
       
    86     
       
    87     DLINFO(( _L("Screenshot URI: %S"), &uri ));
       
    88     MCatalogsHttpOperation* dl = HttpSession().CreateDownloadL( 
       
    89         uri,
       
    90         EFalse );
       
    91     CleanupReleasePushL( *dl );
       
    92 
       
    93     HBufC* tempPath = CNcdProviderUtils::TempPathLC( 
       
    94         NodeId().ClientUid().Name() );
       
    95     
       
    96     // Use provider's temp path    
       
    97     dl->Config().SetDirectoryL( 
       
    98         *tempPath );
       
    99     CleanupStack::PopAndDestroy( tempPath );
       
   100     
       
   101     SetCurrentDownload( CurrentDownload() + 1 );
       
   102     CleanupStack::Pop( dl );
       
   103     DLTRACEOUT(( "" ));
       
   104     return dl;
       
   105     }
       
   106     
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // FinishDownloadL
       
   110 // ---------------------------------------------------------------------------
       
   111 //    
       
   112 void CNcdScreenshotDownloadHandler::FinishDownloadL( 
       
   113     MCatalogsHttpOperation& aDownload, 
       
   114     MNcdFileHandler* aFileHandler)
       
   115     {
       
   116     DLTRACEIN(( "filehandler: %X", aFileHandler ));    
       
   117     
       
   118     HBufC* filename = aDownload.Config().FullPathLC();
       
   119 
       
   120     // Get node
       
   121     CNcdNode& node( NodeL() );
       
   122     
       
   123     // Get node metadata
       
   124     CNcdNodeMetaData& metadata = node.NodeMetaDataL();
       
   125     
       
   126     const CNcdNodeScreenshot& screenshot( metadata.ScreenshotL() );
       
   127     const TDesC& uri( 
       
   128         screenshot.ScreenshotDownloadUri( CurrentDownload() - 1 ) );   
       
   129 
       
   130             
       
   131     DLTRACE(( _L("Moving the file from %S"), filename ));
       
   132 
       
   133     // Moves the file to target location. 
       
   134     // Using metadata's namespace
       
   135     aFileHandler->
       
   136         MoveFileL( *filename, 
       
   137                    metadata.Identifier().NodeNameSpace(),
       
   138                    uri );
       
   139     CleanupStack::PopAndDestroy( filename );
       
   140     
       
   141     DLTRACEOUT( ( "" ) );
       
   142     }
       
   143 
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // Constructor
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 CNcdScreenshotDownloadHandler::CNcdScreenshotDownloadHandler( 
       
   150     CNcdNodeManager& aNodeManager,
       
   151     MCatalogsHttpSession& aHttpSession ) :
       
   152     CNcdBaseDownloadHandler( aNodeManager, aHttpSession )
       
   153     {
       
   154     }