]> cloud.milkyroute.net Git - dolphin.git/blob - src/trash/dolphintrash.cpp
Add missing this parameter
[dolphin.git] / src / trash / dolphintrash.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2018 by Roman Inflianskas <infroma@gmail.com> *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20
21 #include "dolphintrash.h"
22
23 #include <KIO/JobUiDelegate>
24 #include <KJobWidgets>
25 #include <QList>
26 #include <KNotification>
27 #include <KConfig>
28 #include <KConfigGroup>
29
30
31 Trash::Trash()
32 : m_trashDirLister(new KDirLister())
33 {
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);
42 };
43 connect(m_trashDirLister, static_cast<void(KDirLister::*)()>(&KDirLister::completed), this, trashDirContentChanged);
44 m_trashDirLister->openUrl(QStringLiteral("trash:/"));
45 }
46
47 Trash::~Trash()
48 {
49 delete m_trashDirLister;
50 }
51
52 Trash &Trash::instance()
53 {
54 static Trash result;
55 return result;
56 }
57
58 KIO::Job *Trash::empty(QWidget *window)
59 {
60 KIO::JobUiDelegate uiDelegate;
61 uiDelegate.setWindow(window);
62 bool confirmed = uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation);
63 if (confirmed) {
64 KIO::Job* job = KIO::emptyTrash();
65 KJobWidgets::setWindow(job, window);
66 job->uiDelegate()->setAutoErrorHandlingEnabled(true);
67 // as long as KIO doesn't do this, do it ourselves
68 connect(job, &KIO::Job::result, [](){
69 KNotification::event(QStringLiteral("Trash: emptied"), QString(), QPixmap(), nullptr, KNotification::DefaultEvent);
70 });
71 return job;
72 }
73 return nullptr;
74 }
75
76 bool Trash::isEmpty()
77 {
78 KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig);
79 return (trashConfig.group("Status").readEntry("Empty", true));
80 }
81