Dekko
Loading...
Searching...
No Matches
NavMenuStandardFolderDelegate.qml
1/* Copyright (C) 2016 - 2017 Dan Chapman <dpniel@ubuntu.com>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18import QtQuick 2.4
19import Lomiri.Components 1.3
20import Lomiri.Components.Popups 1.3
21import Dekko.Mail 1.0
22import Dekko.Components 1.0
23import Dekko.Mail.Stores.Views 1.0
24import Dekko.Lomiri.Components 1.0
25import Dekko.Lomiri.Constants 1.0
27ListItem {
28 id: li
29
30 property var folder
31 signal subFolderClicked(string name, var key)
32 property bool supportsDescendents: false
33 property bool smartFolder: false
34 readonly property bool isCurrentIndex: layout ? layout.title.text === ViewStore.selectedNavFolder : false
35
36 expansion.expanded: false
37 expansion.height: layout.height + col.height
38 height: layout.height
39 divider.visible: false
40
41 trailingActions: ListItemActions {
42 actions: [
43 openCtxtMenu
44 ]
45 }
46
47 function getIconForFolderType(f) {
48 if (smartFolder) {
49 switch (f.type) {
50 case SmartFolderSet.SmartTodayFolder:
51 return Icons.CalendarTodayIcon;
52 case SmartFolderSet.SmartTodoFolder:
53 return Icons.ViewListSymbolic;
54 case SmartFolderSet.SmartDoneFolder:
55 return Icons.SelectIcon;
56 case SmartFolderSet.SmartCustomFolder:
57 return Icons.FilterIcon;
58 default:
59 return Icons.FilterIcon;
60 }
61 } else {
62 switch (f.folderType) {
63 case StandardFolderSet.StandardFolder:
64 return Icons.FolderIcon
65 case StandardFolderSet.SpecialUseInboxFolder:
66 if (f.hasDescendents) {
67 return Icons.CombineInboxIcon
68 } else {
69 return Icons.InboxIcon
70 }
71 case StandardFolderSet.SpecialUseOutboxFolder:
72 return Icons.InboxIcon
73 case StandardFolderSet.SpecialUseDraftsFolder:
74 return Icons.DraftIcon
75 case StandardFolderSet.SpecialUseSentFolder:
76 return Icons.SendIcon;
77 case StandardFolderSet.SpecialUseTrashFolder:
78 return Icons.DeleteIcon
79 case StandardFolderSet.SpecialUseJunkFolder:
80 return Icons.JunkIcon
81 }
82 }
83 }
84
85
86
87 Action {
88 id: openCtxtMenu
89 iconName: "contextual-menu"
90 onTriggered: PopupUtils.open(Qt.resolvedUrl("../popovers/NavViewContextMenu.qml"), li, {folder: li.folder})
91 }
92
93 Rectangle {
94 anchors.fill: layout ? layout : parent
95 color: Qt.rgba(0, 0, 0, 0.05)
96 visible: li.isCurrentIndex
97 }
98 MouseArea {
99 anchors.fill: parent
100 acceptedButtons: Qt.RightButton
101 onClicked: {
102 if (mouse.button === Qt.RightButton) {
103 openCtxtMenu.trigger()
104 mouse.accepted = true
105 } else {
106 mouse.accepted = false
107 }
108 }
109 }
110
111 ListItemLayout {
112 id: layout
113 title.text: folder ? folder.displayName : ""
114 title.font.weight: Font.DemiBold
115 title.color: LomiriColors.silk
116 height: units.gu(6)
117
119 id: attachmentImg
120 height: units.gu(2.6)
121 width: height
122 name: folder ? getIconForFolderType(folder) : ""
123 color: LomiriColors.silk
124 SlotsLayout.position: SlotsLayout.Leading
125 }
126
127 LomiriShape {
128 id: shape
129 // TODO: We should probably display total count for To-Do smart folder
130 visible: folder && folder.unreadCount > 0
131 aspect: LomiriShape.Flat
132 color: LomiriColors.slate
133 height: units.gu(2.2)
134 width: countLable.width < height ? height : countLable.width + units.gu(1)
135 Label {
136 id: countLable
137 anchors.margins: units.gu(0.5)
138 anchors.centerIn: parent
139 fontSize: "small"
140 color: LomiriColors.porcelain
141 text: folder ? folder.unreadCount : ""
142 }
143 }
144
145 Item {
146 visible: model.index === 0 && supportsDescendents
147 height: units.gu(3)
148 width: units.gu(4)
149 Rectangle {
150 anchors.left: parent.left
151 height: parent.height
152 width: units.dp(1)
153 color: LomiriColors.slate
154 }
155 Icon {
156 height: Style.defaultSpacing
157 width: height
158 anchors.right: parent.right
159 anchors.rightMargin: units.gu(0.5)
160 anchors.verticalCenter: parent.verticalCenter
161 name: li.expansion.expanded ? "up" : "down"
162 }
163 SlotsLayout.position: SlotsLayout.Last
164 AbstractButton {
165 anchors.fill: parent
166 onClicked: li.expansion.expanded = !li.expansion.expanded
167 }
168 }
169 }
170 Column {
171 id: col
172 visible: folder && folder.hasDescendents
173 anchors.left: parent.left
174 anchors.leftMargin: units.gu(1.5)
175 anchors.top: layout.bottom
176 anchors.right: parent.right
177 Repeater {
178 model: folder ? folder.descendents : 0
179 delegate: ListItem {
180 id: delegate
181 divider.visible: false
182 height: dlayout.height
183 onClicked: li.subFolderClicked(dlayout.title.text, model.qtObject.messageKey)
184 Rectangle {
185 anchors.fill: parent
186 color: Qt.rgba(0, 0, 0, 0.05)
187 visible: layout ? dlayout.title.text === ViewStore.selectedNavFolder : false
188 }
189 ListItemLayout {
190 id: dlayout
191 height: units.gu(5)
192 title.text: qsTr("Inbox (%1)").arg(qtObject.displayName)
193 title.color: LomiriColors.silk
194
196 height: units.gu(2.4)
197 width: height
198 name: Icons.InboxIcon
199 color: LomiriColors.silk
200 SlotsLayout.position: SlotsLayout.Leading
201 }
202
203 LomiriShape {
204 id: dshape
205 visible: qtObject.unreadCount > 0
206 aspect: LomiriShape.Flat
207 color: LomiriColors.slate
208 height: units.gu(2.2)
209 width: dcountLable.width < height ? height : dcountLable.width + units.gu(1)
210 Label {
211 id: dcountLable
212 anchors.margins: units.gu(0.5)
213 anchors.centerIn: parent
214 text: qtObject.unreadCount
215 fontSize: "small"
216 color: LomiriColors.porcelain
217 }
218 }
219 }
220 }
221 }
222 }
223}
224