Dekko
Loading...
Searching...
No Matches
MessageListDelegate.qml
1/* Copyright (C) 2014-2016 Dan Chapman <dpniel@ubuntu.com>
2
3 This file is part of the Dekko email client for Ubuntu Touch/
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 QtQuick.Controls.Suru 2.2
20import Lomiri.Components 1.3
21import Lomiri.Components.Popups 1.1
22import QtGraphicalEffects 1.0
23import Dekko.Components 1.0
24import Dekko.Mail 1.0
25import Dekko.Mail.API 1.0
26import Dekko.Mail.Settings 1.0
27import Dekko.Lomiri.Components 1.0
28import "../popovers"
29import Dekko.Lomiri.Constants 1.0
30
31ListItemWithActions {
32 id: normalMessageItemDelegate
33
34 //---------------------------------
35 // PROPERTIES
36 //---------------------------------
37 property bool canLoad: false
38 property var msg
39 onMsgChanged: {
40 if (msg) {
41 canLoad = true
42 } else {
43 canLoad = false
44 }
45 }
46
47 property alias avatarVisible: inner_name.visible
48
49 property Action flagAction: Action {
50 id: flagAction
51 text: canLoad && msg.isImportant ? qsTr("Un-mark flagged") : qsTr("Mark flagged")
52 iconSource: canLoad && msg.isImportant ? Paths.actionIconUrl(Paths.UnStarredIcon) :
53 Paths.actionIconUrl(Paths.StarredIcon)
54
55 onTriggered: MessageActions.markMessageImportant(msg.messageId, !msg.isImportant)
56 }
57
58 property Action readAction: Action {
59 id: markReadAction
60 text: canLoad && msg.isRead ? qsTr("Mark as un-read") : qsTr("Mark as read")
61 iconSource: canLoad && msg.isRead ? Paths.actionIconUrl(Paths.MailUnreadIcon) :
62 Paths.actionIconUrl(Paths.MailReadIcon)
63 onTriggered: Client.markMessageRead(msg.messageId, !msg.isRead);
64 }
65
66 property Action moveAction: Action {
67 text: qsTr("Move message")
68 iconSource: Paths.actionIconUrl(Paths.InboxIcon)
69 }
70
71 property Action contextAction: Action {
72 text: qsTr("Context menu")
73 iconName: "contextual-menu"
74 onTriggered: rightClickActions.trigger()
75 }
76
77 property Action rightClickActions: Action {
78 id: rightClick
79 onTriggered: PopupUtils.open(Qt.resolvedUrl("../popovers/MessageListActionPopover.qml"),
80 msgListDelegate,
81 {
82 msg: normalMessageItemDelegate.msg
83 })
84 }
85
86 //---------------------------------
87 // OBJECT PROPERTIES
88 //---------------------------------
89 showDivider: false
90 height: main.height
91 triggerActionOnMouseRelease: true
92
93 //---------------------------------
94 // COMPONENTS
95 //---------------------------------
96 ListItemLayout {
97 id: main
98 title.text: msg ? msg.from.name : ""
99 title.font.bold: canLoad && !msg.isRead
100 title.fontSize: "x-small"
101 title.elide: Text.ElideRight
102 title.wrapMode: Text.NoWrap
103
104 subtitle.text: msg ? msg.subject : ""
105 subtitle.font.bold: canLoad && !msg.isRead
106 subtitle.fontSize: "medium"
107 subtitle.elide: Text.ElideRight
108 subtitle.wrapMode: Text.NoWrap
109
110 summary.maximumLineCount: PolicyManager.views.previewLines
111 summary.text: canLoad && msg.preview ? msg.preview : " "
112 summary.fontSize: "medium"
113
114 padding.top: units.gu(1)
115 padding.bottom: units.gu(1)
116
118 id: inner_name
119 msg: normalMessageItemDelegate.msg
120 visible: true
121 height: units.gu(6)
122 width: height
123 SlotsLayout.position: SlotsLayout.Leading
124 onClicked: {
125 if (inner_name.state === "front") {
126 ViewActions.pushToStageArea(ViewKeys.messageListStack, Qt.resolvedUrl("../views/ContactFilterView.qml"),
127 {
128 sender: msg.from,
129 title: msg.from.name,
130 email: msg.from.address,
131 initials: msg.from.initials,
132 filterKey: msg.senderMsgKey
133 }
134 )
135 }
136 }
137 }
138
139 Item {
140 id: inner_infoCol
141
142 property int iconsVerticalSpacing: units.gu(0.5)
143 property int iconsHorizontalSpacing: units.gu(1.0)
144
145 height: inner_timeLabel.height + units.gu(1) + star.height
146 width: Math.max(inner_timeLabel.width, star.width + attachmentImg.width + units.gu(1))
147 SlotsLayout.overrideVerticalPositioning: true
148
149 Label {
150 id: inner_timeLabel
151 y: main.mainSlot.y + main.title.y
152 + main.title.baselineOffset - baselineOffset
153 anchors.right: parent.right
154 text: msg ? msg.prettyDate : ""
155 fontSize: "small"
156 }
157
159 id: star
160 height: Style.defaultSpacing
161 width: height
162 anchors {
163 right: parent.right
164 top: inner_timeLabel.bottom
165 topMargin: parent.iconsVerticalSpacing
166 }
167 name: canLoad && msg.isImportant ? Icons.StarredIcon : Icons.UnStarredIcon
168 Suru.highlightType: Suru.WarningHighlight
169 color: canLoad && msg.isImportant ? Suru.highlightColor : LomiriColors.ash
170 MouseArea {
171 anchors.fill: parent
172 onClicked: MessageActions.markMessageImportant(msg.messageId, !msg.isImportant)
173 }
174 }
175
177 id: attachmentImg
178 height: Style.defaultSpacing
179 width: visible ? height : 0
180 anchors {
181 right: star.left
182 rightMargin: parent.iconsHorizontalSpacing
183 top: inner_timeLabel.bottom
184 topMargin: parent.iconsVerticalSpacing
185 }
186 visible: canLoad && msg.hasAttachments
187 name: Icons.AttachmentIcon
188 color: LomiriColors.ash
189 }
190 }
191 }
192}
Definition main.qml:18