feat: add moveToTrash interface

This commit is contained in:
kateleet 2021-12-26 16:57:41 +08:00
parent a5630037c3
commit 1eb918beb0
3 changed files with 37 additions and 0 deletions

View file

@ -35,6 +35,18 @@
#include <QIcon> #include <QIcon>
#include <QDir> #include <QDir>
// KIO
#include <KIO/CopyJob>
#include <KIO/Job>
#include <KIO/PreviewJob>
#include <KIO/DeleteJob>
#include <KIO/DropJob>
#include <KIO/FileUndoManager>
#include <KIO/JobUiDelegate>
#include <KIO/Paste>
#include <KIO/PasteJob>
#include <KIO/RestoreJob>
Application::Application(int& argc, char** argv) Application::Application(int& argc, char** argv)
: QApplication(argc, argv) : QApplication(argc, argv)
, m_instance(false) , m_instance(false)
@ -78,6 +90,22 @@ void Application::openFiles(const QStringList &paths)
} }
} }
void Application::moveToTrash(const QStringList &paths)
{
if (paths.isEmpty())
return;
QList<QUrl> urls;
for (const QString &path : paths) {
urls.append(QUrl::fromLocalFile(path));
}
KIO::Job *job = KIO::trash(urls);
job->uiDelegate()->setAutoErrorHandlingEnabled(true);
KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, urls, QUrl(QStringLiteral("trash:/")), job);
}
void Application::emptyTrash() void Application::emptyTrash()
{ {
Window *w = new Window; Window *w = new Window;
@ -121,6 +149,9 @@ bool Application::parseCommandLineArgs()
QCommandLineOption emptyTrashOption(QStringList() << "e" << "empty-trash" << "Empty Trash"); QCommandLineOption emptyTrashOption(QStringList() << "e" << "empty-trash" << "Empty Trash");
parser.addOption(emptyTrashOption); parser.addOption(emptyTrashOption);
QCommandLineOption moveToTrashOption(QStringList() << "mtr" << "move-to-trash" << "Move To Trash");
parser.addOption(moveToTrashOption);
parser.process(arguments()); parser.process(arguments());
if (m_instance) { if (m_instance) {
@ -140,6 +171,8 @@ bool Application::parseCommandLineArgs()
if (parser.isSet(emptyTrashOption)) { if (parser.isSet(emptyTrashOption)) {
// Empty Dialog // Empty Dialog
iface.call("emptyTrash"); iface.call("emptyTrash");
} else if (parser.isSet(moveToTrashOption)) {
iface.call("moveToTrash", parser.positionalArguments());
} else { } else {
iface.call("openFiles", formatUriList(parser.positionalArguments())); iface.call("openFiles", formatUriList(parser.positionalArguments()));
} }

View file

@ -33,6 +33,7 @@ public:
// DBus // DBus
void openFiles(const QStringList &paths); void openFiles(const QStringList &paths);
void moveToTrash(const QStringList &paths);
void emptyTrash(); void emptyTrash();
private: private:

View file

@ -4,6 +4,9 @@
<method name="openFiles"> <method name="openFiles">
<arg type="as" direction="in"/> <arg type="as" direction="in"/>
</method> </method>
<method name="moveToTrash">
<arg type="as" direction="in"/>
</method>
<method name="emptyTrash"></method> <method name="emptyTrash"></method>
</interface> </interface>
</node> </node>