summaryrefslogtreecommitdiff
path: root/raveos-theme/hyprland/theme-data/DankMaterialShell/quickshell/Modules/ControlCenter/BuiltinPlugins/CupsWidget.qml
blob: a2753977df67718e9442ab62724f08956e8f7812 (plain)
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
import QtQuick
import QtQuick.Layouts
import qs.Common
import qs.Services
import qs.Widgets
import qs.Modules.Plugins

PluginComponent {
    id: root

    Ref {
        service: CupsService
    }

    ccWidgetIcon: CupsService.cupsAvailable && CupsService.getPrintersNum() > 0 ? "print" : "print_disabled"
    ccWidgetPrimaryText: I18n.tr("Printers")
    ccWidgetSecondaryText: {
        if (CupsService.cupsAvailable && CupsService.getPrintersNum() > 0) {
            return I18n.tr("Printers: ") + CupsService.getPrintersNum() + " - " + I18n.tr("Jobs: ") + CupsService.getTotalJobsNum();
        } else {
            if (!CupsService.cupsAvailable) {
                return I18n.tr("Print Server not available");
            } else {
                return I18n.tr("No printer found");
            }
        }
    }
    ccWidgetIsActive: CupsService.cupsAvailable && CupsService.getTotalJobsNum() > 0

    onCcWidgetToggled: {}

    ccDetailContent: Component {
        Rectangle {
            id: detailRoot
            implicitHeight: detailColumn.implicitHeight + Theme.spacingM * 2
            radius: Theme.cornerRadius
            color: Theme.withAlpha(Theme.surfaceContainerHigh, Theme.popupTransparency)

            DankActionButton {
                anchors.top: parent.top
                anchors.right: parent.right
                anchors.topMargin: Theme.spacingS
                anchors.rightMargin: Theme.spacingS
                iconName: "settings"
                buttonSize: 24
                iconSize: 14
                iconColor: Theme.surfaceVariantText
                onClicked: {
                    PopoutService.closeControlCenter();
                    PopoutService.openSettingsWithTab("printers");
                }
            }

            Column {
                visible: !CupsService.cupsAvailable || CupsService.getPrintersNum() == 0
                anchors.centerIn: parent
                spacing: Theme.spacingS

                DankIcon {
                    name: "print_disabled"
                    size: 36
                    color: Theme.surfaceVariantText
                    anchors.horizontalCenter: parent.horizontalCenter
                }

                StyledText {
                    text: !CupsService.cupsAvailable ? I18n.tr("Print Server not available") : I18n.tr("No printer found")
                    font.pixelSize: Theme.fontSizeMedium
                    color: Theme.surfaceVariantText
                    anchors.horizontalCenter: parent.horizontalCenter
                }
            }

            Column {
                id: detailColumn
                anchors.fill: parent
                anchors.margins: Theme.spacingM
                spacing: Theme.spacingS
                visible: CupsService.cupsAvailable && CupsService.getPrintersNum() > 0
                height: visible ? 120 : 0

                RowLayout {
                    spacing: Theme.spacingS
                    width: parent.width

                    DankDropdown {
                        id: printerDropdown
                        text: ""
                        Layout.fillWidth: true
                        Layout.maximumWidth: parent.width - 180
                        description: ""
                        currentValue: {
                            CupsService.getSelectedPrinter();
                        }
                        options: CupsService.getPrintersNames()
                        onValueChanged: value => {
                            CupsService.setSelectedPrinter(value);
                        }
                    }

                    Column {
                        spacing: Theme.spacingS

                        StyledText {
                            text: CupsService.getCurrentPrinterStatePrettyShort()
                            font.pixelSize: Theme.fontSizeSmall
                            color: Theme.surfaceText
                            font.weight: Font.Medium
                            anchors.horizontalCenter: parent.horizontalCenter
                        }

                        Row {
                            spacing: Theme.spacingM

                            Rectangle {
                                height: 24
                                width: 80
                                radius: 14
                                color: printerStatusToggle.containsMouse ? Theme.errorHover : Theme.surfaceLight
                                visible: true
                                opacity: 1.0

                                Row {
                                    anchors.centerIn: parent
                                    spacing: Theme.spacingXS

                                    DankIcon {
                                        anchors.verticalCenter: parent.verticalCenter
                                        name: CupsService.getCurrentPrinterState() === "stopped" ? "play_arrow" : "pause"
                                        size: Theme.fontSizeSmall + 4
                                        color: Theme.surfaceText
                                    }

                                    StyledText {
                                        anchors.verticalCenter: parent.verticalCenter
                                        text: CupsService.getCurrentPrinterState() === "stopped" ? I18n.tr("Resume") : I18n.tr("Pause")
                                        font.pixelSize: Theme.fontSizeSmall
                                        color: Theme.surfaceText
                                        font.weight: Font.Medium
                                    }
                                }

                                MouseArea {
                                    id: printerStatusToggle
                                    anchors.fill: parent
                                    hoverEnabled: true
                                    cursorShape: Qt.PointingHandCursor
                                    enabled: true
                                    onClicked: {
                                        const selected = CupsService.getSelectedPrinter();
                                        if (CupsService.getCurrentPrinterState() === "stopped") {
                                            CupsService.resumePrinter(selected);
                                        } else {
                                            CupsService.pausePrinter(selected);
                                        }
                                    }
                                }
                            }

                            Rectangle {
                                height: 24
                                width: 80
                                radius: 14
                                color: clearJobsToggle.containsMouse ? Theme.errorHover : Theme.surfaceLight
                                visible: true
                                opacity: 1.0

                                Row {
                                    anchors.centerIn: parent
                                    spacing: Theme.spacingXS

                                    DankIcon {
                                        anchors.verticalCenter: parent.verticalCenter
                                        name: "delete_forever"
                                        size: Theme.fontSizeSmall + 4
                                        color: Theme.surfaceText
                                    }

                                    StyledText {
                                        anchors.verticalCenter: parent.verticalCenter
                                        text: I18n.tr("Jobs")
                                        font.pixelSize: Theme.fontSizeSmall
                                        color: Theme.surfaceText
                                        font.weight: Font.Medium
                                    }
                                }

                                MouseArea {
                                    id: clearJobsToggle
                                    anchors.fill: parent
                                    hoverEnabled: true
                                    cursorShape: Qt.PointingHandCursor
                                    enabled: true
                                    onClicked: {
                                        const selected = CupsService.getSelectedPrinter();
                                        CupsService.purgeJobs(selected);
                                    }
                                }
                            }
                        }
                    }
                }

                Rectangle {
                    height: 1
                    width: parent.width
                    color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12)
                }

                DankFlickable {
                    width: parent.width
                    height: 160
                    contentHeight: listCol.height
                    clip: true

                    Column {
                        id: listCol
                        width: parent.width
                        spacing: Theme.spacingXS

                        Item {
                            width: parent.width
                            height: 120
                            visible: CupsService.getCurrentPrinterJobs().length === 0

                            Column {
                                anchors.centerIn: parent
                                spacing: Theme.spacingS

                                DankIcon {
                                    name: "work"
                                    size: 36
                                    color: Theme.surfaceVariantText
                                    anchors.horizontalCenter: parent.horizontalCenter
                                }

                                StyledText {
                                    text: I18n.tr("The job queue of this printer is empty")
                                    font.pixelSize: Theme.fontSizeMedium
                                    color: Theme.surfaceVariantText
                                    anchors.horizontalCenter: parent.horizontalCenter
                                }
                            }
                        }

                        Repeater {
                            model: CupsService.getCurrentPrinterJobs()

                            delegate: Rectangle {
                                required property var modelData

                                width: parent ? parent.width : 300
                                height: 50
                                radius: Theme.cornerRadius
                                color: Theme.surfaceLight
                                border.width: 1
                                border.color: Theme.outlineLight
                                opacity: 1.0

                                RowLayout {
                                    anchors.left: parent.left
                                    anchors.right: parent.right
                                    anchors.verticalCenter: parent.verticalCenter
                                    anchors.margins: Theme.spacingM
                                    spacing: Theme.spacingM

                                    DankIcon {
                                        name: "docs"
                                        size: Theme.iconSize + 2
                                        color: Theme.surfaceText
                                        Layout.alignment: Qt.AlignVCenter
                                    }

                                    Column {
                                        spacing: 2
                                        Layout.alignment: Qt.AlignVCenter
                                        Layout.fillWidth: true

                                        StyledText {
                                            text: "[" + modelData.id + "] " + modelData.state + " (" + (modelData.size / 1024) + "kb)"
                                            font.pixelSize: Theme.fontSizeMedium
                                            color: Theme.surfaceText
                                            elide: Text.ElideRight
                                            wrapMode: Text.NoWrap
                                            width: parent.width
                                        }

                                        StyledText {
                                            text: {
                                                var date = new Date(modelData.timeCreated);
                                                return date.toLocaleString(Qt.locale(), Locale.ShortFormat);
                                            }
                                            font.pixelSize: Theme.fontSizeSmall
                                            color: Theme.surfaceTextMedium
                                        }
                                    }

                                    Item {
                                        Layout.fillWidth: true
                                    }
                                }

                                DankActionButton {
                                    id: cancelJobButton
                                    anchors.right: parent.right
                                    anchors.rightMargin: Theme.spacingM
                                    anchors.verticalCenter: parent.verticalCenter
                                    iconName: "delete"
                                    buttonSize: 36
                                    onClicked: {
                                        CupsService.cancelJob(CupsService.getSelectedPrinter(), modelData.id);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}