<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>59796</bug_id>
          
          <creation_ts>2003-06-15 06:09:26 +0000</creation_ts>
          <short_desc>the suggest renaming could be more intelligent (when you try to copy a file over another one)</short_desc>
          <delta_ts>2004-02-16 10:36:26 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>10</classification_id>
          <classification>Unmaintained</classification>
          <product>kio</product>
          <component>general</component>
          <version>unspecified</version>
          <rep_platform>Compiled Sources</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Hadacek Nicolas">hadacek</reporter>
          <assigned_to name="David Faure">faure</assigned_to>
          <cc>devriese</cc>
    
    <cc>fnschy</cc>
    
    <cc>jeremyhu</cc>
    
    <cc>kossebau</cc>
    
    <cc>neitzke</cc>
          
          <cf_commitlink></cf_commitlink>
          <cf_versionfixedin></cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>140052</commentid>
    <comment_count>0</comment_count>
    <who name="Hadacek Nicolas">hadacek</who>
    <bug_when>2003-06-15 06:09:26 +0000</bug_when>
    <thetext>Version:            (using KDE Devel)
Installed from:    Compiled sources

in directory &quot;a&quot; you have a file &quot;a.png&quot;.
in directory &quot;b&quot; you have files &quot;a.png&quot; and &quot;a_1.png&quot;

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

a more usdeful behaviour would be to find the first &quot;a_i.png&quot; which does not exists and to propose that instead.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>176864</commentid>
    <comment_count>1</comment_count>
    <who name="Stephan Binner">binner</who>
    <bug_when>2003-11-15 21:05:44 +0000</bug_when>
    <thetext>*** Bug 68288 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>176875</commentid>
    <comment_count>2</comment_count>
    <who name="Stephan Binner">binner</who>
    <bug_when>2003-11-15 21:24:36 +0000</bug_when>
    <thetext>*** Bug 68146 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>192295</commentid>
    <comment_count>3</comment_count>
    <who name="Thiago Macieira">thiago</who>
    <bug_when>2004-01-07 04:59:54 +0000</bug_when>
    <thetext>*** Bug 72018 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>192410</commentid>
    <comment_count>4</comment_count>
    <who name="Dominique Devriese">devriese</who>
    <bug_when>2004-01-07 13:49:48 +0000</bug_when>
    <thetext>It&apos;s a bit of a corner case, but imho, this is more of a normal bug than a wishlist one.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>192486</commentid>
    <comment_count>5</comment_count>
    <who name="Thiago Macieira">thiago</who>
    <bug_when>2004-01-07 16:23:32 +0000</bug_when>
    <thetext>It was a wishlist because it&apos;s an unimplemented feature. But name it what you will.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>193102</commentid>
    <comment_count>6</comment_count>
    <who name="Stephan Binner">binner</who>
    <bug_when>2004-01-09 15:12:45 +0000</bug_when>
    <thetext>*** Bug 72216 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>205421</commentid>
    <comment_count>7</comment_count>
      <attachid>4674</attachid>
    <who name="Anna Nymos">fnschy</who>
    <bug_when>2004-02-13 16:00:36 +0000</bug_when>
    <thetext>Created attachment 4674
Proposed patch

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

Looking forward to your comments,
Anna</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>205449</commentid>
    <comment_count>8</comment_count>
    <who name="David Faure">faure</who>
    <bug_when>2004-02-13 17:04:57 +0000</bug_when>
    <thetext>On Friday 13 February 2004 16:00, Anna Nymos wrote:
&gt; The patch adds a new helper function which recurses until a non-existent
&gt; filename is found.

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

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>205673</commentid>
    <comment_count>9</comment_count>
    <who name="David Faure">faure</who>
    <bug_when>2004-02-14 12:45:31 +0000</bug_when>
    <thetext>CVS commit by faure: 

Fixed 59796, &quot;the suggest renaming could be more intelligent&quot;, based on patch
by Anna Nymos &lt;fnschy-at-yahoo.de&gt;
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 &lt;qlayout.h&gt;
 #include &lt;qlineedit.h&gt;
+#include &lt;qdir.h&gt;
 
 #include &lt;kmessagebox.h&gt;
@@ -424,15 +425,10 @@ void RenameDlg::b1Pressed()
   done( 1 );
 }
