Warning, /plasma-mobile/calindori/src/contents/ui/CalendarEditor.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Dimitris Kardarakos <dimkard@posteo.net> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 import QtQuick 2.7 0008 import QtQuick.Controls 2.0 as Controls2 0009 import QtQuick.Layouts 1.3 0010 import org.kde.kirigami 2.12 as Kirigami 0011 import org.kde.calindori 0.1 as Calindori 0012 0013 Kirigami.Page { 0014 id: root 0015 0016 enum Mode { 0017 Create, 0018 AddExisting, 0019 Edit 0020 } 0021 0022 property var loadedCalendar 0023 property alias calendarName: nameInput.text 0024 property alias ownerName: ownerNameInput.text 0025 property alias ownerEmail: ownerEmail.text 0026 property int mode: CalendarEditor.Mode.Create 0027 property url calendarFile 0028 0029 signal calendarEditorSaved 0030 signal calendarEditorCancelled 0031 0032 title: mode === CalendarEditor.Mode.Edit ? calendarName : i18n("New calendar") 0033 0034 function addLocalCalendarCfgEntry() { 0035 var insertResult = Calindori.CalindoriConfig.addInternalCalendar(root.calendarName, root.ownerName, root.ownerEmail); 0036 0037 if(!(insertResult.success)) { 0038 validationFooter.text = insertResult.reason; 0039 validationFooter.visible = true; 0040 return; 0041 } 0042 0043 validationFooter.visible = false; 0044 calendarEditorSaved(); 0045 } 0046 0047 function addSharedCalendarCfgEntry() { 0048 var addSharedResult = Calindori.CalindoriConfig.addExternalCalendar(root.calendarName, root.ownerName, root.ownerEmail, root.calendarFile); 0049 0050 if(!(addSharedResult.success)) { 0051 validationFooter.text = addSharedResult.reason; 0052 validationFooter.visible = true; 0053 return; 0054 } 0055 0056 Calindori.CalindoriConfig.setOwnerInfo(root.calendarName, root.ownerName, root.ownerEmail); 0057 0058 validationFooter.visible = false; 0059 calendarEditorSaved(); 0060 } 0061 0062 Kirigami.FormLayout { 0063 id: calendarInputPage 0064 0065 anchors.centerIn: parent 0066 0067 Controls2.TextField { 0068 id: nameInput 0069 0070 visible: root.mode !== CalendarEditor.Mode.Edit 0071 Kirigami.FormData.label: i18n("Calendar:") 0072 } 0073 0074 Controls2.Label { 0075 id: fileName 0076 0077 property bool showFileName: (root.mode == CalendarEditor.Mode.AddExisting) && (root.calendarFile != "") 0078 0079 visible: showFileName 0080 Kirigami.FormData.label: i18n("File:") 0081 text: showFileName ? Calindori.CalendarController.fileNameFromUrl(root.calendarFile) : "" 0082 } 0083 0084 Kirigami.Separator { 0085 Kirigami.FormData.label: i18n("Owner") 0086 Kirigami.FormData.isSection: true 0087 } 0088 0089 Controls2.TextField { 0090 id: ownerNameInput 0091 0092 Kirigami.FormData.label: i18n("Name:") 0093 } 0094 0095 Controls2.TextField { 0096 id: ownerEmail 0097 0098 Kirigami.FormData.label: i18n("Email:") 0099 } 0100 0101 } 0102 0103 actions { 0104 0105 left: Kirigami.Action { 0106 id: cancelAction 0107 0108 text: i18n("Cancel") 0109 icon.name : "dialog-cancel" 0110 0111 onTriggered: { 0112 calendarEditorCancelled(); 0113 } 0114 } 0115 0116 main: Kirigami.Action { 0117 id: saveAction 0118 0119 text: i18n("Save") 0120 enabled: (mode == CalendarEditor.Mode.AddExisting) ? (root.calendarName != "" && root.calendarFile != "") : (root.calendarName != "") 0121 0122 icon.name : "dialog-ok" 0123 0124 onTriggered: { 0125 if ((mode === CalendarEditor.Mode.AddExisting) || (mode === CalendarEditor.Mode.Create)) { 0126 var canAddResult = Calindori.CalindoriConfig.canAddCalendar(root.calendarName); 0127 0128 if(canAddResult && !(canAddResult.success)) { 0129 validationFooter.text = canAddResult.reason; 0130 validationFooter.visible = true; 0131 return; 0132 } 0133 } 0134 0135 switch(mode) { 0136 case CalendarEditor.Mode.AddExisting: 0137 addSharedCalendarCfgEntry(); 0138 break; 0139 case CalendarEditor.Mode.Create: 0140 addLocalCalendarCfgEntry(); 0141 break; 0142 case CalendarEditor.Mode.Edit: 0143 Calindori.CalindoriConfig.setOwnerInfo(root.calendarName, root.ownerName, root.ownerEmail); 0144 calendarEditorSaved(); 0145 break; 0146 default: 0147 return; 0148 } 0149 } 0150 } 0151 0152 right: Kirigami.Action { 0153 id: addFile 0154 0155 visible: root.mode == CalendarEditor.Mode.AddExisting 0156 text: i18n("Add") 0157 icon.name: "list-add" 0158 0159 onTriggered: fileChooser.open() 0160 } 0161 0162 } 0163 0164 footer: Kirigami.InlineMessage { 0165 id: validationFooter 0166 0167 showCloseButton: true 0168 type: Kirigami.MessageType.Warning 0169 visible: false 0170 } 0171 0172 FileChooser { 0173 id: fileChooser 0174 0175 onAccepted: root.calendarFile = fileUrl 0176 } 0177 0178 }