codhandler/codeng/src/FileSaver.cpp
branchRCL_3
changeset 93 79859ed3eea9
parent 62 c711bdda59f4
child 94 919f36ff910f
equal deleted inserted replaced
92:e1bea15f9a39 93:79859ed3eea9
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: 
    14 * Description:
    15 *      Implementation of class CFileSaver.   
    15 *      Implementation of class CFileSaver.
    16 *      
    16 *
    17 *
    17 *
    18 */
    18 */
    19 
    19 
       
    20 
    20 // INCLUDE FILES
    21 // INCLUDE FILES
    21 #include <browser_platform_variant.hrh>
    22 //#include <platform/mw/Browser_platform_variant.hrh>
       
    23 #include <Browser_platform_variant.hrh>
    22 #include "FileSaver.h"
    24 #include "FileSaver.h"
    23 #include "CodBuffStorage.h"
    25 #include "CodBuffStorage.h"
    24 #include "CodLoadObserver.h"
    26 #include "CodLoadObserver.h"
    25 #include "RFeatMgr.h"
    27 #include "RFeatMgr.h"
    26 #include "CodUtil.h"
    28 #include "CodUtil.h"
    29 #include "CodPanic.h"
    31 #include "CodPanic.h"
    30 #include "DrmHandler.h"
    32 #include "DrmHandler.h"
    31 #include "CodData.h"
    33 #include "CodData.h"
    32 
    34 
    33 #include <f32file.h>
    35 #include <f32file.h>
    34 #include <httpdownloadmgrcommon.h>
    36 #include <HttpDownloadMgrCommon.h>
    35 #include <DocumentHandler.h>
    37 #include <DocumentHandler.h>
    36 #include <pathinfo.h>
    38 #include <pathinfo.h>
       
    39 
       
    40 // following one line is temporary: AVKON dependency removal
       
    41 #undef BRDO_APP_GALLERY_SUPPORTED_FF
    37 
    42 
    38 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
    43 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
    39 #include <MGXFileManagerFactory.h>
    44 #include <MGXFileManagerFactory.h>
    40 #include <CMGXFileManager.h>
    45 #include <CMGXFileManager.h>
    41 #endif
    46 #endif
    42 
    47 
    43 #include <DcfEntry.h>
    48 #include <DcfEntry.h>
    44 #include <DcfRep.h>
    49 #include <DcfRep.h>
    45 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
    46 #include <DownloadPathHandler.h>
       
    47 #endif
       
    48 
    50 
    49 const TInt KDefaultStorageBufferSize = 128 * 1024;
    51 const TInt KDefaultStorageBufferSize = 128 * 1024;
    50 const TInt KDefaultStorageBufferSizePD = 16 * 1024;
    52 const TInt KDefaultStorageBufferSizePD = 16 * 1024;
       
    53 
    51 
    54 
    52 // ================= MEMBER FUNCTIONS =======================
    55 // ================= MEMBER FUNCTIONS =======================
    53 
    56 
    54 // ---------------------------------------------------------
    57 // ---------------------------------------------------------
    55 // CFileSaver::NewL()
    58 // CFileSaver::NewL()
    79 void CFileSaver::ConstructL()
    82 void CFileSaver::ConstructL()
    80     {
    83     {
    81     CCodSaver::ConstructL();
    84     CCodSaver::ConstructL();
    82     iBufferSize =  KDefaultStorageBufferSize ;
    85     iBufferSize =  KDefaultStorageBufferSize ;
    83     iProgressiveDownload = EFalse ;
    86     iProgressiveDownload = EFalse ;
    84     
    87 
    85     iStorage = CCodBuffStorage::NewL(this);
    88     iStorage = CCodBuffStorage::NewL(this);
    86     }
    89     }
    87 
    90 
    88 // ---------------------------------------------------------
    91 // ---------------------------------------------------------
    89 // CFileSaver::CFileSaver()
    92 // CFileSaver::CFileSaver()
   105   iRootPath( aRootPath ),
   108   iRootPath( aRootPath ),
   106   iFname( aFname)
   109   iFname( aFname)
   107     {
   110     {
   108     CLOG(( ECodEng, 2, _L("*** CFileSaver::CFileSaver") ));
   111     CLOG(( ECodEng, 2, _L("*** CFileSaver::CFileSaver") ));
   109     }
   112     }
   110   
   113 
   111 // ---------------------------------------------------------
   114 // ---------------------------------------------------------
   112 // CFileSaver::~CFileSaver()
   115 // CFileSaver::~CFileSaver()
   113 // ---------------------------------------------------------
   116 // ---------------------------------------------------------
   114 //
   117 //
   115 CFileSaver::~CFileSaver()
   118 CFileSaver::~CFileSaver()
   126 //
   129 //
   127 void CFileSaver::OpenStoreL()
   130 void CFileSaver::OpenStoreL()
   128     {
   131     {
   129     CLOG(( ECodEng, 2, _L("CFileSaver::OpenStoreL") ));
   132     CLOG(( ECodEng, 2, _L("CFileSaver::OpenStoreL") ));
   130     __ASSERT_DEBUG( iState == EInit, CodPanic( ECodInternal ) );
   133     __ASSERT_DEBUG( iState == EInit, CodPanic( ECodInternal ) );
   131     
   134 
   132     // Store (temp file) is not opened now.
   135     // Store (temp file) is not opened now.
   133     // Opening is deferred until first data chunk arrives.
   136     // Opening is deferred until first data chunk arrives.
   134 
   137 
   135     TInt err = iFile.Open(  iFs, 
   138     TInt err = iFile.Open(  iFs,
   136                             iFname, 
   139                             iFname,
   137                             EFileShareAny | 
   140                             EFileShareAny |
   138                             EFileStream | 
   141                             EFileStream |
   139 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
   142 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
   140                             EFileWrite |
   143                             EFileWrite |
   141                             EFileWriteDirectIO );
   144                             EFileWriteDirectIO );
   142 #else                            
   145 #else
   143                             EFileWrite );
   146                             EFileWrite );
   144 #endif                            
   147 #endif
   145                        
   148 
   146 	if(err == KErrNotFound)                               
   149 	if(err == KErrNotFound)
   147 	    {
   150 	    {
   148         err = iFile.Replace( iFs, 
   151         err = iFile.Replace( iFs,
   149                            iFname, 
   152                            iFname,
   150                            EFileShareAny | 
   153                            EFileShareAny |
   151                            EFileStream | 
   154                            EFileStream |
   152 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
   155 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
   153                                        EFileWrite |
   156                                        EFileWrite |
   154                                        EFileWriteDirectIO );
   157                                        EFileWriteDirectIO );
   155 #else                           
   158 #else
   156                            EFileWrite );
   159                            EFileWrite );
   157 #endif                           
   160 #endif
   158 
   161 
   159 	    }
   162 	    }
   160 
   163 
   161     if( !err )
   164     if( !err )
   162         {
   165         {
   164         iFile.Seek( ESeekEnd, pos );
   167         iFile.Seek( ESeekEnd, pos );
   165         }
   168         }
   166     iSize = 0;
   169     iSize = 0;
   167     iState = EStoreOpen;
   170     iState = EStoreOpen;
   168     }
   171     }
   169     
   172 
   170 // ---------------------------------------------------------
   173 // ---------------------------------------------------------
   171 // CFileSaver::AppendData()
   174 // CFileSaver::AppendData()
   172 // ---------------------------------------------------------
   175 // ---------------------------------------------------------
   173 //
   176 //
   174 TInt CFileSaver::AppendData( const TDesC8& aData )
   177 TInt CFileSaver::AppendData( const TDesC8& aData )
   184 
   187 
   185         /*if( !iPausable )
   188         /*if( !iPausable )
   186             {
   189             {
   187             // nothing persisted yet. If there's a file with the same name,
   190             // nothing persisted yet. If there's a file with the same name,
   188             // delete it.
   191             // delete it.
   189             err = iFile.Replace( iFs, 
   192             err = iFile.Replace( iFs,
   190                                    iFname, 
   193                                    iFname,
   191                                    EFileShareAny | 
   194                                    EFileShareAny |
   192                                    EFileStream | 
   195                                    EFileStream |
   193                                    EFileWrite );
   196                                    EFileWrite );
   194             }
   197             }
   195         else*/
   198         else*/
   196 
   199 
   197         }
   200         }
   198     if ( !err )
   201     if ( !err )
   199         {
   202         {
   200         err = iStorage->WriteOutNextBodyDataL(aData );
   203         err = iStorage->WriteOutNextBodyDataL(aData );
   201         }
   204         }
   202     
   205 
   203     CLOG(( EHttpLoad, 2, _L("<- CFileSaver::AppendData returns (%d)"), err ));
   206     CLOG(( EHttpLoad, 2, _L("<- CFileSaver::AppendData returns (%d)"), err ));
   204     return err;
   207     return err;
   205     }
   208     }
   206 
   209 
   207 // ---------------------------------------------------------
   210 // ---------------------------------------------------------
   245     // The transport size may also be different, if compression or some
   248     // The transport size may also be different, if compression or some
   246     // packaging format is used."
   249     // packaging format is used."
   247     //
   250     //
   248     // There is a safety upper bound on the transaction size, that is already
   251     // There is a safety upper bound on the transaction size, that is already
   249     // applied. See SetMaxSize().
   252     // applied. See SetMaxSize().
   250     
   253 
   251     TDataType drm( KOma1DrmMessageContentType );
   254     TDataType drm( KOma1DrmMessageContentType );
   252     TDataType dcf( KOma1DcfContentType );
   255     TDataType dcf( KOma1DcfContentType );
   253 
   256 
   254     if ( iType == drm )
   257     if ( iType == drm )
   255         {
   258         {
   282             }
   285             }
   283         }
   286         }
   284     else
   287     else
   285         {
   288         {
   286         // Other than DRM stuff arrived. Proper check for MIME type.
   289         // Other than DRM stuff arrived. Proper check for MIME type.
   287         if( !(*aData[aData.ActiveDownload()]).HasType( iType.Des8() ) && ! iDocHandler.CanSaveL(iType) )
   290         if( !(*aData[aData.ActiveDownload()]).HasType( iType.Des8() ) )
   288             {
   291             {
   289             CLOG(( ECodEng, 4, _L("  mismatch") ));
   292             CLOG(( ECodEng, 4, _L("  mismatch") ));
   290             User::Leave( KErrCodAttributeMismatch );
   293             User::Leave( KErrCodAttributeMismatch );
   291             }
   294             }
   292         }
   295         }
   309 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   312 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   310    In this case leave and go to the next state.
   313    In this case leave and go to the next state.
   311 */
   314 */
   312     if (!aAttached)
   315     if (!aAttached)
   313 	    {
   316 	    {
   314 #if 0 
   317 #if 0
   315         RFs fs;
   318         RFs fs;
   316         TInt err( KErrNone );
   319         TInt err( KErrNone );
   317         HBufC* filename = HBufC::NewLC(KMaxFileName);
   320         HBufC* filename = HBufC::NewLC(KMaxFileName);
   318         TPtr filenamePtr = filename->Des();
   321         TPtr filenamePtr = filename->Des();
   319         filenamePtr = iRootPath;
   322         filenamePtr = iRootPath;
   323         CFileMan* file=CFileMan::NewL(fs);
   326         CFileMan* file=CFileMan::NewL(fs);
   324         CleanupStack::PushL(file);
   327         CleanupStack::PushL(file);
   325         TInt error = fs.MkDirAll(filenamePtr);
   328         TInt error = fs.MkDirAll(filenamePtr);
   326         if (error!=KErrNone && error!=KErrAlreadyExists)
   329         if (error!=KErrNone && error!=KErrAlreadyExists)
   327            {
   330            {
   328             User::Leave(error);   
   331             User::Leave(error);
   329            }
   332            }
   330    
   333 
   331         // Find a unique name to avoid any conflict.
   334         // Find a unique name to avoid any conflict.
   332         // Here iFname has full path of current location of file
   335         // Here iFname has full path of current location of file
   333         // and filename has destination path.
   336         // and filename has destination path.
   334         FindUniqueDestinationFileNameL( iFname, filename );
   337         FindUniqueDestinationFileNameL( iFname, filename );
   335         
   338 
   336         filenamePtr = filename->Des();     
   339         filenamePtr = filename->Des();
   337                
   340 
   338         err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   341         err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   339     
   342 
   340         if(err != KErrNone)
   343         if(err != KErrNone)
   341            {
   344            {
   342            User::Leave(err);
   345            User::Leave(err);
   343            }
   346            }
   344        
   347 
   345         iFname = filenamePtr;              
   348         iFname = filenamePtr;
   346         NotifyMediaGalleryL( filenamePtr );        
   349         NotifyMediaGalleryL( filenamePtr );
   347         CleanupStack::PopAndDestroy(file);
   350         CleanupStack::PopAndDestroy(file);
   348         CleanupStack::PopAndDestroy(&fs);
   351         CleanupStack::PopAndDestroy(&fs);
   349         CleanupStack::PopAndDestroy(filename);
   352         CleanupStack::PopAndDestroy(filename);
   350 #else
   353 #else
   351         RFs fs;
   354         RFs fs;
   352         User::LeaveIfError( fs.Connect() );
   355         User::LeaveIfError( fs.Connect() );
   353         CleanupClosePushL(fs);
   356         CleanupClosePushL(fs);
   354         CFileMan* file=CFileMan::NewL(fs);
   357         CFileMan* file=CFileMan::NewL(fs);
   355         CleanupStack::PushL(file);
   358         CleanupStack::PushL(file);
   356 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
   359 
   357         CDownloadPathHandler* downloadPathPlugin = NULL;
   360 
   358 
       
   359         if ( aData.Count() )
       
   360             {
       
   361             // Get the mime type of the first media object
       
   362             TPtrC8 mimeType = (*aData[1]).Type();
       
   363             downloadPathPlugin = GetDownloadPathPluginInstanceL( mimeType );
       
   364 
       
   365             if( downloadPathPlugin )
       
   366                 {
       
   367                 CleanupStack::PushL( downloadPathPlugin );
       
   368                 }
       
   369             }
       
   370 #endif
       
   371         for( TInt i = 1; i <= aData.Count() ; ++i )
   361         for( TInt i = 1; i <= aData.Count() ; ++i )
   372             {
   362             {
   373             HBufC* filename = HBufC::NewLC(KMaxFileName);
   363             HBufC* filename = HBufC::NewLC(KMaxFileName);
   374             TPtr filenamePtr = filename->Des();
   364             TPtr filenamePtr = filename->Des();
   375             filenamePtr = (*aData[i]).iRootPath;
   365             filenamePtr = (*aData[i]).iRootPath;
   376             
   366 
   377 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
   367             filenamePtr.Append(_L("download\\"));
   378             if( downloadPathPlugin )
       
   379                 {
       
   380                 TFileName iTempFlName = (*aData[i]).iFullName->Des();
       
   381                 GetUpdatedPathFromPluginL( downloadPathPlugin,iTempFlName, filenamePtr );
       
   382                 }
       
   383             else
       
   384                 {
       
   385                 filenamePtr.Append( _L( "download\\" ) );
       
   386                 }
       
   387 #else
       
   388             filenamePtr.Append( _L( "download\\" ) );
       
   389                 
       
   390 #endif
       
   391             
       
   392             TInt error = fs.MkDirAll(filenamePtr);
   368             TInt error = fs.MkDirAll(filenamePtr);
   393             if (error!=KErrNone && error!=KErrAlreadyExists)
   369             if (error!=KErrNone && error!=KErrAlreadyExists)
   394                {
   370                {
   395                 User::Leave(error);   
   371                 User::Leave(error);
   396                }
   372                }
   397             iFname = (*aData[i]).iFullName->Des();
   373             iFname = (*aData[i]).iFullName->Des();
   398             
   374 
   399             // Find a unique name to avoid any conflict.
   375             // Find a unique name to avoid any conflict.
   400             // Here iFname has full path of current location of file
   376             // Here iFname has full path of current location of file
   401             // and filename has destination path.
   377             // and filename has destination path.
   402             FindUniqueDestinationFileNameL( iFname, filename );
   378             FindUniqueDestinationFileNameL( iFname, filename );
   403             
   379 
   404             filenamePtr = filename->Des();
   380             filenamePtr = filename->Des();
   405             TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   381             TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   406             if(err != KErrNone)
   382             if(err != KErrNone)
   407             	{
   383             	{
   408             	User::LeaveIfError(err);
   384             	User::LeaveIfError(err);
   409             	}
   385             	}
   410             iFname = filenamePtr;              
   386             iFname = filenamePtr;
   411             NotifyMediaGalleryL( filenamePtr );
   387             NotifyMediaGalleryL( filenamePtr );
   412 
   388 
   413             (*aData[i]).iFileName = iFname;
   389             (*aData[i]).iFileName = iFname;
   414             (*aData[i]).iFullName = NameL();
   390             (*aData[i]).iFullName = NameL();
   415             CleanupStack::PopAndDestroy(filename);
   391             CleanupStack::PopAndDestroy(filename);
   416             }
   392             }
   417 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
   418         if( downloadPathPlugin )
       
   419             {
       
   420             CleanupStack::PopAndDestroy( downloadPathPlugin );
       
   421             }
       
   422 #endif
       
   423         CleanupStack::PopAndDestroy(file);
   393         CleanupStack::PopAndDestroy(file);
   424         CleanupStack::PopAndDestroy(&fs);
   394         CleanupStack::PopAndDestroy(&fs);
   425 
   395 
   426 #endif // RD_MULTIPLE_DRIVE
   396 #endif // RD_MULTIPLE_DRIVE
   427     // TODO set iType to that of the packaged object (??)
   397     // TODO set iType to that of the packaged object (??)
   453 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   423 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   454    In this case leave and go to the next state.
   424    In this case leave and go to the next state.
   455 */
   425 */
   456     if (!aAttached)
   426     if (!aAttached)
   457 	    {
   427 	    {
   458 #ifdef RD_MULTIPLE_DRIVE 
   428 #ifdef RD_MULTIPLE_DRIVE
   459         RFs fs;
   429         RFs fs;
   460         TInt err( KErrNone );
   430         TInt err( KErrNone );
   461         HBufC* filename = HBufC::NewLC(KMaxFileName);
   431         HBufC* filename = HBufC::NewLC(KMaxFileName);
   462         TPtr filenamePtr = filename->Des();
   432         TPtr filenamePtr = filename->Des();
   463         filenamePtr = iRootPath;
   433         filenamePtr = iRootPath;
   464 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
   434         filenamePtr.Append(_L("download\\"));
   465         // Get the mime type of the content
       
   466         TPtrC8 mimeType( iType.Des8() );
       
   467         CDownloadPathHandler* downloadPathPlugin = NULL;
       
   468         downloadPathPlugin = GetDownloadPathPluginInstanceL( mimeType );
       
   469 
       
   470         if( downloadPathPlugin )
       
   471             {
       
   472             CleanupStack::PushL( downloadPathPlugin );
       
   473             GetUpdatedPathFromPluginL( downloadPathPlugin,iFname, filenamePtr );
       
   474             CleanupStack::PopAndDestroy( downloadPathPlugin );
       
   475             }
       
   476         else
       
   477             {
       
   478             filenamePtr.Append( _L( "download\\" ) );
       
   479             }
       
   480 #else
       
   481             filenamePtr.Append( _L( "download\\" ) );
       
   482             
       
   483 #endif
       
   484         User::LeaveIfError( fs.Connect() );
   435         User::LeaveIfError( fs.Connect() );
   485         CleanupClosePushL(fs);
   436         CleanupClosePushL(fs);
   486         CFileMan* file=CFileMan::NewL(fs);
   437         CFileMan* file=CFileMan::NewL(fs);
   487         CleanupStack::PushL(file);
   438         CleanupStack::PushL(file);
   488         TInt error = fs.MkDirAll(filenamePtr);
   439         TInt error = fs.MkDirAll(filenamePtr);
   489         if (error!=KErrNone && error!=KErrAlreadyExists)
   440         if (error!=KErrNone && error!=KErrAlreadyExists)
   490            {
   441            {
   491             User::Leave(error);   
   442             User::Leave(error);
   492            }
   443            }
   493    
   444 
   494         // Find a unique name to avoid any conflict.
   445         // Find a unique name to avoid any conflict.
   495         // Here iFname has full path of current location of file
   446         // Here iFname has full path of current location of file
   496         // and filename has destination path.
   447         // and filename has destination path.
   497         FindUniqueDestinationFileNameL( iFname, filename );
   448         FindUniqueDestinationFileNameL( iFname, filename );
   498         
   449 
   499         filenamePtr = filename->Des();     
   450         filenamePtr = filename->Des();
   500                
   451 
   501         err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   452         err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   502     
   453 
   503         if(err != KErrNone)
   454         if(err != KErrNone)
   504            {
   455            {
   505            User::Leave(err);
   456            User::Leave(err);
   506            }
   457            }
   507        
   458 
   508         iFname = filenamePtr;              
   459         iFname = filenamePtr;
   509         NotifyMediaGalleryL( filenamePtr );        
   460         NotifyMediaGalleryL( filenamePtr );
   510         CleanupStack::PopAndDestroy(file);
   461         CleanupStack::PopAndDestroy(file);
   511         CleanupStack::PopAndDestroy(&fs);
   462         CleanupStack::PopAndDestroy(&fs);
   512         CleanupStack::PopAndDestroy(filename);
   463         CleanupStack::PopAndDestroy(filename);
   513 #else
   464 #else
   514             RFs fs;
   465             RFs fs;
   522             CFileMan* file=CFileMan::NewL(fs);
   473             CFileMan* file=CFileMan::NewL(fs);
   523             CleanupStack::PushL(file);
   474             CleanupStack::PushL(file);
   524             TInt error = fs.MkDirAll(filenamePtr);
   475             TInt error = fs.MkDirAll(filenamePtr);
   525             if (error!=KErrNone && error!=KErrAlreadyExists)
   476             if (error!=KErrNone && error!=KErrAlreadyExists)
   526                {
   477                {
   527                 User::Leave(error);   
   478                 User::Leave(error);
   528                }
   479                }
   529 
   480 
   530             // Find a unique name to avoid any conflict.
   481             // Find a unique name to avoid any conflict.
   531             // Here iFname has full path of current location of file
   482             // Here iFname has full path of current location of file
   532             // and filename has destination path.
   483             // and filename has destination path.
   533             FindUniqueDestinationFileNameL( iFname, filename );
   484             FindUniqueDestinationFileNameL( iFname, filename );
   534             
   485 
   535             filenamePtr = filename->Des();
   486             filenamePtr = filename->Des();
   536             TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   487             TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   537         
   488 
   538             if(err != KErrNone)
   489             if(err != KErrNone)
   539                {
   490                {
   540                User::Leave(err);
   491                User::Leave(err);
   541                 }
   492                 }
   542             iFname = filenamePtr;              
   493             iFname = filenamePtr;
   543             NotifyMediaGalleryL( filenamePtr );
   494             NotifyMediaGalleryL( filenamePtr );
   544             CleanupStack::PopAndDestroy(file);
   495             CleanupStack::PopAndDestroy(file);
   545             CleanupStack::PopAndDestroy(&fs);
   496             CleanupStack::PopAndDestroy(&fs);
   546             CleanupStack::PopAndDestroy(filename);
   497             CleanupStack::PopAndDestroy(filename);
   547 #endif // RD_MULTIPLE_DRIVE
   498 #endif // RD_MULTIPLE_DRIVE
   607     CLOG(( ECodEng, 2, _L("-> CFileSaver::Cleanup") ));
   558     CLOG(( ECodEng, 2, _L("-> CFileSaver::Cleanup") ));
   608     // Clean up the temporary file, ignore errors.
   559     // Clean up the temporary file, ignore errors.
   609     // Expected error: KErrNotFound (if there is no temp file).
   560     // Expected error: KErrNotFound (if there is no temp file).
   610     // Unexpected error: all the rest -> nothing we can do with them.
   561     // Unexpected error: all the rest -> nothing we can do with them.
   611     CloseStore();
   562     CloseStore();
   612     
   563 
   613 	if( aDeleteFile )
   564 	if( aDeleteFile )
   614 	    {
   565 	    {
   615 #ifdef __TEST_COD_LOG
   566 #ifdef __TEST_COD_LOG
   616         TInt err =  // ('Log-only' variable.)
   567         TInt err =  // ('Log-only' variable.)
   617 #endif /* def __TEST_COD_LOG */
   568 #endif /* def __TEST_COD_LOG */
   631         }
   582         }
   632     iState = EInit;
   583     iState = EInit;
   633     CLOG(( ECodEng, 2, _L("<- CFileSaver::Cleanup") ));
   584     CLOG(( ECodEng, 2, _L("<- CFileSaver::Cleanup") ));
   634     }
   585     }
   635 
   586 
   636   
   587 
   637 // ---------------------------------------------------------
   588 // ---------------------------------------------------------
   638 // CFileSaver::UpdateDCFRepositoryL()
   589 // CFileSaver::UpdateDCFRepositoryL()
   639 // Update saved file to DCFRepository  
   590 // Update saved file to DCFRepository
   640 // ---------------------------------------------------------
   591 // ---------------------------------------------------------
   641 // 
   592 //
   642 void CFileSaver::UpdateDCFRepositoryL( const TDesC& aFileName )
   593 void CFileSaver::UpdateDCFRepositoryL( const TDesC& aFileName )
   643     {
   594     {
   644     CDcfEntry* dcfEntry = NULL;
   595     CDcfEntry* dcfEntry = NULL;
   645     dcfEntry = CDcfEntry::NewL();    
   596     dcfEntry = CDcfEntry::NewL();
   646     CleanupStack::PushL( dcfEntry );
   597     CleanupStack::PushL( dcfEntry );
   647     
   598 
   648     CDcfRep* dcfRep = NULL;
   599     CDcfRep* dcfRep = NULL;
   649     dcfRep = CDcfRep::NewL();
   600     dcfRep = CDcfRep::NewL();
   650     CleanupStack::PushL( dcfRep );
   601     CleanupStack::PushL( dcfRep );
   651 
   602 
   652     dcfEntry->SetLocationL( aFileName, 0 );    
   603     dcfEntry->SetLocationL( aFileName, 0 );
   653     dcfRep->UpdateL( dcfEntry );
   604     dcfRep->UpdateL( dcfEntry );
   654     CleanupStack::PopAndDestroy(2); // dcfEntry, dcfRep
   605     CleanupStack::PopAndDestroy(2); // dcfEntry, dcfRep
   655     }   
   606     }
   656     
   607 
   657 // ---------------------------------------------------------
   608 // ---------------------------------------------------------
   658 // CFileSaver::UpdateMediaGalleryIfNeededL()
   609 // CFileSaver::UpdateMediaGalleryIfNeededL()
   659 // Calls MediaGallery Update method so that media gallery
   610 // Calls MediaGallery Update method so that media gallery
   660 // knows update its view.
   611 // knows update its view.
   661 // ---------------------------------------------------------
   612 // ---------------------------------------------------------
   662 // 
   613 //
   663 
   614 
   664 
   615 
   665 void CFileSaver::UpdateMediaGalleryIfNeededL( const TDesC& aFileName )
   616 void CFileSaver::UpdateMediaGalleryIfNeededL( const TDesC& aFileName )
   666     {
   617     {
   667 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF           
   618 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
   668     CMGXFileManager* fm = MGXFileManagerFactory::NewFileManagerL( iFs );
   619     CMGXFileManager* fm = MGXFileManagerFactory::NewFileManagerL( iFs );
   669     CleanupStack::PushL(fm);
   620     CleanupStack::PushL(fm);
   670     fm->UpdateL(aFileName);
   621     fm->UpdateL(aFileName);
   671     CleanupStack::PopAndDestroy(); // fm
   622     CleanupStack::PopAndDestroy(); // fm
   672 #endif    
   623 #endif
   673     }
   624     }
   674 // ---------------------------------------------------------
   625 // ---------------------------------------------------------
   675 // CFileSaver::NotifyMediaGalleryL()
   626 // CFileSaver::NotifyMediaGalleryL()
   676 // Notify media gallery about the new file.
   627 // Notify media gallery about the new file.
   677 // ---------------------------------------------------------
   628 // ---------------------------------------------------------
   678 // 
   629 //
   679 void CFileSaver::NotifyMediaGalleryL( const TDesC& aFileName )
   630 void CFileSaver::NotifyMediaGalleryL( const TDesC& aFileName )
   680     {
   631     {
   681 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF    
   632 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
   682     
   633 
   683     CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL( iFs );
   634     CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL( iFs );
   684     CleanupStack::PushL( mgFileManager );
   635     CleanupStack::PushL( mgFileManager );
   685 
   636 
   686     TRAP_IGNORE( mgFileManager->UpdateL() );
   637     TRAP_IGNORE( mgFileManager->UpdateL() );
   687     CleanupStack::PopAndDestroy( mgFileManager );
   638     CleanupStack::PopAndDestroy( mgFileManager );
   688 
   639 
   689     // Notify Media Gallery
   640     // Notify Media Gallery
   690     TRAP_IGNORE( UpdateMediaGalleryIfNeededL( aFileName ) );
   641     TRAP_IGNORE( UpdateMediaGalleryIfNeededL( aFileName ) );
   691 
   642 
   692 #endif
   643 #endif
   693     
   644 
   694     
   645 
   695     // Notify DCF repository
   646     // Notify DCF repository
   696     TRAP_IGNORE( UpdateDCFRepositoryL( aFileName ) );
   647     TRAP_IGNORE( UpdateDCFRepositoryL( aFileName ) );
   697     }
   648     }
   698 // ---------------------------------------------------------
   649 // ---------------------------------------------------------
   699 // CFileSaver::DownloadedFileSize()
   650 // CFileSaver::DownloadedFileSize()
   702 TInt CFileSaver::DownloadedFileSize()
   653 TInt CFileSaver::DownloadedFileSize()
   703     {
   654     {
   704     // check how many bytes are already persisted
   655     // check how many bytes are already persisted
   705     TInt DownloadedSize(0);
   656     TInt DownloadedSize(0);
   706     TInt err = iFile.Size( (TInt&)DownloadedSize );
   657     TInt err = iFile.Size( (TInt&)DownloadedSize );
   707     
   658 
   708     CLOG(( ECodStorage, 2, _L("CFileSaver::DownloadedFileSize  Downloaded size = %d  error = %d"), \
   659     CLOG(( ECodStorage, 2, _L("CFileSaver::DownloadedFileSize  Downloaded size = %d  error = %d"), \
   709                DownloadedSize,err ));
   660                DownloadedSize,err ));
   710 
   661 
   711     if(err != KErrNone)
   662     if(err != KErrNone)
   712         return err;
   663         return err;
   713     return DownloadedSize;
   664     return DownloadedSize;
   714     }
   665     }
   715     
   666 
   716     
   667 
   717 /**
   668 /**
   718 * Discard the old contents
   669 * Discard the old contents
   719 */        
   670 */
   720 void CFileSaver::ResetL()
   671 void CFileSaver::ResetL()
   721     {
   672     {
   722     
   673 
   723     
   674 
   724     iFile.Close();
   675     iFile.Close();
   725     
   676 
   726     User::LeaveIfError( iFile.Replace(  iFs, 
   677     User::LeaveIfError( iFile.Replace(  iFs,
   727                                         iFname, 
   678                                         iFname,
   728                                         EFileShareAny | 
   679                                         EFileShareAny |
   729                                         EFileStream | 
   680                                         EFileStream |
   730                                         EFileWrite ) );
   681                                         EFileWrite ) );
   731     }
   682     }
   732 
   683 
   733 
   684 
   734 // -----------------------------------------------------------------------------
   685 // -----------------------------------------------------------------------------
   740     iProgressiveDownload = aValue;
   691     iProgressiveDownload = aValue;
   741     if( iProgressiveDownload )
   692     if( iProgressiveDownload )
   742         {
   693         {
   743         iBufferSize = KDefaultStorageBufferSizePD;
   694         iBufferSize = KDefaultStorageBufferSizePD;
   744         }
   695         }
   745     
   696 
   746     
   697 
   747     if( iBufferSize != iStorage->CurrentBufferSize())
   698     if( iBufferSize != iStorage->CurrentBufferSize())
   748         {
   699         {
   749         FlushL();
   700         FlushL();
   750         }
   701         }
   751 
   702 
   752     if ( iFile.SubSessionHandle() )
   703     if ( iFile.SubSessionHandle() )
   753         {
   704         {
   754      	
   705 
   755         if( iProgressiveDownload )
   706         if( iProgressiveDownload )
   756             {
   707             {
   757             if( iLength != KDefaultContentLength )    
   708             if( iLength != KDefaultContentLength )
   758                 {
   709                 {
   759                 iFile.SetSize( iLength );
   710                 iFile.SetSize( iLength );
   760                 }
   711                 }
   761             }
   712             }
   762         else
   713         else
   788 // Called if download completed.
   739 // Called if download completed.
   789 // -----------------------------------------------------------------------------
   740 // -----------------------------------------------------------------------------
   790 //
   741 //
   791 void CFileSaver::OnComplete()
   742 void CFileSaver::OnComplete()
   792     {
   743     {
   793     CLOG(( ECodEng, 2, _L("-> CFileSaver::OnComplete") ));    
   744     CLOG(( ECodEng, 2, _L("-> CFileSaver::OnComplete") ));
   794     FlushL();
   745     FlushL();
   795     iStorage->ClearErrors();
   746     iStorage->ClearErrors();
   796     iFile.Close();
   747     iFile.Close();
   797     CLOG(( ECodEng, 2, _L("<- CFileSaver::OnComplete") ));     
   748     CLOG(( ECodEng, 2, _L("<- CFileSaver::OnComplete") ));
   798     }
   749     }
   799 
   750 
   800 
   751 
   801 
   752 
   802 
   753 
   805 // ---------------------------------------------------------
   756 // ---------------------------------------------------------
   806 HBufC* CFileSaver::NameL() const
   757 HBufC* CFileSaver::NameL() const
   807     {
   758     {
   808     return iFname.AllocL();
   759     return iFname.AllocL();
   809     }
   760     }
   810 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
   811 
       
   812 // ---------------------------------------------------------
       
   813 // CFileSaver::GetDownloadPathPluginInstanceL
       
   814 // ---------------------------------------------------------
       
   815 CDownloadPathHandler* CFileSaver::GetDownloadPathPluginInstanceL(TPtrC8& mimetype )
       
   816     {
       
   817     CDownloadPathHandler* downloadPathPlugin = NULL;
       
   818     TRAPD( kErr, downloadPathPlugin = CDownloadPathHandler::NewL( mimetype ) );
       
   819     if( kErr != KErrNone )
       
   820         {
       
   821         downloadPathPlugin = NULL;
       
   822         }
       
   823     return downloadPathPlugin;
       
   824     }
       
   825 
       
   826 // ---------------------------------------------------------
       
   827 // CFileSaver::GetUpdatedPathFromPluginL
       
   828 // ---------------------------------------------------------
       
   829 void CFileSaver::GetUpdatedPathFromPluginL(CDownloadPathHandler* downloadPathPlugin,TFileName& fname, TPtr& fileNamePtr)
       
   830     {
       
   831     TRAPD( kErr, downloadPathPlugin->GetUpdatedPathL( fname, fileNamePtr ) );
       
   832     if( kErr == KErrNone )
       
   833         {
       
   834         fileNamePtr.Append( _L( "\\" ) );
       
   835         }
       
   836     else
       
   837         {
       
   838         fileNamePtr.Append( _L( "download\\" ) );
       
   839         }
       
   840     }
       
   841 #endif
       
   842 
       
   843 //EOF