filemanager/src/filemanager/src/operationservice/fmoperationresultprocesser.cpp
changeset 25 b7bfdea70ca2
parent 16 ada7962b4308
child 27 df183af6b92f
equal deleted inserted replaced
16:ada7962b4308 25:b7bfdea70ca2
    19 #include "fmoperationservice.h"
    19 #include "fmoperationservice.h"
    20 #include "fmoperationformat.h"
    20 #include "fmoperationformat.h"
    21 #include "fmviewdetailsdialog.h"
    21 #include "fmviewdetailsdialog.h"
    22 #include "fmdlgutils.h"
    22 #include "fmdlgutils.h"
    23 #include "fmutils.h"
    23 #include "fmutils.h"
    24 
    24 #include <hbaction.h>
    25 #include <hbprogressdialog.h>
    25 #include <hbprogressdialog.h>
    26 #include <hbaction.h>
    26 #include <hbaction.h>
    27 #include <hbmessagebox.h>
    27 #include <hbglobal.h>
       
    28 #include <QFileInfo>
    28 
    29 
    29 FmOperationResultProcesser::FmOperationResultProcesser( FmOperationService *operationService )
    30 FmOperationResultProcesser::FmOperationResultProcesser( FmOperationService *operationService )
    30     : mOperationService( operationService ), mNote( 0 )
    31     : mOperationService( operationService ), mNote( 0 )
    31 {
    32 {
    32 }
    33 }
    37 
    38 
    38 void FmOperationResultProcesser::onAskForRename(
    39 void FmOperationResultProcesser::onAskForRename(
    39     FmOperationBase* operationBase, const QString &srcFile, QString *destFile )
    40     FmOperationBase* operationBase, const QString &srcFile, QString *destFile )
    40 {
    41 {
    41     Q_UNUSED( operationBase );
    42     Q_UNUSED( operationBase );
       
    43     int maxFileNameLength = FmUtils::getMaxFileNameLength();
    42     
    44     
    43     QString questionText = QString( "file " ) +
    45     QString questionText = QString( "file " ) +
    44         srcFile + QString( " already exist, please rename:" );
    46         srcFile + QString( " already exist, please rename:" );
    45     QString value;
    47     QString value;   
    46     FmDlgUtils::showTextQuery( questionText, value, true );
    48     QFileInfo fileInfo(srcFile);
    47     *destFile = value;
    49     bool ret = FmDlgUtils::showTextQuery( questionText, value, true, maxFileNameLength, QString(), false );
       
    50     while ( ret ) {
       
    51         // remove whitespace from the start and the end.
       
    52         value = value.trimmed();
       
    53         QString newTargetPath = FmUtils::fillPathWithSplash(
       
    54                                 fileInfo.absolutePath() ) + value;
       
    55         QString errString;
       
    56         // check if name/path is available for use.
       
    57         if( !FmUtils::checkNewFolderOrFile( newTargetPath, errString ) ) {
       
    58             FmDlgUtils::information( errString );
       
    59             ret = FmDlgUtils::showTextQuery( questionText, value, true, maxFileNameLength, QString(), false );
       
    60             continue;
       
    61         } else {
       
    62             break;
       
    63         }
       
    64     }   
       
    65 	if( ret ) {
       
    66 		*destFile = value;
       
    67 	}
    48 }
    68 }
    49 
    69 
    50 void FmOperationResultProcesser::onAskForReplace(
    70 void FmOperationResultProcesser::onAskForReplace(
    51     FmOperationBase* operationBase, const QString &srcFile, const QString &destFile, bool *isAccepted )
    71     FmOperationBase* operationBase, const QString &srcFile, const QString &destFile, bool *isAccepted )
    52 {
    72 {
    53     Q_UNUSED( operationBase );
    73     Q_UNUSED( operationBase );
    54     Q_UNUSED( destFile );
    74     Q_UNUSED( destFile );
    55     
    75     
    56     QString questionText = QString( "file " ) +
    76     QString questionText = QString( "file " ) +
    57         srcFile + QString( " already exist, replace it?" );
    77         srcFile + QString( " already exist, replace it?" );
    58     if( HbMessageBox::question( questionText ) ) {
    78     if( FmDlgUtils::question( questionText ) ) {
    59         *isAccepted = true;
    79         *isAccepted = true;
    60     } else {
    80     } else {
    61         *isAccepted = false;
    81         *isAccepted = false;
    62     }
    82     }
    63 }
    83 }
    64 
    84 
       
    85 void FmOperationResultProcesser::onShowNote( FmOperationBase* operationBase, const char *noteString )
       
    86 {
       
    87     FmDlgUtils::information(hbTrId(noteString));
       
    88 }
       
    89 
    65 void FmOperationResultProcesser::onNotifyWaiting( FmOperationBase* operationBase, bool cancelable )
    90 void FmOperationResultProcesser::onNotifyWaiting( FmOperationBase* operationBase, bool cancelable )
    66 {
    91 {
    67     QString title = tr("Operation");
    92     QString title = hbTrId("Operation");
    68     switch( operationBase->operationType() )
    93     switch( operationBase->operationType() )
    69     {
    94     {
    70     case FmOperationService::EOperationTypeBackup:
    95     case FmOperationService::EOperationTypeBackup:
    71         title = hbTrId("backuping");
    96         title = hbTrId("backuping");
    72         break;
    97         break;
   117     showPreparing( title, cancelable );
   142     showPreparing( title, cancelable );
   118 }
   143 }
   119 
   144 
   120 void FmOperationResultProcesser::onNotifyStart( FmOperationBase* operationBase, bool cancelable, int maxSteps )
   145 void FmOperationResultProcesser::onNotifyStart( FmOperationBase* operationBase, bool cancelable, int maxSteps )
   121 {
   146 {
   122     QString title = tr("Operation");
   147     QString title = hbTrId("Operation");
   123     switch( operationBase->operationType() )
   148     switch( operationBase->operationType() )
   124     {
   149     {
   125     case FmOperationService::EOperationTypeBackup:
   150     case FmOperationService::EOperationTypeBackup:
   126         title = hbTrId("backup...");
   151         title = hbTrId("backup...");
   127         break;
   152         break;
   177 				FmUtils::getDriveLetterFromPath( paramFolderDetails->folderPath() ) );
   202 				FmUtils::getDriveLetterFromPath( paramFolderDetails->folderPath() ) );
   178             break;
   203             break;
   179         }
   204         }
   180     case FmOperationService::EOperationTypeFormat:
   205     case FmOperationService::EOperationTypeFormat:
   181         {
   206         {
   182             HbMessageBox::information( QString( hbTrId("Format succeed!")) );
   207             FmDlgUtils::information( QString( hbTrId("Format succeed!")) );
   183             FmOperationFormat *paramFormat = static_cast<FmOperationFormat*>( operationBase );
   208             FmOperationFormat *paramFormat = static_cast<FmOperationFormat*>( operationBase );
   184             QString title( tr( "Drive name ") );  
   209             QString title( hbTrId( "Drive name ") );  
   185             QString driveName( paramFormat->driverName() );
   210             QString driveName( paramFormat->driverName() );
   186             QString volumeName;
   211             FmDriverInfo driverInfo = FmUtils::queryDriverInfo( driveName );
   187             while( FmDlgUtils::showTextQuery( title, volumeName, false, FmMaxLengthofDriveName ) ){
   212             FmDriverInfo::DriveState state = driverInfo.driveState();
       
   213             if( ( state & FmDriverInfo::EDriveAvailable ) &&
       
   214                 ( state & FmDriverInfo::EDriveRemovable ) &&
       
   215                 !( state & FmDriverInfo::EDriveMassStorage ) ) { 
       
   216                 QString volumeName;
       
   217                 while( FmDlgUtils::showTextQuery( title, volumeName, false, FmMaxLengthofDriveName ) ){
   188                     int err = FmUtils::renameDrive( driveName, volumeName );
   218                     int err = FmUtils::renameDrive( driveName, volumeName );
   189                     if ( err == FmErrNone ){
   219                     if ( err == FmErrNone ){
   190                         HbMessageBox::information( hbTrId( "The name has been changed!" ) );
   220                         FmDlgUtils::information( hbTrId( "The name has been changed!" ) );
   191                         mOperationService->on_operationThread_refreshModel( driveName );
   221                         mOperationService->on_operationThread_refreshModel( driveName );
   192                         break;
   222                         break;
   193                     } else if( err == FmErrBadName ) {
   223                     } else if( err == FmErrBadName ) {
   194                         HbMessageBox::information( hbTrId( "Illegal characters! Use only letters and numbers." ) );
   224                         FmDlgUtils::information( hbTrId( "Illegal characters! Use only letters and numbers." ) );
   195                     } else{
   225                     } else{
   196                         HbMessageBox::information( hbTrId( "Error occurred, operation cancelled!" ) );
   226                         FmDlgUtils::information( hbTrId( "Error occurred, operation cancelled!" ) );
   197                         break;
   227                         break;
   198                     }                
   228                     }                
   199                 }
   229                 }
       
   230             }
   200             break;
   231             break;
   201         }
   232         }
   202     case FmOperationService::EOperationTypeBackup:
   233     case FmOperationService::EOperationTypeBackup:
   203         {
   234         {
   204             HbMessageBox::information( QString( hbTrId("Backup succeed!")) );
   235             FmDlgUtils::information( QString( hbTrId("Backup succeed!")) );
   205             break;
   236             break;
   206         }
   237         }
   207     case FmOperationService::EOperationTypeRestore:
   238     case FmOperationService::EOperationTypeRestore:
   208         {
   239         {
   209             HbMessageBox::information( QString( hbTrId("Restore succeed!")) );
   240             FmDlgUtils::information( QString( hbTrId("Restore succeed!")) );
   210             break;
   241             break;
   211         }
   242         }
   212     default:
   243     default:
   213         HbMessageBox::information( QString( hbTrId("Operation finished")) );
   244         FmDlgUtils::information( QString( hbTrId("Operation finished")) );
   214 
   245 
   215     }
   246     }
   216 }
   247 }
   217 void FmOperationResultProcesser::onNotifyError( FmOperationBase* operationBase, int error, QString errString )
   248 void FmOperationResultProcesser::onNotifyError( FmOperationBase* operationBase, int error, QString errString )
   218 {
   249 {
   219     Q_UNUSED( errString );
   250     Q_UNUSED( errString );
   220     failAndCloseProgress();
   251     failAndCloseProgress();
   221     switch( error )
   252     switch( error )
   222     {
   253     {
   223         case FmErrAlreadyStarted:
   254         case FmErrAlreadyStarted:
   224             HbMessageBox::information( QString( hbTrId("Operation already started!")) );
   255             FmDlgUtils::information( QString( hbTrId("Operation already started!")) );
       
   256             return;
       
   257         case FmErrLocked:
       
   258             FmDlgUtils::information( QString( hbTrId("Operation failed because drive is locked!")) );
       
   259             return;
       
   260         case FmErrPathNotFound:
       
   261             FmDlgUtils::information( QString( hbTrId("Operation failed because can not find target path or drive is not available!") ) );
       
   262             return;
       
   263         case FmErrCorrupt:
       
   264             FmDlgUtils::information( QString( hbTrId("Operation failed because target media is corrupted!") ) );
       
   265             return;
       
   266         case FmErrNotReady: // Caused when MMC & OTG is not inserted when start backup
       
   267             FmDlgUtils::information( QString( hbTrId("Operation failed because device is not ready!") ) );
       
   268             return;
       
   269         case FmErrDisMounted: // Caused by eject MMC when preparing backup
       
   270             FmDlgUtils::information( QString( hbTrId("Operation failed because device has been removed!") ) );
   225             return;
   271             return;
   226         case FmErrDiskFull:
   272         case FmErrDiskFull:
   227             HbMessageBox::information( QString( hbTrId("Not enough space. Operation cancelled.!")) );
   273             FmDlgUtils::information( QString( hbTrId("Not enough space. Operation cancelled!")) );
   228             return;
   274             return;
   229         case FmErrCopyDestToSubFolderInSrc:
   275         case FmErrCopyDestToSubFolderInSrc:
   230             HbMessageBox::information( QString( hbTrId("Can not copy to sub folder!")) );
   276             FmDlgUtils::information( QString( hbTrId("Can not copy to sub folder!")) );
   231             return;
   277             return;
   232         case FmErrMoveDestToSubFolderInSrc:
   278         case FmErrMoveDestToSubFolderInSrc:
   233             HbMessageBox::information( QString( hbTrId("Can not move to sub folder!")) );
   279             FmDlgUtils::information( QString( hbTrId("Can not move to sub folder!")) );
   234             return;
   280             return;
   235         case FmErrCannotRemove:{
   281         case FmErrCannotRemove:{
   236             if( operationBase->operationType() == FmOperationService::EOperationTypeCopy ) {
   282             if( operationBase->operationType() == FmOperationService::EOperationTypeCopy ) {
   237                 // when copy a file/dir to same name destination, and delete dest fail, this error will occur
   283                 // when copy a file/dir to same name destination, and delete dest fail, this error will occur
   238                 HbMessageBox::information( QString( hbTrId( "Can not copy because %1 can not be deleted!" ).arg( errString ) ) );
   284                 FmDlgUtils::information( QString( hbTrId( "Can not copy because %1 can not be deleted!" ).arg( errString ) ) );
   239                 return;
   285                 return;
   240             }
   286             }
   241             else if( operationBase->operationType() == FmOperationService::EOperationTypeMove ) {
   287             else if( operationBase->operationType() == FmOperationService::EOperationTypeMove ) {
   242                 // when move a file/dir to same name destination, and delete dest fail, this error will occur
   288                 // when move a file/dir to same name destination, and delete dest fail, this error will occur
   243                 HbMessageBox::information( QString( hbTrId( "Can not move because %1 can not be deleted!" ).arg( errString ) ) );
   289                 FmDlgUtils::information( QString( hbTrId( "Can not move because %1 can not be deleted!" ).arg( errString ) ) );
   244                 return;
   290                 return;
   245             }
   291             }
   246             // when delete file/dir fail, this error will occur
   292             // when delete file/dir fail, this error will occur
   247             HbMessageBox::information( QString( hbTrId( "Can not delete %1!" ).arg( errString ) ) );
   293             FmDlgUtils::information( QString( hbTrId( "Can not delete %1!" ).arg( errString ) ) );
   248             return; 
   294             return; 
   249         }      
   295         }      
   250         case FmErrRemoveDefaultFolder:{
   296         case FmErrRemoveDefaultFolder:{
   251             if( operationBase->operationType() == FmOperationService::EOperationTypeMove ) {
   297             if( operationBase->operationType() == FmOperationService::EOperationTypeMove ) {
   252                 // when move a default folder
   298                 // when move a default folder
   253                 HbMessageBox::information( QString( hbTrId( "Could not move because the default folder %1 can not be deleted!" ).arg( errString ) ) );
   299                 FmDlgUtils::information( QString( hbTrId( "Could not move because the default folder %1 can not be deleted!" ).arg( errString ) ) );
   254                 return;
   300                 return;
   255             }
   301             }
   256             else {
   302             else {
   257                // when delete the default folder
   303                // when delete the default folder
   258                HbMessageBox::information( QString( hbTrId( "Could not remove the default folder %1 " ).arg( errString ) ) );
   304                FmDlgUtils::information( QString( hbTrId( "Could not remove the default folder %1 " ).arg( errString ) ) );
   259                return;
   305                return;
   260             }
   306             }
   261         }
   307         }
   262     }
   308     }
   263 
   309 
   264     switch( operationBase->operationType() )
   310     switch( operationBase->operationType() )
   265     {
   311     {
   266     case FmOperationService::EOperationTypeFormat:
   312     case FmOperationService::EOperationTypeFormat:
   267         HbMessageBox::information( QString( hbTrId("Format failed!")) );
   313         FmDlgUtils::information( QString( hbTrId("Format failed!")) );
   268         break;
   314         break;
   269     default:
   315     default:
   270         HbMessageBox::information( QString( hbTrId("Operation failed")) );
   316         FmDlgUtils::information( QString( hbTrId("Operation failed")) );
   271     }
   317     }
   272 
   318 
   273 }
   319 }
   274 
   320 
   275 void FmOperationResultProcesser::onNotifyCanceled( FmOperationBase* operationBase )
   321 void FmOperationResultProcesser::onNotifyCanceled( FmOperationBase* operationBase )
   276 {
   322 {
   277     Q_UNUSED( operationBase );
   323     Q_UNUSED( operationBase );
   278     cancelProgress();
   324     cancelProgress();
   279     HbMessageBox::information( QString( hbTrId("Operation Canceled!") ) );
   325     FmDlgUtils::information( QString( hbTrId("Operation Canceled!") ) );
   280 }
   326 }
   281 
   327 
   282 
   328 
   283 void FmOperationResultProcesser::onProgressCancelled()
   329 void FmOperationResultProcesser::onProgressCancelled()
   284 {
   330 {
   302 //        connect( mNote, SIGNAL( cancelled() ), this, SLOT(onProgressCancelled() ) );
   348 //        connect( mNote, SIGNAL( cancelled() ), this, SLOT(onProgressCancelled() ) );
   303 //    } else {
   349 //    } else {
   304 //        mNote->setProgressDialogType( HbProgressDialog::WaitNote );
   350 //        mNote->setProgressDialogType( HbProgressDialog::WaitNote );
   305 //    }
   351 //    }
   306     mNote->setText( title );
   352     mNote->setText( title );
   307     if( !cancelable )
   353     QList<QAction *> actionList = mNote->actions();
   308         mNote->primaryAction()->setDisabled( true );
   354     if (actionList.size() > 0) {        
   309     else
   355         QAction *cancelAction = actionList.at(0);
   310         mNote->primaryAction()->setDisabled( false );
   356         if (!cancelable) {
   311     mNote->exec();
   357             cancelAction->setDisabled( true );
       
   358         } else {
       
   359             cancelAction->setDisabled( false );
       
   360         }        
       
   361     } 
       
   362     mNote->open();
   312 
   363 
   313 }
   364 }
   314 
   365 
   315 void FmOperationResultProcesser::showPreparing( QString title, bool cancelable )
   366 void FmOperationResultProcesser::showPreparing( QString title, bool cancelable )
   316 {
   367 {
   331 //    }
   382 //    }
   332     mNote->setMinimum(0);
   383     mNote->setMinimum(0);
   333     mNote->setMaximum( 65535 );
   384     mNote->setMaximum( 65535 );
   334     mNote->setProgressValue( 0 );
   385     mNote->setProgressValue( 0 );
   335     mNote->setText( title );
   386     mNote->setText( title );
   336     if( !cancelable ){
   387     QList<QAction *> actionList = mNote->actions();
   337         mNote->primaryAction()->setDisabled( true );  
   388     if (actionList.size() > 0) {        
   338     }
   389         QAction *cancelAction = actionList.at(0);
   339     else{
   390         if (!cancelable) {
   340         mNote->primaryAction()->setDisabled( false );       
   391             cancelAction->setDisabled( true );
   341     }
   392         } else {
   342     mNote->exec();
   393             cancelAction->setDisabled( false );
       
   394         }        
       
   395     } 
       
   396     mNote->open();
   343 }
   397 }
   344 
   398 
   345 void FmOperationResultProcesser::showProgress( QString title, bool cancelable, int maxValue )
   399 void FmOperationResultProcesser::showProgress( QString title, bool cancelable, int maxValue )
   346 {
   400 {
   347     qDebug("show progress");
   401     qDebug("show progress");
   363 
   417 
   364     mNote->setMinimum(0);
   418     mNote->setMinimum(0);
   365     mNote->setMaximum( maxValue );
   419     mNote->setMaximum( maxValue );
   366 
   420 
   367     mNote->setProgressValue( 0 );
   421     mNote->setProgressValue( 0 );
   368 
   422     QList<QAction *> actionList = mNote->actions();
   369     if( !cancelable ){
   423     if (actionList.size() > 0) {        
   370         mNote->primaryAction()->setDisabled( true );
   424         QAction *cancelAction = actionList.at(0);
   371     }
   425         if(!cancelable) {
   372     else{
   426             cancelAction->setDisabled( true );
   373         mNote->primaryAction()->setDisabled( false );
   427         } else {
   374     }
   428             cancelAction->setDisabled( false );
   375 
   429         }        
   376     mNote->exec();
   430     } 
       
   431     mNote->open();
   377 }
   432 }
   378 
   433 
   379 void FmOperationResultProcesser::setProgress( int value )
   434 void FmOperationResultProcesser::setProgress( int value )
   380 {
   435 {
   381     qDebug("set progress");
   436     qDebug("set progress");