8import org.mauikit.controls as Maui
10import "dateutils.js" as DateUtils
11import "labelutils.js" as LabelUtils
12import org.mauikit.calendar
18 readonly property bool darkMode: LabelUtils.isDarkColor(Maui.Theme.backgroundColor)
20 function switchView(newViewComponent, viewSettings) {
21 if(appMain.pageStack.layers.depth > 1) {
22 appMain.pageStack.layers.pop(appMain.pageStack.layers.initialItem);
24 if (appMain.pageStack.depth > 1) {
25 appMain.pageStack.pop();
27 appMain.pageStack.replace(newViewComponent);
29 if (appMain.filterHeaderBarLoaderItem.active && appMain.pageStack.currentItem.mode !== KalendarApplication.Contact) {
30 appMain.pageStack.currentItem.header = appMain.filterHeaderBarLoaderItem.item;
34 for(
const [key, value] of
Object.entries(viewSettings)) {
35 appMain.pageStack.currentItem[key] = value;
39 if (appMain.pageStack.currentItem.mode === KalendarApplication.Event) {
40 appMain.pageStack.currentItem.setToDate(appMain.selectedDate,
true);
44 function editorToUse() {
45 if (!
Maui.Handy.isMobile) {
46 appMain.editorWindowedLoaderItem.active =
true
47 return appMain.editorWindowedLoaderItem.item.incidenceEditorPage
49 appMain.pageStack.layers.push(incidenceEditorPage);
50 return incidenceEditorPage;
54 function setUpAdd(type, addDate, collectionId, includeTime) {
55 let editorToUse = utilsObject.editorToUse();
56 if (editorToUse.editMode || !editorToUse.incidenceWrapper) {
57 editorToUse.incidenceWrapper =
Qt.createQmlObject(
'import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}',
58 editorToUse,
"incidence");
60 editorToUse.editMode =
false;
63 editorToUse.incidenceWrapper.setNewEvent();
65 editorToUse.incidenceWrapper.setNewTodo();
68 if(addDate !== undefined && !isNaN(addDate.getTime())) {
69 let existingStart = editorToUse.incidenceWrapper.incidenceStart;
70 let existingEnd = editorToUse.incidenceWrapper.incidenceEnd;
72 let newStart = addDate;
73 let newEnd =
new Date(newStart.getFullYear(), newStart.getMonth(), newStart.getDate(), newStart.getHours() + 1, newStart.getMinutes());
76 newStart =
new Date(addDate.setHours(existingStart.getHours(), existingStart.getMinutes()));
77 newEnd =
new Date(addDate.setHours(existingStart.getHours() + 1, existingStart.getMinutes()));
81 editorToUse.incidenceWrapper.incidenceStart = newStart;
82 editorToUse.incidenceWrapper.incidenceEnd = newEnd;
84 editorToUse.incidenceWrapper.incidenceEnd = newStart;
88 if(collectionId && collectionId >= 0) {
89 editorToUse.incidenceWrapper.collectionId = collectionId;
90 }
else if(type ===
IncidenceWrapper.TypeEvent && Config.lastUsedEventCollection > -1) {
91 editorToUse.incidenceWrapper.collectionId = Config.lastUsedEventCollection;
92 }
else if (type ===
IncidenceWrapper.TypeTodo && Config.lastUsedTodoCollection > -1) {
93 editorToUse.incidenceWrapper.collectionId = Config.lastUsedTodoCollection;
95 editorToUse.incidenceWrapper.collectionId = CalendarManager.defaultCalendarId(editorToUse.incidenceWrapper);
99 function setUpAddSubTodo(parentWrapper) {
100 let editorToUse = utilsObject.editorToUse();
101 if (editorToUse.editMode || !editorToUse.incidenceWrapper) {
102 editorToUse.incidenceWrapper =
Qt.createQmlObject(
'import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}',
103 editorToUse,
"incidence");
105 editorToUse.editMode =
false;
106 editorToUse.incidenceWrapper.setNewTodo();
107 editorToUse.incidenceWrapper.parent = parentWrapper.uid;
108 editorToUse.incidenceWrapper.collectionId = parentWrapper.collectionId;
109 editorToUse.incidenceWrapper.incidenceStart = parentWrapper.incidenceStart;
110 editorToUse.incidenceWrapper.incidenceEnd = parentWrapper.incidenceEnd;
113 function setUpView(modelData) {
114 appMain.incidenceInfoDrawer.incidenceData = modelData;
115 appMain.incidenceInfoDrawer.open();
118 function fakeModelDataFromIncidenceWrapper(incidenceWrapper) {
120 const collectionDetails = CalendarManager.getCollectionDetails(incidenceWrapper.collectionId)
121 const fakeModelData = {
122 "text": incidenceWrapper.summary,
123 "description": incidenceWrapper.description,
124 "location": incidenceWrapper.location,
125 "startTime": incidenceWrapper.incidenceStart,
126 "endTime": incidenceWrapper.incidenceEnd,
127 "allDay": incidenceWrapper.allDay,
128 "todoCompleted": incidenceWrapper.todoCompleted,
129 "priority": incidenceWrapper.priority,
135 "durationString": incidenceWrapper.durationDisplayString,
136 "recurs": incidenceWrapper.recurrenceData.type !== 0,
137 "hasReminders": incidenceWrapper.remindersModel.rowCount() > 0,
138 "isOverdue": incidenceWrapper.incidenceType ===
IncidenceWrapper.TypeTodo &&
139 !isNaN(incidenceWrapper.incidenceEnd.getTime()) &&
140 incidenceWrapper.incidenceEnd < appMain.currentDate,
141 "isReadOnly": collectionDetails.readOnly,
142 "color": collectionDetails.color,
143 "collectionId": incidenceWrapper.collectionId,
144 "incidenceId": incidenceWrapper.uid,
145 "incidenceType": incidenceWrapper.incidenceType,
146 "incidenceTypeStr": incidenceWrapper.incidenceTypeStr,
147 "incidenceTypeIcon": incidenceWrapper.incidenceIconName,
148 "incidencePtr": incidenceWrapper.incidencePtr,
152 return fakeModelData;
155 function setUpEdit(incidencePtr) {
156 let editorToUse = utilsObject.editorToUse();
157 editorToUse.incidenceWrapper =
Qt.createQmlObject(
'import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}',
158 editorToUse,
"incidence");
159 editorToUse.incidenceWrapper.incidenceItem = CalendarManager.incidenceItem(incidencePtr);
160 editorToUse.incidenceWrapper.triggerEditMode();
161 editorToUse.editMode =
true;
164 function setUpDelete(incidencePtr, deleteDate) {
165 let incidenceWrapper =
Qt.createQmlObject(
'import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}', utilsObject,
"incidence");
166 incidenceWrapper.incidenceItem = CalendarManager.incidenceItem(incidencePtr);
168 const openDialogWindow = appMain.pageStack.pushDialogLayer(appMain.deleteIncidencePageComponent, {
169 incidenceWrapper: incidenceWrapper,
170 deleteDate: deleteDate
172 width: Maui.Style.units.gridUnit * 32,
173 height: Maui.Style.units.gridUnit * 6
176 openDialogWindow.Keys.escapePressed.connect(function() { openDialogWindow.closeDialog() });
179 function completeTodo(incidencePtr) {
180 let
todo =
Qt.createQmlObject(
'import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}',
181 utilsObject,
"incidence");
183 todo.incidenceItem = CalendarManager.incidenceItem(incidencePtr);
186 todo.todoCompleted = !
todo.todoCompleted;
187 CalendarManager.editIncidence(todo);
191 function setUpIncidenceDateChange(incidenceWrapper, startOffset, endOffset, occurrenceDate, caughtDelegate, allDay=null) {
192 appMain.pageStack.currentItem.dragDropEnabled =
false;
194 if(appMain.pageStack.layers.currentItem && appMain.pageStack.layers.currentItem.dragDropEnabled) {
195 appMain.pageStack.layers.currentItem.dragDropEnabled =
false;
198 if(incidenceWrapper.recurrenceData.type === 0) {
199 if (allDay !== null) {
200 incidenceWrapper.allDay = allDay;
202 CalendarManager.updateIncidenceDates(incidenceWrapper, startOffset, endOffset);
204 const onClosingHandler = () => { caughtDelegate.caught =
false; utilsObject.reenableDragOnCurrentView(); };
205 const openDialogWindow = appMain.pageStack.pushDialogLayer(appMain.recurringIncidenceChangePageComponent, {
206 incidenceWrapper: incidenceWrapper,
207 startOffset: startOffset,
208 endOffset: endOffset,
209 occurrenceDate: occurrenceDate,
210 caughtDelegate: caughtDelegate,
213 width: Maui.Style.units.gridUnit * 34,
214 height: Maui.Style.units.gridUnit * 6,
215 onClosing: onClosingHandler()
218 openDialogWindow.Keys.escapePressed.connect(function() { openDialogWindow.closeDialog() });
222 function reenableDragOnCurrentView() {
223 appMain.pageStack.currentItem.dragDropEnabled =
true;
225 if(appMain.pageStack.layers.currentItem && appMain.pageStack.layers.currentItem.dragDropEnabled) {
226 appMain.pageStack.layers.currentItem.dragDropEnabled =
true;
230 function openDayLayer(selectedDate) {
231 appMain.dayScaleModelLoaderItem.active =
true;
233 if(!isNaN(selectedDate.getTime())) {
234 appMain.selectedDate = selectedDate;
236 appMain.dayViewAction.trigger();
This class is a wrapper for a KCalendarCore::Incidence::Ptr object.
AKONADI_CALENDAR_EXPORT KCalendarCore::Todo::Ptr todo(const Akonadi::Item &item)