]>
cloud.milkyroute.net Git - dolphin.git/blob - src/trash/dolphintrash.cpp
957091e548ceef298d821abcbb3513748b572492
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2018 by Roman Inflianskas <infroma@gmail.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphintrash.h"
23 #include <KIO/JobUiDelegate>
24 #include <KJobWidgets>
26 #include <KNotification>
28 #include <KConfigGroup>
29 #include <KLocalizedString>
32 : m_trashDirLister(new KDirLister())
34 // The trash icon must always be updated dependent on whether
35 // the trash is empty or not. We use a KDirLister that automatically
36 // watches for changes if the number of items has been changed.
37 m_trashDirLister
->setAutoErrorHandlingEnabled(false, nullptr);
38 m_trashDirLister
->setDelayedMimeTypes(true);
39 auto trashDirContentChanged
= [this]() {
40 bool isTrashEmpty
= m_trashDirLister
->items().isEmpty();
41 emit
emptinessChanged(isTrashEmpty
);
43 connect(m_trashDirLister
, QOverload
<>::of(&KCoreDirLister::completed
), this, trashDirContentChanged
);
44 connect(m_trashDirLister
, &KDirLister::itemsDeleted
, this, trashDirContentChanged
);
45 m_trashDirLister
->openUrl(QUrl(QStringLiteral("trash:/")));
50 delete m_trashDirLister
;
53 Trash
&Trash::instance()
59 KIO::Job
*Trash::empty(QWidget
*window
)
61 KIO::JobUiDelegate uiDelegate
;
62 uiDelegate
.setWindow(window
);
63 bool confirmed
= uiDelegate
.askDeleteConfirmation(QList
<QUrl
>(), KIO::JobUiDelegate::EmptyTrash
, KIO::JobUiDelegate::DefaultConfirmation
);
65 KIO::Job
* job
= KIO::emptyTrash();
66 KJobWidgets::setWindow(job
, window
);
67 job
->uiDelegate()->setAutoErrorHandlingEnabled(true);
68 // as long as KIO doesn't do this, do it ourselves
69 connect(job
, &KIO::Job::result
, []() {
70 KNotification::event(QStringLiteral("Trash: emptied"), i18n("Trash Emptied"),
71 i18n("The Trash was emptied."), QStringLiteral("user-trash"),
72 nullptr, KNotification::DefaultEvent
);
81 KConfig
trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig
);
82 return (trashConfig
.group("Status").readEntry("Empty", true));