filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp
changeset 35 060d0b1ab845
parent 30 6e96d2143d46
child 41 fc4654ce4fcb
--- a/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp	Tue Jul 06 14:06:28 2010 +0300
+++ b/filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp	Wed Aug 18 09:39:39 2010 +0300
@@ -18,6 +18,7 @@
 #include "fmoperationbase.h"
 #include "fmoperationservice.h"
 #include "fmoperationformat.h"
+#include "fmoperationviewdetails.h"
 #include "fmviewdetailsdialog.h"
 #include "fmdlgutils.h"
 #include "fmutils.h"
@@ -27,15 +28,25 @@
 #include <hbglobal.h>
 #include <QFileInfo>
 
+/*
+ * Constructs one operation result processer with \a operation Service.
+ */
 FmOperationResultProcesser::FmOperationResultProcesser( FmOperationService *operationService )
     : mOperationService( operationService ), mNote( 0 )
 {
 }
 
+/*
+ * Destructs the operation result processer
+ */
 FmOperationResultProcesser::~FmOperationResultProcesser(void)
 {
 }
 
+/*
+ * Called by operation service on_operation_askForRename
+ * \sa FmOperationService::on_operation_askForRename
+ */
 void FmOperationResultProcesser::onAskForRename(
     FmOperationBase* operationBase, const QString &srcFile, QString *destFile )
 {
@@ -45,28 +56,42 @@
     QString questionText = QString( "file " ) +
         srcFile + QString( " already exist, please rename:" );
     QString value;   
-    QFileInfo fileInfo(srcFile);
-    bool ret = FmDlgUtils::showTextQuery( questionText, value, true, maxFileNameLength, QString(), false );
+    QFileInfo srcFileInfo(srcFile);
+    QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot );
+
+    bool ret = FmDlgUtils::showTextQuery( questionText, value, regExpList,
+        maxFileNameLength, QString(), false );
     while ( ret ) {
         // remove whitespace from the start and the end.
         value = value.trimmed();
         QString newTargetPath = FmUtils::fillPathWithSplash(
-                                fileInfo.absolutePath() ) + value;
+                                srcFileInfo.absolutePath() ) + value;
         QString errString;
         // check if name/path is available for use.
-        if( !FmUtils::checkNewFolderOrFile( newTargetPath, errString ) ) {
+        if( !FmUtils::checkNewFolderOrFile( value, newTargetPath, errString ) ) {
             FmDlgUtils::information( errString );
-            ret = FmDlgUtils::showTextQuery( questionText, value, true, maxFileNameLength, QString(), false );
+            ret = FmDlgUtils::showTextQuery( questionText, value, regExpList, maxFileNameLength, QString(), false );
             continue;
         } else {
             break;
         }
     }   
 	if( ret ) {
+        // Got file/folder name for rename, save it to destFile
 		*destFile = value;
+        QFileInfo destFileInfo( *destFile );
+        if ( ( srcFileInfo.suffix().compare( destFileInfo.suffix(), Qt::CaseInsensitive ) != 0 )
+            && srcFileInfo.isFile() ) {
+            // popup warning when the suffix of file is changed.
+            FmDlgUtils::information( hbTrId( "File may become unusable when file name extension is changed" ) );        
+        }   
 	}
 }
 
+/*
+ * Called by operation service on_operation_askForReplace
+ * \sa FmOperationService::on_operation_askForReplace
+ */
 void FmOperationResultProcesser::onAskForReplace(
     FmOperationBase* operationBase, const QString &srcFile, const QString &destFile, bool *isAccepted )
 {
@@ -82,11 +107,20 @@
     }
 }
 
+/*
+ * Called by operation service on_operation_showNote
+ * \sa FmOperationService::on_operation_showNote
+ */
 void FmOperationResultProcesser::onShowNote( FmOperationBase* operationBase, const char *noteString )
 {
+    Q_UNUSED( operationBase );
     FmDlgUtils::information(hbTrId(noteString));
 }
 
+/*
+ * Called by operation service on_operation_notifyWaiting
+ * \sa FmOperationService::on_operation_notifyWaiting
+ */
 void FmOperationResultProcesser::onNotifyWaiting( FmOperationBase* operationBase, bool cancelable )
 {
     QString title = hbTrId("Operation");
@@ -112,6 +146,10 @@
     showWaiting( title, cancelable );
 }
 
+/*
+ * Called by operation service on_operation_notifyPreparing
+ * \sa FmOperationService::on_operation_notifyPreparing
+ */
 void FmOperationResultProcesser::onNotifyPreparing( FmOperationBase* operationBase, bool cancelable )
 {
     QString title = hbTrId("Operation");
@@ -142,6 +180,10 @@
     showPreparing( title, cancelable );
 }
 
+/*
+ * Called by operation service on_operation_notifyStart
+ * \sa FmOperationService::on_operation_notifyStart
+ */
 void FmOperationResultProcesser::onNotifyStart( FmOperationBase* operationBase, bool cancelable, int maxSteps )
 {
     QString title = hbTrId("Operation");
@@ -172,12 +214,20 @@
     showProgress( title, cancelable, maxSteps );   
 }
 
+/*
+ * Called by operation service on_operation_notifyProgress
+ * \sa FmOperationService::on_operation_notifyProgress
+ */
 void FmOperationResultProcesser::onNotifyProgress( FmOperationBase* operationBase, int currentStep )
 {
     Q_UNUSED( operationBase );
     setProgress( currentStep );
 }
 
