Bug 329406 - kio_desktop should watch trashrc to update trashcan icon in Desktop view
Summary: kio_desktop should watch trashrc to update trashcan icon in Desktop view
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: general (other bugs)
Version First Reported In: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-30 09:28 UTC by Cjacker
Modified: 2024-11-23 21:17 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 6.9
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cjacker 2013-12-30 09:28:17 UTC
the desktopnotifier kded module provide by kio_desktop should watch "trashrc" to update the trashcan icon in Desktop view.

Currently, it watch the "KGlobal::dirs()->localxdgdatadir() + "Trash/files"" to monitor the change of trashcan.

But the freedesktop spec of trash and kio_trash/trashimpl.cpp support more than one trashcan especially for separate partitions that user had write permissions.

It will construct a trashcan like "Trash-$UID" in such partition and trash files directly to it to avoid file copy/move across different partitions.

below patch should fix this problem.
diff -Nur kde-runtime-4.12.0/kioslave/desktop/desktopnotifier.cpp kde-runtime-4.12.0.n/kioslave/desktop/desktopnotifier.cpp
--- kde-runtime-4.12.0/kioslave/desktop/desktopnotifier.cpp 2013-12-12 02:40:13.000000000 +0800
+++ kde-runtime-4.12.0.n/kioslave/desktop/desktopnotifier.cpp   2013-12-30 17:17:09.978155948 +0800
@@ -39,8 +39,16 @@
     dirWatch = new KDirWatch(this);
     dirWatch->addDir(KGlobalSettings::desktopPath());
     dirWatch->addDir(KGlobal::dirs()->localxdgdatadir() + "Trash/files");
+   
+    //trash can is not only in homedir, may also in seperate partitions.
+    //watch local trash can is not enough, a better way it to watch trashrc config file. 
+    QString trashrc = KStandardDirs::locateLocal( "config", "trashrc" );
+    dirWatch->addFile(trashrc);

     connect(dirWatch, SIGNAL(dirty(QString)), SLOT(dirty(QString)));
+    //for watch trashrc.
+    connect(dirWatch, SIGNAL(created(QString)), SLOT(dirty(QString)));
+    connect(dirWatch, SIGNAL(deleted(QString)), SLOT(dirty(QString)));
 }

 void DesktopNotifier::watchDir(const QString &path)
@@ -50,9 +58,9 @@

 void DesktopNotifier::dirty(const QString &path)
 {
-    Q_UNUSED(path)
-
-    if (path.startsWith(KGlobal::dirs()->localxdgdatadir() + "Trash/files")) {
+    QString trashrc = KStandardDirs::locateLocal( "config", "trashrc" );
+    
+    if (path.startsWith(KGlobal::dirs()->localxdgdatadir() + "Trash/files") || path==trashrc ) {
         // Trigger an update of the trash icon
         if (QFile::exists(KGlobalSettings::desktopPath() + "/trash.desktop"))
             org::kde::KDirNotify::emitFilesChanged(QStringList() << "desktop:/trash.desktop");
                                                                                                          

 

Reproducible: Always

Steps to Reproduce:
1. mount a seperate partition and give the read/write permission to a user.
2. trash files in this partition, it will create a ".Trash-$UID" in this partition topdir.
3. The trash icon in desktop will not changed.
Comment 1 Cjacker 2013-12-31 11:57:52 UTC
Still had some problems, the trash icon sometimes show as a "gear icon" after update....

also, trashrc will not updated some times even empty the trashcan.

Maybe the kio_trash codes need more review carefully.
Comment 2 David Faure 2014-01-14 08:38:09 UTC
The usual solution is rather to listen to KDirNotify dbus signals for trash:/
(as KDirLister / KDirModel already do).

Watching either trashrc or Trash/files should be unnecessary.

The code that adds or removes files to the trash always calls
org::kde::KDirNotify::emitFilesAdded("trash:/"); 
(e.g. konq_operations.cpp, ./dolphin/src/panels/places/placespanel.cpp:425:, high-level KIO jobs themselves...)
Comment 3 Jeff Stern 2020-04-02 15:16:03 UTC
As of April 2020, I am noticing what is probably the same or similar problem.

I am trying to train myself to use a command-line python-based utility (trash-cli: https://github.com/andreafrancia/trash-cli, albeit via pip install) instead of rm / rm -i, so that I can avoid shooting self in foot occasionally.  The trash-cli utility comes with these cli commands:

  trash-put (alias: trash)
  trash-list
  trash-rm
  trash-empty
  trash-restore

Since both trash-cli and KDE supposedly conform to the freedesktop.org Trash specification, they should theoretically play well together.

And for the most part, they do seem to play well together, with the exception of the updating of the KDE Trash status desktop icon:

1) When using this command to put a file in the trash via command-line, the Trash icon on the desktop does not update to show that there is now a file in the trash:

$ touch testfile.txt
$ trash-put testfile.txt

2) Likewise, when there are files already in the Trash (whether put there by KDE drag/drop, or via trash-put cli command), and the Trash desktop icon shows that it has files in it, then when I empty the trash via:

  $ trash-empty

that empties the trash, sure enough, but the deskop icon does not update to show empty.

- openSUSE Tumbleweed 20200326
- x86_64 GNU/Linux 5.5.11-1-default #1 SMP
- KDE 5.18.3-1 (openSUSE packages)

Let me know if there is any more information I can provide. Thank you
Comment 4 Jeff Stern 2020-04-02 15:23:44 UTC
Correction:
- KDE Plasma: 5.18.3-1 (openSUSE packages)
- KDE Frameworks: 5.68.0
- QT: 5.14.1
Comment 5 Nate Graham 2024-11-23 21:17:31 UTC
Tested this again in current git master and it works fine. There's clearly code checking for this now. I think we can call it fixed.