Bug 54632 - Ctrl+V Paste replaces files without asking
Summary: Ctrl+V Paste replaces files without asking
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR critical
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
: 52303 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-02-14 13:01 UTC by Lubos Lunak
Modified: 2003-02-20 04:43 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lubos Lunak 2003-02-14 13:01:23 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources

Put something that's not a file into the clipboard (e.g. Ctrl+PrintScreen or some text). Try to put the contents on the desktop by using Ctrl+V. Since the clipboard contents are not a file, a dialog asking for the name for the contents will pop up. The bug is that if a file with such name already exists, it is silently overwritten. This doesn't happen with copy&paste of files, only with non-file clipboard contents. The bug also happens with Konqueror, as this seems to be a bug in the iconview.
Comment 1 George Staikos 2003-02-14 17:15:34 UTC
Subject: Re:  Ctrl+V Paste replaces files without asking

On Friday 14 February 2003 07:03, Lubos Lunak wrote:

>            What    |Removed                     |Added
> ---------------------------------------------------------------------------
>- Severity|normal                      |major

I think we can safely say this is a show stopper for 3.1.1 and 3.2.0.


Comment 2 Maksim Orlovich 2003-02-15 01:19:08 UTC
KIO::pasteData seems like the relevant spot. It has a TODO note on this, BTW 
 
Also: shouldn't release-criticil bugs be criticial and not major? 
 
 
Comment 3 Jens Dagerbo 2003-02-18 04:19:57 UTC
 
It didn't stop 3.1 :) -  http://bugs.kde.org/show_bug.cgi?id=52303 
 
I was looking to fix my old report when I found this dupe. My naive fix:  
 
--- ../kdecvs/kdelibs/kio/kio/paste.cpp	2003-02-18 04:01:50.000000000 +0100 
+++ paste.cpp	2003-02-18 04:01:14.000000000 +0100 
@@ -124,9 +124,14 @@ 
     KURL myurl(u); 
     myurl.addPath( l.text() ); 
 
+	if ( KIO::NetAccess::exists( myurl, false ) ) 
+	{ 
+		KMessageBox::error( 0l, i18n("File already exists") ); 
+		return; 
+	} 
+ 
     // We could use KIO::put here, but that would require a class 
     // for the slotData call. With NetAcess, we can do a synchronous call. 
-    // NOTE: upload() overwrites the destination if it exists. TODO dialog box. 
 
     KTempFile tempFile; 
     tempFile.setAutoDelete( true ); 
 
Comment 4 Christian Loose 2003-02-19 17:32:57 UTC
*** Bug 52303 has been marked as a duplicate of this bug. ***
Comment 5 George Staikos 2003-02-20 04:43:40 UTC
Subject: kdelibs/kio/kio

CVS commit by staikos: 

CCMAIL: 54632-done@bugs.kde.org

Prompt before overwriting when pasting non-files from the clipboard.

The observer change is to allow a non-job to use the observer for the rename
dialog.  It just checks for 0L in the job parameter and avoids crashing.


  M +10 -6     observer.cpp   1.48
  M +26 -1     paste.cpp   1.40


--- kdelibs/kio/kio/observer.cpp  #1.47:1.48
@@ -375,10 +375,14 @@ RenameDlg_Result Observer::open_RenameDl
                                            )
 {
-  kdDebug(KDEBUG_OBSERVER) << "Observer::open_RenameDlg job=" << job << " progressId=" << job->progressId() << endl;
+  kdDebug(KDEBUG_OBSERVER) << "Observer::open_RenameDlg job=" << job << " progressId=" << (job ? job->progressId() : "?") << endl;
   // Hide existing dialog box if any
+  if (job)
   m_uiserver->setJobVisible( job->progressId(), false );
   // We now do it in process.
-  RenameDlg_Result res =  KIO::open_RenameDlg( caption, src, dest, mode, newDest, sizeSrc, sizeDest,
-                              ctimeSrc, ctimeDest, mtimeSrc, mtimeDest );
+  RenameDlg_Result res =  KIO::open_RenameDlg( caption, src, dest, mode,
+                                               newDest, sizeSrc, sizeDest,
+                                               ctimeSrc, ctimeDest, mtimeSrc,
+                                               mtimeDest );
+  if (job)
   m_uiserver->setJobVisible( job->progressId(), true );
   return res;

--- kdelibs/kio/kio/paste.cpp  #1.39:1.40
@@ -21,4 +21,7 @@
 #include "kio/global.h"
 #include "kio/netaccess.h"
+#include "kio/observer.h"
+#include "kio/renamedlg.h"
+#include "kio/kprotocolmanager.h"
 
 #include <qapplication.h>
@@ -125,7 +128,29 @@ void KIO::pasteData( const KURL& u, cons
     myurl.addPath( l.text() );
 
+    if (KIO::NetAccess::exists(myurl, false))
+    {
+        kdDebug(7007) << "Paste will overwrite file.  Prompting..." << endl;
+        RenameDlg_Result res = R_OVERWRITE;
+
+        QString newPath;
+        // Ask confirmation about resuming previous transfer
+        res = Observer::self()->open_RenameDlg(
+                          0L, i18n("File Already Exists"),
+                          u.prettyURL(0, KURL::StripFileProtocol),
+                          myurl.prettyURL(0, KURL::StripFileProtocol),
+                          (RenameDlg_Mode) (M_OVERWRITE | M_SINGLE), newPath);
+
+        if ( res == R_RENAME )
+        {
+            myurl = newPath;
+        }
+        else if ( res == R_CANCEL )
+        {
+            return;
+        }
+    }
+
     // We could use KIO::put here, but that would require a class
     // for the slotData call. With NetAcess, we can do a synchronous call.
-    // NOTE: upload() overwrites the destination if it exists. TODO dialog box.
 
     KTempFile tempFile;