コード例 #1
0
///@todo change this implementation to something nativ, not using system()
bool ImageImporter::copy_file(const QString& src, const QString& dest)
{
    QString call = QString("cp \"%1\" \"%2\"").arg(src).arg(dest);
    system(call);

    QFileInfo srcFi(src);
    QFileInfo destFi(dest);
    return (srcFi.exists() && destFi.exists());
}
コード例 #2
0
/*
 * Starts the operation.
 * \a isStopped flag the outside stop operation
 */
void FmOperationCopyOrMove::start( volatile bool *isStopped )
{
    mStop = isStopped; 
    mTotalSize   = 0;
    mCopiedOrMovedSize  = 0;
    mCurrentStep = 0;

    if ( mSourceList.empty() ) {
        emit notifyError( FmErrWrongParam, mErrString );    
        return ;
    }
	emit notifyPreparing( true );

    int numofFolders = 0;
    int numofFiles      = 0;

    int ret = FmFolderDetails::queryDetailOfContentList( mSourceList, numofFolders, 
        numofFiles, mTotalSize, mStop, true );
    if( ret != FmErrNone ) {
        emit notifyError( ret, mErrString );
        return;        
    }    
    if ( !targetHasEnoughSpace() ) {
        emit notifyError( FmErrDiskFull, mErrString );
        return;
        }    
    emit notifyStart( true, mTotalSteps );

    foreach( const QString& source, mSourceList ) {
        // formatPath, but do not append splash in the end
        // Otherwise could not get fileName in QFileInfo::fileName
        QString checkedSource( FmUtils::formatPath( source ) );
        QFileInfo fi( checkedSource );
        if( !fi.exists() ) {
            mErrString = checkedSource;   
            emit driveSpaceChanged();
            emit notifyError( FmErrSrcPathDoNotExist, mErrString );
            return;
        }
        QString newName;
        bool    isAcceptReplace = false;
        QFileInfo destFi( mTargetPath + fi.fileName() );

        // while for duplicated file/dir
        while( destFi.exists() ) {
            if( destFi.isFile() && destFi.absoluteFilePath().compare( fi.absoluteFilePath(), Qt::CaseInsensitive ) != 0 ) {
                emit askForReplace( destFi.absoluteFilePath(), fi.absoluteFilePath(), &isAcceptReplace );
                if( isAcceptReplace ) {
                    //delete src file
                    if( !QFile::remove( destFi.absoluteFilePath() ) ) {
                        mErrString = destFi.absoluteFilePath();
                        ret = FmErrCannotRemove;
                        break;
                    }
                    destFi.setFile( destFi.absoluteFilePath() );
                } else {
                    queryForRename( destFi.absoluteFilePath(), &newName );
                    if( newName.isEmpty() ) {
                        ret = FmErrCancel;
                        break;
                    }
                    QString targetName = mTargetPath + newName;
                    destFi.setFile( targetName );
                }
            } else{
                // destination is dir
                queryForRename( destFi.absoluteFilePath(), &newName );
                if( newName.isEmpty() ) {
                    ret = FmErrCancel;
                    break;
                }
                QString targetName = mTargetPath + newName;
                destFi.setFile( targetName );
            }
        }
        if( ret != FmErrNone ) {
            // 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();
            emit notifyError( ret, mErrString );
            return;
        }
        ret = copyOrMove( checkedSource, mTargetPath, newName );
        if( ret != FmErrNone ) {
            emit driveSpaceChanged();
            emit notifyError( ret, mErrString );            
            return;
        }
    }