filemanager/src/filemanager/src/fmfilebrowsewidget.cpp
changeset 29 b3155376f2b4
parent 24 1d0c87b42e2e
child 30 6e96d2143d46
equal deleted inserted replaced
24:1d0c87b42e2e 29:b3155376f2b4
   686 void FmFileBrowseWidget::on_renameAction_triggered()
   686 void FmFileBrowseWidget::on_renameAction_triggered()
   687 {
   687 {
   688     QString filePath = mModel->filePath( mCurrentItem->modelIndex() );
   688     QString filePath = mModel->filePath( mCurrentItem->modelIndex() );
   689     QFileInfo fileInfo = mModel->fileInfo( mCurrentItem->modelIndex() );
   689     QFileInfo fileInfo = mModel->fileInfo( mCurrentItem->modelIndex() );
   690     int maxFileNameLength = FmUtils::getMaxFileNameLength();
   690     int maxFileNameLength = FmUtils::getMaxFileNameLength();
   691     
   691     QString oldSuffix( fileInfo.suffix() );
   692     QString newName( fileInfo.fileName() );
   692     QString newName( fileInfo.fileName() );
   693     while( FmDlgUtils::showTextQuery( hbTrId( "Enter new name for %1" ).arg( newName ), newName, true,
   693     while( FmDlgUtils::showTextQuery( hbTrId( "Enter new name for %1" ).arg( newName ), newName, true,
   694             maxFileNameLength, QString() , true ) ){
   694             maxFileNameLength, QString() , true ) ){
       
   695         // remove whitespace from the start and the end.
       
   696         newName = newName.trimmed();
   695         QString newTargetPath = FmUtils::fillPathWithSplash(
   697         QString newTargetPath = FmUtils::fillPathWithSplash(
   696             fileInfo.absolutePath() ) + newName;
   698             fileInfo.absolutePath() ) + newName;
   697         QFileInfo newFileInfo( newTargetPath );
   699         QFileInfo newFileInfo( newTargetPath );
   698 		if( !FmUtils::checkFolderFileName( newName ) ) {
   700 		if( !FmUtils::checkFolderFileName( newName ) ) {
   699             FmDlgUtils::information( hbTrId( "Invalid file or folder name!" ) );
   701             FmDlgUtils::information( hbTrId( "Invalid file or folder name!" ) );
   709         }
   711         }
   710 
   712 
   711         if( !rename( fileInfo.absoluteFilePath(), newTargetPath ) ) {
   713         if( !rename( fileInfo.absoluteFilePath(), newTargetPath ) ) {
   712             FmDlgUtils::information( hbTrId("Rename failed!") );
   714             FmDlgUtils::information( hbTrId("Rename failed!") );
   713         }
   715         }
       
   716         else {
       
   717             QString newSuffix( newFileInfo.suffix() );
       
   718             if ( oldSuffix != newSuffix ) {
       
   719                 FmDlgUtils::information( hbTrId( "File may become unusable when file name extension is changed" ) );        
       
   720             }   
       
   721         }
   714         break;
   722         break;
   715     }   
   723     }
   716 }
   724 }