在 Linux 中使用 C++ 将文件移动到垃圾箱
我正在尝试使用 C++(也使用 QT4 作为 GUI)将文件移动(删除)到垃圾桶(在 Linux 中)。不幸的是,这似乎很难做到,而且据我所知,还没有一个统一的 API。
我希望我的应用程序不仅可以在 KDE 上运行,还可以在 GNOME、Xfce 和其他 Linux 桌面环境上运行。这就是为什么我正在寻找一种更通用的方法。
到目前为止我能找到的最好的是:
- send2trash< /a> - 但这使用的是 Python/QT4 而不是 C++/QT4
- trash-cli - 它的缺点是它是一个独立的命令行程序而不是一个库,
我会对任何需要尽可能少的桌面环境特定代码的方法感到满意。或者换句话说,它尽可能独立于 KDE/GNOME/Xfce 组件。
任何寻找解决方案的帮助(如果有的话)将不胜感激。
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:
- send2trash - but that's using Python/QT4 and not C++/QT4
- trash-cli - this has the drawback of being a stand alone command line program and not a library
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不找到一个终端命令来移动文件,然后调用 system()在你的 C++ 程序中运行它?
这可能(我还没有测试过)是 Linux 中通过终端将文件移动到垃圾箱的一种可能的方式。您只需将命令作为带引号的字符串传递给
system()
并在 C++ 实现中调用它。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.答案就在
http://www.freedesktop.org/wiki/Specifications/trash-spec
你只需要编写 C++ 代码将文件移动到这样的目录中。
您可以使用 boost 文件系统 移动文件,并且可以检索 XDG_DATA_HOME 值使用 cstlib getenv。
The answer is in
http://www.freedesktop.org/wiki/Specifications/trash-spec
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.
据我所知,Linux 中本来就没有标准的垃圾桶。
As far as I know there's no standard trash can in Linux in the first place.