From 34e7a3db8086531971b6bca4c4adbd2f77bf250b Mon Sep 17 00:00:00 2001 From: Dimitris Kardarakos Date: Sat, 9 Mar 2019 19:02:54 +0200 Subject: [PATCH] Provide a confirmation dialog before calendar deletion --- src/contents/ui/CalendarAction.qml | 14 ++---- src/contents/ui/ConfirmationSheet.qml | 62 +++++++++++++++++++++++++++ src/contents/ui/Main.qml | 12 ++++++ src/resources.qrc | 1 + 4 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 src/contents/ui/ConfirmationSheet.qml diff --git a/src/contents/ui/CalendarAction.qml b/src/contents/ui/CalendarAction.qml index ef2765c..2b176cd 100644 --- a/src/contents/ui/CalendarAction.qml +++ b/src/contents/ui/CalendarAction.qml @@ -27,6 +27,8 @@ Kirigami.Action { property bool isCalendar: true property var configuration + signal deleteCalendar + checked: (text == configuration.activeCalendar) Kirigami.Action { @@ -42,16 +44,6 @@ Kirigami.Action { text: "Delete" iconName: "delete" - onTriggered: { - if (configuration.activeCalendar == parent.text) { - showPassiveNotification("Active calendar cannot be deleted"); - } - else { - var toRemoveCalendarComponent = Qt.createQmlObject("import org.kde.phone.calindori 0.1 as Calindori; Calindori.LocalCalendar { name: \"" + parent.text + "\"}",root); - toRemoveCalendarComponent.deleteCalendar(); - configuration.removeCalendar(parent.text); - showPassiveNotification("Calendar " + parent.text + " has been deleted"); - } - } + onTriggered: (configuration.activeCalendar == parent.text) ? showPassiveNotification("Active calendar cannot be deleted") : deleteCalendar() } } diff --git a/src/contents/ui/ConfirmationSheet.qml b/src/contents/ui/ConfirmationSheet.qml new file mode 100644 index 0000000..4ab2934 --- /dev/null +++ b/src/contents/ui/ConfirmationSheet.qml @@ -0,0 +1,62 @@ +/* + * Copyright 2019 Dimitris Kardarakos + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library 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. + */ +import QtQuick 2.0 +import QtQuick.Controls 2.4 as Controls2 +import QtQuick.Layouts 1.11 +import org.kde.kirigami 2.4 as Kirigami +import org.kde.phone.calindori 0.1 as Calindori + +Kirigami.OverlaySheet { + id: deleteSheet + + property string calendar + property var configuration + + contentItem: Controls2.Label { + Layout.fillWidth: true + wrapMode: Text.WordWrap + text: "All data included in this calendar will be deleted. Proceed with deletion?" + } + + parent: applicationWindow().overlay + + footer: RowLayout { + Item { + Layout.fillWidth: true + } + + Controls2.ToolButton { + text: qsTr("Delete") + + onClicked: { + var toRemoveCalendarComponent = Qt.createQmlObject("import org.kde.phone.calindori 0.1 as Calindori; Calindori.LocalCalendar { name: \"" + deleteSheet.calendar + "\"}",root); + toRemoveCalendarComponent.deleteCalendar(); + configuration.removeCalendar(deleteSheet.calendar); + showPassiveNotification("Calendar " + deleteSheet.calendar + " has been deleted"); + deleteSheet.close(); + } + } + + Controls2.ToolButton { + text: qsTr("Cancel") + + onClicked: deleteSheet.close() + } + } +} diff --git a/src/contents/ui/Main.qml b/src/contents/ui/Main.qml index e2f459e..932beea 100644 --- a/src/contents/ui/Main.qml +++ b/src/contents/ui/Main.qml @@ -20,6 +20,7 @@ import QtQuick 2.1 import QtQuick.Layouts 1.2 import org.kde.kirigami 2.0 as Kirigami +import QtQuick.Controls 2.4 as Controls2 import org.kde.phone.calindori 0.1 as Calindori import "Utils.js" as Utils @@ -89,6 +90,11 @@ Kirigami.ApplicationWindow { CalendarAction { configuration: calindoriConfig + + onDeleteCalendar: { + deleteSheet.calendar = text; + deleteSheet.open(); + } } } @@ -217,5 +223,11 @@ Kirigami.ApplicationWindow { } } + + ConfirmationSheet { + id: deleteSheet + + configuration: calindoriConfig + } } diff --git a/src/resources.qrc b/src/resources.qrc index f5c1b7c..3a74267 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -13,5 +13,6 @@ contents/ui/CalendarInputPage.qml contents/code/Utils.js contents/ui/CalendarAction.qml + contents/ui/ConfirmationSheet.qml -- GitLab