I'm trying to move (delete) a file to a Trash Can (in Linux) using C++ (also using QT4 for GUI). Unfortunately it seems to be quite difficult to do so and as far as I can tell there isn't a unified API for it.
I would like for my application to run not only on KDE but on GNOME, Xfce and other Linux desktop environments. That's why I'm searching for a more universal approach.
The best I could find so far is:
I would be happy with any approach that requires as little desktop environment specific code as possible. Or in other words that's as much independent from KDE/GNOME/Xfce components as possible.
Any help in finding a solution (if there even is one) would be greatly appreciated.
Deleting a file or folder permanentlyBy directing the rm command to an asterisk ( * ), you delete all files and folders inside the Trash folder without deleting the Trash folder itself. If you accidentally delete the Trash folder, however, you can just recreate it because directories are easy and free to create.
Even if your Linux desktop environment of choice doesn't place an icon for it on the desktop, your Linux distro already has a trash directory. The advantage of relegating files to a trash directory is that it gives you the option to view all the deleted files and even restore files, empty the trash, etc.
The answer is in
http://www.freedesktop.org/wiki/Specifications/trash-spec
For every user a “home trash” directory MUST be available. Its name and location are $XDG_DATA_HOME/Trash
you only need to write C++ code move your file into such directory.
You can move files using boost file system and you can retrieve the XDG_DATA_HOME value using cstlib getenv.
Why not find a terminal command to move the files and then call system() to run it for you inside your C++ program?
This might (I haven't tested it) be a possible one-liner in Linux to move files to the trash via the terminal. You would just pass the command as a quoted string to system()
and call it in your C++ implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With