-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanel.qml
More file actions
491 lines (424 loc) · 17.4 KB
/
Copy pathPanel.qml
File metadata and controls
491 lines (424 loc) · 17.4 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
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import Quickshell
import qs.Commons
import qs.Widgets
import qs.Services.UI
Item {
id: root
property var pluginApi: null
readonly property var geometryPlaceholder: panelContainer
readonly property bool allowAttach: true
readonly property var mainInstance: pluginApi?.mainInstance
readonly property var services: mainInstance?.services ?? []
readonly property int upCount: mainInstance?.upCount ?? 0
readonly property int totalCount: mainInstance?.totalCount ?? 0
readonly property bool isChecking: mainInstance?.isChecking ?? false
readonly property string discoveryState: mainInstance?.discoveryState ?? "idle"
readonly property string discoveryError: mainInstance?.discoveryError ?? ""
readonly property double lastDiscoveryAt: mainInstance?.lastDiscoveryAt ?? 0
readonly property var allServers: mainInstance?.servers ?? []
readonly property string activeServerName: mainInstance?.activeServerName ?? "Sem servidor"
readonly property string activeServerId: mainInstance?.activeServerId ?? ""
readonly property bool multipleServers: allServers.length > 1
property bool panelReady: true
readonly property int tileSize: 110
readonly property int tileSpacing: Style.marginS
readonly property string pluginDir: Quickshell.env("HOME") + "/.config/noctalia/plugins/server-dashboard"
readonly property bool hasServices: services.length > 0
readonly property bool showErrorScreen: !hasServices && discoveryState === "error"
readonly property bool showLoadingScreen: !hasServices && discoveryState === "loading"
function timeAgo(ts) {
if (!ts) return "nunca"
var s = Math.round((Date.now() - ts) / 1000)
if (s < 5) return "agora"
if (s < 60) return s + "s atrás"
if (s < 3600) return Math.floor(s / 60) + "min atrás"
return Math.floor(s / 3600) + "h atrás"
}
implicitWidth: 520
implicitHeight: 1100
Rectangle {
id: panelContainer
anchors.fill: parent
color: "transparent"
visible: panelReady
ColumnLayout {
anchors.fill: parent
anchors.margins: Style.marginM
spacing: Style.marginM
// ─── Header ──────────────────────────────────────────────────────────
NBox {
Layout.fillWidth: true
Layout.preferredHeight: 64
RowLayout {
anchors.fill: parent
anchors.leftMargin: Style.marginL
anchors.rightMargin: Style.marginS
spacing: Style.marginM
Rectangle {
width: 42
height: 42
radius: Style.radiusM
color: Qt.rgba(Color.mPrimary.r, Color.mPrimary.g, Color.mPrimary.b, 0.18)
NIcon {
anchors.centerIn: parent
icon: "server"
pointSize: Style.fontSizeXL
color: Color.mPrimary
}
}
Item {
id: headerInfoColumn
Layout.fillWidth: true
implicitHeight: headerCol.implicitHeight
ColumnLayout {
id: headerCol
anchors.fill: parent
spacing: 1
RowLayout {
spacing: 4
Layout.fillWidth: true
NText {
text: root.activeServerName
pointSize: Style.fontSizeL
font.weight: Font.DemiBold
color: serverSwitcherArea.containsMouse && root.multipleServers
? Color.mPrimary : Color.mOnSurface
elide: Text.ElideRight
Behavior on color { ColorAnimation { duration: 120 } }
}
NIcon {
visible: root.multipleServers
icon: "chevron-down"
pointSize: Style.fontSizeS
color: serverSwitcherArea.containsMouse ? Color.mPrimary : Color.mOnSurfaceVariant
}
Item { Layout.fillWidth: true }
}
RowLayout {
spacing: Style.marginS
Rectangle {
width: 7; height: 7; radius: 4
Layout.alignment: Qt.AlignVCenter
color: root.discoveryState === "error" ? "#EF4444"
: root.totalCount === 0 ? Color.mOutline
: root.upCount === root.totalCount ? "#22C55E"
: root.upCount === 0 ? "#EF4444" : "#F59E0B"
}
NText {
text: {
if (root.discoveryState === "error") return "erro no discovery"
if (root.totalCount === 0) return "nenhum serviço"
return root.upCount + " de " + root.totalCount + " online"
}
pointSize: Style.fontSizeXS
color: Color.mOnSurfaceVariant
}
NText {
visible: root.lastDiscoveryAt > 0
text: "• descoberto " + root.timeAgo(root.lastDiscoveryAt)
pointSize: Style.fontSizeXS
color: Color.mOnSurfaceVariant
opacity: 0.6
}
}
}
MouseArea {
id: serverSwitcherArea
anchors.fill: parent
hoverEnabled: true
cursorShape: root.multipleServers ? Qt.PointingHandCursor : Qt.ArrowCursor
enabled: root.multipleServers
onClicked: serverSwitcherMenu.popup()
}
Menu {
id: serverSwitcherMenu
Repeater {
model: root.allServers
MenuItem {
required property var modelData
text: (modelData.id === root.activeServerId ? "✓ " : " ") + modelData.name
onTriggered: if (mainInstance) mainInstance.switchServer(modelData.id)
}
}
}
}
NIconButton {
icon: "search"
tooltipText: "Descobrir do servidor agora"
enabled: root.discoveryState !== "loading"
opacity: root.discoveryState === "loading" ? 0.45 : 1.0
onClicked: if (mainInstance) mainInstance.runDiscovery()
}
NIconButton {
icon: "refresh"
tooltipText: "Verificar status agora"
enabled: !root.isChecking && root.hasServices
opacity: root.isChecking ? 0.45 : 1.0
onClicked: if (mainInstance) mainInstance.refresh()
RotationAnimation on rotation {
running: root.isChecking
loops: Animation.Infinite
from: 0; to: 360
duration: 1000
}
}
NIconButton {
icon: "settings"
tooltipText: "Configurações"
onClicked: {
if (pluginApi) pluginApi.withCurrentScreen(function(screen) {
BarService.openPluginSettings(screen, pluginApi.manifest)
})
}
}
}
}
// ─── Body ────────────────────────────────────────────────────────────
NBox {
Layout.fillWidth: true
Layout.fillHeight: true
// ▶ ERROR STATE
ColumnLayout {
anchors.centerIn: parent
width: parent.width - Style.marginXL * 2
visible: root.showErrorScreen
spacing: Style.marginM
NIcon {
icon: "alert-circle"
pointSize: 48
color: "#EF4444"
Layout.alignment: Qt.AlignHCenter
}
NText {
text: "Não foi possível descobrir serviços"
pointSize: Style.fontSizeL
font.weight: Font.Medium
color: Color.mOnSurface
Layout.alignment: Qt.AlignHCenter
horizontalAlignment: Text.AlignHCenter
}
NText {
text: root.discoveryError
pointSize: Style.fontSizeS
color: Color.mOnSurfaceVariant
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
Layout.topMargin: Style.marginM
spacing: Style.marginS
NButton {
text: "Tentar de novo"
icon: "refresh"
onClicked: if (mainInstance) mainInstance.runDiscovery()
}
NButton {
text: "Configurações"
icon: "settings"
outlined: true
onClicked: if (pluginApi) pluginApi.withCurrentScreen(function(screen) {
BarService.openPluginSettings(screen, pluginApi.manifest)
})
}
}
}
// ▶ LOADING STATE
ColumnLayout {
anchors.centerIn: parent
visible: root.showLoadingScreen
spacing: Style.marginM
NBusyIndicator {
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: 48
Layout.preferredHeight: 48
}
NText {
text: "Conectando ao servidor..."
pointSize: Style.fontSizeS
color: Color.mOnSurfaceVariant
Layout.alignment: Qt.AlignHCenter
}
}
// ▶ NORMAL: grid
ScrollView {
anchors.fill: parent
anchors.margins: Style.marginM
visible: root.hasServices && !root.showErrorScreen
contentWidth: availableWidth
clip: true
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ColumnLayout {
width: parent.width
spacing: Style.marginL
Repeater {
model: mainInstance ? mainInstance.uniqueCategories() : []
ColumnLayout {
id: categoryGroup
Layout.fillWidth: true
spacing: Style.marginS
required property string modelData
readonly property var categoryServices: mainInstance ? mainInstance.servicesIn(modelData) : []
readonly property int categoryUp: {
var n = 0
for (var i = 0; i < categoryServices.length; i++) {
if (mainInstance && mainInstance.statusOf(categoryServices[i].url) === "up") n++
}
return n
}
// Category header
RowLayout {
Layout.fillWidth: true
Layout.leftMargin: 2
Layout.bottomMargin: 2
spacing: Style.marginS
NText {
text: categoryGroup.modelData.toUpperCase()
pointSize: Style.fontSizeXS
font.weight: Font.DemiBold
font.letterSpacing: 1.2
color: Color.mOnSurfaceVariant
}
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: 1
color: Color.mOutline
opacity: 0.3
}
NText {
text: categoryGroup.categoryUp + "/" + categoryGroup.categoryServices.length
pointSize: Style.fontSizeXS
color: Color.mOnSurfaceVariant
opacity: 0.7
font.family: Settings.data.ui.fontFixed
}
}
// Tiles flow
Flow {
Layout.fillWidth: true
spacing: root.tileSpacing
Repeater {
model: categoryGroup.categoryServices
Rectangle {
id: tile
required property var modelData
width: root.tileSize
height: root.tileSize
radius: Style.radiusM
clip: true
readonly property string status: mainInstance ? mainInstance.statusOf(modelData.url) : "unknown"
readonly property bool isUp: status === "up"
readonly property bool isDown: status === "down"
readonly property color brandColor: modelData.color || Color.mPrimary
color: tileMouse.containsMouse
? Qt.rgba(brandColor.r, brandColor.g, brandColor.b, 0.18)
: Qt.rgba(0, 0, 0, 0.28)
Behavior on color { ColorAnimation { duration: 150 } }
border.width: 1
border.color: tileMouse.containsMouse
? Qt.rgba(brandColor.r, brandColor.g, brandColor.b, 0.6)
: Qt.rgba(255, 255, 255, 0.06)
Behavior on border.color { ColorAnimation { duration: 150 } }
opacity: tile.isDown ? 0.6 : 1.0
Behavior on opacity { NumberAnimation { duration: 200 } }
// Left accent bar
Rectangle {
width: 4
height: parent.height
anchors.left: parent.left
color: tile.brandColor
radius: 2
}
// Status dot
Rectangle {
width: 8
height: 8
radius: 4
anchors.top: parent.top
anchors.right: parent.right
anchors.margins: 7
color: tile.isUp ? "#22C55E"
: tile.isDown ? "#EF4444"
: "#9CA3AF"
SequentialAnimation on opacity {
running: tile.isDown
loops: Animation.Infinite
NumberAnimation { to: 0.35; duration: 700 }
NumberAnimation { to: 1.0; duration: 700 }
}
}
ColumnLayout {
anchors.fill: parent
anchors.leftMargin: 10
anchors.rightMargin: 6
anchors.topMargin: 10
anchors.bottomMargin: 8
spacing: 4
Item {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter
readonly property bool hasIcon: tile.modelData.iconFile !== undefined && tile.modelData.iconFile !== ""
Image {
id: logoImage
anchors.centerIn: parent
visible: parent.hasIcon && logoImage.status !== Image.Error
source: parent.hasIcon
? "file://" + root.pluginDir + "/" + tile.modelData.iconFile
: ""
sourceSize.width: 64
sourceSize.height: 64
width: 56
height: 56
fillMode: Image.PreserveAspectFit
smooth: true
asynchronous: true
}
Text {
anchors.centerIn: parent
visible: !logoImage.visible
text: tile.modelData.icon || tile.modelData.name.charAt(0).toUpperCase()
color: tile.brandColor
font.pixelSize: 36
font.weight: Font.Bold
}
}
Text {
text: tile.modelData.name
color: Color.mOnSurface
font.pixelSize: 10
font.weight: Font.Medium
Layout.alignment: Qt.AlignHCenter
Layout.maximumWidth: root.tileSize - 24
elide: Text.ElideRight
horizontalAlignment: Text.AlignHCenter
}
}
MouseArea {
id: tileMouse
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: if (mainInstance) mainInstance.openService(tile.modelData.url)
}
ToolTip.visible: tileMouse.containsMouse
ToolTip.delay: 700
ToolTip.text: tile.modelData.name + " (" + tile.modelData.rawName + ")\n"
+ tile.modelData.url + "\n"
+ (tile.isUp ? "● Online" : tile.isDown ? "● Offline" : "○ Verificando...")
}
}
}
}
}
}
}
}
}
}
}