[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdebase/libkonq
From:       Stephan Binner <binner () kde ! org>
Date:       2005-01-08 15:45:11
Message-ID: 20050108154511.BA4E219D27 () office ! kde ! org
[Download RAW message or body]

CVS commit by binner: 

Use new public RenameDlg::suggestName()


  M +3 -44     knewmenu.cc   1.100
  M +3 -15     konq_operations.cc   1.157


--- kdebase/libkonq/knewmenu.cc  #1.99:1.100
@@ -33,4 +33,5 @@
 
 #include <kio/job.h>
+#include <kio/renamedlg.h>
 
 #include <kpropertiesdialog.h>
@@ -348,46 +349,4 @@ void KNewMenu::slotNewDir()
 }
 
-// copied from kdelibs/kio/kio/renamedlg.cpp
-static QString suggestName(const KURL& baseURL, const QString& oldName)
-{
-  QString dotSuffix, suggestedName;
-  QString basename = oldName;
-
-  int index = basename.find( '.' );
-  if ( index != -1 ) {
-    dotSuffix = basename.mid( index );
-    basename.truncate( index );
-  }
-
-  int pos = basename.findRev( '_' );
-  if(pos != -1 ){
-    QString tmp = basename.mid( pos+1 );
-    bool ok;
-    int number = tmp.toInt( &ok );
-    if ( !ok ) {// ok there is no number
-      suggestedName = basename + "1" + dotSuffix;
-    }
-    else {
-     // yes there's already a number behind the _ so increment it by one
-      basename.replace( pos+1, tmp.length(), QString::number(number+1) );
-      suggestedName = basename + dotSuffix;
-    }
-  }
-  else // no underscore yet
-    suggestedName = basename + "_1" + dotSuffix ;
-
-  // Check if suggested name already exists
-  bool exists = false;
-  // TODO: network transparency. However, using NetAccess from a modal dialog
-  // could be a problem, no? (given that it uses a modal widget itself....)
-  if ( baseURL.isLocalFile() )
-     exists = QFileInfo( baseURL.path(+1) + suggestedName ).exists();
-
-  if ( !exists )
-    return suggestedName;
-  else // already exists -> recurse
-    return suggestName( baseURL, suggestedName );
-}
-
 void KNewMenu::slotNewFile()
 {
@@ -448,5 +407,5 @@ void KNewMenu::slotNewFile()
                 defaultFile.addPath( KIO::encodeFileName( text ) );
                 if ( defaultFile.isLocalFile() && QFile::exists( defaultFile.path() ) )
-                    text = suggestName( *it, text);
+                    text = KIO::RenameDlg::suggestName( *it, text);
 
                 KURL templateURL;
@@ -468,5 +427,5 @@ void KNewMenu::slotNewFile()
         defaultFile.addPath( KIO::encodeFileName( text ) );
         if ( defaultFile.isLocalFile() && QFile::exists( defaultFile.path() ) )
-            text = suggestName( *(popupFiles.begin()), text);
+            text = KIO::RenameDlg::suggestName( *(popupFiles.begin()), text);
 
         name = KInputDialog::getText( QString::null, entry.comment,

--- kdebase/libkonq/konq_operations.cc  #1.156:1.157
@@ -50,4 +50,5 @@
 #include <kio/paste.h>
 #include <kio/netaccess.h>
+#include <kio/renamedlg.h>
 #include <konq_drag.h>
 #include <konq_iconviewwidget.h>
@@ -749,19 +750,6 @@ void KonqOperations::newDir( QWidget * p
     bool ok;
     QString name = i18n( "New Folder" );
-    if (baseURL.isLocalFile())
-    {
-       QString base = name;
-       int n = 2;
-       while(true)
-       {
-          KURL url=baseURL;
-          url.addPath( name );
-
-          if (access(QFile::encodeName(url.path()), F_OK) == -1)
-             break;
-
-          name = base + QString("_%1").arg(n++);
-       }
-    }
+    if ( baseURL.isLocalFile() && QFileInfo( baseURL.path(+1) + name ).exists() )
+        name = KIO::RenameDlg::suggestName( baseURL, i18n( "New Folder" ) );
 
     name = KInputDialog::getText ( i18n( "New Folder" ),


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic