filemanager/src/filemanager/src/operationservice/fmoperationmove.cpp
changeset 25 b7bfdea70ca2
parent 16 ada7962b4308
equal deleted inserted replaced
16:ada7962b4308 25:b7bfdea70ca2
    93                         ret = FmErrCannotRemove;
    93                         ret = FmErrCannotRemove;
    94                         break;
    94                         break;
    95                     }
    95                     }
    96                     destFi.setFile( destFi.absoluteFilePath() );
    96                     destFi.setFile( destFi.absoluteFilePath() );
    97                 } else {
    97                 } else {
    98                     emit askForRename( destFi.absoluteFilePath(), &newName );
    98                     queryForRename( destFi.absoluteFilePath(), &newName );
    99                     if( newName.isEmpty() ) {
    99                     if( newName.isEmpty() ) {
   100                         ret = FmErrCancel;
   100                         ret = FmErrCancel;
   101                         break;
   101                         break;
   102                     }
   102                     }
   103                     QString targetName = mTargetPath + newName;
   103                     QString targetName = mTargetPath + newName;
   104                     destFi.setFile( targetName );
   104                     destFi.setFile( targetName );
   105                 }
   105                 }
   106             } else{
   106             } else{
   107                 // destination is dir
   107                 // destination is dir
   108                 emit askForRename( destFi.absoluteFilePath(), &newName );
   108                 queryForRename( destFi.absoluteFilePath(), &newName );
   109                 if( newName.isEmpty() ) {
   109                 if( newName.isEmpty() ) {
   110                     ret = FmErrCancel;
   110                     ret = FmErrCancel;
   111                     break;
   111                     break;
   112                 }
   112                 }
   113                 QString targetName = mTargetPath + newName;
   113                 QString targetName = mTargetPath + newName;
   153         }
   153         }
   154         if( !QFile::remove( source ) ) {
   154         if( !QFile::remove( source ) ) {
   155             *mErrString = source;
   155             *mErrString = source;
   156             ret = FmErrCannotRemove;
   156             ret = FmErrCannotRemove;
   157         }
   157         }
   158         IncreaseProgress( fileSize );
   158         increaseProgress( fileSize );
   159     } else if (fi.isDir()) {
   159     } else if (fi.isDir()) {
   160         if( FmUtils::isDefaultFolder( source ) ){
   160         if( FmUtils::isDefaultFolder( source ) ){
   161             ret = FmErrRemoveDefaultFolder;
   161             ret = FmErrRemoveDefaultFolder;
   162         }
   162         }
   163         else{
   163         else{
   178 
   178 
   179     return ret;
   179     return ret;
   180 }
   180 }
   181 int FmOperationMove::moveDirInsideContent( const QString &srcPath, const QString &destPath )
   181 int FmOperationMove::moveDirInsideContent( const QString &srcPath, const QString &destPath )
   182 {
   182 {
   183     if( destPath.contains( srcPath, Qt::CaseInsensitive ) ) {
   183     QFileInfo srcInfo( srcPath );
       
   184     QFileInfo destInfo( destPath );
       
   185         
       
   186     QString destUpPath = FmUtils::fillPathWithSplash( destInfo.absolutePath() );
       
   187     if( destUpPath.contains( srcPath, Qt::CaseInsensitive ) ) {
   184         *mErrString = destPath;
   188         *mErrString = destPath;
   185         return FmErrMoveDestToSubFolderInSrc;
   189         return FmErrMoveDestToSubFolderInSrc;
   186     }
   190     }
   187 
   191     
   188     QFileInfo srcInfo( srcPath );
       
   189     if( !srcInfo.isDir() || !srcInfo.exists() ) {
   192     if( !srcInfo.isDir() || !srcInfo.exists() ) {
   190         *mErrString = srcPath;
   193         *mErrString = srcPath;
   191         return FmErrSrcPathDoNotExist;
   194         return FmErrSrcPathDoNotExist;
   192     }
   195     }
   193 
   196     
   194     QFileInfo destInfo( destPath );
       
   195     if( !destInfo.exists() ) {
   197     if( !destInfo.exists() ) {
   196         if( !destInfo.dir().mkdir( destInfo.absoluteFilePath() ) ) {
   198         if( !destInfo.dir().mkdir( destInfo.absoluteFilePath() ) ) {
   197             *mErrString = destPath;
   199             *mErrString = destPath;
   198             return FmErrCannotMakeDir;
   200             return FmErrCannotMakeDir;
   199         }
   201         }
   221             }
   223             }
   222             if( !QFile::remove( fileInfo.absoluteFilePath() ) ) {
   224             if( !QFile::remove( fileInfo.absoluteFilePath() ) ) {
   223                 *mErrString = fileInfo.absoluteFilePath();
   225                 *mErrString = fileInfo.absoluteFilePath();
   224                 return FmErrCannotRemove;
   226                 return FmErrCannotRemove;
   225             }
   227             }
   226             IncreaseProgress( fileSize );
   228             increaseProgress( fileSize );
   227         } else if( fileInfo.isDir() ) {
   229         } else if( fileInfo.isDir() ) {
   228             //makedir
   230             //makedir
   229             QString newDirPath = destPath + fileInfo.absoluteFilePath().mid( srcPath.length() );
   231             QString newDirPath = destPath + fileInfo.absoluteFilePath().mid( srcPath.length() );
   230             if( !QDir( newDirPath ).exists() && !QDir( destPath ).mkdir( newDirPath ) ) {
   232             if( !QDir( newDirPath ).exists() && !QDir( destPath ).mkdir( newDirPath ) ) {
   231                 *mErrString = newDirPath;
   233                 *mErrString = newDirPath;
   254     }
   256     }
   255 
   257 
   256     return FmErrNone;
   258     return FmErrNone;
   257 }
   259 }
   258 
   260 
   259 void FmOperationMove::IncreaseProgress( quint64 size )
   261 void FmOperationMove::increaseProgress( quint64 size )
   260 {
   262 {
   261     if( mTotalSize <=0 ) {
   263     if( mTotalSize <=0 ) {
   262         return;
   264         return;
   263     }
   265     }
   264     mMovedSize += size;
   266     mMovedSize += size;
   267         mCurrentStep = step;
   269         mCurrentStep = step;
   268         emit notifyProgress( mCurrentStep );
   270         emit notifyProgress( mCurrentStep );
   269     }
   271     }
   270 }
   272 }
   271 
   273 
   272 
   274 void FmOperationMove::queryForRename( const QString &srcFile, QString *destFile )
       
   275 {
       
   276     emit askForRename( srcFile, destFile );
       
   277 }