]>
cloud.milkyroute.net Git - dolphin.git/blob - src/trash/dolphintrash.cpp
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"
10 #include <KIO/JobUiDelegate>
11 #include <kio_version.h>
12 #include <KJobWidgets>
14 #include <KNotification>
16 #include <KConfigGroup>
17 #include <KLocalizedString>
20 : m_trashDirLister(new KDirLister())
22 // The trash icon must always be updated dependent on whether
23 // the trash is empty or not. We use a KDirLister that automatically
24 // watches for changes if the number of items has been changed.
25 #if KIO_VERSION < QT_VERSION_CHECK(5, 82, 0)
26 m_trashDirLister
->setAutoErrorHandlingEnabled(false, nullptr);
28 m_trashDirLister
->setAutoErrorHandlingEnabled(false);
30 m_trashDirLister
->setDelayedMimeTypes(true);
31 auto trashDirContentChanged
= [this]() {
32 bool isTrashEmpty
= m_trashDirLister
->items().isEmpty();
33 Q_EMIT
emptinessChanged(isTrashEmpty
);
35 connect(m_trashDirLister
, QOverload
<>::of(&KCoreDirLister::completed
), this, trashDirContentChanged
);
36 connect(m_trashDirLister
, &KDirLister::itemsDeleted
, this, trashDirContentChanged
);
37 m_trashDirLister
->openUrl(QUrl(QStringLiteral("trash:/")));
42 delete m_trashDirLister
;
45 Trash
&Trash::instance()
51 KIO::Job
*Trash::empty(QWidget
*window
)
53 KIO::JobUiDelegate uiDelegate
;
54 uiDelegate
.setWindow(window
);
55 bool confirmed
= uiDelegate
.askDeleteConfirmation(QList
<QUrl
>(), KIO::JobUiDelegate::EmptyTrash
, KIO::JobUiDelegate::DefaultConfirmation
);
57 KIO::Job
* job
= KIO::emptyTrash();
58 KJobWidgets::setWindow(job
, window
);
59 job
->uiDelegate()->setAutoErrorHandlingEnabled(true);
60 // as long as KIO doesn't do this, do it ourselves
61 connect(job
, &KIO::Job::result
, []() {
62 KNotification::event(QStringLiteral("Trash: emptied"), i18n("Trash Emptied"),
63 i18n("The Trash was emptied."), QStringLiteral("user-trash"),
64 nullptr, KNotification::DefaultEvent
);
73 KConfig
trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig
);
74 return (trashConfig
.group("Status").readEntry("Empty", true));