Warning, /plasma-mobile/calindori/src/contents/ui/ManageCalendarsPage.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Dimitris Kardarakos <dimkard@posteo.net> 0003 * SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org> 0004 * 0005 * SPDX-License-Identifier: GPL-3.0-or-later 0006 */ 0007 0008 import QtQuick 2.15 0009 import QtQuick.Layouts 1.15 0010 import QtQuick.Controls 2.15 as Controls 0011 import QtQml.Models 2.15 0012 import org.kde.kirigami 2.19 as Kirigami 0013 import org.kde.calindori 0.1 as Calindori 0014 0015 Kirigami.ScrollablePage { 0016 id: root 0017 0018 property var applicationFooter 0019 property var calendarModel 0020 property bool isExternal: false 0021 0022 mainAction: Kirigami.Action { 0023 text: root.isExternal ? i18n("Add") : i18n("Create") 0024 iconName: root.isExternal ? "resource-calendar-child-insert" : "resource-calendar-insert" 0025 onTriggered: { 0026 applicationWindow().pageStack.push(calendarEditor, 0027 {mode: root.isExternal ? CalendarEditor.Mode.AddExisting : CalendarEditor.Mode.Create}); 0028 } 0029 } 0030 0031 ListView { 0032 id: listView 0033 model: calendarModel 0034 currentIndex: -1 0035 0036 Kirigami.PlaceholderMessage { 0037 anchors.centerIn: parent 0038 visible: listView.count === 0 0039 0040 icon.name: "view-calendar" 0041 text: root.isExternal ? i18n("No external calendars found") : 0042 i18n("No calendars found") 0043 explanation: root.isExternal ? i18n("Import an existing calendar file.") : 0044 i18n("Add a new calendar.") 0045 helpfulAction: root.mainAction 0046 } 0047 0048 // create new calendar editor 0049 Component { 0050 id: calendarEditor 0051 0052 CalendarEditor { 0053 loadedCalendar: root.calendar 0054 onCalendarEditorSaved: pageStack.pop() 0055 onCalendarEditorCancelled: pageStack.pop() 0056 } 0057 } 0058 0059 // dialog that pops up for editing 0060 Kirigami.MenuDialog { 0061 id: modifyDialog 0062 property var calendarName: "" 0063 property bool calendarActive: Calindori.CalindoriConfig !== null ? (Calindori.CalindoriConfig.activeCalendar === calendarName) : false 0064 0065 title: i18n("Modify " + calendarName) 0066 actions: [ 0067 Kirigami.Action { 0068 text: i18n("Activate") 0069 iconName: "dialog-ok" 0070 visible: !modifyDialog.calendarActive 0071 0072 onTriggered: { 0073 modifyDialog.close(); 0074 Calindori.CalindoriConfig.activeCalendar = modifyDialog.calendarName; 0075 popExtraLayers(); 0076 showPassiveNotification(i18n("Calendar %1 has been activated", modifyDialog.calendarName)); 0077 } 0078 }, 0079 0080 Kirigami.Action { 0081 text: i18n("Delete") 0082 iconName: "entry-delete" 0083 visible: !Calindori.CalindoriConfig.isExternal(modifyDialog.calendarName) 0084 onTriggered: { 0085 modifyDialog.close(); 0086 if (modifyDialog.calendarActive) { 0087 showPassiveNotification(i18n("Calendar must not be active when being deleted.")); 0088 } else { 0089 deleteSheet.calendarName = modifyDialog.calendarName; 0090 deleteSheet.timer.restart(); 0091 } 0092 } 0093 }, 0094 0095 Kirigami.Action { 0096 text: i18n("Remove") 0097 iconName: "edit-delete" 0098 visible: Calindori.CalindoriConfig.isExternal(modifyDialog.calendarName) 0099 onTriggered: { 0100 modifyDialog.close(); 0101 if (modifyDialog.calendarActive) { 0102 showPassiveNotification(i18n("Calendar must not be active when being deleted.")); 0103 } else { 0104 Calindori.CalindoriConfig.removeCalendar(modifyDialog.calendarName); 0105 } 0106 } 0107 }, 0108 0109 Kirigami.Action { 0110 text: i18n("Edit details") 0111 iconName: "edit-entry" 0112 onTriggered: { 0113 modifyDialog.close(); 0114 applicationWindow().pageStack.push(editor, { calendarName: modifyDialog.calendarName }); 0115 } 0116 }, 0117 0118 Kirigami.Action { 0119 text: i18n("Import calendar file") 0120 iconName: "document-import" 0121 onTriggered: { 0122 modifyDialog.close(); 0123 root.applicationFooter.targetCalendarName = modifyDialog.calendarName; 0124 fileChooser.open(); 0125 } 0126 }, 0127 0128 Kirigami.Action { 0129 text: i18n("Export calendar to file") 0130 iconName: "document-export" 0131 onTriggered: { 0132 modifyDialog.close(); 0133 var exportResult = Calindori.CalendarController.exportData(modifyDialog.calendarName); 0134 root.applicationFooter.text = exportResult.reason; 0135 0136 if (!(exportResult.success)) { 0137 root.applicationFooter.footerMode = MessageBoard.FooterMode.EndExportFailure; 0138 return; 0139 } 0140 0141 root.applicationFooter.targetFolder = exportResult.targetFolder; 0142 root.applicationFooter.footerMode = MessageBoard.FooterMode.EndExportSuccess; 0143 } 0144 } 0145 ] 0146 } 0147 0148 // confirmation dialog for deletion 0149 Kirigami.PromptDialog { 0150 id: deleteSheet 0151 property string calendarName 0152 0153 title: i18n("Confirm") 0154 subtitle: i18n("All data included in this calendar will be deleted. Proceed with deletion?") 0155 0156 standardButtons: Kirigami.Dialog.Yes | Kirigami.Dialog.No 0157 onAccepted: { 0158 var toRemoveCalendarComponent = Qt.createQmlObject("import org.kde.calindori 0.1 as Calindori; Calindori.LocalCalendar { name: \"" + calendarName + "\"}",deleteSheet); 0159 toRemoveCalendarComponent.deleteCalendar(); 0160 Calindori.CalindoriConfig.removeCalendar(calendarName); 0161 } 0162 0163 // workaround for dialog closing immediately 0164 property var timer: Timer { 0165 interval: 50 0166 running: false 0167 onTriggered: deleteSheet.open(); 0168 } 0169 } 0170 0171 // calendar editor 0172 Component { 0173 id: editor 0174 0175 CalendarEditor { 0176 id: editor 0177 mode: CalendarEditor.Mode.Edit 0178 ownerName: Calindori.CalindoriConfig.ownerName(editor.calendarName) 0179 ownerEmail: Calindori.CalindoriConfig.ownerEmail(editor.calendarName) 0180 0181 onCalendarEditorCancelled: applicationWindow().pageStack.pop() 0182 onCalendarEditorSaved: { 0183 applicationWindow().pageStack.pop(); 0184 if (Calindori.CalindoriConfig.activeCalendar && (Calindori.CalindoriConfig.activeCalendar.name === editor.calendarName)) { 0185 Calindori.CalindoriConfig.activeCalendar.ownerName = ownerName; 0186 Calindori.CalindoriConfig.activeCalendar.ownerEmail = ownerEmail; 0187 } 0188 } 0189 } 0190 } 0191 0192 FileChooser { 0193 id: fileChooser 0194 0195 onAccepted: Calindori.DataHandler.importFromUrl(fileUrl) 0196 } 0197 0198 // list delegate 0199 delegate: Kirigami.SwipeListItem { 0200 property string calendarName: modelData 0201 0202 contentItem: RowLayout { 0203 spacing: 0 0204 0205 Kirigami.Icon { 0206 Layout.leftMargin: Kirigami.Units.largeSpacing 0207 Layout.rightMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing 0208 Layout.alignment: Qt.AlignVCenter 0209 source: "view-calendar" 0210 implicitHeight: Kirigami.Units.iconSizes.smallMedium 0211 implicitWidth: Kirigami.Units.iconSizes.smallMedium 0212 } 0213 0214 Kirigami.Heading { 0215 Layout.fillWidth: true 0216 type: Kirigami.Heading.Secondary 0217 level: 6 0218 text: calendarName 0219 elide: Text.ElideRight 0220 } 0221 } 0222 0223 onClicked: { 0224 modifyDialog.calendarName = calendarName 0225 modifyDialog.open(); 0226 } 0227 0228 actions: [ 0229 Kirigami.Action { 0230 text: i18n("Modify") 0231 icon.name: "entry-edit" 0232 onTriggered: { 0233 modifyDialog.calendarName = calendarName 0234 modifyDialog.open(); 0235 } 0236 } 0237 ] 0238 } 0239 0240 } 0241 }