filemanager/src/filemanager/src/fmfileview.cpp
changeset 29 b3155376f2b4
parent 24 1d0c87b42e2e
child 30 6e96d2143d46
--- a/filemanager/src/filemanager/src/fmfileview.cpp	Fri Jun 11 13:29:48 2010 +0300
+++ b/filemanager/src/filemanager/src/fmfileview.cpp	Wed Jun 23 18:03:11 2010 +0300
@@ -394,13 +394,15 @@
 {
     int maxFileNameLength = FmUtils::getMaxFileNameLength();
     QString associatedDrive = FmUtils::getDriveLetterFromPath( mWidget->currentPath().absoluteFilePath() );
+    QString path = FmUtils::fillPathWithSplash( mWidget->currentPath().absoluteFilePath() );
+    QString dirName = createDefaultFolderName( path );
     
-    QString dirName( hbTrId( "New folder" ) );
-    QString path = FmUtils::fillPathWithSplash( mWidget->currentPath().absoluteFilePath() );
-    QDir dir( path );
+    QDir dir( path );  
     if( dir.exists() ) {
         while( FmDlgUtils::showTextQuery( hbTrId( "Enter name for " ), dirName,
             true, maxFileNameLength, associatedDrive , false ) ){
+            // remove whitespace from the start and the end.
+            dirName = dirName.trimmed();
             QString newTargetPath = FmUtils::fillPathWithSplash(
                 dir.absolutePath() ) + dirName;
             QFileInfo newFileInfo( newTargetPath );
@@ -510,3 +512,25 @@
 {
     this->setTitle( title );
 }
+
+QString FmFileView::createDefaultFolderName( const QString &path )
+{
+    QString dirBaseName( hbTrId( "New folder" ) );
+    QString dirName( dirBaseName );
+    QString dirAbsolutePath( path + dirName );
+    QFileInfo fileInfo( dirAbsolutePath );
+    int i = 0;    
+    while ( fileInfo.exists() ) {
+        ++i;
+        dirName = dirBaseName;
+        dirName.append( hbTrId("(") );
+        if ( i < 10 ) {
+            dirName.append( hbTrId("0") );                        
+        }
+        dirName.append( QString::number(i) );
+        dirName.append( hbTrId(")") );
+        dirAbsolutePath = path + dirName;
+        fileInfo.setFile( dirAbsolutePath );
+    }
+    return dirName;
+}