-// Propose button clicked
-void RenameDlg::b8Pressed()
-{
-  int pos;
-
-  /* no name to play with */
-  if ( d-&gt;m_pLineEdit-&gt;text().isEmpty() )
-    return;
 
-  QString dotSuffix, tmp;
-  QString basename = d-&gt;m_pLineEdit-&gt;text();
+static QString suggestName(const KURL&amp; baseURL, const QString&amp; oldName)
+{
+        kdDebug() &lt;&lt; &quot;suggestName &quot; &lt;&lt; baseURL &lt;&lt; &quot; oldName=&quot; &lt;&lt; oldName &lt;&lt; endl;
+  QString dotSuffix, suggestedName;
+  QString basename = oldName;
 
   int index = basename.find( &apos;.&apos; );
@@ -440,32 +436,47 @@ void RenameDlg::b8Pressed()
     dotSuffix = basename.mid( index );
     basename.truncate( index );
-  } else
-    dotSuffix = QString::null;
+  }
   
-  pos = basename.findRev(&apos;_&apos; );
+  int pos = basename.findRev( &apos;_&apos; );
   if(pos != -1 ){
+    QString tmp = basename.mid( pos+1 );
     bool ok;
-    tmp = basename.right( basename.length() - (pos + 1) );
-    int number = tmp.toInt( &amp;ok, 10 );
+    int number = tmp.toInt( &amp;ok );
     if ( !ok ) {// ok there is no number
-      basename.append(&quot;_1&quot; );
-      d-&gt;m_pLineEdit-&gt;setText(basename + dotSuffix );
-      return;
+      suggestedName = basename + &quot;1&quot; + dotSuffix;
     }
     else {
      // yes there&apos;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-&gt;m_pLineEdit-&gt;setText( basename + dotSuffix );
-      return;
+      basename.replace( pos+1, tmp.length(), QString::number(number+1) );
+      suggestedName = basename + dotSuffix;
     }
   }
   else // no underscore yet
-  {
-    d-&gt;m_pLineEdit-&gt;setText( basename + &quot;_1&quot; + dotSuffix );
+    suggestedName = basename + &quot;_1&quot; + 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 -&gt; recurse
+    return suggestName( baseURL, suggestedName );
+}
+
+// Propose button clicked
+void RenameDlg::b8Pressed()
+{
+  /* no name to play with */
+  if ( d-&gt;m_pLineEdit-&gt;text().isEmpty() )
     return;
 
-  }
-  return; // we should never return from here jic
+  KURL destDirectory( d-&gt;dest );
+  destDirectory.setPath( destDirectory.directory() );
+  d-&gt;m_pLineEdit-&gt;setText( suggestName( destDirectory, d-&gt;m_pLineEdit-&gt;text() ) );
+  return;
 }
 


</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>206202</commentid>
    <comment_count>10</comment_count>
    <who name="Michael Goffioul">kdeprint_bugs</who>
    <bug_when>2004-02-16 10:36:26 +0000</bug_when>
    <thetext>*** Bug 68399 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>4674</attachid>
            <date>2004-02-13 16:00:36 +0000</date>
            <delta_ts>2004-02-13 16:00:36 +0000</delta_ts>
            <desc>Proposed patch</desc>
            <filename>rename_suggest.diff</filename>
            <type>text/plain</type>
            <size>2927</size>
            <attacher name="Anna Nymos">fnschy</attacher>
            
              <data encoding="base64">SW5kZXg6IGtpby9raW8vcmVuYW1lZGxnLmNwcAo9PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09ClJDUyBmaWxlOiAvaG9tZS9r
ZGUva2RlbGlicy9raW8va2lvL3JlbmFtZWRsZy5jcHAsdgpyZXRyaWV2aW5nIHJldmlzaW9uIDEu
NzAKZGlmZiAtdSAtMyAtcCAtcjEuNzAgcmVuYW1lZGxnLmNwcAotLS0ga2lvL2tpby9yZW5hbWVk
bGcuY3BwCTIwIEphbiAyMDA0IDIwOjM4OjA1IC0wMDAwCTEuNzAKKysrIGtpby9raW8vcmVuYW1l
ZGxnLmNwcAkxMyBGZWIgMjAwNCAxNDozNjoyNCAtMDAwMApAQCAtMjgsNiArMjgsNyBAQAogI2lu
Y2x1ZGUgPHFsYWJlbC5oPgogI2luY2x1ZGUgPHFsYXlvdXQuaD4KICNpbmNsdWRlIDxxbGluZWVk
aXQuaD4KKyNpbmNsdWRlIDxxZGlyLmg+CiAKICNpbmNsdWRlIDxrbWVzc2FnZWJveC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