Warning, /plasma-mobile/calindori/src/contents/ui/IncidenceListView.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2020 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.ScrollablePage {
0014     id: root
0015 
0016     property date incidenceStartDt
0017     property var calendar
0018     property int incidenceType : -1
0019     property int filterMode: 0
0020 
0021     /**
0022     * @brief Remove the editor page from the stack. If an incidence page exists in the page stack, remove it as well
0023     *
0024     */
0025     function removeEditorPage() {
0026         pageStack.pop();
0027         if(pageStack.lastItem && pageStack.lastItem.hasOwnProperty("isIncidencePage")) {
0028             pageStack.pop(incidencePage);
0029         }
0030     }
0031 
0032     title: incidenceType == 0 ? i18n("Events") : i18n("Tasks")
0033     leftPadding: 0
0034     rightPadding: 0
0035 
0036     actions.main: Kirigami.Action {
0037         id: mainAction
0038 
0039         icon.name: "resource-calendar-insert"
0040         text: (incidenceType === 0) ? i18n("Create Event") : i18n("Create Task")
0041         onTriggered: {
0042             var currentDt = Calindori.CalendarController.localSystemDateTime();
0043             var lStartDt = (incidenceType == 0 && (incidenceStartDt == null || isNaN(incidenceStartDt))) ? new Date(currentDt.getTime() - currentDt.getMinutes()*60000 + 3600000) : incidenceStartDt;
0044             pageStack.push(incidenceType == 0 ? eventEditor : todoEditor, { startDt: lStartDt } );
0045         }
0046     }
0047 
0048     contextualActions: [
0049         Kirigami.Action {
0050             property alias hide: incidenceModel.filterHideCompleted
0051             icon.name: hide ? "show_table_row" : "hide_table_row"
0052             visible: incidenceType == 1
0053             text: hide ? i18n("Show Completed") : i18n("Hide Completed")
0054             onTriggered: hide = !(hide)
0055         }
0056     ]
0057 
0058     Kirigami.PlaceholderMessage {
0059         anchors.centerIn: parent
0060         icon.name: incidenceType == 0 ? "tag-events" : "view-calendar-tasks"
0061         width: parent.width - (Kirigami.Units.largeSpacing * 4)
0062         visible: listView.count == 0
0063         text: !isNaN(incidenceStartDt) ? i18n("Nothing scheduled for %1", incidenceStartDt.toLocaleDateString(_appLocale, Locale.ShortFormat)) : i18n("Nothing scheduled")
0064         helpfulAction: mainAction
0065     }
0066 
0067     ListView {
0068         id: listView
0069 
0070         anchors.fill: parent
0071         model: incidenceModel
0072         enabled: count > 0
0073         spacing: Kirigami.Units.largeSpacing
0074 
0075         section {
0076             property: incidenceType == 0 ? "displayStartDate" : "displayDueDate"
0077             criteria: ViewSection.FullString
0078             delegate: Kirigami.ListSectionHeader {
0079                 label: section
0080             }
0081         }
0082 
0083         delegate: Kirigami.BasicListItem {
0084             id: itemDelegate
0085 
0086             reserveSpaceForIcon: false
0087             label: "%1\t%2".arg(model.allday ? i18n("All day") : (incidenceType == 0 ? model.displayStartTime : model.displayDueTime)).arg(model.summary)
0088             topPadding: Kirigami.Units.gridUnit
0089             bottomPadding: Kirigami.Units.gridUnit
0090 
0091             onClicked: {
0092                 if(pageStack.lastItem && pageStack.lastItem.hasOwnProperty("isIncidencePage")) {
0093                     pageStack.pop(incidencePage);
0094                 }
0095 
0096                 pageStack.push(incidencePage, { incidence: model })
0097             }
0098         }
0099     }
0100 
0101     Calindori.IncidenceModel {
0102         id: incidenceModel
0103 
0104         filterMode: root.filterMode
0105         filterHideCompleted: true
0106         appLocale: _appLocale
0107     }
0108 
0109     Component {
0110         id: incidencePage
0111 
0112         IncidencePage {
0113             calendar: root.calendar
0114         }
0115     }
0116 
0117     Component {
0118         id: eventEditor
0119 
0120         EventEditorPage {
0121             calendar: Calindori.CalendarController.activeCalendar
0122 
0123             onEditcompleted: removeEditorPage()
0124         }
0125     }
0126 
0127     Component {
0128         id: todoEditor
0129 
0130         TodoEditorPage {
0131             onEditcompleted: removeEditorPage()
0132         }
0133     }
0134 }
0135