--- a/codhandler/codeng/src/FileSaver.cpp Thu Aug 19 10:58:56 2010 +0300
+++ b/codhandler/codeng/src/FileSaver.cpp Tue Aug 31 16:17:46 2010 +0300
@@ -11,14 +11,16 @@
*
* Contributors:
*
-* Description:
-* Implementation of class CFileSaver.
-*
+* Description:
+* Implementation of class CFileSaver.
+*
*
*/
+
// INCLUDE FILES
-#include <browser_platform_variant.hrh>
+//#include <platform/mw/Browser_platform_variant.hrh>
+#include <Browser_platform_variant.hrh>
#include "FileSaver.h"
#include "CodBuffStorage.h"
#include "CodLoadObserver.h"
@@ -31,10 +33,13 @@
#include "CodData.h"
#include <f32file.h>
-#include <httpdownloadmgrcommon.h>
+#include <HttpDownloadMgrCommon.h>
#include <DocumentHandler.h>
#include <pathinfo.h>
+// following one line is temporary: AVKON dependency removal
+#undef BRDO_APP_GALLERY_SUPPORTED_FF
+
#ifdef BRDO_APP_GALLERY_SUPPORTED_FF
#include <MGXFileManagerFactory.h>
#include <CMGXFileManager.h>
@@ -42,13 +47,11 @@
#include <DcfEntry.h>
#include <DcfRep.h>
-#ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
-#include <DownloadPathHandler.h>
-#endif
const TInt KDefaultStorageBufferSize = 128 * 1024;
const TInt KDefaultStorageBufferSizePD = 16 * 1024;
+
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
@@ -81,7 +84,7 @@
CCodSaver::ConstructL();
iBufferSize = KDefaultStorageBufferSize ;
iProgressiveDownload = EFalse ;
-
+
iStorage = CCodBuffStorage::NewL(this);
}
@@ -107,7 +110,7 @@
{
CLOG(( ECodEng, 2, _L("*** CFileSaver::CFileSaver") ));
}
-
+
// ---------------------------------------------------------
// CFileSaver::~CFileSaver()
// ---------------------------------------------------------
@@ -128,33 +131,33 @@
{
CLOG(( ECodEng, 2, _L("CFileSaver::OpenStoreL") ));
__ASSERT_DEBUG( iState == EInit, CodPanic( ECodInternal ) );
-
+
// Store (temp file) is not opened now.
// Opening is deferred until first data chunk arrives.
- TInt err = iFile.Open( iFs,
- iFname,
- EFileShareAny |
- EFileStream |
+ TInt err = iFile.Open( iFs,
+ iFname,
+ EFileShareAny |
+ EFileStream |
#ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
EFileWrite |
EFileWriteDirectIO );
-#else
+#else
EFileWrite );
-#endif
-
- if(err == KErrNotFound)
+#endif
+
+ if(err == KErrNotFound)
{
- err = iFile.Replace( iFs,
- iFname,
- EFileShareAny |
- EFileStream |
+ err = iFile.Replace( iFs,
+ iFname,
+ EFileShareAny |
+ EFileStream |
#ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
EFileWrite |
EFileWriteDirectIO );
-#else
+#else
EFileWrite );
-#endif
+#endif
}
@@ -166,7 +169,7 @@
iSize = 0;
iState = EStoreOpen;
}
-
+
// ---------------------------------------------------------
// CFileSaver::AppendData()
// ---------------------------------------------------------
@@ -186,10 +189,10 @@
{
// nothing persisted yet. If there's a file with the same name,
// delete it.
- err = iFile.Replace( iFs,
- iFname,
- EFileShareAny |
- EFileStream |
+ err = iFile.Replace( iFs,
+ iFname,
+ EFileShareAny |
+ EFileStream |
EFileWrite );
}
else*/
@@ -199,7 +202,7 @@
{
err = iStorage->WriteOutNextBodyDataL(aData );
}
-
+
CLOG(( EHttpLoad, 2, _L("<- CFileSaver::AppendData returns (%d)"), err ));
return err;
}
@@ -247,7 +250,7 @@
//
// There is a safety upper bound on the transaction size, that is already
// applied. See SetMaxSize().
-
+
TDataType drm( KOma1DrmMessageContentType );
TDataType dcf( KOma1DcfContentType );
@@ -284,7 +287,7 @@
else
{
// Other than DRM stuff arrived. Proper check for MIME type.
- if( !(*aData[aData.ActiveDownload()]).HasType( iType.Des8() ) && ! iDocHandler.CanSaveL(iType) )
+ if( !(*aData[aData.ActiveDownload()]).HasType( iType.Des8() ) )
{
CLOG(( ECodEng, 4, _L(" mismatch") ));
User::Leave( KErrCodAttributeMismatch );
@@ -311,7 +314,7 @@
*/
if (!aAttached)
{
-#if 0
+#if 0
RFs fs;
TInt err( KErrNone );
HBufC* filename = HBufC::NewLC(KMaxFileName);
@@ -325,25 +328,25 @@
TInt error = fs.MkDirAll(filenamePtr);
if (error!=KErrNone && error!=KErrAlreadyExists)
{
- User::Leave(error);
+ User::Leave(error);
}
-
+
// Find a unique name to avoid any conflict.
// Here iFname has full path of current location of file
// and filename has destination path.
FindUniqueDestinationFileNameL( iFname, filename );
-
- filenamePtr = filename->Des();
-
+
+ filenamePtr = filename->Des();
+
err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
-
+
if(err != KErrNone)
{
User::Leave(err);
}
-
- iFname = filenamePtr;
- NotifyMediaGalleryL( filenamePtr );
+
+ iFname = filenamePtr;
+ NotifyMediaGalleryL( filenamePtr );
CleanupStack::PopAndDestroy(file);
CleanupStack::PopAndDestroy(&fs);
CleanupStack::PopAndDestroy(filename);
@@ -353,73 +356,40 @@
CleanupClosePushL(fs);
CFileMan* file=CFileMan::NewL(fs);
CleanupStack::PushL(file);
-#ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
- CDownloadPathHandler* downloadPathPlugin = NULL;
- if ( aData.Count() )
- {
- // Get the mime type of the first media object
- TPtrC8 mimeType = (*aData[1]).Type();
- downloadPathPlugin = GetDownloadPathPluginInstanceL( mimeType );
- if( downloadPathPlugin )
- {
- CleanupStack::PushL( downloadPathPlugin );
- }
- }
-#endif
for( TInt i = 1; i <= aData.Count() ; ++i )
{
HBufC* filename = HBufC::NewLC(KMaxFileName);
TPtr filenamePtr = filename->Des();
filenamePtr = (*aData[i]).iRootPath;
-
-#ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
- if( downloadPathPlugin )
- {
- TFileName iTempFlName = (*aData[i]).iFullName->Des();
- GetUpdatedPathFromPluginL( downloadPathPlugin,iTempFlName, filenamePtr );
- }
- else
- {
- filenamePtr.Append( _L( "download\\" ) );
- }
-#else
- filenamePtr.Append( _L( "download\\" ) );
-
-#endif
-
+
+ filenamePtr.Append(_L("download\\"));
TInt error = fs.MkDirAll(filenamePtr);
if (error!=KErrNone && error!=KErrAlreadyExists)
{
- User::Leave(error);
+ User::Leave(error);
}
iFname = (*aData[i]).iFullName->Des();
-
+
// Find a unique name to avoid any conflict.
// Here iFname has full path of current location of file
// and filename has destination path.
FindUniqueDestinationFileNameL( iFname, filename );
-
+
filenamePtr = filename->Des();
TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
if(err != KErrNone)
{
User::LeaveIfError(err);
}
- iFname = filenamePtr;
+ iFname = filenamePtr;
NotifyMediaGalleryL( filenamePtr );
(*aData[i]).iFileName = iFname;
(*aData[i]).iFullName = NameL();
CleanupStack::PopAndDestroy(filename);
}
-#ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
- if( downloadPathPlugin )
- {
- CleanupStack::PopAndDestroy( downloadPathPlugin );
- }
-#endif
CleanupStack::PopAndDestroy(file);
CleanupStack::PopAndDestroy(&fs);
@@ -455,32 +425,13 @@
*/
if (!aAttached)
{
-#ifdef RD_MULTIPLE_DRIVE
+#ifdef RD_MULTIPLE_DRIVE
RFs fs;
TInt err( KErrNone );
HBufC* filename = HBufC::NewLC(KMaxFileName);
TPtr filenamePtr = filename->Des();
filenamePtr = iRootPath;
-#ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
- // Get the mime type of the content
- TPtrC8 mimeType( iType.Des8() );
- CDownloadPathHandler* downloadPathPlugin = NULL;
- downloadPathPlugin = GetDownloadPathPluginInstanceL( mimeType );
-
- if( downloadPathPlugin )
- {
- CleanupStack::PushL( downloadPathPlugin );
- GetUpdatedPathFromPluginL( downloadPathPlugin,iFname, filenamePtr );
- CleanupStack::PopAndDestroy( downloadPathPlugin );
- }
- else
- {
- filenamePtr.Append( _L( "download\\" ) );
- }
-#else
- filenamePtr.Append( _L( "download\\" ) );
-
-#endif
+ filenamePtr.Append(_L("download\\"));
User::LeaveIfError( fs.Connect() );
CleanupClosePushL(fs);
CFileMan* file=CFileMan::NewL(fs);
@@ -488,25 +439,25 @@
TInt error = fs.MkDirAll(filenamePtr);
if (error!=KErrNone && error!=KErrAlreadyExists)
{
- User::Leave(error);
+ User::Leave(error);
}
-
+
// Find a unique name to avoid any conflict.
// Here iFname has full path of current location of file
// and filename has destination path.
FindUniqueDestinationFileNameL( iFname, filename );
-
- filenamePtr = filename->Des();
-
+
+ filenamePtr = filename->Des();
+
err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
-
+
if(err != KErrNone)
{
User::Leave(err);
}
-
- iFname = filenamePtr;
- NotifyMediaGalleryL( filenamePtr );
+
+ iFname = filenamePtr;
+ NotifyMediaGalleryL( filenamePtr );
CleanupStack::PopAndDestroy(file);
CleanupStack::PopAndDestroy(&fs);
CleanupStack::PopAndDestroy(filename);
@@ -524,22 +475,22 @@
TInt error = fs.MkDirAll(filenamePtr);
if (error!=KErrNone && error!=KErrAlreadyExists)
{
- User::Leave(error);
+ User::Leave(error);
}
// Find a unique name to avoid any conflict.
// Here iFname has full path of current location of file
// and filename has destination path.
FindUniqueDestinationFileNameL( iFname, filename );
-
+
filenamePtr = filename->Des();
TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
-
+
if(err != KErrNone)
{
User::Leave(err);
}
- iFname = filenamePtr;
+ iFname = filenamePtr;
NotifyMediaGalleryL( filenamePtr );
CleanupStack::PopAndDestroy(file);
CleanupStack::PopAndDestroy(&fs);
@@ -609,7 +560,7 @@
// Expected error: KErrNotFound (if there is no temp file).
// Unexpected error: all the rest -> nothing we can do with them.
CloseStore();
-
+
if( aDeleteFile )
{
#ifdef __TEST_COD_LOG
@@ -633,53 +584,53 @@
CLOG(( ECodEng, 2, _L("<- CFileSaver::Cleanup") ));
}
-
+
// ---------------------------------------------------------
// CFileSaver::UpdateDCFRepositoryL()
-// Update saved file to DCFRepository
+// Update saved file to DCFRepository
// ---------------------------------------------------------
-//
+//
void CFileSaver::UpdateDCFRepositoryL( const TDesC& aFileName )
{
CDcfEntry* dcfEntry = NULL;
- dcfEntry = CDcfEntry::NewL();
+ dcfEntry = CDcfEntry::NewL();
CleanupStack::PushL( dcfEntry );
-
+
CDcfRep* dcfRep = NULL;
dcfRep = CDcfRep::NewL();
CleanupStack::PushL( dcfRep );
- dcfEntry->SetLocationL( aFileName, 0 );
+ dcfEntry->SetLocationL( aFileName, 0 );
dcfRep->UpdateL( dcfEntry );
CleanupStack::PopAndDestroy(2); // dcfEntry, dcfRep
- }
-
+ }
+
// ---------------------------------------------------------
// CFileSaver::UpdateMediaGalleryIfNeededL()
// Calls MediaGallery Update method so that media gallery
// knows update its view.
// ---------------------------------------------------------
-//
+//
void CFileSaver::UpdateMediaGalleryIfNeededL( const TDesC& aFileName )
{
-#ifdef BRDO_APP_GALLERY_SUPPORTED_FF
+#ifdef BRDO_APP_GALLERY_SUPPORTED_FF
CMGXFileManager* fm = MGXFileManagerFactory::NewFileManagerL( iFs );
CleanupStack::PushL(fm);
fm->UpdateL(aFileName);
CleanupStack::PopAndDestroy(); // fm
-#endif
+#endif
}
// ---------------------------------------------------------
// CFileSaver::NotifyMediaGalleryL()
// Notify media gallery about the new file.
// ---------------------------------------------------------
-//
+//
void CFileSaver::NotifyMediaGalleryL( const TDesC& aFileName )
{
-#ifdef BRDO_APP_GALLERY_SUPPORTED_FF
-
+#ifdef BRDO_APP_GALLERY_SUPPORTED_FF
+
CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL( iFs );
CleanupStack::PushL( mgFileManager );
@@ -690,8 +641,8 @@
TRAP_IGNORE( UpdateMediaGalleryIfNeededL( aFileName ) );
#endif
-
-
+
+
// Notify DCF repository
TRAP_IGNORE( UpdateDCFRepositoryL( aFileName ) );
}
@@ -704,7 +655,7 @@
// check how many bytes are already persisted
TInt DownloadedSize(0);
TInt err = iFile.Size( (TInt&)DownloadedSize );
-
+
CLOG(( ECodStorage, 2, _L("CFileSaver::DownloadedFileSize Downloaded size = %d error = %d"), \
DownloadedSize,err ));
@@ -712,21 +663,21 @@
return err;
return DownloadedSize;
}
-
-
+
+
/**
* Discard the old contents
-*/
+*/
void CFileSaver::ResetL()
{
-
-
+
+
iFile.Close();
-
- User::LeaveIfError( iFile.Replace( iFs,
- iFname,
- EFileShareAny |
- EFileStream |
+
+ User::LeaveIfError( iFile.Replace( iFs,
+ iFname,
+ EFileShareAny |
+ EFileStream |
EFileWrite ) );
}
@@ -742,8 +693,8 @@
{
iBufferSize = KDefaultStorageBufferSizePD;
}
-
-
+
+
if( iBufferSize != iStorage->CurrentBufferSize())
{
FlushL();
@@ -751,10 +702,10 @@
if ( iFile.SubSessionHandle() )
{
-
+
if( iProgressiveDownload )
{
- if( iLength != KDefaultContentLength )
+ if( iLength != KDefaultContentLength )
{
iFile.SetSize( iLength );
}
@@ -790,11 +741,11 @@
//
void CFileSaver::OnComplete()
{
- CLOG(( ECodEng, 2, _L("-> CFileSaver::OnComplete") ));
+ CLOG(( ECodEng, 2, _L("-> CFileSaver::OnComplete") ));
FlushL();
iStorage->ClearErrors();
iFile.Close();
- CLOG(( ECodEng, 2, _L("<- CFileSaver::OnComplete") ));
+ CLOG(( ECodEng, 2, _L("<- CFileSaver::OnComplete") ));
}
@@ -807,37 +758,3 @@
{
return iFname.AllocL();
}
-#ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
-
-// ---------------------------------------------------------
-// CFileSaver::GetDownloadPathPluginInstanceL
-// ---------------------------------------------------------
-CDownloadPathHandler* CFileSaver::GetDownloadPathPluginInstanceL(TPtrC8& mimetype )
- {
- CDownloadPathHandler* downloadPathPlugin = NULL;
- TRAPD( kErr, downloadPathPlugin = CDownloadPathHandler::NewL( mimetype ) );
- if( kErr != KErrNone )
- {
- downloadPathPlugin = NULL;
- }
- return downloadPathPlugin;
- }
-
-// ---------------------------------------------------------
-// CFileSaver::GetUpdatedPathFromPluginL
-// ---------------------------------------------------------
-void CFileSaver::GetUpdatedPathFromPluginL(CDownloadPathHandler* downloadPathPlugin,TFileName& fname, TPtr& fileNamePtr)
- {
- TRAPD( kErr, downloadPathPlugin->GetUpdatedPathL( fname, fileNamePtr ) );
- if( kErr == KErrNone )
- {
- fileNamePtr.Append( _L( "\\" ) );
- }
- else
- {
- fileNamePtr.Append( _L( "download\\" ) );
- }
- }
-#endif
-
-//EOF