Bug 59796 - the suggest renaming could be more intelligent (when you try to copy a file over another one)
Summary: the suggest renaming could be more intelligent (when you try to copy a file o...
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
: 68146 68288 68399 72018 72216 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-06-15 06:09 UTC by Hadacek Nicolas
Modified: 2004-02-16 10:36 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Proposed patch (2.86 KB, patch)
2004-02-13 16:00 UTC, Anna Nymos
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hadacek Nicolas 2003-06-15 06:09:26 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources

in directory "a" you have a file "a.png".
in directory "b" you have files "a.png" and "a_1.png"

when copying or moving the file from directory "a" to "b", a dialog asks for overwriting
or propose some name for renaming. Unfortunately it always propose "a_1.png" even
when it already exists... leading it to ask again for "a_2.png"...

a more usdeful behaviour would be to find the first "a_i.png" which does not exists and to propose that instead.
Comment 1 Stephan Binner 2003-11-15 21:05:44 UTC
*** Bug 68288 has been marked as a duplicate of this bug. ***
Comment 2 Stephan Binner 2003-11-15 21:24:36 UTC
*** Bug 68146 has been marked as a duplicate of this bug. ***
Comment 3 Thiago Macieira 2004-01-07 04:59:54 UTC
*** Bug 72018 has been marked as a duplicate of this bug. ***
Comment 4 Dominique Devriese 2004-01-07 13:49:48 UTC
It's a bit of a corner case, but imho, this is more of a normal bug than a wishlist one.
Comment 5 Thiago Macieira 2004-01-07 16:23:32 UTC
It was a wishlist because it's an unimplemented feature. But name it what you will.
Comment 6 Stephan Binner 2004-01-09 15:12:45 UTC
*** Bug 72216 has been marked as a duplicate of this bug. ***
Comment 7 Anna Nymos 2004-02-13 16:00:36 UTC
Created attachment 4674 [details]
Proposed patch

The patch adds a new helper function which recurses until a non-existent
filename is found.
In addition the suggestion for 'file_' is now 'file_1' and not 'file__1' as it
used to be.

Looking forward to your comments,
Anna
Comment 8 David Faure 2004-02-13 17:04:57 UTC
On Friday 13 February 2004 16:00, Anna Nymos wrote:
> The patch adds a new helper function which recurses until a non-existent
> filename is found.

Thanks for the patch.
The basic idea is good, but it currently only works with local paths,
I'm improving it to work with any URL, patch coming up soon.

Comment 9 David Faure 2004-02-14 12:45:31 UTC
CVS commit by faure: 

Fixed 59796, "the suggest renaming could be more intelligent", based on patch
by Anna Nymos <fnschy-at-yahoo.de>
CCMAIL: 59796-done@bugs.kde.org


  M +38 -27    renamedlg.cpp   1.71


--- kdelibs/kio/kio/renamedlg.cpp  #1.70:1.71
@@ -29,4 +29,5 @@
 #include <qlayout.h>
 #include <qlineedit.h>
+#include <qdir.h>
 
 #include <kmessagebox.h>
@@ -424,15 +425,10 @@ void RenameDlg::b1Pressed()
   done( 1 );
 }
-// Propose button clicked
-void RenameDlg::b8Pressed()
-{
-  int pos;
-
-  /* no name to play with */
-  if ( d->m_pLineEdit->text().isEmpty() )
-    return;
 
-  QString dotSuffix, tmp;
-  QString basename = d->m_pLineEdit->text();
+static QString suggestName(const KURL& baseURL, const QString& oldName)
+{
+        kdDebug() << "suggestName " << baseURL << " oldName=" << oldName << endl;
+  QString dotSuffix, suggestedName;
+  QString basename = oldName;
 
   int index = basename.find( '.' );
@@ -440,32 +436,47 @@ void RenameDlg::b8Pressed()
     dotSuffix = basename.mid( index );
     basename.truncate( index );
-  } else
-    dotSuffix = QString::null;
+  }
   
-  pos = basename.findRev('_' );
+  int pos = basename.findRev( '_' );
   if(pos != -1 ){
+    QString tmp = basename.mid( pos+1 );
     bool ok;
-    tmp = basename.right( basename.length() - (pos + 1) );
-    int number = tmp.toInt( &ok, 10 );
+    int number = tmp.toInt( &ok );
     if ( !ok ) {// ok there is no number
-      basename.append("_1" );
-      d->m_pLineEdit->setText(basename + dotSuffix );
-      return;
+      suggestedName = basename + "1" + dotSuffix;
     }
     else {
      // yes there's already a number behind the _ so increment it by one
-      QString tmp2 = QString::number ( number + 1 );
-      basename.replace( pos+1, tmp.length() ,tmp2);
-      d->m_pLineEdit->setText( basename + dotSuffix );
-      return;
+      basename.replace( pos+1, tmp.length(), QString::number(number+1) );
+      suggestedName = basename + dotSuffix;
     }
   }
   else // no underscore yet
-  {
-    d->m_pLineEdit->setText( basename + "_1" + dotSuffix );
+    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 );
+}
+
+// Propose button clicked
+void RenameDlg::b8Pressed()
+{
+  /* no name to play with */
+  if ( d->m_pLineEdit->text().isEmpty() )
     return;
 
-  }
-  return; // we should never return from here jic
+  KURL destDirectory( d->dest );
+  destDirectory.setPath( destDirectory.directory() );
+  d->m_pLineEdit->setText( suggestName( destDirectory, d->m_pLineEdit->text() ) );
+  return;
 }
 


Comment 10 Michael Goffioul 2004-02-16 10:36:26 UTC
*** Bug 68399 has been marked as a duplicate of this bug. ***