codhandler/codeng/src/FileSaver.cpp
branchRCL_3
changeset 62 c711bdda59f4
parent 58 220a17280356
child 93 79859ed3eea9
equal deleted inserted replaced
59:1f3c3f2f5b0a 62:c711bdda59f4
    40 #include <CMGXFileManager.h>
    40 #include <CMGXFileManager.h>
    41 #endif
    41 #endif
    42 
    42 
    43 #include <DcfEntry.h>
    43 #include <DcfEntry.h>
    44 #include <DcfRep.h>
    44 #include <DcfRep.h>
       
    45 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
    46 #include <DownloadPathHandler.h>
       
    47 #endif
    45 
    48 
    46 const TInt KDefaultStorageBufferSize = 128 * 1024;
    49 const TInt KDefaultStorageBufferSize = 128 * 1024;
    47 const TInt KDefaultStorageBufferSizePD = 16 * 1024;
    50 const TInt KDefaultStorageBufferSizePD = 16 * 1024;
    48 
    51 
    49 // ================= MEMBER FUNCTIONS =======================
    52 // ================= MEMBER FUNCTIONS =======================
   348         RFs fs;
   351         RFs fs;
   349         User::LeaveIfError( fs.Connect() );
   352         User::LeaveIfError( fs.Connect() );
   350         CleanupClosePushL(fs);
   353         CleanupClosePushL(fs);
   351         CFileMan* file=CFileMan::NewL(fs);
   354         CFileMan* file=CFileMan::NewL(fs);
   352         CleanupStack::PushL(file);
   355         CleanupStack::PushL(file);
   353         
   356 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
   354         
   357         CDownloadPathHandler* downloadPathPlugin = NULL;
       
   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
   355         for( TInt i = 1; i <= aData.Count() ; ++i )
   371         for( TInt i = 1; i <= aData.Count() ; ++i )
   356             {
   372             {
   357             HBufC* filename = HBufC::NewLC(KMaxFileName);
   373             HBufC* filename = HBufC::NewLC(KMaxFileName);
   358             TPtr filenamePtr = filename->Des();
   374             TPtr filenamePtr = filename->Des();
   359             filenamePtr = (*aData[i]).iRootPath;
   375             filenamePtr = (*aData[i]).iRootPath;
   360 
   376             
   361             filenamePtr.Append(_L("download\\"));
   377 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
   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             
   362             TInt error = fs.MkDirAll(filenamePtr);
   392             TInt error = fs.MkDirAll(filenamePtr);
   363             if (error!=KErrNone && error!=KErrAlreadyExists)
   393             if (error!=KErrNone && error!=KErrAlreadyExists)
   364                {
   394                {
   365                 User::Leave(error);   
   395                 User::Leave(error);   
   366                }
   396                }
   382 
   412 
   383             (*aData[i]).iFileName = iFname;
   413             (*aData[i]).iFileName = iFname;
   384             (*aData[i]).iFullName = NameL();
   414             (*aData[i]).iFullName = NameL();
   385             CleanupStack::PopAndDestroy(filename);
   415             CleanupStack::PopAndDestroy(filename);
   386             }
   416             }
       
   417 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
   418         if( downloadPathPlugin )
       
   419             {
       
   420             CleanupStack::PopAndDestroy( downloadPathPlugin );
       
   421             }
       
   422 #endif
   387         CleanupStack::PopAndDestroy(file);
   423         CleanupStack::PopAndDestroy(file);
   388         CleanupStack::PopAndDestroy(&fs);
   424         CleanupStack::PopAndDestroy(&fs);
   389 
   425 
   390 #endif // RD_MULTIPLE_DRIVE
   426 #endif // RD_MULTIPLE_DRIVE
   391     // TODO set iType to that of the packaged object (??)
   427     // TODO set iType to that of the packaged object (??)
   423         RFs fs;
   459         RFs fs;
   424         TInt err( KErrNone );
   460         TInt err( KErrNone );
   425         HBufC* filename = HBufC::NewLC(KMaxFileName);
   461         HBufC* filename = HBufC::NewLC(KMaxFileName);
   426         TPtr filenamePtr = filename->Des();
   462         TPtr filenamePtr = filename->Des();
   427         filenamePtr = iRootPath;
   463         filenamePtr = iRootPath;
   428         filenamePtr.Append(_L("download\\"));
   464 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
   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
   429         User::LeaveIfError( fs.Connect() );
   484         User::LeaveIfError( fs.Connect() );
   430         CleanupClosePushL(fs);
   485         CleanupClosePushL(fs);
   431         CFileMan* file=CFileMan::NewL(fs);
   486         CFileMan* file=CFileMan::NewL(fs);
   432         CleanupStack::PushL(file);
   487         CleanupStack::PushL(file);
   433         TInt error = fs.MkDirAll(filenamePtr);
   488         TInt error = fs.MkDirAll(filenamePtr);
   750 // ---------------------------------------------------------
   805 // ---------------------------------------------------------
   751 HBufC* CFileSaver::NameL() const
   806 HBufC* CFileSaver::NameL() const
   752     {
   807     {
   753     return iFname.AllocL();
   808     return iFname.AllocL();
   754     }
   809     }
       
   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