filemanager/src/filemanager/src/operationservice/fmoperationformat_s60.cpp
changeset 37 15bc28c9dd51
parent 16 ada7962b4308
child 46 d58987eac7e8
--- a/filemanager/src/filemanager/src/operationservice/fmoperationformat_s60.cpp	Mon May 03 12:24:39 2010 +0300
+++ b/filemanager/src/filemanager/src/operationservice/fmoperationformat_s60.cpp	Tue Aug 24 10:24:14 2010 +0800
@@ -26,28 +26,50 @@
 #include <e32property.h>
 #include <coreapplicationuisdomainpskeys.h>
 
-FmOperationFormat::FmOperationFormat( QObject *parent, QString mDriverName ) : FmOperationBase( parent, FmOperationService::EOperationTypeFormat ),
+/* \fn  void driveSpaceChanged()
+ * This signal is emitted when copy or move is completed, and used to update the drive size.
+ */
+
+/*
+ * Constructs a format operation with \a parent
+ * \a mDriverName the drive to be formatted.
+ */
+FmOperationFormat::FmOperationFormat( QObject *parent, const QString &mDriverName ) : FmOperationBase( parent, FmOperationService::EOperationTypeFormat ),
     mDriverName( mDriverName )
 {
+    connect( this, SIGNAL( driveSpaceChanged() ),
+            parent, SLOT( on_operation_driveSpaceChanged() ) );
 }
+
+/*
+ * Destructs the operation.
+ */
 FmOperationFormat::~FmOperationFormat()
 {
 }
 
+/*
+ * Returns the to be formatted drive name
+ */
 QString FmOperationFormat::driverName()
 {
     return mDriverName;
 }
 
-int FmOperationFormat::start()
+/*
+ * Starts to format.
+ * \a isStopped not used
+ */
+void FmOperationFormat::start( volatile bool */*isStopped*/ )
 { 
     QString logString = "FmOperationFormat::start";
-    FmLogger::log( logString );
+    FM_LOG( logString );
     
     emit notifyPreparing( false );
     
     if( mDriverName.isEmpty() ) {
-        return FmErrWrongParam;
+        emit notifyError( FmErrWrongParam, QString() );
+        return;
     }
     
     RFormat format;
@@ -56,7 +78,8 @@
     int err = fs.Connect();
     
     if( err != KErrNone ){
-        return FmErrTypeFormatFailed;
+        emit notifyError( FmErrTypeFormatFailed, QString() );
+        return;
     }
 
     TInt drive = 0;
@@ -73,19 +96,19 @@
     
     if( err == KErrNone ){
         logString = "emit notifyStart";
-        FmLogger::log( logString );
+        FM_LOG( logString );
         mTotalSteps = finalValue;
         emit notifyStart( false, finalValue );
     }
     
     logString = "Format open error:" + QString::number( err );
-    FmLogger::log( logString );
+    FM_LOG( logString );
     
     if( err == KErrLocked ){
         err = fs.ErasePassword( drive );
         
         logString = "ErasePassword error:" + QString::number( err );
-        FmLogger::log( logString );
+        FM_LOG( logString );
         
         if( err == KErrNone ){
             err = format.Open(
@@ -93,12 +116,12 @@
             
             if( err == KErrNone ){
                 logString = "emit notifyStart";
-                FmLogger::log( logString );
+                FM_LOG( logString );
                 mTotalSteps = finalValue;
                 emit notifyStart( false, finalValue );
             }           
             logString = "Second format open error:" + QString::number( err );
-            FmLogger::log( logString );
+            FM_LOG( logString );
         }
     }
     
@@ -110,13 +133,13 @@
             
             if( err == KErrNone ){
                 logString = "emit notifyStart";
-                FmLogger::log( logString );
+                FM_LOG( logString );
                 mTotalSteps = finalValue;
                 emit notifyStart( false, finalValue );
             } 
             
             logString = "Reallyformat open error:" + QString::number( err );
-            FmLogger::log( logString );
+            FM_LOG( logString );
         }
     }
     
@@ -126,7 +149,7 @@
         err = fs.FileSystemName( fsName, drive  );
         
         logString = "FileSystemName error:" + QString::number( err );
-        FmLogger::log( logString );
+        FM_LOG( logString );
 
         if ( err == KErrNone && fsName.Length() > 0 )
             {
@@ -137,7 +160,7 @@
                     ECoreAppUIsEjectCommandUsed );
             
             logString = "Prevent SysAp shutting down applications" ;
-            FmLogger::log( logString );
+            FM_LOG( logString );
             }
         else
             {
@@ -146,7 +169,7 @@
             err = KErrCancel;
             
             logString = QString( "Format cancel" );
-            FmLogger::log( logString );
+            FM_LOG( logString );
             }
         }
     
@@ -154,17 +177,17 @@
     
         while ( finalValue ){        
             logString = "Format tracks:" + QString::number( finalValue );
-            FmLogger::log( logString );
+            FM_LOG( logString );
             err = format.Next( finalValue );
             
             if( err != KErrNone ){ 
                 logString = "Format error:" + QString::number( err );
-                FmLogger::log( logString );
+                FM_LOG( logString );
                 break; 
             }
             
             logString = "emit notifyProgress";
-            FmLogger::log( logString );
+            FM_LOG( logString );
             emit notifyProgress( mTotalSteps - finalValue );
         }
     }
@@ -177,9 +200,14 @@
     }
 
     if( err == KErrNone ){
-        return FmErrNone;
+        emit notifyFinish();        
     }
     else{
-        return FmErrTypeFormatFailed;
+        emit notifyError( FmErrTypeFormatFailed, QString() );
     }
+    // refresh drive space no care if cancel, error or finished.
+    // as filemanger cannot notify drive space changed
+    // do not refresh path as QFileSystemModel will do auto-refresh
+    emit driveSpaceChanged();    
+    
 }