svgtviewer/SvgtViewerPlugin/AppObserverUtilSrc/SVGTFileManager.cpp
branchRCL_3
changeset 18 20b99a6d6175
parent 0 632761c941a7
equal deleted inserted replaced
17:e52958d06c29 18:20b99a6d6175
       
     1 /*
       
     2 * Copyright (c) 2004, 2005 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:  File operations, used when "Save" option is selected.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <flogger.h>
       
    23 #include <eikenv.h>
       
    24 #include <pathinfo.h>
       
    25 #include <sysutil.h>
       
    26 
       
    27 #include "SVGTViewerAppDbgFlags.hrh"
       
    28 #include "SVGTFileManager.h"
       
    29 #include "SVGTUISaveListener.h"
       
    30 
       
    31 
       
    32 #ifdef SVGTVIEWERAPP_DBG_FLAG    
       
    33 _LIT( KFileLoggingDir, "SVGTViewer" );
       
    34 _LIT( KFileLog, "SaveLog.txt" );
       
    35 #endif
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CSVGTFileManager::CSVGTFileManager
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CSVGTFileManager::CSVGTFileManager() : CActive(0)
       
    46     {
       
    47     }
       
    48 
       
    49     
       
    50 // -----------------------------------------------------------------------------
       
    51 // CSVGTFileManager::ConstructL
       
    52 // Symbian 2nd phase constructor can leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 void CSVGTFileManager::ConstructL()
       
    56     {
       
    57     iEikEnv = CEikonEnv::Static();    
       
    58     iFileMan = CFileMan::NewL( iEikEnv->FsSession(),this );
       
    59     iProgressUpdater =  CPeriodic::NewL( 0 );
       
    60     // Add this active object to the scheduler.
       
    61     CActiveScheduler::Add( this );    
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CSVGTFileManager::NewL
       
    66 // Two-phased constructor.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C CSVGTFileManager* CSVGTFileManager::NewL()
       
    70     {
       
    71     CSVGTFileManager* self = new( ELeave ) CSVGTFileManager();   
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL();
       
    74     CleanupStack::Pop( self );
       
    75     return self;
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CSVGTFileManager::~CSVGTFileManager   
       
    80 // Destructor
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C CSVGTFileManager::~CSVGTFileManager()
       
    84     {
       
    85     delete iFileMan;
       
    86     delete iProgressUpdater;
       
    87     // Reset the callback implementation pointer
       
    88     iCallback = NULL;
       
    89     // Reset the environment pointer
       
    90     iEikEnv = NULL;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CSVGTFileManager::StartCopyOperationL
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 EXPORT_C TInt CSVGTFileManager::StartCopyOperationL( 
       
    98     MSVGTUISaveListener* aCallback, const TDesC& anOld, const TDesC& aNew )
       
    99     {
       
   100     if (IsActive())
       
   101         {
       
   102         return KErrInUse;
       
   103         }
       
   104 
       
   105     iPosition = 0;
       
   106     iCancel = EFalse;
       
   107     RFile lFile;
       
   108     TInt RetVal = KErrNone;//return value
       
   109     iCallback = aCallback;   
       
   110     RetVal = lFile.Open(iEikEnv->FsSession(),anOld, EFileRead); 
       
   111     if ( RetVal != KErrNone)
       
   112         {
       
   113         // if there was a problem opening this file then this should return here 
       
   114         //itself. Or else RTIY-6JNVHS error would occur.
       
   115         return RetVal ;
       
   116         } 
       
   117     lFile.Size(iFileSize);//get the file size into iFileSize
       
   118     lFile.Close();//no filehandle should be open while doing a "move"        
       
   119      
       
   120    
       
   121 #ifdef SVGTVIEWERAPP_DBG_FLAG    
       
   122     _LIT( errorMsg2, "Size read");   
       
   123     PrintDebugMsg( errorMsg2 );
       
   124 #endif
       
   125         
       
   126     // Check disk space
       
   127     TParsePtrC parse(aNew);
       
   128 
       
   129 #ifndef RD_MULTIPLE_DRIVE
       
   130     if( parse.Drive().CompareF( PathInfo::MemoryCardRootPath().Left(2) ) == 0 )
       
   131         {
       
   132         if (SysUtil::MMCSpaceBelowCriticalLevelL(&(iEikEnv->FsSession()),iFileSize))
       
   133             {            
       
   134             return KErrDiskFull; // UI shows note
       
   135             }
       
   136         }
       
   137     else
       
   138         {
       
   139         if (SysUtil::FFSSpaceBelowCriticalLevelL(&(iEikEnv->FsSession()),iFileSize))
       
   140             {
       
   141             User::Leave(KErrDiskFull); // Phone memory full, Avkon shows note
       
   142             }
       
   143         }  
       
   144 #else
       
   145 //********************** Added the support for multiple drive ************************
       
   146     TInt intDrive;
       
   147     TChar ch = parse.Drive()[0];
       
   148     
       
   149     User::LeaveIfError( RFs::CharToDrive(ch,intDrive) );
       
   150     
       
   151     if( SysUtil::DiskSpaceBelowCriticalLevelL(&(iEikEnv->FsSession()),
       
   152                                 iFileSize, intDrive ))
       
   153         {
       
   154         User::Leave( KErrDiskFull); // Disk full, Avkon shows note
       
   155         }
       
   156     
       
   157 //************************************************************************************        
       
   158 
       
   159 #endif    
       
   160 
       
   161     // start copying
       
   162     if( iMove )
       
   163         {
       
   164         User::LeaveIfError(
       
   165             iFileMan->Move(anOld,aNew,CFileMan::EOverWrite,iStatus));
       
   166         }
       
   167     
       
   168     if ( !iProgressUpdater->IsActive() )
       
   169         {
       
   170         // start progress updater
       
   171         iProgressUpdater->Start(KSVGTOneSecond,KSVGTOneSecond, 
       
   172                     TCallBack(CSVGTFileManager::ProgressUpdate, this));
       
   173 
       
   174         }    
       
   175     
       
   176    
       
   177     SetActive();
       
   178 
       
   179     return RetVal;
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CSVGTFileManager::StartCopyOperationL
       
   184 //   Overloaded version with RFile Input.
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 EXPORT_C TInt CSVGTFileManager::StartCopyOperationL( 
       
   188     MSVGTUISaveListener* aCallback, RFile& aSrcHandle, const TDesC& aNew )
       
   189     {
       
   190     TFileName sourceFileName;
       
   191     aSrcHandle.FullName( sourceFileName );
       
   192     aSrcHandle.Size(iFileSize);
       
   193     if ( iMove )
       
   194         {
       
   195         aSrcHandle.Close();
       
   196         return StartCopyOperationL( aCallback, sourceFileName, aNew );   
       
   197         }
       
   198     else
       
   199         {
       
   200     
       
   201         if (IsActive())
       
   202             {
       
   203             return KErrInUse;
       
   204             }
       
   205 
       
   206         iPosition = 0;
       
   207         iCancel = EFalse;
       
   208 
       
   209         iCallback = aCallback;   
       
   210             
       
   211         
       
   212         // Check disk space
       
   213         TParsePtrC parse(aNew);
       
   214 
       
   215 #ifndef RD_MULTIPLE_DRIVE
       
   216         if( parse.Drive().CompareF( PathInfo::MemoryCardRootPath().Left(2) ) == 0 )
       
   217             {
       
   218             if (SysUtil::MMCSpaceBelowCriticalLevelL(&(iEikEnv->FsSession()),iFileSize))
       
   219                 {       
       
   220                 return KErrDiskFull; // UI shows note
       
   221                 }
       
   222             }
       
   223         else
       
   224             {
       
   225             if (SysUtil::FFSSpaceBelowCriticalLevelL(&(iEikEnv->FsSession()),iFileSize))
       
   226                 {
       
   227                 User::Leave(KErrDiskFull); // Phone memory full, Avkon shows note
       
   228                 }
       
   229             }  
       
   230 #else
       
   231 //********************** Added the support for multiple drive ************************
       
   232     TInt intDrive;
       
   233     TChar ch = parse.Drive()[0];
       
   234     
       
   235     User::LeaveIfError( RFs::CharToDrive(ch,intDrive) );
       
   236     
       
   237     if( SysUtil::DiskSpaceBelowCriticalLevelL(&(iEikEnv->FsSession()),
       
   238                                 iFileSize, intDrive ))
       
   239         {
       
   240         User::Leave( KErrDiskFull); // Disk full, Avkon shows note
       
   241         }
       
   242     
       
   243 //************************************************************************************        
       
   244 
       
   245 #endif 
       
   246         
       
   247         User::LeaveIfError(
       
   248                 iFileMan->Copy(aSrcHandle,aNew,CFileMan::EOverWrite,iStatus));
       
   249           
       
   250         
       
   251         if ( !iProgressUpdater->IsActive() )
       
   252             {
       
   253             // start progress updater
       
   254             iProgressUpdater->Start(KSVGTOneSecond,KSVGTOneSecond, 
       
   255                         TCallBack(CSVGTFileManager::ProgressUpdate, this));
       
   256 
       
   257             } 
       
   258         SetActive();
       
   259         return KErrNone;
       
   260 
       
   261         }       
       
   262     }
       
   263 // -----------------------------------------------------------------------------
       
   264 // CSVGTFileManager::DoCancel
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 EXPORT_C void CSVGTFileManager::CancelCopy()
       
   268     {
       
   269     iCancel = ETrue;
       
   270     iProgressUpdater->Cancel();
       
   271     Cancel();
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CSVGTFileManager::SetAllowMove
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 EXPORT_C void CSVGTFileManager::SetAllowMove( TInt32 aValue )
       
   279     {
       
   280     iMove = aValue; 
       
   281     }
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // CSVGTFileManager::RunL
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 void CSVGTFileManager::RunL() 
       
   288     {   
       
   289     iProgressUpdater->Cancel();
       
   290 
       
   291     if (iCallback)
       
   292         {
       
   293         if (iCancel)
       
   294             {
       
   295             iCallback->SVGTSavingDoneL(KErrCancel);
       
   296             }
       
   297         else
       
   298             {
       
   299             iCallback->SVGTSavingDoneL(iStatus.Int());
       
   300             }
       
   301         }
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CSVGTFileManager::NotifyFileManOperation
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 MFileManObserver::TControl CSVGTFileManager::NotifyFileManOperation()
       
   309     {
       
   310     if (iCancel)
       
   311         {
       
   312         return MFileManObserver::ECancel;
       
   313         }
       
   314 #ifdef SVGTVIEWERAPP_DBG_FLAG    
       
   315     TBuf<40> msg;
       
   316     _LIT( errorMsg, "NotifyFileManOperation %d");
       
   317     msg.Format(errorMsg, iFileMan->BytesTransferredByCopyStep() );
       
   318     PrintDebugMsg( msg );
       
   319 #endif    
       
   320     iPosition += iFileMan->BytesTransferredByCopyStep();
       
   321     return MFileManObserver::EContinue;
       
   322     }
       
   323 
       
   324 // -----------------------------------------------------------------------------
       
   325 // CSVGTFileManager::DoCancel
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 void CSVGTFileManager::DoCancel()
       
   329     {
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CSVGTFileManager::ProgressUpdate
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 TInt CSVGTFileManager::ProgressUpdate(TAny* aPtr)
       
   337     {
       
   338     if ( aPtr )
       
   339         {
       
   340         static_cast<CSVGTFileManager*>(aPtr)->DoProgressUpdate();        
       
   341         }
       
   342     return KErrNone;
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CSVGTFileManager::DoProgressUpdate
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 void CSVGTFileManager::DoProgressUpdate()
       
   350     {
       
   351     if (iCallback)
       
   352         {    
       
   353         iCallback->SVGTPositionChanged((iPosition*KSVGTPercent)/iFileSize);
       
   354         }
       
   355     }
       
   356 #ifdef SVGTVIEWERAPP_DBG_FLAG    
       
   357 // -----------------------------------------------------------------------------
       
   358 // CSVGTFileManager::PrintDebugMsg
       
   359 // -----------------------------------------------------------------------------
       
   360 //
       
   361 void CSVGTFileManager::PrintDebugMsg( const TDesC&  aMsg )
       
   362     {
       
   363 #ifdef _DEBUG        
       
   364     RFileLogger::Write( KFileLoggingDir, KFileLog, 
       
   365                         EFileLoggingModeAppend, aMsg );
       
   366 #endif    
       
   367     }
       
   368 #endif    
       
   369 
       
   370 //  End of File