]>
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 <KJobWidgets>
13 #include <KNotification>
15 #include <KConfigGroup>
16 #include <KLocalizedString>
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, nullptr);
25 m_trashDirLister
->setDelayedMimeTypes(true);
26 auto trashDirContentChanged
= [this]() {
27 bool isTrashEmpty
= m_trashDirLister
->items().isEmpty();
28 emit
emptinessChanged(isTrashEmpty
);
30 connect(m_trashDirLister
, QOverload
<>::of(&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 KIO::Job
*Trash::empty(QWidget
*window
)
48 KIO::JobUiDelegate uiDelegate
;
49 uiDelegate
.setWindow(window
);
50 bool confirmed
= uiDelegate
.askDeleteConfirmation(QList
<QUrl
>(), KIO::JobUiDelegate::EmptyTrash
, KIO::JobUiDelegate::DefaultConfirmation
);
52 KIO::Job
* job
= KIO::emptyTrash();
53 KJobWidgets::setWindow(job
, window
);
54 job
->uiDelegate()->setAutoErrorHandlingEnabled(true);
55 // as long as KIO doesn't do this, do it ourselves
56 connect(job
, &KIO::Job::result
, []() {
57 KNotification::event(QStringLiteral("Trash: emptied"), i18n("Trash Emptied"),
58 i18n("The Trash was emptied."), QStringLiteral("user-trash"),
59 nullptr, KNotification::DefaultEvent
);
68 KConfig
trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig
);
69 return (trashConfig
.group("Status").readEntry("Empty", true));