filemanager/src/filemanager/src/fmfileview.cpp
changeset 29 b3155376f2b4
parent 24 1d0c87b42e2e
child 30 6e96d2143d46
equal deleted inserted replaced
24:1d0c87b42e2e 29:b3155376f2b4
   392 
   392 
   393 void FmFileView::on_newFolder_triggered()
   393 void FmFileView::on_newFolder_triggered()
   394 {
   394 {
   395     int maxFileNameLength = FmUtils::getMaxFileNameLength();
   395     int maxFileNameLength = FmUtils::getMaxFileNameLength();
   396     QString associatedDrive = FmUtils::getDriveLetterFromPath( mWidget->currentPath().absoluteFilePath() );
   396     QString associatedDrive = FmUtils::getDriveLetterFromPath( mWidget->currentPath().absoluteFilePath() );
   397     
       
   398     QString dirName( hbTrId( "New folder" ) );
       
   399     QString path = FmUtils::fillPathWithSplash( mWidget->currentPath().absoluteFilePath() );
   397     QString path = FmUtils::fillPathWithSplash( mWidget->currentPath().absoluteFilePath() );
   400     QDir dir( path );
   398     QString dirName = createDefaultFolderName( path );
       
   399     
       
   400     QDir dir( path );  
   401     if( dir.exists() ) {
   401     if( dir.exists() ) {
   402         while( FmDlgUtils::showTextQuery( hbTrId( "Enter name for " ), dirName,
   402         while( FmDlgUtils::showTextQuery( hbTrId( "Enter name for " ), dirName,
   403             true, maxFileNameLength, associatedDrive , false ) ){
   403             true, maxFileNameLength, associatedDrive , false ) ){
       
   404             // remove whitespace from the start and the end.
       
   405             dirName = dirName.trimmed();
   404             QString newTargetPath = FmUtils::fillPathWithSplash(
   406             QString newTargetPath = FmUtils::fillPathWithSplash(
   405                 dir.absolutePath() ) + dirName;
   407                 dir.absolutePath() ) + dirName;
   406             QFileInfo newFileInfo( newTargetPath );
   408             QFileInfo newFileInfo( newTargetPath );
   407             if( !FmUtils::checkFolderFileName( dirName ) ) {
   409             if( !FmUtils::checkFolderFileName( dirName ) ) {
   408                 FmDlgUtils::information( hbTrId( "Invalid file or folder name!" ) );
   410                 FmDlgUtils::information( hbTrId( "Invalid file or folder name!" ) );
   508 
   510 
   509 void FmFileView::on_mainWidget_setTitle( const QString &title )
   511 void FmFileView::on_mainWidget_setTitle( const QString &title )
   510 {
   512 {
   511     this->setTitle( title );
   513     this->setTitle( title );
   512 }
   514 }
       
   515 
       
   516 QString FmFileView::createDefaultFolderName( const QString &path )
       
   517 {
       
   518     QString dirBaseName( hbTrId( "New folder" ) );
       
   519     QString dirName( dirBaseName );
       
   520     QString dirAbsolutePath( path + dirName );
       
   521     QFileInfo fileInfo( dirAbsolutePath );
       
   522     int i = 0;    
       
   523     while ( fileInfo.exists() ) {
       
   524         ++i;
       
   525         dirName = dirBaseName;
       
   526         dirName.append( hbTrId("(") );
       
   527         if ( i < 10 ) {
       
   528             dirName.append( hbTrId("0") );                        
       
   529         }
       
   530         dirName.append( QString::number(i) );
       
   531         dirName.append( hbTrId(")") );
       
   532         dirAbsolutePath = path + dirName;
       
   533         fileInfo.setFile( dirAbsolutePath );
       
   534     }
       
   535     return dirName;
       
   536 }