From 24ee16ad993c5c858963250f961afdddebb51703 Mon Sep 17 00:00:00 2001 From: revenmartin Date: Fri, 21 May 2021 15:55:58 +0800 Subject: [PATCH] Add empty-trash dialog --- CMakeLists.txt | 1 + helper/fm.cpp | 32 +++++++++++++++ helper/fm.h | 35 +++++++++++++++++ main.cpp | 12 ++++++ model/foldermodel.cpp | 10 +---- qml.qrc | 1 + qml/Dialogs/EmptyTrashDialog.qml | 67 ++++++++++++++++++++++++++++++++ 7 files changed, 150 insertions(+), 8 deletions(-) create mode 100644 helper/fm.cpp create mode 100644 helper/fm.h create mode 100644 qml/Dialogs/EmptyTrashDialog.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index 49235ab..c465110 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ add_executable(cutefish-filemanager helper/datehelper.cpp helper/thumbnailer.cpp helper/pathhistory.cpp + helper/fm.cpp desktopiconprovider.cpp diff --git a/helper/fm.cpp b/helper/fm.cpp new file mode 100644 index 0000000..7c4b533 --- /dev/null +++ b/helper/fm.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: revenmartin + * + * 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 3 of the License, or + * 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, see . + */ + +#include "fm.h" +#include + +Fm::Fm(QObject *parent) : QObject(parent) +{ + +} + +void Fm::emptyTrash() +{ + KIO::Job *job = KIO::emptyTrash(); + job->start(); +} diff --git a/helper/fm.h b/helper/fm.h new file mode 100644 index 0000000..1c7e7f9 --- /dev/null +++ b/helper/fm.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: revenmartin + * + * 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 3 of the License, or + * 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, see . + */ + +#ifndef FM_H +#define FM_H + +#include + +class Fm : public QObject +{ + Q_OBJECT + +public: + explicit Fm(QObject *parent = nullptr); + + Q_INVOKABLE static void emptyTrash(); +}; + +#endif // FM_H diff --git a/main.cpp b/main.cpp index c9a8d76..0cc0b13 100644 --- a/main.cpp +++ b/main.cpp @@ -35,6 +35,7 @@ #include "desktop/desktopview.h" #include "helper/thumbnailer.h" #include "helper/datehelper.h" +#include "helper/fm.h" int main(int argc, char *argv[]) { @@ -64,6 +65,7 @@ int main(int argc, char *argv[]) qmlRegisterType(uri, 1, 0, "RubberBand"); qmlRegisterType(uri, 1, 0, "ItemViewAdapter"); qmlRegisterType(uri, 1, 0, "DesktopSettings"); + qmlRegisterType(uri, 1, 0, "Fm"); qmlRegisterAnonymousType(uri, 1); QCommandLineParser parser; @@ -74,6 +76,10 @@ int main(int argc, char *argv[]) QCommandLineOption desktopOption(QStringList() << "d" << "desktop" << "Desktop Mode"); parser.addOption(desktopOption); + + QCommandLineOption emptyTrashOption(QStringList() << "e" << "empty-trash" << "Empty Trash"); + parser.addOption(emptyTrashOption); + parser.process(app); if (parser.isSet(desktopOption)) { @@ -81,6 +87,12 @@ int main(int argc, char *argv[]) DesktopView view; view.show(); return app.exec(); + } else if (parser.isSet(emptyTrashOption)) { + // Empty Dialog + QQmlApplicationEngine engine; + const QUrl url(QStringLiteral("qrc:/qml/Dialogs/EmptyTrashDialog.qml")); + engine.load(url); + return app.exec(); } QQmlApplicationEngine engine; diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 7e9285f..5e47e4c 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -44,6 +44,7 @@ #include #include #include +#include // Qt Quick #include @@ -54,7 +55,6 @@ #include #include #include -#include #include #include #include @@ -749,13 +749,7 @@ void FolderModel::moveSelectedToTrash() void FolderModel::emptyTrash() { - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(QApplication::desktop()); - - if (uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::emptyTrash(); - job->uiDelegate()->setAutoErrorHandlingEnabled(true); - } + QProcess::startDetached("cutefish-filemanager", QStringList() << "-e"); } void FolderModel::keyDeletePress() diff --git a/qml.qrc b/qml.qrc index 3d9d877..8d647c7 100644 --- a/qml.qrc +++ b/qml.qrc @@ -43,5 +43,6 @@ qml/OptionsMenu.qml images/light/up.svg images/dark/up.svg + qml/Dialogs/EmptyTrashDialog.qml diff --git a/qml/Dialogs/EmptyTrashDialog.qml b/qml/Dialogs/EmptyTrashDialog.qml new file mode 100644 index 0000000..2080d28 --- /dev/null +++ b/qml/Dialogs/EmptyTrashDialog.qml @@ -0,0 +1,67 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Window 2.12 +import QtQuick.Layouts 1.12 +import FishUI 1.0 as FishUI +import Cutefish.FileManager 1.0 + +Window { + id: control + + title: qsTr("File Manager") + flags: Qt.Dialog + visible: true + + width: 300 + FishUI.Units.largeSpacing * 2 + height: _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 3 + + minimumWidth: width + minimumHeight: height + maximumWidth: width + maximumHeight: height + + Fm { + id: fm + } + + Rectangle { + anchors.fill: parent + color: FishUI.Theme.backgroundColor + } + + ColumnLayout { + id: _mainLayout + anchors.fill: parent + anchors.leftMargin: FishUI.Units.largeSpacing + anchors.rightMargin: FishUI.Units.largeSpacing + anchors.bottomMargin: FishUI.Units.smallSpacing + spacing: FishUI.Units.largeSpacing + + Label { + text: qsTr("Do you want to permanently delete all files from the Trash?") + Layout.fillWidth: true + wrapMode: Text.Wrap + } + + RowLayout { + spacing: FishUI.Units.largeSpacing + + Button { + text: qsTr("Cancel") + Layout.fillWidth: true + onClicked: control.close() + } + + Button { + text: qsTr("Empty Trash") + focus: true + Layout.fillWidth: true + onClicked: { + fm.emptyTrash() + control.close() + } + flat: true + } + } + } +}