Main.qml 7.13 KB
Newer Older
Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
1
/*
2
 *   Copyright 2019 Dimitris Kardarakos <dimkard@posteo.net>
Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2 or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import QtQuick 2.1
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.0 as Kirigami
23
import QtQuick.Controls 2.4 as Controls2
24
import org.kde.phone.calindori 0.1 as Calindori
25
import "Utils.js" as Utils
Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
26 27 28

Kirigami.ApplicationWindow {
    id: root
29 30 31 32 33 34

    /**
     * To be emitted when data displayed should be refreshed
     */
    signal refreshNeeded;

Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
35 36
    globalDrawer: Kirigami.GlobalDrawer {
        id: drawer
37 38 39 40 41 42

        title: "Calindori"
        actions: [
            Kirigami.Action {
                id: calendarActions

43
                text: i18n("Calendars")
44
                iconName: "view-calendar"
45 46

                Kirigami.Action {
47
                    text: i18n("Create")
48
                    iconName: "list-add"
49
                    onTriggered: root.pageStack.push(calendarEditor, {mode: "add"})
50 51 52
                }

                Kirigami.Action {
53
                    text: i18n("Import")
54 55
                    iconName: "document-import"

56
                    onTriggered: root.pageStack.push(calendarEditor, {mode: "import"})
57 58 59 60 61
                }

                Kirigami.Action {
                    separator: true
                }
62 63 64 65 66
            },

            Kirigami.Action {
                id: show

67
                text: i18n("Show")
68
                iconName: "view-choose"
69 70 71

                Kirigami.Action {
                    text: "Calendar"
72
                    iconName: "view-calendar-day"
73 74
                    onTriggered: {
                        pageStack.clear();
75
                        pageStack.push(calendarDashboardComponent);
76 77 78 79
                    }
                }

                Kirigami.Action {
80
                    text: i18n("Tasks (%1)", localCalendar.name)
81
                    iconName: "view-calendar-tasks"
82 83
                    onTriggered: {
                        pageStack.clear();
84
                        pageStack.push(todosView, { todoDt: localCalendar.nulldate });
85 86
                    }
                }
87 88
            }
        ]
89

90
        Component.onCompleted: Utils.loadGlobalActions(calindoriConfig.calendars, calendarActions, calendarAction)
Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
91
    }
92 93 94 95

    contextDrawer: Kirigami.ContextDrawer {
        id: contextDrawer
    }
96

Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
97
    pageStack.initialPage: [calendarDashboardComponent]
98
    pageStack.defaultColumnWidth: pageStack.width
99 100 101 102

    Calindori.Config {
        id: calindoriConfig

103 104
        onActiveCalendarChanged: Utils.loadGlobalActions(calindoriConfig.calendars, calendarActions, calendarAction)
        onCalendarsChanged: Utils.loadGlobalActions(calindoriConfig.calendars, calendarActions, calendarAction)
105 106 107 108 109 110 111
    }

    Calindori.LocalCalendar {
        id: localCalendar

        name: calindoriConfig.activeCalendar

112 113
        onNameChanged: {
            root.refreshNeeded();
114 115
            if (root.pageStack.depth > 1) {
                root.pageStack.pop(null);
116
                root.pageStack.push(calendarDashboardComponent);
117
            }
118
        }
119 120
    }

121 122 123 124
    /**
     * Action that represents a calendar configuration entry
     * It is added dynamically to the global drawer
     */
125 126 127
    Component {
        id: calendarAction

128 129
        CalendarAction {
            configuration: calindoriConfig
130 131 132 133 134

            onDeleteCalendar: {
                deleteSheet.calendar = text;
                deleteSheet.open();
            }
135 136
        }
    }
Nicolas Fella's avatar
Nicolas Fella committed
137

Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
138 139
    Component {
        id: calendarDashboardComponent
140

141
        Kirigami.Page {
142

143
            title: calendarMonthView.displayedMonthName + " " + calendarMonthView.displayedYear
144

145
            actions {
146 147
                left: Kirigami.Action {
                    iconName: "go-previous"
148

149
                    onTriggered: calendarMonthView.previousMonth()
150
                }
151

152 153
                main: Kirigami.Action {
                    iconName: "view-calendar-day"
154

155
                    onTriggered: calendarMonthView.goToday()
156
                }
157

158 159
                right: Kirigami.Action {
                    iconName: "go-next"
160

161
                    onTriggered: calendarMonthView.nextMonth()
162
                }
163

164
                contextualActions: [
165 166
                    Kirigami.Action {
                        iconName: "view-calendar-tasks"
167
                        text: i18n("Tasks")
168

169 170
                        onTriggered: root.pageStack.push(todosView, { todoDt: calendarMonthView.selectedDate })
                    },
171 172 173

                    Kirigami.Action {
                        iconName: "view-calendar-events"
174
                        text: i18n("Events")
175

176
                        onTriggered: root.pageStack.push(eventsView, { eventStartDt: calendarMonthView.selectedDate })
177 178
                    }
                ]
179
            }
180

181 182
            CalendarMonthView {
                id: calendarMonthView
183 184

                anchors.centerIn: parent
185 186
                showHeader: true
                showMonthName: true
187

Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
188 189
                todosCount: function (todosDate) {
                    return localCalendar.todosCount(todosDate);
190
                }
191

192 193 194 195
                eventsCount: function (eventsDate) {
                    return localCalendar.eventsCount(eventsDate);
                }

196 197 198 199 200
                onSelectedDateChanged: {
                    if (root.pageStack.depth > 1) {
                        root.pageStack.pop(null);
                    }
                }
201

202 203
                Connections {
                    target: root
204

205
                    onRefreshNeeded: calendarMonthView.refresh()
206
                }
207
            }
Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
208 209
        }
    }
210

211
    Component {
Nicolas Fella's avatar
Nicolas Fella committed
212
        id: todosView
213

214 215 216 217 218
        TodosView {

            calendar: localCalendar

            onTasksUpdated: root.refreshNeeded()
Nicolas Fella's avatar
Nicolas Fella committed
219

220 221 222 223 224 225
            Connections {
                target: root

                onRefreshNeeded: reload()
            }
        }
226 227
    }

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
    Component {
        id: eventsView

        EventsView {
            calendar: localCalendar

            onEventsUpdated: root.refreshNeeded()

            Connections {
                target: root

                onRefreshNeeded: reload()
            }
        }
    }

244
    Component {
245
        id: calendarEditor
246

247
        CalendarEditor {
248

249
            configuration: calindoriConfig
250

251
            onCalendarAdded: {
252
                root.refreshNeeded();
253
                root.pageStack.pop(calendarEditor);
254 255 256
            }

            onCalendarAddCanceled: {
257
                root.pageStack.pop(calendarEditor);
258 259 260
            }

        }
261
    }
262 263 264 265 266 267

    ConfirmationSheet {
        id: deleteSheet

        configuration: calindoriConfig
    }
Dimitris Kardarakos's avatar
Dimitris Kardarakos committed
268
}
269