Summary: | the suggest renaming could be more intelligent (when you try to copy a file over another one) | ||
---|---|---|---|
Product: | [Unmaintained] kio | Reporter: | Hadacek Nicolas <hadacek> |
Component: | general | Assignee: | David Faure <faure> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | devriese, fnschy, jeremyhu, kossebau, neitzke |
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: | Proposed patch |
Description
Hadacek Nicolas
2003-06-15 06:09:26 UTC
*** Bug 68288 has been marked as a duplicate of this bug. *** *** Bug 68146 has been marked as a duplicate of this bug. *** *** Bug 72018 has been marked as a duplicate of this bug. *** It's a bit of a corner case, but imho, this is more of a normal bug than a wishlist one. It was a wishlist because it's an unimplemented feature. But name it what you will. *** Bug 72216 has been marked as a duplicate of this bug. *** 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
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.
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; } *** Bug 68399 has been marked as a duplicate of this bug. *** |