+/*
+ * Called by operation service on_operation_notifyFinish
+ * \sa FmOperationService::on_operation_notifyFinish
+ */
 void FmOperationResultProcesser::onNotifyFinish( FmOperationBase* operationBase )
 {
     
@@ -210,15 +260,21 @@
             QString driveName( paramFormat->driverName() );
             FmDriverInfo driverInfo = FmUtils::queryDriverInfo( driveName );
             FmDriverInfo::DriveState state = driverInfo.driveState();
+            FmDriverInfo::DriveType driveType = driverInfo.driveType();
+            
+            // If drive is available and it is mmc or usb memory
             if( ( state & FmDriverInfo::EDriveAvailable ) &&
-                ( state & FmDriverInfo::EDriveRemovable ) &&
-                !( state & FmDriverInfo::EDriveMassStorage ) ) { 
-                QString volumeName;
-                while( FmDlgUtils::showTextQuery( title, volumeName, false, FmMaxLengthofDriveName ) ){
+                ( driveType == FmDriverInfo::EDriveTypeMemoryCard ||
+                  driveType == FmDriverInfo::EDriveTypeUsbMemory ) ) { 
+                bool needToSetVolume = false;
+                QString volumeName = FmUtils::getVolumeNameWithDefaultNameIfNull( driveName, needToSetVolume );                            
+                //use isReturnFalseWhenNoTextChanged = false in order that FmUtils::renameDrive( driveName, volumeName ) will
+                //be excuted at lease once to set the volume name.
+                while( FmDlgUtils::showTextQuery( title, volumeName, QStringList(), FmMaxLengthofDriveName, QString(), false ) ){                    
                     int err = FmUtils::renameDrive( driveName, volumeName );
-                    if ( err == FmErrNone ){
+                    if ( err == FmErrNone ) {
                         FmDlgUtils::information( hbTrId( "The name has been changed!" ) );
-                        mOperationService->on_operationThread_refreshModel( driveName );
+                        mOperationService->on_operation_driveSpaceChanged();
                         break;
                     } else if( err == FmErrBadName ) {
                         FmDlgUtils::information( hbTrId( "Illegal characters! Use only letters and numbers." ) );
@@ -245,12 +301,21 @@
 
     }
 }
-void FmOperationResultProcesser::onNotifyError( FmOperationBase* operationBase, int error, QString errString )
+
+/*
+ * Called by operation service on_operation_notifyError
+ * \sa FmOperationService::on_operation_notifyError
+ */
+void FmOperationResultProcesser::onNotifyError( FmOperationBase* operationBase, int error, const QString &errString )
 {
     Q_UNUSED( errString );
     failAndCloseProgress();
     switch( error )
     {
+        case FmErrCancel:
+            cancelProgress();
+            FmDlgUtils::information( QString( hbTrId("Operation Canceled!") ) );
+            return;
         case FmErrAlreadyStarted:
             FmDlgUtils::information( QString( hbTrId("Operation already started!")) );
             return;
@@ -318,21 +383,20 @@
 
 }
 
-void FmOperationResultProcesser::onNotifyCanceled( FmOperationBase* operationBase )
-{
-    Q_UNUSED( operationBase );
-    cancelProgress();
-    FmDlgUtils::information( QString( hbTrId("Operation Canceled!") ) );
-}
-
-
+/*
+ * Responds to waiting note's cancel signal.
+ */
 void FmOperationResultProcesser::onProgressCancelled()
 {
     mOperationService->cancelOperation();
 }
 
 
-//
+/*
+ * Shows the waiting dialog with 
+ * \a title the title of the dialog.
+ * \a cancelable whether it could be cancelled.
+ */
 void FmOperationResultProcesser::showWaiting( QString title, bool cancelable )
 {
     qDebug("show warning");
@@ -363,6 +427,11 @@
 
 }
 
+/*
+ * Shows the preparing dialog with 
+ * \a title the title of the dialog.
+ * \a cancelable whether it could be cancelled.
+ */
 void FmOperationResultProcesser::showPreparing( QString title, bool cancelable )
 {
     qDebug("show preparing");
@@ -396,6 +465,11 @@
     mNote->open();
 }
 
+/*
+ * Shows the progress dialog with 
+ * \a title the title of the dialog.
+ * \a cancelable whether it could be cancelled.
+ */
 void FmOperationResultProcesser::showProgress( QString title, bool cancelable, int maxValue )
 {
     qDebug("show progress");
@@ -431,12 +505,19 @@
     mNote->open();
 }
 
+/*
+ * Sets the current progress value to be \a value 
+ */
 void FmOperationResultProcesser::setProgress( int value )
 {
     qDebug("set progress");
     if( mNote )
         mNote->setProgressValue( value );
 }
+
+/*
+ * Finishes the progress.
+ */
 void FmOperationResultProcesser::finishProgress()
 {
     qDebug("finish progress");
@@ -445,6 +526,9 @@
     }
 }
 
+/*
+ * Cancels the progress bar.
+ */
 void FmOperationResultProcesser::cancelProgress()
 {
     qDebug("cancel progress");
@@ -453,6 +537,9 @@
     }
 }
 
+/*
+ * Fails and closes the progress bar.
+ */
 void FmOperationResultProcesser::failAndCloseProgress()
 {
     qDebug("fail progress");