-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskwarriorWidget.qml
More file actions
327 lines (289 loc) · 13 KB
/
TaskwarriorWidget.qml
File metadata and controls
327 lines (289 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Common
import qs.Widgets
import qs.Modules.Plugins
import "translations.js" as Tr
PluginComponent {
id: root
layerNamespacePlugin: "taskwarrior"
property var tasks: []
readonly property int pendingCount: tasks.length
property bool showAddInput: false
readonly property string lang: Qt.locale().name.split(/[_-]/)[0]
function tr(key) { return Tr.tr(key, lang) }
function trn(key, count) { return Tr.trn(key, count, lang) }
function formatDue(raw) {
if (!raw) return ""
const due = new Date(
raw.substring(0,4) + "-" + raw.substring(4,6) + "-" + raw.substring(6,8) +
"T" + raw.substring(9,11) + ":" + raw.substring(11,13) + ":" + raw.substring(13,15) + "Z"
)
const diffMin = Math.round((due - new Date()) / 60000)
if (diffMin < -2880) return Math.round(diffMin / 1440) + "d"
if (diffMin < -1440) return tr("yesterday")
if (diffMin < -60) return Math.round(diffMin / 60) + "h"
if (diffMin < 0) return diffMin + "min"
if (diffMin < 1) return tr("now")
if (diffMin < 60) return diffMin + "min"
if (diffMin < 1440) return Math.round(diffMin / 60) + "h"
if (diffMin < 2880) return tr("tomorrow")
return Math.round(diffMin / 1440) + "d"
}
function markDone(uuid) {
const p = doneProcessComponent.createObject(root, { taskUuid: uuid })
if (p) p.running = true
}
function addTask(args) {
if (args.trim().length === 0) return
const p = addTaskProcessComponent.createObject(root, { args: args })
if (p) p.running = true
}
function submitTask(inputField) {
root.addTask(inputField.text)
inputField.text = ""
root.showAddInput = false
}
Component {
id: doneProcessComponent
Process {
property string taskUuid: ""
command: ["task", taskUuid.toString(), "done"]
onExited: (exitCode) => {
if (exitCode !== 0)
console.error("[taskwarrior] failed to complete task", taskUuid)
taskProcess.running = true
destroy()
}
}
}
Component {
id: addTaskProcessComponent
Process {
property string args: ""
command: ["task", "add"].concat(args.trim().split(/\s+/).filter(s => s.length > 0))
onExited: (exitCode) => {
if (exitCode !== 0)
console.error("[taskwarrior] failed to add task")
taskProcess.running = true
destroy()
}
}
}
Process {
id: taskProcess
running: false
command: ["sh", "-c", "task status:pending export"]
stdout: StdioCollector {
onStreamFinished: {
try {
const parsed = JSON.parse(text)
root.tasks = parsed.sort((a, b) => (b.urgency ?? 0) - (a.urgency ?? 0))
} catch (e) {
console.error("[taskwarrior] parse error:", e)
}
}
}
}
Timer {
interval: 60000
repeat: true
running: true
onTriggered: taskProcess.running = true
}
Component.onCompleted: taskProcess.running = true
horizontalBarPill: Component {
Row {
spacing: (root.barConfig?.noBackground ?? false) ? 1 : 2
DankIcon {
name: "task_alt"
size: Theme.barIconSize(root.barThickness, -4)
color: Theme.widgetIconColor
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
text: root.pendingCount.toString()
font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale)
color: Theme.widgetTextColor
anchors.verticalCenter: parent.verticalCenter
}
}
}
verticalBarPill: Component {
Column {
spacing: 1
DankIcon {
name: "task_alt"
size: Theme.barIconSize(root.barThickness)
color: Theme.widgetIconColor
anchors.horizontalCenter: parent.horizontalCenter
}
StyledText {
text: root.pendingCount.toString()
font.pixelSize: Theme.barTextSize(root.barThickness, root.barConfig?.fontScale)
color: Theme.widgetTextColor
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
popoutContent: Component {
PopoutComponent {
headerText: tr("Tasks")
detailsText: trn("%{count} pending", root.pendingCount)
showCloseButton: true
headerActions: Component {
Row {
spacing: 4
DankActionButton {
iconName: "add"
iconColor: Theme.surfaceVariantText
buttonSize: 28
tooltipText: tr("Add task")
tooltipSide: "bottom"
onClicked: {
root.showAddInput = !root.showAddInput
if (!root.showAddInput) addInput.text = ""
}
}
DankActionButton {
iconName: "refresh"
iconColor: Theme.surfaceVariantText
buttonSize: 28
tooltipText: tr("Refresh")
tooltipSide: "bottom"
onClicked: taskProcess.running = true
}
}
}
Column {
width: parent.width
spacing: Theme.spacingS
Row {
visible: root.showAddInput
width: parent.width
spacing: 4
DankTextField {
id: addInput
placeholderText: tr("e.g. Buy milk +shopping priority:H")
width: parent.width - submitBtn.width - parent.spacing
Keys.onReturnPressed: root.submitTask(addInput)
Keys.onEscapePressed: {
root.showAddInput = false
addInput.text = ""
}
}
DankButton {
id: submitBtn
text: tr("Add")
onClicked: root.submitTask(addInput)
}
}
Repeater {
model: root.tasks.slice(0, 10)
delegate: StyledRect {
required property var modelData
width: parent.width
height: cardContent.implicitHeight + Theme.spacingM * 2
radius: Theme.cornerRadius
color: Theme.withAlpha(Theme.surfaceContainerHighest, Theme.popupTransparency)
Row {
id: cardContent
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: Theme.spacingM
spacing: Theme.spacingM
Rectangle {
width: 8; height: 8; radius: 4
anchors.verticalCenter: parent.verticalCenter
color: {
const u = modelData.urgency ?? 0
if (u >= 10) return Theme.error
if (u >= 5) return Theme.warning ?? Theme.primary
return Theme.primary
}
}
Column {
width: parent.width - 8 - 28 - Theme.spacingM * 2
spacing: 2
StyledText {
width: parent.width
text: modelData.description ?? ""
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceText
elide: Text.ElideRight
}
Row {
spacing: Theme.spacingS
visible: !!(modelData.priority || modelData.due || (modelData.tags ?? []).length > 0)
Rectangle {
visible: !!modelData.priority
width: priorityLabel.implicitWidth + 6
height: priorityLabel.implicitHeight + 2
radius: 3
color: {
switch (modelData.priority) {
case "H": return Theme.error
case "M": return Theme.warning ?? Theme.primary
default: return Theme.surfaceVariantText
}
}
anchors.verticalCenter: parent.verticalCenter
StyledText {
id: priorityLabel
anchors.centerIn: parent
text: modelData.priority ?? ""
font.pixelSize: Theme.fontSizeSmall - 2
color: Theme.onPrimary ?? "white"
font.weight: Font.Bold
}
}
StyledText {
visible: !!modelData.due
text: root.formatDue(modelData.due ?? "")
font.pixelSize: Theme.fontSizeSmall - 2
color: {
const d = modelData.due ?? ""
if (!d) return Theme.surfaceVariantText
const due = new Date(d.substring(0,4)+"-"+d.substring(4,6)+"-"+d.substring(6,8)+"T"+d.substring(9,11)+":"+d.substring(11,13)+":"+d.substring(13,15)+"Z")
return due < new Date() ? Theme.error : Theme.surfaceVariantText
}
anchors.verticalCenter: parent.verticalCenter
}
Repeater {
model: modelData.tags ?? []
delegate: Rectangle {
required property string modelData
height: tagLabel.implicitHeight + 4
width: tagLabel.implicitWidth + 10
radius: height / 2
color: Theme.surfaceContainerHigh ?? Theme.surfaceVariant ?? "#33ffffff"
anchors.verticalCenter: parent.verticalCenter
StyledText {
id: tagLabel
anchors.centerIn: parent
text: modelData
font.pixelSize: Theme.fontSizeSmall - 2
color: Theme.primary
}
}
}
}
}
DankActionButton {
iconName: "check_circle"
iconColor: Theme.primary
buttonSize: 28
tooltipText: tr("Mark done")
tooltipSide: "left"
anchors.verticalCenter: parent.verticalCenter
onClicked: root.markDone(modelData.uuid)
}
}
}
}
}
}
}
}