diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -205,6 +205,8 @@ dolphinrecenttabsmenu.cpp dolphintabpage.cpp dolphintabwidget.cpp + trash/dolphintrash.cpp + trash/dolphintrashwidget.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,8 @@ #include "views/dolphinview.h" #include "views/viewmodecontroller.h" +#include "trash/dolphintrashwidget.h" +#include "trash/dolphintrash.h" DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const QPoint& pos, @@ -154,13 +156,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 "trash/dolphintrashwidget.h" #ifdef KF5Activities_FOUND namespace KActivities { @@ -322,6 +323,7 @@ QVBoxLayout* m_topLayout; KUrlNavigator* m_urlNavigator; DolphinSearchBox* m_searchBox; + TrashWidget* m_trashWidget; KMessageWidget* m_messageWidget; DolphinView* m_view; diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -18,22 +18,24 @@ ***************************************************************************/ #include "dolphinviewcontainer.h" +#include "trash/dolphintrashwidget.h" #include #include #include #include #include #include +#include +#include #include #include #include #include #include #include #include -#include #include #include #include @@ -55,6 +57,7 @@ m_topLayout(nullptr), m_urlNavigator(nullptr), m_searchBox(nullptr), + m_trashWidget(nullptr), m_messageWidget(nullptr), m_view(nullptr), m_filterBar(nullptr), @@ -92,6 +95,9 @@ connect(m_searchBox, &DolphinSearchBox::searchRequest, this, &DolphinViewContainer::startSearching); connect(m_searchBox, &DolphinSearchBox::returnPressed, this, &DolphinViewContainer::requestFocus); + m_trashWidget = new TrashWidget(this); + m_trashWidget->hide(); + m_messageWidget = new KMessageWidget(this); m_messageWidget->setCloseButtonVisible(true); m_messageWidget->hide(); @@ -186,9 +192,17 @@ this, &DolphinViewContainer::requestFocus); connect(m_view, &DolphinView::urlChanged, m_filterBar, &FilterBar::slotUrlChanged); + connect(m_view, &DolphinView::urlChanged, [this](const QUrl &url){ + if (url.scheme() == QLatin1String("trash")) + m_trashWidget->show(); + else + m_trashWidget->hide(); + }); + m_topLayout->addWidget(m_urlNavigator); m_topLayout->addWidget(m_searchBox); + m_topLayout->addWidget(m_trashWidget); m_topLayout->addWidget(m_messageWidget); m_topLayout->addWidget(m_view); m_topLayout->addWidget(m_filterBar); 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/trash/dolphintrash.h b/src/trash/dolphintrash.h new file mode 100644 --- /dev/null +++ b/src/trash/dolphintrash.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * 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 + +void emptyTrash(QWidget *window); + +#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,38 @@ +/*************************************************************************** + * 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 + +void emptyTrash(QWidget *window) +{ + 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); + job->uiDelegate()->setAutoErrorHandlingEnabled(true); + } +} diff --git a/src/trash/dolphintrashwidget.h b/src/trash/dolphintrashwidget.h new file mode 100644 --- /dev/null +++ b/src/trash/dolphintrashwidget.h @@ -0,0 +1,37 @@ +/*************************************************************************** + * 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 DOLPHINTRASHWIDGET_H +#define DOLPHINTRASHWIDGET_H + +#include + +class TrashWidget: public QWidget +{ + Q_OBJECT + +public: + explicit TrashWidget(QWidget* parent = nullptr); + ~TrashWidget() override; + +protected: + void keyReleaseEvent(QKeyEvent* event) override; +}; + +#endif // DOLPHINTRASHWIDGET_H diff --git a/src/trash/dolphintrashwidget.cpp b/src/trash/dolphintrashwidget.cpp new file mode 100644 --- /dev/null +++ b/src/trash/dolphintrashwidget.cpp @@ -0,0 +1,50 @@ +/*************************************************************************** + * 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 "dolphintrashwidget.h" +#include "dolphintrash.h" + +#include +#include +#include +#include +#include +#include + +TrashWidget::TrashWidget(QWidget* parent) : + QWidget(parent) +{ + // Create empty trash button + QPushButton *emptyTrashButton = new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash-symbolic")), "&Empty trash", this); + emptyTrashButton->setFocus(); + connect(emptyTrashButton, &QPushButton::clicked, [this](){ + emptyTrash(this); + hide(); + }); + + // Apply layout + QHBoxLayout* hLayout = new QHBoxLayout(this); + hLayout->setMargin(0); + hLayout->addStretch(); + hLayout->addWidget(emptyTrashButton); +} + +TrashWidget::~TrashWidget() +{ +}