]>
cloud.milkyroute.net Git - dolphin.git/blob - src/trash/dolphintrash.cpp
dd71135a52b166cd980d904d2cde73b6cd1df188
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 <KIO/DeleteOrTrashJob>
13 #include <KLocalizedString>
14 #include <KNotification>
19 : m_trashDirLister(new KDirLister())
21 // The trash icon must always be updated dependent on whether
22 // the trash is empty or not. We use a KDirLister that automatically
23 // watches for changes if the number of items has been changed.
24 m_trashDirLister
->setAutoErrorHandlingEnabled(false);
25 m_trashDirLister
->setDelayedMimeTypes(true);
26 auto trashDirContentChanged
= [this]() {
27 bool isTrashEmpty
= m_trashDirLister
->items().isEmpty();
28 Q_EMIT
emptinessChanged(isTrashEmpty
);
30 connect(m_trashDirLister
, &KCoreDirLister::completed
, this, trashDirContentChanged
);
31 connect(m_trashDirLister
, &KDirLister::itemsDeleted
, this, trashDirContentChanged
);
32 m_trashDirLister
->openUrl(QUrl(QStringLiteral("trash:/")));
37 delete m_trashDirLister
;
40 Trash
&Trash::instance()
46 static void notifyEmptied()
48 // As long as KIO doesn't do this, do it ourselves
49 KNotification::event(QStringLiteral("Trash: emptied"),
50 i18n("Trash Emptied"),
51 i18n("The Trash was emptied."),
52 QStringLiteral("user-trash"),
53 KNotification::DefaultEvent
);
56 void Trash::empty(QWidget
*window
)
58 using Iface
= KIO::AskUserActionInterface
;
59 auto *emptyJob
= new KIO::DeleteOrTrashJob(QList
<QUrl
>{}, Iface::EmptyTrash
, Iface::DefaultConfirmation
, window
);
60 QObject::connect(emptyJob
, &KIO::Job::result
, notifyEmptied
);
66 KConfig
trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig
);
67 return (trashConfig
.group("Status").readEntry("Empty", true));
70 #include "moc_dolphintrash.cpp"