Add empty-trash dialog

This commit is contained in:
revenmartin 2021-05-21 15:55:58 +08:00
parent 39f8e9da82
commit 24ee16ad99
7 changed files with 150 additions and 8 deletions

View file

@ -37,6 +37,7 @@ add_executable(cutefish-filemanager
helper/datehelper.cpp helper/datehelper.cpp
helper/thumbnailer.cpp helper/thumbnailer.cpp
helper/pathhistory.cpp helper/pathhistory.cpp
helper/fm.cpp
desktopiconprovider.cpp desktopiconprovider.cpp

32
helper/fm.cpp Normal file
View file

@ -0,0 +1,32 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: revenmartin <revenmartin@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "fm.h"
#include <KIO/EmptyTrashJob>
Fm::Fm(QObject *parent) : QObject(parent)
{
}
void Fm::emptyTrash()
{
KIO::Job *job = KIO::emptyTrash();
job->start();
}

35
helper/fm.h Normal file
View file

@ -0,0 +1,35 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: revenmartin <revenmartin@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef FM_H
#define FM_H
#include <QObject>
class Fm : public QObject
{
Q_OBJECT
public:
explicit Fm(QObject *parent = nullptr);
Q_INVOKABLE static void emptyTrash();
};
#endif // FM_H

View file

@ -35,6 +35,7 @@
#include "desktop/desktopview.h" #include "desktop/desktopview.h"
#include "helper/thumbnailer.h" #include "helper/thumbnailer.h"
#include "helper/datehelper.h" #include "helper/datehelper.h"
#include "helper/fm.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -64,6 +65,7 @@ int main(int argc, char *argv[])
qmlRegisterType<RubberBand>(uri, 1, 0, "RubberBand"); qmlRegisterType<RubberBand>(uri, 1, 0, "RubberBand");
qmlRegisterType<ItemViewAdapter>(uri, 1, 0, "ItemViewAdapter"); qmlRegisterType<ItemViewAdapter>(uri, 1, 0, "ItemViewAdapter");
qmlRegisterType<DesktopSettings>(uri, 1, 0, "DesktopSettings"); qmlRegisterType<DesktopSettings>(uri, 1, 0, "DesktopSettings");
qmlRegisterType<Fm>(uri, 1, 0, "Fm");
qmlRegisterAnonymousType<QAction>(uri, 1); qmlRegisterAnonymousType<QAction>(uri, 1);
QCommandLineParser parser; QCommandLineParser parser;
@ -74,6 +76,10 @@ int main(int argc, char *argv[])
QCommandLineOption desktopOption(QStringList() << "d" << "desktop" << "Desktop Mode"); QCommandLineOption desktopOption(QStringList() << "d" << "desktop" << "Desktop Mode");
parser.addOption(desktopOption); parser.addOption(desktopOption);
QCommandLineOption emptyTrashOption(QStringList() << "e" << "empty-trash" << "Empty Trash");
parser.addOption(emptyTrashOption);
parser.process(app); parser.process(app);
if (parser.isSet(desktopOption)) { if (parser.isSet(desktopOption)) {
@ -81,6 +87,12 @@ int main(int argc, char *argv[])
DesktopView view; DesktopView view;
view.show(); view.show();
return app.exec(); 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; QQmlApplicationEngine engine;

View file

@ -44,6 +44,7 @@
#include <QPainter> #include <QPainter>
#include <QDrag> #include <QDrag>
#include <QDir> #include <QDir>
#include <QProcess>
// Qt Quick // Qt Quick
#include <QQuickItem> #include <QQuickItem>
@ -54,7 +55,6 @@
#include <KIO/PreviewJob> #include <KIO/PreviewJob>
#include <KIO/DeleteJob> #include <KIO/DeleteJob>
#include <KIO/DropJob> #include <KIO/DropJob>
#include <KIO/EmptyTrashJob>
#include <KIO/FileUndoManager> #include <KIO/FileUndoManager>
#include <KIO/JobUiDelegate> #include <KIO/JobUiDelegate>
#include <KIO/Paste> #include <KIO/Paste>
@ -749,13 +749,7 @@ void FolderModel::moveSelectedToTrash()
void FolderModel::emptyTrash() void FolderModel::emptyTrash()
{ {
KIO::JobUiDelegate uiDelegate; QProcess::startDetached("cutefish-filemanager", QStringList() << "-e");
uiDelegate.setWindow(QApplication::desktop());
if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) {
KIO::Job *job = KIO::emptyTrash();
job->uiDelegate()->setAutoErrorHandlingEnabled(true);
}
} }
void FolderModel::keyDeletePress() void FolderModel::keyDeletePress()

View file

@ -43,5 +43,6 @@
<file>qml/OptionsMenu.qml</file> <file>qml/OptionsMenu.qml</file>
<file>images/light/up.svg</file> <file>images/light/up.svg</file>
<file>images/dark/up.svg</file> <file>images/dark/up.svg</file>
<file>qml/Dialogs/EmptyTrashDialog.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -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
}
}
}
}