Bug 88615

Summary: KIO:del() should use Trash
Product: [Unmaintained] kio Reporter: Jason Hihn <scorp1us>
Component: generalAssignee: David Faure <faure>
Status: RESOLVED FIXED    
Severity: wishlist    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Jason Hihn 2004-09-01 18:31:07 UTC
Version:            (using KDE KDE 3.3.0)
Installed from:    I Don't Know
OS:                Linux

ISSUE:
In repsonse to this lovely piece of fan mail: 
 http://article.gmane.org/gmane.comp.kde.digikam.devel/1093

SOLUTION:
It appears that KIO::del() should respect the Trash can. Adding in support in such a global manner should avoid that mishap from occuring in the future and it will provide Trash support transparently as well for other apps. 

RISKS: 
1) too much is moved to trash, rather than deleted. 
While this may make a for a busy trash can, saving stuff in the trash is much more safe than not. Authors are free to use unlink() or other means to bypass this mechanism.
Comment 1 David Faure 2004-09-01 20:09:56 UTC
KIO::del() has to remain doing what it always did - after all Konqueror offers both "Move to Trash" and "Delete", so for the latter we need del(). Many other apps use del() to really delete (backup files etc.)

However, given that I'm working on a new trash system, I am planning to provide an API for it, e.g. a KIO::trash( url list ). It will basically be a move( urls, "trash:/" ). Thanks for the BR, it confirms the need for an easy API for this. Will close when done.
Comment 2 David Faure 2004-09-03 16:09:29 UTC
CVS commit by faure: 

Added convenience method KIO::trash( url or url list ), to encapsulate the
trash implementation (it now moves to "trash:/"). Should also make it easy
for apps to use it instead of del().
CCMAIL: 88615-done@bugs.kde.org


  M +12 -0     job.cpp   1.407
  M +21 -0     job.h   1.101
  M +1 -0      jobclasses.h   1.147


--- kdelibs/kio/kio/job.cpp  #1.406:1.407
@@ -3593,4 +3593,16 @@ CopyJob *KIO::linkAs(const KURL& src, co
 }
 
+CopyJob *KIO::trash(const KURL& src, bool showProgressInfo )
+{
+    KURL::List srcList;
+    srcList.append( src );
+    return new CopyJob( srcList, KURL( "trash:/" ), CopyJob::Move, false, showProgressInfo );
+}
+
+CopyJob *KIO::trash(const KURL::List& srcList, bool showProgressInfo )
+{
+    return new CopyJob( srcList, KURL( "trash:/" ), CopyJob::Move, false, showProgressInfo );
+}
+
 //////////
 

--- kdelibs/kio/kio/job.h  #1.100:1.101
@@ -477,4 +477,25 @@ namespace KIO {
 
     /**
+     * Trash a file or directory.
+     * This is currently only supported for local files and directories.
+     * Use "KURL src; src.setPath( path );" to create a URL from a path.
+     *
+     * @param src file to delete
+     * @param showProgressInfo true to show progress information
+     * @return the job handling the operation
+     */
+    CopyJob *trash( const KURL& src, bool showProgressInfo = true );
+
+    /**
+     * Trash a list of files or directories.
+     * This is currently only supported for local files and directories.
+     *
+     * @param src the files to delete
+     * @param showProgressInfo true to show progress information
+     * @return the job handling the operation
+     */
+    CopyJob *trash( const KURL::List& src, bool showProgressInfo = true );
+
+    /**
      * Delete a file or directory.
      *

--- kdelibs/kio/kio/jobclasses.h  #1.146:1.147
@@ -1384,4 +1384,5 @@ namespace KIO {
     };
 
+    /// @internal
     struct CopyInfo
     {