1/*
2 * SPDX-FileCopyrightText: 2020 Dimitris Kardarakos <dimkard@posteo.net>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7import QtQuick 2.14
8import QtQml.Models 2.14
9import QtQuick.Layouts 1.14
10import org.kde.kirigami 2.6 as Kirigami
11import org.kde.calindori 0.1 as Calindori
12
13Kirigami.GlobalDrawer {
14    id: root
15
16    property var monthView
17    property var calendar
18    property bool wideScreen: false
19    property var applicationFooter
20
21    handleVisible: !root.wideScreen
22    modal: !root.wideScreen
23
24    header: Kirigami.AbstractApplicationHeader {
25        topPadding: Kirigami.Units.smallSpacing
26        bottomPadding: Kirigami.Units.largeSpacing
27        leftPadding: Kirigami.Units.largeSpacing
28        rightPadding: Kirigami.Units.smallSpacing
29        implicitHeight: Kirigami.Units.gridUnit * 2
30        Kirigami.Heading {
31            level: 1
32            text: _calindoriConfig && _calindoriConfig.activeCalendar
33            Layout.fillWidth: true
34        }
35    }
36
37    actions: [
38        Kirigami.Action {
39            id: show
40
41            text: i18n("View")
42            iconName: "view-choose"
43            expandible: true
44
45            Kirigami.Action {
46                text: i18n("Month")
47
48                onTriggered: {
49                    popExtraLayers();
50                    popAll();
51                    pageStack.push(monthView);
52                }
53            }
54
55            Kirigami.Action {
56                text: i18n("Day")
57
58                onTriggered: {
59                    popExtraLayers();
60                    popAll();
61                    pageStack.push(dayView);
62                }
63            }
64
65            Kirigami.Action {
66                text: i18n("Week")
67
68                onTriggered: {
69                    popExtraLayers();
70                    popAll();
71                    pageStack.push(weekView, { startDate: Calindori.CalendarController.localSystemDateTime() } );
72                }
73            }
74
75            Kirigami.Action {
76                text: i18n("All Tasks")
77
78                onTriggered: {
79                    popExtraLayers();
80                    popAll();
81                    pageStack.push(incidenceView, { incidenceType: 1, filterMode: 9 });
82                }
83            }
84
85            Kirigami.Action {
86                text: i18n("All Events")
87
88                onTriggered: {
89                    popExtraLayers();
90                    popAll();
91                    pageStack.push(incidenceView, { incidenceType: 0, filterMode: 8 });
92                }
93            }
94        },
95
96        Kirigami.Action {
97            id: calendarManagement
98
99            text: i18n("Calendars")
100            iconName: "view-calendar"
101
102            // Internal Calendars
103            Kirigami.Action {
104                id: localCalendars
105
106                iconName: "view-calendar"
107                text: i18n("Local")
108                expandible: true
109                children: [calendarCreateAction]
110
111            }
112
113            // External Calendars
114            Kirigami.Action {
115                id: externalCalendars
116
117                visible: true
118                iconName: "view-calendar"
119                text: i18n("External")
120                expandible: true
121                children: [calendarAddExistingAction]
122            }
123        },
124
125        Kirigami.Action {
126            text: i18n("Settings")
127            iconName: "settings-configure"
128
129            onTriggered: {
130                popExtraLayers();
131                pageStack.layers.push(settingsPage);
132            }
133        },
134
135        Kirigami.Action {
136            id: aboutAction
137
138            iconName: "help-about-symbolic"
139            text: i18n("About")
140
141            onTriggered: {
142                popExtraLayers();
143                pageStack.layers.push(aboutInfoPage);
144            }
145        }
146    ]
147
148    Instantiator {
149        model: _calindoriConfig && _calindoriConfig.internalCalendars
150
151        delegate: CalendarAction {
152            loadedCalendar: root.calendar
153            text: modelData
154            messageFooter: root.applicationFooter
155        }
156
157        onObjectAdded: localCalendars.children.push(object)
158
159        onObjectRemoved: {
160            // HACK this is not pretty because onObjectRemoved is called for each calendar, but we cannot remove a single child
161            localCalendars.children = [];
162            localCalendars.children.push(calendarCreateAction);
163        }
164    }
165
166    Instantiator {
167        model: _calindoriConfig && _calindoriConfig.externalCalendars
168
169        delegate: CalendarAction {
170            loadedCalendar: root.calendar
171            text: modelData
172            messageFooter: root.applicationFooter
173        }
174
175        onObjectAdded: externalCalendars.children.push(object)
176
177        onObjectRemoved: {
178            // HACK this is not pretty because onObjectRemoved is called for each calendar, but we cannot remove a single child
179            externalCalendars.children = [];
180            externalCalendars.children.push(calendarAddExistingAction);
181        }
182    }
183
184    Item {
185        visible: false
186
187        states: [
188            State {
189                when: root.wideScreen
190                PropertyChanges { target: root; drawerOpen: true }
191            },
192            State {
193                when: !root.wideScreen
194                PropertyChanges { target: root; drawerOpen: false }
195            }
196        ]
197    }
198
199    Kirigami.Action {
200        id: calendarCreateAction
201
202        text: i18n("Create")
203        iconName: "resource-calendar-insert"
204
205        onTriggered: {
206            pageStack.layers.push(calendarEditor, {mode: CalendarEditor.Mode.Create});
207        }
208    }
209
210    Kirigami.Action {
211        id: calendarAddExistingAction
212
213        text: i18n("Add")
214        iconName: "resource-calendar-child-insert"
215
216        onTriggered: {
217
218            pageStack.layers.push(calendarEditor, {mode: CalendarEditor.Mode.AddExisting});
219        }
220    }
221
222    Component {
223        id: calendarEditor
224
225        CalendarEditor {
226
227            loadedCalendar: root.calendar
228
229            onCalendarEditorSaved: pageStack.layers.pop()
230
231            onCalendarEditorCancelled: pageStack.layers.pop()
232
233        }
234    }
235
236    Component {
237        id: dayView
238
239        DayPage {
240            wideScreen: root.wideScreen
241        }
242    }
243
244    Component {
245        id: weekView
246
247        WeekPage {
248            wideScreen: root.wideScreen
249        }
250    }
251
252    Component {
253        id: incidenceView
254
255        IncidenceListView {
256            calendar: root.calendar
257        }
258    }
259
260    Component {
261        id: settingsPage
262
263        SettingsPage {}
264    }
265
266    Component {
267        id: aboutInfoPage
268
269        Kirigami.AboutPage
270        {
271            aboutData: _aboutData
272        }
273    }
274}
275