Debian Codegraph @

src/app/qml/ui/FileDetailsPopover.qml

raw
1 /*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Arto Jalkanen <[email protected]>
17 */
18 import QtQuick 2.4
19 import Lomiri.Components 1.3
20 import Lomiri.Components.Popups 1.3
21 import QtQuick.Layouts 1.1
22
23 Dialog {
24 id: root
25 property var model
26
27 function dateTimeFormat(dateTime) {
28 return Qt.formatDateTime(dateTime, Qt.DefaultLocaleShortDate) || "Unknown"
29 }
30
31 function permissionsToString(model) {
32 var permissions = []
33 if (model.isReadable) {
34 permissions.push(i18n.tr("Readable"))
35 }
36 if (model.isWritable) {
37 permissions.push(i18n.tr("Writable"))
38 }
39 if (model.isExecutable) {
40 permissions.push(i18n.tr("Executable"))
41 }
42
43 // Now why does this not work?
44 // return permissions.join(", ")
45 var permStr = ""
46 for (var i = 0; i < permissions.length; ++i) {
47 if (permStr.length > 0) {
48 permStr += ", "
49 }
50 permStr += permissions[i]
51 }
52 return permStr
53 }
54
55 __closeOnDismissAreaPress: true
56
57 Component.onCompleted: {
58 __foreground.itemSpacing = units.gu(0)
59 }
60
61 RowLayout {
62 Icon {
63 Layout.preferredWidth: units.gu(6)
64 Layout.preferredHeight: width
65 name: model.iconName
66 visible: !image.visible
67 }
68
69 Image {
70 id: image
71 Layout.preferredWidth: units.gu(6)
72 Layout.preferredHeight: width
73 sourceSize: Qt.size(units.gu(6), width)
74 visible: status == Image.Ready
75
76 source: model.mimeType.indexOf("image/") > -1 ? model.filePath : ""
77 fillMode: Image.PreserveAspectFit
78 asynchronous: true
79 }
80
81 ListItemLayout {
82 Layout.fillWidth: true
83 Layout.fillHeight: true
84 title.text: FmUtils.pathTitle(model.filePath)
85 subtitle.text: model.mimeTypeDescription
86 summary.text: model.fileSize
87 }
88 }
89
90 Rectangle {
91 anchors { left: parent.left; right: parent.right }
92 height: units.dp(1)
93 color: theme.palette.normal.base
94 }
95
96 ListItemLayout {
97 anchors { left: parent.left; right: parent.right }
98 anchors.leftMargin: units.gu(-2)
99 anchors.rightMargin: units.gu(-2)
100 subtitle.text: i18n.tr("Where:")
101 summary.maximumLineCount: Number.MAX_VALUE
102 summary.wrapMode: Text.WrapAtWordBoundaryOrAnywhere
103 summary.text: model.filePath.toString().replace(/^\//, i18n.tr("My Device") + " > ").replace(/\//g, " > ")
104 }
105
106 Rectangle {
107 anchors { left: parent.left; right: parent.right }
108 height: units.dp(1)
109 color: theme.palette.normal.base
110 }
111
112 ListItem {
113 divider.visible: false
114 height: dateGrid.height + units.gu(4)
115
116 GridLayout {
117 id: dateGrid
118 anchors.verticalCenter: parent.verticalCenter
119 columns: 2
120 rowSpacing: units.dp(2)
121
122 // Row #1
123 Label {
124 Layout.fillWidth: true
125 textSize: Label.Small
126 color: theme.palette.normal.backgroundSecondaryText
127 text: i18n.tr("Created:")
128 }
129
130 Label {
131 textSize: Label.Small
132 color: theme.palette.normal.backgroundTertiaryText
133 text: dateTimeFormat(model.creationDate)
134 }
135
136 // Row #2
137 Label {
138 Layout.fillWidth: true
139 textSize: Label.Small
140 color: theme.palette.normal.backgroundSecondaryText
141 text: i18n.tr("Modified:")
142 }
143
144 Label {
145 textSize: Label.Small
146 color: theme.palette.normal.backgroundTertiaryText
147 text: dateTimeFormat(model.modifiedDate)
148 }
149
150 // Row #3
151 Label {
152 Layout.fillWidth: true
153 textSize: Label.Small
154 color: theme.palette.normal.backgroundSecondaryText
155 text: i18n.tr("Accessed:")
156 }
157
158 Label {
159 textSize: Label.Small
160 color: theme.palette.normal.backgroundTertiaryText
161 text: dateTimeFormat(model.accessedDate)
162 }
163 }
164 }
165
166 Rectangle {
167 anchors { left: parent.left; right: parent.right }
168 height: units.dp(1)
169 color: theme.palette.normal.base
170 }
171
172 ListItemLayout {
173 anchors { left: parent.left; right: parent.right }
174 anchors.leftMargin: units.gu(-2)
175 anchors.rightMargin: units.gu(-2)
176 subtitle.text: i18n.tr("Permissions:")
177 summary.maximumLineCount: Number.MAX_VALUE
178 summary.wrapMode: Text.WrapAtWordBoundaryOrAnywhere
179 summary.text: permissionsToString(model)
180 }
181
182 Button {
183 id: closeButton
184 text: i18n.tr("Close")
185 color: LomiriColors.graphite
186 onClicked: {
187 PopupUtils.close(root)
188 }
189 }
190 }