Repository navigation
Expand file tree
/
Copy pathPanel.qml
More file actions
1402 lines (1258 loc) · 45.5 KB
/
Copy pathPanel.qml
File metadata and controls
1402 lines (1258 loc) · 45.5 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import qs.Commons
import qs.Ui
Panel {
id: root
moduleName: "marcuspelo.omalink"
ipcTarget: "marcuspelo.omalink"
// ---------------------------------------------------------------- config
readonly property string baseUrl: {
var v = settings ? settings.baseUrl : undefined
var fromSettings = (typeof v === "string" && v.length > 0) ? v : ""
var raw = fromSettings || root.envBaseUrl || ""
return raw.replace(/\/+$/, "")
}
readonly property int pageSize: {
var v = settings ? settings.pageSize : undefined
return (typeof v === "number" && v >= 5) ? v : 20
}
readonly property int defaultCollectionId: {
var v = settings ? settings.defaultCollectionId : undefined
return (typeof v === "number" && v > 0) ? v : 0
}
readonly property color fg: root.bar ? root.bar.foreground : Color.foreground
readonly property color dim: Qt.darker(fg, 1.45)
readonly property string fontFamily: root.bar ? root.bar.fontFamily : "JetBrainsMono Nerd Font"
readonly property string barIcon: "" // nf-fa-link
// ---------------------------------------------------------------- credentials
property string apiKey: ""
property string envBaseUrl: ""
property bool apiKeyLoaded: false
property int myUserId: 0
// Backslash/quote escaping alone is not enough: a raw CR or LF byte in any
// value (e.g. a server-controlled `nextCursor`/link `id` from Linkwarden)
// ends the current `key = "..."` line in the curl -K config regardless of
// the surrounding quotes, letting the rest of the value be parsed as new
// curl directives (arbitrary `-K` options — including local file
// read/write via `upload-file`/`output`). Escaping \r and \n to their
// literal two-character curl quoted-string escapes keeps them inside the
// value instead of breaking the config's line structure.
function curlConfigEscape(s) {
return String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"')
.replace(/\r/g, "\\r").replace(/\n/g, "\\n")
}
function parseEnv(raw) {
var lines = String(raw || "").split("\n")
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim()
if (!line || line.indexOf("#") === 0) continue
var eq = line.indexOf("=")
if (eq < 0) continue
var key = line.substring(0, eq).trim()
var value = line.substring(eq + 1).trim().replace(/^["']|["']$/g, "")
if (key === "API_KEY") root.apiKey = value
else if (key === "URL_BASE" || key === "BASE_URL") root.envBaseUrl = value
}
root.apiKeyLoaded = true
}
// ---------------------------------------------------------------- networking
// Every Linkwarden call is built as a `curl -K -` config and written to the
// process's stdin, never passed as argv/URL — keeps the bearer token and
// JSON bodies out of `ps`/`/proc/<pid>/cmdline`.
function startRequest(proc, method, path, query, body) {
var url = root.baseUrl + "/api/v1" + path
if (query) url += (path.indexOf("?") >= 0 ? "&" : "?") + query
var config = 'url = "' + root.curlConfigEscape(url) + '"\n'
config += 'header = "Authorization: Bearer ' + root.curlConfigEscape(root.apiKey) + '"\n'
config += 'header = "Accept: application/json"\n'
if (method && method !== "GET") config += 'request = "' + method + '"\n'
if (body !== undefined) {
config += 'header = "Content-Type: application/json"\n'
config += 'data = "' + root.curlConfigEscape(JSON.stringify(body)) + '"\n'
}
proc.reqConfig = config
proc.command = ["curl", "-sS", "--max-time", "10", "-K", "-"]
proc.stdinEnabled = true
proc.running = true
}
// Success payloads never carry `response` as a plain string; error payloads
// always do ({"response": "message"}), so this is the one reliable signal
// across every Linkwarden endpoint used here.
function parseApiError(data) {
if (data && typeof data.response === "string") return data.response
return ""
}
// ---------------------------------------------------------------- account
function fetchMe() {
if (meProc.running) return
root.startRequest(meProc, "GET", "/users/me")
}
function handleMe(raw) {
try {
var data = JSON.parse(String(raw || ""))
var err = root.parseApiError(data)
if (err) return
if (data.response && data.response.id) root.myUserId = data.response.id
} catch (e) {}
}
// ---------------------------------------------------------------- collections
property var collections: []
function fetchCollections() {
if (collectionsProc.running) return
root.startRequest(collectionsProc, "GET", "/collections")
}
function handleCollections(raw) {
try {
var data = JSON.parse(String(raw || ""))
var err = root.parseApiError(data)
root.collections = err ? [] : (data.response || [])
} catch (e) {
root.collections = []
}
}
// Linkwarden's PUT /links/{id} requires a concrete {id, ownerId} collection
// on every update (no "leave unchanged" or "default" option server-side),
// so the dropdown only ever offers real collections — never a synthetic
// empty value.
readonly property var collectionOptions: {
var opts = []
for (var i = 0; i < root.collections.length; i++)
opts.push({ value: String(root.collections[i].id), label: root.collections[i].name })
return opts
}
function findCollection(id) {
for (var i = 0; i < root.collections.length; i++)
if (root.collections[i].id === id) return root.collections[i]
return null
}
function defaultFormCollectionValue() {
if (root.defaultCollectionId > 0 && root.findCollection(root.defaultCollectionId))
return String(root.defaultCollectionId)
for (var i = 0; i < root.collections.length; i++)
if (root.collections[i].name === "Unorganized") return String(root.collections[i].id)
return root.collections.length > 0 ? String(root.collections[0].id) : ""
}
// ---------------------------------------------------------------- tags
property var tagOptions: []
function fetchTags() {
if (tagsProc.running) return
root.startRequest(tagsProc, "GET", "/tags")
}
function handleTags(raw) {
try {
var data = JSON.parse(String(raw || ""))
var err = root.parseApiError(data)
if (err || !data.data || !data.data.tags) { root.tagOptions = []; return }
root.tagOptions = data.data.tags.map(function(t) { return t.name })
} catch (e) {
root.tagOptions = []
}
}
// ---------------------------------------------------------------- list (search / favorites)
property string activeTab: "all" // "all" | "favorites"
property string searchQuery: ""
property var items: []
property bool listLoading: false
property bool hasError: false
property string errorText: ""
property var nextCursor: null
function switchTab(tab) {
if (root.activeTab === tab) return
root.activeTab = tab
root.nextCursor = null
root.refreshList()
}
function refreshList() {
if (!root.apiKeyLoaded || !root.apiKey || !root.baseUrl) return
root.nextCursor = null
root.fetchList(false)
}
function fetchList(append) {
if (listProc.running) return
root.listLoading = true
root.hasError = false
listProc.appendResults = !!append
var query = ""
if (root.searchQuery) query += "searchQueryString=" + encodeURIComponent(root.searchQuery)
if (append && root.nextCursor) query += (query ? "&" : "") + "cursor=" + encodeURIComponent(root.nextCursor)
if (root.activeTab === "favorites") {
query += (query ? "&" : "") + "pinnedOnly=true"
root.startRequest(listProc, "GET", "/links", query)
} else {
root.startRequest(listProc, "GET", "/search", query)
}
}
function handleListResult(raw, append) {
root.listLoading = false
try {
var data = JSON.parse(String(raw || ""))
var err = root.parseApiError(data)
if (err) {
root.hasError = true
root.errorText = err
if (!append) root.items = []
return
}
var links = []
var cursor = null
if (data.data && Array.isArray(data.data.links)) {
links = data.data.links
cursor = (data.data.nextCursor !== undefined) ? data.data.nextCursor : null
} else if (Array.isArray(data.response)) {
links = data.response
}
root.items = append ? root.items.concat(links) : links
root.nextCursor = cursor
root.hasError = false
root.errorText = ""
} catch (e) {
root.hasError = true
root.errorText = "Failed to read Linkwarden response"
if (!append) root.items = []
}
}
function loadMore() {
if (!root.nextCursor || listProc.running) return
root.fetchList(true)
}
function isPinned(link) {
var by = link && link.pinnedBy
if (!by || !root.myUserId) return false
for (var i = 0; i < by.length; i++) {
var entry = by[i]
var id = (entry && typeof entry === "object") ? entry.id : entry
if (id === root.myUserId) return true
}
return false
}
function domainOf(url) {
try {
var m = String(url || "").match(/^[a-z]+:\/\/([^\/]+)/i)
return m ? m[1] : String(url || "")
} catch (e) {
return String(url || "")
}
}
// GET /api/v1/getFavicon has no security requirement in Linkwarden's OpenAPI
// spec (verified against a live instance: no Authorization header needed,
// 200 image/{png,x-icon} on hit, 204 on no favicon, 308 if given a full URL
// instead of just the origin) — unlike every other endpoint this plugin
// calls. That's why this is the one request built as a plain URL for
// Image.source instead of going through startRequest/curl: there's no
// bearer token or JSON body to keep off argv here. Passing just the origin
// (not the full link URL) skips the 308 the API would otherwise issue, and
// lets Image's own cache dedupe repeated fetches across links on the same
// domain.
function faviconUrl(link) {
var url = link && link.url ? String(link.url) : ""
var m = url.match(/^[a-z]+:\/\/[^\/]+/i)
var origin = m ? m[0] : url
if (!root.baseUrl || !origin) return ""
return root.baseUrl + "/api/v1/getFavicon?url=" + encodeURIComponent(origin)
}
function relativeTime(iso) {
if (!iso) return ""
var t = Date.parse(iso)
if (isNaN(t)) return ""
var diffSec = Math.max(0, (Date.now() - t) / 1000)
if (diffSec < 60) return "just now"
var mins = Math.floor(diffSec / 60)
if (mins < 60) return mins + "m ago"
var hours = Math.floor(mins / 60)
if (hours < 24) return hours + "h ago"
return Math.floor(hours / 24) + "d ago"
}
// ---------------------------------------------------------------- pin/favorite
property int pinBusyId: 0
// Despite the OpenAPI docs describing pinnedBy/tags/collection as optional
// on PUT /links/{id}, the live server rejects the update entirely unless
// id, url, tags (possibly []) and a concrete collection {id, ownerId} are
// all present — confirmed against a real instance. Every PUT must go
// through this to stay valid.
function requiredPutBase(link) {
var col = link.collection
return {
id: link.id,
url: link.url,
name: link.name || "",
description: link.description || "",
tags: (link.tags || []).map(function(t) { return { name: t.name } }),
collection: col ? { id: col.id, ownerId: col.ownerId } : null
}
}
function togglePin(link) {
if (!link || pinProc.running) return
if (!link.collection) {
root.hasError = true
root.errorText = "Missing collection info for this link — refresh and try again"
return
}
root.pinBusyId = link.id
var nextPinned = !root.isPinned(link)
var body = root.requiredPutBase(link)
body.pinnedBy = nextPinned ? [{ id: root.myUserId }] : []
pinProc.targetId = link.id
pinProc.nextPinned = nextPinned
root.startRequest(pinProc, "PUT", "/links/" + encodeURIComponent(link.id), "", body)
}
function handlePinResult(raw, targetId, nextPinned) {
root.pinBusyId = 0
try {
var data = JSON.parse(String(raw || ""))
var err = root.parseApiError(data)
if (err) { root.errorText = err; root.hasError = true; return }
} catch (e) {
root.hasError = true
root.errorText = "Failed to update pin status"
return
}
for (var i = 0; i < root.items.length; i++) {
if (root.items[i].id === targetId) {
var updated = root.items.slice()
var link = Object.assign({}, updated[i])
link.pinnedBy = nextPinned ? [{ id: root.myUserId }] : []
updated[i] = link
root.items = updated
break
}
}
}
// ---------------------------------------------------------------- add / edit form
property string viewMode: "list" // "list" | "form" | "settings"
property string formMode: "add" // "add" | "edit"
property int formId: 0
property string formUrl: ""
property string formName: ""
property string formDescription: ""
property string formCollectionValue: ""
property var formTags: []
property string formNewTagText: ""
property bool formSubmitting: false
property string formStatusText: ""
property bool formStatusError: false
function openAddForm() {
root.viewMode = "form"
root.formMode = "add"
root.formId = 0
root.formUrl = ""
root.formName = ""
root.formDescription = ""
root.formCollectionValue = root.defaultFormCollectionValue()
root.formTags = []
root.formNewTagText = ""
root.formStatusText = ""
root.formStatusError = false
}
function openEditForm(link) {
if (!link) return
root.viewMode = "form"
root.formMode = "edit"
root.formId = link.id
root.formUrl = link.url || ""
root.formName = link.name || ""
root.formDescription = link.description || ""
root.formCollectionValue = link.collectionId ? String(link.collectionId) : root.defaultFormCollectionValue()
root.formTags = (link.tags || []).map(function(t) { return t.name })
root.formNewTagText = ""
root.formStatusText = ""
root.formStatusError = false
}
function closeForm() {
root.viewMode = "list"
}
function addNewTag() {
var name = String(root.formNewTagText || "").trim()
if (!name) return
if (root.formTags.indexOf(name) === -1) root.formTags = root.formTags.concat([name])
root.formNewTagText = ""
}
function removeFormTag(name) {
root.formTags = root.formTags.filter(function(t) { return t !== name })
}
function submitForm() {
if (formProc.running) return
var url = String(root.formUrl || "").trim()
if (root.formMode === "add" && !url) {
root.formStatusError = true
root.formStatusText = "URL is required"
return
}
var col = root.formCollectionValue ? root.findCollection(parseInt(root.formCollectionValue)) : null
if (root.formMode === "edit" && !col) {
root.formStatusError = true
root.formStatusText = "Collection list not loaded yet — try again in a moment"
return
}
root.formSubmitting = true
root.formStatusError = false
root.formStatusText = ""
var body = {
name: root.formName || "",
description: root.formDescription || "",
tags: root.formTags.map(function(name) { return { name: name } })
}
if (col) body.collection = { id: col.id, ownerId: col.ownerId }
if (root.formMode === "add") {
body.url = url
root.startRequest(formProc, "POST", "/links", "", body)
} else {
body.id = root.formId
body.url = url
root.startRequest(formProc, "PUT", "/links/" + root.formId, "", body)
}
}
function handleFormResult(raw) {
root.formSubmitting = false
try {
var data = JSON.parse(String(raw || ""))
var err = root.parseApiError(data)
if (err) {
root.formStatusError = true
root.formStatusText = err
return
}
root.formStatusError = false
root.formStatusText = root.formMode === "add" ? "Link added" : "Link updated"
root.refreshList()
formSuccessTimer.restart()
} catch (e) {
root.formStatusError = true
root.formStatusText = "Failed to read Linkwarden response"
}
}
// ---------------------------------------------------------------- delete
property int confirmDeleteId: 0
property int deleteBusyId: 0
function requestDelete(id) {
root.confirmDeleteId = (root.confirmDeleteId === id) ? 0 : id
}
function cancelDelete() {
root.confirmDeleteId = 0
}
function confirmDelete() {
var id = root.confirmDeleteId
if (!id || deleteProc.running) return
root.deleteBusyId = id
deleteProc.targetId = id
root.startRequest(deleteProc, "DELETE", "/links/" + id)
}
function handleDeleteResult(raw, targetId) {
root.deleteBusyId = 0
root.confirmDeleteId = 0
try {
var data = JSON.parse(String(raw || ""))
var err = root.parseApiError(data)
if (err) { root.hasError = true; root.errorText = err; return }
} catch (e) {
root.hasError = true
root.errorText = "Failed to delete link"
return
}
root.items = root.items.filter(function(l) { return l.id !== targetId })
}
// ---------------------------------------------------------------- selection / keyboard
property int selectedIndex: 0
function moveSelection(delta) {
var list = root.items
if (list.length === 0) return
var next = root.selectedIndex + delta
if (next < 0) next = 0
if (next > list.length - 1) next = list.length - 1
root.selectedIndex = next
}
function selectedLink() {
var list = root.items
if (list.length === 0) return null
return list[Math.max(0, Math.min(root.selectedIndex, list.length - 1))]
}
function activateSelection() {
var link = root.selectedLink()
if (link) root.openExternalUrl(link.url)
}
onItemsChanged: root.selectedIndex = 0
// Only http(s) links stored in the user's own Linkwarden are ever handed to
// xdg-open — never anything carrying the bearer token or a linkwarden.app
// internal path.
function openExternalUrl(url) {
if (!/^https?:\/\//i.test(String(url || ""))) return
browserProc.command = ["xdg-open", url]
browserProc.running = true
}
// ---------------------------------------------------------------- settings
property string draftBaseUrl: ""
property int draftPageSize: 20
property int draftDefaultCollectionId: 0
property string settingsStatusText: ""
function openSettingsView() {
root.viewMode = "settings"
root.draftBaseUrl = (settings && settings.baseUrl) || ""
root.draftPageSize = root.pageSize
root.draftDefaultCollectionId = root.defaultCollectionId
root.settingsStatusText = ""
}
function closeSettingsView() {
root.viewMode = "list"
}
function canPersistSettings() {
return !!(root.bar && root.bar.shell && typeof root.bar.shell.updateEntryInline === "function")
}
function saveSettings() {
var next = {
baseUrl: String(root.draftBaseUrl || "").trim(),
pageSize: Math.max(5, Math.min(100, Math.round(Number(root.draftPageSize) || 20))),
defaultCollectionId: Math.max(0, Math.round(Number(root.draftDefaultCollectionId) || 0))
}
root.settings = next
if (root.canPersistSettings()) {
root.bar.shell.updateEntryInline(root.moduleName, next)
root.settingsStatusText = "Saved"
} else {
root.settingsStatusText = "Saved for this session only (bar unavailable)"
}
root.refreshList()
}
// ---------------------------------------------------------------- lifecycle
function bootstrap() {
if (!root.apiKeyLoaded || !root.apiKey || !root.baseUrl) return
if (!root.myUserId) root.fetchMe()
root.fetchCollections()
root.fetchTags()
root.refreshList()
}
onApiKeyLoadedChanged: if (opened) root.bootstrap()
onOpenedChanged: {
if (opened) {
root.viewMode = "list"
root.bootstrap()
Qt.callLater(function() { keyCatcher.forceActiveFocus() })
}
}
Timer {
id: searchDebounce
interval: 400
onTriggered: root.refreshList()
}
Timer {
id: formSuccessTimer
interval: 900
onTriggered: root.closeForm()
}
// ---------------------------------------------------------------- io
FileView {
id: envFile
path: Quickshell.env("HOME") + "/.config/omalink/.env"
watchChanges: true
printErrors: false
onLoaded: {
root.parseEnv(text())
envPermProc.command = ["chmod", "600", envFile.path]
envPermProc.running = true
}
onLoadFailed: {
root.apiKeyLoaded = true
root.hasError = true
root.errorText = "~/.config/omalink/.env not found (see README)"
}
}
Process { id: envPermProc }
Process { id: browserProc }
Process {
id: meProc
property string reqConfig: ""
stdinEnabled: true
onStarted: { meProc.write(meProc.reqConfig); meProc.stdinEnabled = false }
stdout: StdioCollector { waitForEnd: true; onStreamFinished: root.handleMe(text) }
}
Process {
id: collectionsProc
property string reqConfig: ""
stdinEnabled: true
onStarted: { collectionsProc.write(collectionsProc.reqConfig); collectionsProc.stdinEnabled = false }
stdout: StdioCollector { waitForEnd: true; onStreamFinished: root.handleCollections(text) }
}
Process {
id: tagsProc
property string reqConfig: ""
stdinEnabled: true
onStarted: { tagsProc.write(tagsProc.reqConfig); tagsProc.stdinEnabled = false }
stdout: StdioCollector { waitForEnd: true; onStreamFinished: root.handleTags(text) }
}
Process {
id: listProc
property string reqConfig: ""
property bool appendResults: false
stdinEnabled: true
onStarted: { listProc.write(listProc.reqConfig); listProc.stdinEnabled = false }
stdout: StdioCollector { waitForEnd: true; onStreamFinished: root.handleListResult(text, listProc.appendResults) }
onExited: function(code) {
if (code !== 0) {
root.listLoading = false
root.hasError = true
root.errorText = "Linkwarden unavailable at " + root.baseUrl
}
}
}
Process {
id: pinProc
property string reqConfig: ""
property int targetId: 0
property bool nextPinned: false
stdinEnabled: true
onStarted: { pinProc.write(pinProc.reqConfig); pinProc.stdinEnabled = false }
stdout: StdioCollector { waitForEnd: true; onStreamFinished: root.handlePinResult(text, pinProc.targetId, pinProc.nextPinned) }
onExited: function(code) { if (code !== 0) root.pinBusyId = 0 }
}
Process {
id: formProc
property string reqConfig: ""
stdinEnabled: true
onStarted: { formProc.write(formProc.reqConfig); formProc.stdinEnabled = false }
stdout: StdioCollector { waitForEnd: true; onStreamFinished: root.handleFormResult(text) }
onExited: function(code) {
if (code !== 0) {
root.formSubmitting = false
root.formStatusError = true
if (!root.formStatusText) root.formStatusText = "Failed to connect to Linkwarden"
}
}
}
Process {
id: deleteProc
property string reqConfig: ""
property int targetId: 0
stdinEnabled: true
onStarted: { deleteProc.write(deleteProc.reqConfig); deleteProc.stdinEnabled = false }
stdout: StdioCollector { waitForEnd: true; onStreamFinished: root.handleDeleteResult(text, deleteProc.targetId) }
onExited: function(code) { if (code !== 0) root.deleteBusyId = 0 }
}
// ---------------------------------------------------------------- components
// Small favicon tile for a list row. Falls back to root.barIcon (the same
// nf-fa-link glyph the bar chip uses) whenever the Image isn't showing a
// real favicon — covers the loading state, a 204 (no favicon found), and
// any fetch error, same convention as marcuspelo.omatv's Poster component.
component FaviconIcon: Item {
id: favicon
property string source: ""
implicitWidth: Style.space(16)
implicitHeight: Style.space(16)
Text {
anchors.centerIn: parent
visible: faviconImage.status !== Image.Ready
text: root.barIcon
textFormat: Text.PlainText
color: root.dim
font.family: root.fontFamily
font.pixelSize: Style.font.caption
}
Image {
id: faviconImage
anchors.fill: parent
source: favicon.source
asynchronous: true
cache: true
smooth: true
fillMode: Image.PreserveAspectFit
sourceSize.width: 32
sourceSize.height: 32
}
}
// ---------------------------------------------------------------- bar chip
function triggerPress(button) {
if (opened) close(); else open()
}
WidgetButton {
id: button
anchors.fill: parent
bar: root.bar
text: root.hasError ? root.barIcon + " !" : root.barIcon
fixedWidth: root.bar && root.bar.vertical ? -1 : Style.space(30)
fixedHeight: root.bar && root.bar.vertical ? Style.space(26) : -1
tooltipText: root.hasError ? root.errorText : "OmaLink — Linkwarden"
onPressed: function(b) { root.triggerPress(b) }
}
implicitWidth: button.implicitWidth
implicitHeight: button.implicitHeight
// ---------------------------------------------------------------- panel
KeyboardPanel {
id: panel
anchorItem: button
owner: root
bar: root.bar
open: root.opened
focusTarget: keyCatcher
contentWidth: panel.fittedContentWidth(Style.space(480))
contentHeight: panel.fittedContentHeight(contentColumn.implicitHeight, Style.space(680))
PanelKeyCatcher {
id: keyCatcher
anchors.fill: parent
blocked: searchField.activeFocus || urlField.activeFocus || nameField.activeFocus
|| descriptionField.activeFocus || newTagField.activeFocus || baseUrlField.activeFocus
onCloseRequested: {
if (root.confirmDeleteId) root.cancelDelete()
else if (root.viewMode !== "list") root.viewMode = "list"
else root.close()
}
onMoveRequested: function(dx, dy) {
if (root.viewMode !== "list") return
if (dy !== 0) root.moveSelection(dy)
else if (dx < 0) root.switchTab("all")
else if (dx > 0) root.switchTab("favorites")
}
onActivateRequested: if (root.viewMode === "list") root.activateSelection()
onDeleteRequested: {
if (root.viewMode !== "list") return
var link = root.selectedLink()
if (link) root.requestDelete(link.id)
}
onTextKey: function(t) {
var k = String(t).toLowerCase()
if (root.viewMode !== "list") return
if (k === "/") {
Qt.callLater(function() { searchField.forceActiveFocus(); searchField.selectAll() })
} else if (k === "a") {
root.openAddForm()
} else if (k === "e") {
var link = root.selectedLink()
if (link) root.openEditForm(link)
} else if (k === "f") {
var l2 = root.selectedLink()
if (l2) root.togglePin(l2)
} else if (k === "r") {
root.refreshList()
}
}
}
ColumnLayout {
id: contentColumn
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
spacing: Style.space(10)
// ------------------------------------------------------------ header
RowLayout {
Layout.fillWidth: true
spacing: 8
Text {
text: root.barIcon + " " + (root.viewMode === "form" ? (root.formMode === "add" ? "Add link" : "Edit link") : root.viewMode === "settings" ? "Settings" : "OmaLink")
color: root.fg
font.family: root.fontFamily
font.pixelSize: Style.font.title
font.bold: true
Layout.fillWidth: true
}
Button {
visible: root.viewMode === "list"
text: "+ Add"
foreground: root.fg
accent: Color.accent
tooltipText: "Add a new link (a)"
fontFamily: root.fontFamily
fontSize: Style.font.caption
horizontalPadding: Style.spacing.controlPaddingX
verticalPadding: Style.spacing.controlPaddingY
onClicked: root.openAddForm()
}
Button {
visible: root.viewMode === "list"
text: root.listLoading ? "Refreshing…" : "Refresh"
foreground: root.fg
tooltipText: "Refresh now (r)"
fontFamily: root.fontFamily
fontSize: Style.font.caption
horizontalPadding: Style.spacing.controlPaddingX
verticalPadding: Style.spacing.controlPaddingY
active: root.listLoading
onClicked: root.refreshList()
}
Button {
visible: root.viewMode === "list"
text: "⚙"
foreground: root.fg
tooltipText: "Settings"
fontFamily: root.fontFamily
fontSize: Style.font.caption
horizontalPadding: Style.spacing.controlPaddingX
verticalPadding: Style.spacing.controlPaddingY
onClicked: root.openSettingsView()
}
Button {
visible: root.viewMode !== "list"
text: "Back"
foreground: root.fg
fontFamily: root.fontFamily
fontSize: Style.font.caption
horizontalPadding: Style.spacing.controlPaddingX
verticalPadding: Style.spacing.controlPaddingY
onClicked: root.viewMode === "settings" ? root.closeSettingsView() : root.closeForm()
}
}
// ------------------------------------------------------------ settings view
ColumnLayout {
visible: root.viewMode === "settings"
Layout.fillWidth: true
spacing: Style.space(10)
Text {
text: "Linkwarden base URL"
color: root.dim
font.family: root.fontFamily
font.pixelSize: Style.font.caption
}
TextField {
id: baseUrlField
Layout.fillWidth: true
placeholderText: "https://link.example.com"
foreground: root.fg
text: root.draftBaseUrl
onTextChanged: root.draftBaseUrl = text
}
NumberField {
label: "Results per page"
value: root.draftPageSize
from: 5
to: 100
stepSize: 5
foreground: root.fg
accent: Color.accent
fontFamily: root.fontFamily
onModified: function(v) { root.draftPageSize = v }
}
NumberField {
label: "Default collection ID (0 = Unorganized)"
value: root.draftDefaultCollectionId
from: 0
to: 999999
stepSize: 1
foreground: root.fg
accent: Color.accent
fontFamily: root.fontFamily
onModified: function(v) { root.draftDefaultCollectionId = v }
}
Text {
visible: root.settingsStatusText !== ""
Layout.fillWidth: true
text: root.settingsStatusText
color: root.dim
font.family: root.fontFamily
font.pixelSize: Style.font.caption
wrapMode: Text.WordWrap
}
Button {
text: "Save"
foreground: root.fg
accent: Color.accent
fontFamily: root.fontFamily
fontSize: Style.font.caption
horizontalPadding: Style.spacing.controlPaddingX
verticalPadding: Style.spacing.controlPaddingY
onClicked: root.saveSettings()
}
Text {
Layout.fillWidth: true
text: "The API token stays in ~/.config/omalink/.env and is not editable here."
color: root.dim
font.family: root.fontFamily
font.pixelSize: Style.font.caption
wrapMode: Text.WordWrap
}
Text {
Layout.fillWidth: true
text: "Tip: disabling and re-enabling the plugin resets this field. Add URL_BASE=... to ~/.config/omalink/.env to keep a fallback that survives that."
color: root.dim
font.family: root.fontFamily
font.pixelSize: Style.font.caption
wrapMode: Text.WordWrap
}
}
// ------------------------------------------------------------ add/edit form view
ColumnLayout {
visible: root.viewMode === "form"
Layout.fillWidth: true
spacing: Style.space(10)
TextField {
id: urlField
Layout.fillWidth: true
placeholderText: "https://example.com"
foreground: root.fg
text: root.formUrl
onTextChanged: root.formUrl = text
}
TextField {
id: nameField
Layout.fillWidth: true
placeholderText: "Name (optional)"
foreground: root.fg
text: root.formName
onTextChanged: root.formName = text
}
TextField {
id: descriptionField
Layout.fillWidth: true
placeholderText: "Description (optional)"