diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -205,6 +205,7 @@ dolphinrecenttabsmenu.cpp dolphintabpage.cpp dolphintabwidget.cpp + trash/dolphintrash.cpp filterbar/filterbar.cpp main.cpp panels/information/filemetadataconfigurationdialog.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -56,6 +56,7 @@ #include "views/dolphinview.h" #include "views/viewmodecontroller.h" +#include "trash/dolphintrash.h" DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const QPoint& pos, @@ -154,13 +155,7 @@ addShowMenuBarAction(); if (exec(m_pos) == emptyTrashAction) { - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(m_mainWindow); - if (uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job* job = KIO::emptyTrash(); - KJobWidgets::setWindow(job, m_mainWindow); - job->uiDelegate()->setAutoErrorHandlingEnabled(true); - } + emptyTrash(m_mainWindow); } } diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -31,6 +31,7 @@ #include #include +#include #ifdef KF5Activities_FOUND namespace KActivities { @@ -321,6 +322,7 @@ private: QVBoxLayout* m_topLayout; KUrlNavigator* m_urlNavigator; + QPushButton* m_emptyTrashButton; DolphinSearchBox* m_searchBox; KMessageWidget* m_messageWidget; diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -25,15 +25,16 @@ #include #include #include +#include +#include #include #include #include #include #include #include #include -#include #include #include #include @@ -49,11 +50,14 @@ #include "statusbar/dolphinstatusbar.h" #include "views/viewmodecontroller.h" #include "views/viewproperties.h" +#include "trash/dolphintrash.h" +#include "trash/dolphintrash.h" DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) : QWidget(parent), m_topLayout(nullptr), m_urlNavigator(nullptr), + m_emptyTrashButton(nullptr), m_searchBox(nullptr), m_messageWidget(nullptr), m_view(nullptr), @@ -72,6 +76,9 @@ m_topLayout->setSpacing(0); m_topLayout->setMargin(0); + QHBoxLayout *navigatorLayout = new QHBoxLayout(this); + navigatorLayout->setMargin(0); + m_urlNavigator = new KUrlNavigator(new KFilePlacesModel(this), url, this); connect(m_urlNavigator, &KUrlNavigator::activated, this, &DolphinViewContainer::activate); @@ -85,6 +92,13 @@ KUrlComboBox* editor = m_urlNavigator->editor(); editor->setCompletionMode(KCompletion::CompletionMode(settings->urlCompletionMode())); + m_emptyTrashButton = new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash-symbolic")), "&Empty Trash", this); + connect(m_emptyTrashButton, &QPushButton::clicked, [this](){ + if (emptyTrash(this)) + m_emptyTrashButton->hide(); + }); + m_emptyTrashButton->hide(); + m_searchBox = new DolphinSearchBox(this); m_searchBox->hide(); connect(m_searchBox, &DolphinSearchBox::activated, this, &DolphinViewContainer::activate); @@ -186,8 +200,17 @@ this, &DolphinViewContainer::requestFocus); connect(m_view, &DolphinView::urlChanged, m_filterBar, &FilterBar::slotUrlChanged); - - m_topLayout->addWidget(m_urlNavigator); + connect(m_view, &DolphinView::urlChanged, [this](const QUrl &url){ + if (url.scheme() == QLatin1String("trash") && !isTrashEmpty()) + m_emptyTrashButton->show(); + else + m_emptyTrashButton->hide(); + }); + + navigatorLayout->addWidget(m_urlNavigator); + navigatorLayout->addWidget(m_emptyTrashButton); + + m_topLayout->addLayout(navigatorLayout); m_topLayout->addWidget(m_searchBox); m_topLayout->addWidget(m_messageWidget); m_topLayout->addWidget(m_view); diff --git a/src/filterbar/filterbar.cpp b/src/filterbar/filterbar.cpp --- a/src/filterbar/filterbar.cpp +++ b/src/filterbar/filterbar.cpp @@ -138,4 +138,3 @@ break; } } - diff --git a/src/panels/places/placespanel.h b/src/panels/places/placespanel.h --- a/src/panels/places/placespanel.h +++ b/src/panels/places/placespanel.h @@ -67,11 +67,9 @@ void slotItemDropEventStorageSetupDone(int index, bool success); void slotAboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event); void slotUrlsDropped(const QUrl& dest, QDropEvent* event, QWidget* parent); - void slotTrashUpdated(KJob* job); void slotStorageSetupDone(int index, bool success); private: - void emptyTrash(); void addEntry(); void editEntry(int index); diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -24,6 +24,7 @@ #include "placespanel.h" #include "dolphin_generalsettings.h" +#include "trash/dolphintrash.h" #include "global.h" #include @@ -228,7 +229,7 @@ QAction* action = menu.exec(pos.toPoint()); if (action) { if (action == emptyTrashAction) { - emptyTrash(); + emptyTrash(this); } else { // The index might have changed if devices were added/removed while // the context menu was open. @@ -427,15 +428,6 @@ } } -void PlacesPanel::slotTrashUpdated(KJob* job) -{ - if (job->error()) { - emit errorMessage(job->errorString()); - } - // as long as KIO doesn't do this, do it ourselves - KNotification::event(QStringLiteral("Trash: emptied"), QString(), QPixmap(), nullptr, KNotification::DefaultEvent); -} - void PlacesPanel::slotStorageSetupDone(int index, bool success) { disconnect(m_model, &PlacesItemModel::storageSetupDone, @@ -455,17 +447,6 @@ } } -void PlacesPanel::emptyTrash() -{ - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(window()); - if (uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job* job = KIO::emptyTrash(); - KJobWidgets::setWindow(job, window()); - connect(job, &KIO::Job::result, this, &PlacesPanel::slotTrashUpdated); - } -} - void PlacesPanel::addEntry() { const int index = m_controller->selectionManager()->currentItem(); diff --git a/src/trash/dolphintrash.h b/src/trash/dolphintrash.h new file mode 100644 --- /dev/null +++ b/src/trash/dolphintrash.h @@ -0,0 +1,28 @@ +/*************************************************************************** + * Copyright (C) 2018 by Roman Inflianskas * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef DOLPHINTRASH_H +#define DOLPHINTRASH_H + +#include + +bool emptyTrash(QWidget* window); +bool isTrashEmpty(); + +#endif // DOLPHINTRASH_H diff --git a/src/trash/dolphintrash.cpp b/src/trash/dolphintrash.cpp new file mode 100644 --- /dev/null +++ b/src/trash/dolphintrash.cpp @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2018 by Roman Inflianskas * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "dolphintrash.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool emptyTrash(QWidget *window) +{ + KIO::JobUiDelegate uiDelegate; + uiDelegate.setWindow(window); + bool confirmed = uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation); + if (confirmed) { + KIO::Job* job = KIO::emptyTrash(); + KJobWidgets::setWindow(job, window); + job->uiDelegate()->setAutoErrorHandlingEnabled(true); + QObject::connect(job, &KIO::Job::result, [](){ + KNotification::event(QStringLiteral("Trash: emptied"), QString(), QPixmap(), nullptr, KNotification::DefaultEvent); + }); + } + return confirmed; +} + +bool isTrashEmpty() +{ + KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); + return (trashConfig.group("Status").readEntry("Empty", true)); +}