feat: add moveToTrash interface
This commit is contained in:
parent
a5630037c3
commit
1eb918beb0
3 changed files with 37 additions and 0 deletions
|
@ -35,6 +35,18 @@
|
|||
#include <QIcon>
|
||||
#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)
|
||||
: 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<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()
|
||||
{
|
||||
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()));
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
|
||||
// DBus
|
||||
void openFiles(const QStringList &paths);
|
||||
void moveToTrash(const QStringList &paths);
|
||||
void emptyTrash();
|
||||
|
||||
private:
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
<method name="openFiles">
|
||||
<arg type="as" direction="in"/>
|
||||
</method>
|
||||
<method name="moveToTrash">
|
||||
<arg type="as" direction="in"/>
|
||||
</method>
|
||||
<method name="emptyTrash"></method>
|
||||
</interface>
|
||||
</node>
|
||||
|
|
Loading…
Reference in a new issue