]>
cloud.milkyroute.net Git - dolphin.git/blob - src/trash/dolphintrash.cpp
e1530bfaeb4b2c5c5bbea5dd7677283a05ac3e07
2 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2018 Roman Inflianskas <infroma@gmail.com>
5 * SPDX-License-Identifier: GPL-2.0-or-later
8 #include "dolphintrash.h"
11 #include <KConfigGroup>
12 #include <KLocalizedString>
13 #include <KNotification>
16 #include <kio_version.h>
17 #if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0)
18 #include <KIO/DeleteOrTrashJob>
20 #include <KIO/JobUiDelegate>
21 #include <KJobWidgets>
25 : m_trashDirLister(new KDirLister())
27 // The trash icon must always be updated dependent on whether
28 // the trash is empty or not. We use a KDirLister that automatically
29 // watches for changes if the number of items has been changed.
30 m_trashDirLister
->setAutoErrorHandlingEnabled(false);
31 m_trashDirLister
->setDelayedMimeTypes(true);
32 auto trashDirContentChanged
= [this]() {
33 bool isTrashEmpty
= m_trashDirLister
->items().isEmpty();
34 Q_EMIT
emptinessChanged(isTrashEmpty
);
36 connect(m_trashDirLister
, &KCoreDirLister::completed
, this, trashDirContentChanged
);
37 connect(m_trashDirLister
, &KDirLister::itemsDeleted
, this, trashDirContentChanged
);
38 m_trashDirLister
->openUrl(QUrl(QStringLiteral("trash:/")));
43 delete m_trashDirLister
;
46 Trash
&Trash::instance()
52 static void notifyEmptied()
54 // As long as KIO doesn't do this, do it ourselves
55 KNotification::event(QStringLiteral("Trash: emptied"),
56 i18n("Trash Emptied"),
57 i18n("The Trash was emptied."),
58 QStringLiteral("user-trash"),
60 KNotification::DefaultEvent
);
63 void Trash::empty(QWidget
*window
)
65 #if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0)
66 using Iface
= KIO::AskUserActionInterface
;
67 auto *emptyJob
= new KIO::DeleteOrTrashJob(QList
<QUrl
>{}, Iface::EmptyTrash
, Iface::DefaultConfirmation
, window
);
68 QObject::connect(emptyJob
, &KIO::Job::result
, notifyEmptied
);
71 KIO::JobUiDelegate uiDelegate
;
72 uiDelegate
.setWindow(window
);
73 bool confirmed
= uiDelegate
.askDeleteConfirmation(QList
<QUrl
>(), KIO::JobUiDelegate::EmptyTrash
, KIO::JobUiDelegate::DefaultConfirmation
);
75 KIO::Job
*job
= KIO::emptyTrash();
76 KJobWidgets::setWindow(job
, window
);
77 job
->uiDelegate()->setAutoErrorHandlingEnabled(true);
78 QObject::connect(job
, &KIO::Job::result
, notifyEmptied
);
85 KConfig
trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig
);
86 return (trashConfig
.group("Status").readEntry("Empty", true));