]>
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"
11 #include <KConfigGroup>
12 #include <KLocalizedString>
13 #include <KNotification>
16 #include <KIO/DeleteOrTrashJob>
17 #include <kio_version.h>
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 m_trashDirLister
->setAutoErrorHandlingEnabled(false);
26 m_trashDirLister
->setDelayedMimeTypes(true);
27 auto trashDirContentChanged
= [this]() {
28 bool isTrashEmpty
= m_trashDirLister
->items().isEmpty();
29 Q_EMIT
emptinessChanged(isTrashEmpty
);
31 connect(m_trashDirLister
, &KCoreDirLister::completed
, this, trashDirContentChanged
);
32 connect(m_trashDirLister
, &KDirLister::itemsDeleted
, this, trashDirContentChanged
);
33 m_trashDirLister
->openUrl(QUrl(QStringLiteral("trash:/")));
38 delete m_trashDirLister
;
41 Trash
&Trash::instance()
47 static void notifyEmptied()
49 // As long as KIO doesn't do this, do it ourselves
50 KNotification::event(QStringLiteral("Trash: emptied"),
51 i18n("Trash Emptied"),
52 i18n("The Trash was emptied."),
53 QStringLiteral("user-trash"),
55 KNotification::DefaultEvent
);
58 void Trash::empty(QWidget
*window
)
60 using Iface
= KIO::AskUserActionInterface
;
61 auto *emptyJob
= new KIO::DeleteOrTrashJob(QList
<QUrl
>{}, Iface::EmptyTrash
, Iface::DefaultConfirmation
, window
);
62 QObject::connect(emptyJob
, &KIO::Job::result
, notifyEmptied
);
68 KConfig
trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig
);
69 return (trashConfig
.group("Status").readEntry("Empty", true));
72 #include "moc_dolphintrash.cpp"