diff --git a/application.cpp b/application.cpp index bc57f94..9adb65b 100644 --- a/application.cpp +++ b/application.cpp @@ -35,6 +35,18 @@ #include #include +// KIO +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + Application::Application(int& argc, char** argv) : QApplication(argc, argv) , m_instance(false) @@ -78,6 +90,22 @@ void Application::openFiles(const QStringList &paths) } } +void Application::moveToTrash(const QStringList &paths) +{ + if (paths.isEmpty()) + return; + + QList 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() { Window *w = new Window; @@ -121,6 +149,9 @@ bool Application::parseCommandLineArgs() QCommandLineOption emptyTrashOption(QStringList() << "e" << "empty-trash" << "Empty Trash"); parser.addOption(emptyTrashOption); + QCommandLineOption moveToTrashOption(QStringList() << "mtr" << "move-to-trash" << "Move To Trash"); + parser.addOption(moveToTrashOption); + parser.process(arguments()); if (m_instance) { @@ -140,6 +171,8 @@ bool Application::parseCommandLineArgs() if (parser.isSet(emptyTrashOption)) { // Empty Dialog iface.call("emptyTrash"); + } else if (parser.isSet(moveToTrashOption)) { + iface.call("moveToTrash", parser.positionalArguments()); } else { iface.call("openFiles", formatUriList(parser.positionalArguments())); } diff --git a/application.h b/application.h index c6ebd2d..b87df0f 100644 --- a/application.h +++ b/application.h @@ -33,6 +33,7 @@ public: // DBus void openFiles(const QStringList &paths); + void moveToTrash(const QStringList &paths); void emptyTrash(); private: diff --git a/com.cutefish.FileManager.xml b/com.cutefish.FileManager.xml index 58366a4..fef4ce0 100644 --- a/com.cutefish.FileManager.xml +++ b/com.cutefish.FileManager.xml @@ -4,6 +4,9 @@ + + +