mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-30 16:32:50 -05:00
cups: sync with API changes
This commit is contained in:
@@ -28,7 +28,9 @@ PluginComponent {
|
||||
}
|
||||
ccWidgetIsActive: CupsService.cupsAvailable && CupsService.getTotalJobsNum() > 0
|
||||
|
||||
onCcWidgetToggled: {}
|
||||
onCcWidgetToggled: {
|
||||
|
||||
}
|
||||
|
||||
ccDetailContent: Component {
|
||||
Rectangle {
|
||||
@@ -274,7 +276,7 @@ PluginComponent {
|
||||
iconName: "delete"
|
||||
buttonSize: 36
|
||||
onClicked: {
|
||||
CupsService.cancelJob(modelData.id)
|
||||
CupsService.cancelJob(CupsService.getSelectedPrinter(), modelData.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pragma Singleton
|
||||
|
||||
pragma ComponentBehavior: Bound
|
||||
pragma ComponentBehavior
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
@@ -45,7 +45,7 @@ Singleton {
|
||||
|
||||
function onCupsStateUpdate(data) {
|
||||
console.log("CupsService: Subscription update received")
|
||||
updateState(data)
|
||||
getState()
|
||||
}
|
||||
|
||||
function onCapabilitiesChanged() {
|
||||
@@ -71,17 +71,31 @@ Singleton {
|
||||
}
|
||||
|
||||
function getState() {
|
||||
if (!cupsAvailable) return
|
||||
if (!cupsAvailable)
|
||||
return
|
||||
|
||||
DMSService.sendRequest("cups.getState", null, response => {
|
||||
DMSService.sendRequest("cups.getPrinters", null, response => {
|
||||
if (response.result) {
|
||||
updateState(response.result)
|
||||
updatePrinters(response.result)
|
||||
fetchAllJobs()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function updateState(state) {
|
||||
printerNames = Object.keys(state.printers)
|
||||
function updatePrinters(printersData) {
|
||||
printerNames = printersData.map(p => p.name)
|
||||
|
||||
let printersObj = {}
|
||||
for (var i = 0; i < printersData.length; i++) {
|
||||
let printer = printersData[i]
|
||||
printersObj[printer.name] = {
|
||||
"state": printer.state,
|
||||
"stateReason": printer.stateReason,
|
||||
"jobs": []
|
||||
}
|
||||
}
|
||||
printers = printersObj
|
||||
|
||||
if (printerNames.length > 0) {
|
||||
if (selectedPrinter.length > 0) {
|
||||
if (!printerNames.includes(selectedPrinter)) {
|
||||
@@ -91,7 +105,26 @@ Singleton {
|
||||
selectedPrinter = printerNames[0]
|
||||
}
|
||||
}
|
||||
printers = state.printers
|
||||
}
|
||||
|
||||
function fetchAllJobs() {
|
||||
for (var i = 0; i < printerNames.length; i++) {
|
||||
fetchJobsForPrinter(printerNames[i])
|
||||
}
|
||||
}
|
||||
|
||||
function fetchJobsForPrinter(printerName) {
|
||||
const params = {
|
||||
"printerName": printerName
|
||||
}
|
||||
|
||||
DMSService.sendRequest("cups.getJobs", params, response => {
|
||||
if (response.result && printers[printerName]) {
|
||||
let updatedPrinters = Object.assign({}, printers)
|
||||
updatedPrinters[printerName].jobs = response.result
|
||||
printers = updatedPrinters
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getSelectedPrinter() {
|
||||
@@ -109,19 +142,22 @@ Singleton {
|
||||
}
|
||||
|
||||
function getPrintersNum() {
|
||||
if (!cupsAvailable) return 0
|
||||
if (!cupsAvailable)
|
||||
return 0
|
||||
|
||||
return printerNames.length
|
||||
}
|
||||
|
||||
function getPrintersNames() {
|
||||
if (!cupsAvailable) return []
|
||||
if (!cupsAvailable)
|
||||
return []
|
||||
|
||||
return printerNames
|
||||
}
|
||||
|
||||
function getTotalJobsNum() {
|
||||
if (!cupsAvailable) return 0
|
||||
if (!cupsAvailable)
|
||||
return 0
|
||||
|
||||
var result = 0
|
||||
for (var i = 0; i < printerNames.length; i++) {
|
||||
@@ -134,53 +170,58 @@ Singleton {
|
||||
}
|
||||
|
||||
function getCurrentPrinterState() {
|
||||
if (!cupsAvailable || !selectedPrinter) return ""
|
||||
if (!cupsAvailable || !selectedPrinter)
|
||||
return ""
|
||||
|
||||
var printer = printers[selectedPrinter]
|
||||
return printer.state
|
||||
}
|
||||
|
||||
function getCurrentPrinterStatePrettyShort() {
|
||||
if (!cupsAvailable || !selectedPrinter) return ""
|
||||
if (!cupsAvailable || !selectedPrinter)
|
||||
return ""
|
||||
|
||||
var printer = printers[selectedPrinter]
|
||||
return getPrinterStateTranslation(printer.state) +
|
||||
" (" + getPrinterStateReasonTranslation(printer.stateReason) + ")"
|
||||
return getPrinterStateTranslation(printer.state) + " (" + getPrinterStateReasonTranslation(printer.stateReason) + ")"
|
||||
}
|
||||
|
||||
function getCurrentPrinterStatePretty() {
|
||||
if (!cupsAvailable || !selectedPrinter) return ""
|
||||
if (!cupsAvailable || !selectedPrinter)
|
||||
return ""
|
||||
|
||||
var printer = printers[selectedPrinter]
|
||||
return getPrinterStateTranslation(printer.state) +
|
||||
" (" + I18n.tr("Reason") + ": " + getPrinterStateReasonTranslation(printer.stateReason) + ")"
|
||||
return getPrinterStateTranslation(printer.state) + " (" + I18n.tr("Reason") + ": " + getPrinterStateReasonTranslation(printer.stateReason) + ")"
|
||||
}
|
||||
|
||||
function getCurrentPrinterJobs() {
|
||||
if (!cupsAvailable || !selectedPrinter) return []
|
||||
if (!cupsAvailable || !selectedPrinter)
|
||||
return []
|
||||
|
||||
return getJobs(selectedPrinter)
|
||||
}
|
||||
|
||||
function getJobs(printerName) {
|
||||
if (!cupsAvailable) return ""
|
||||
if (!cupsAvailable)
|
||||
return ""
|
||||
|
||||
var printer = printers[printerName]
|
||||
return printer.jobs
|
||||
}
|
||||
|
||||
function getJobsNum(printerName) {
|
||||
if (!cupsAvailable) return 0
|
||||
if (!cupsAvailable)
|
||||
return 0
|
||||
|
||||
var printer = printers[printerName]
|
||||
return printer.jobs.length
|
||||
}
|
||||
|
||||
function pausePrinter(printerName) {
|
||||
if (!cupsAvailable) return
|
||||
if (!cupsAvailable)
|
||||
return
|
||||
|
||||
const params = {
|
||||
printerName: printerName
|
||||
"printerName": printerName
|
||||
}
|
||||
|
||||
DMSService.sendRequest("cups.pausePrinter", params, response => {
|
||||
@@ -191,10 +232,11 @@ Singleton {
|
||||
}
|
||||
|
||||
function resumePrinter(printerName) {
|
||||
if (!cupsAvailable) return
|
||||
if (!cupsAvailable)
|
||||
return
|
||||
|
||||
const params = {
|
||||
printerName: printerName
|
||||
"printerName": printerName
|
||||
}
|
||||
|
||||
DMSService.sendRequest("cups.resumePrinter", params, response => {
|
||||
@@ -204,30 +246,37 @@ Singleton {
|
||||
})
|
||||
}
|
||||
|
||||
function cancelJob(jobid) {
|
||||
if (!cupsAvailable) return
|
||||
function cancelJob(printerName, jobID) {
|
||||
if (!cupsAvailable)
|
||||
return
|
||||
|
||||
const params = {
|
||||
jobid: jobid
|
||||
"printerName": printerName,
|
||||
"jobID": jobID
|
||||
}
|
||||
|
||||
DMSService.sendRequest("cups.cancelJob", params, response => {
|
||||
if (response.error) {
|
||||
ToastService.showError(I18n.tr("Failed to cancel selected job") + " - " + response.error)
|
||||
} else {
|
||||
fetchJobsForPrinter(printerName)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function purgeJobs(printerName) {
|
||||
if (!cupsAvailable) return
|
||||
if (!cupsAvailable)
|
||||
return
|
||||
|
||||
const params = {
|
||||
printerName: printerName
|
||||
"printerName": printerName
|
||||
}
|
||||
|
||||
DMSService.sendRequest("cups.purgeJobs", params, response => {
|
||||
if (response.error) {
|
||||
ToastService.showError(I18n.tr("Failed to cancel all jobs") + " - " + response.error)
|
||||
} else {
|
||||
fetchJobsForPrinter(printerName)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -299,15 +348,7 @@ Singleton {
|
||||
}
|
||||
|
||||
function getPrinterStateReasonTranslation(reason) {
|
||||
let allReasons = Object.assign({},
|
||||
reasonsGeneral,
|
||||
reasonsSupplies,
|
||||
reasonsMedia,
|
||||
reasonsParts,
|
||||
reasonsErrors,
|
||||
reasonsService,
|
||||
reasonsConnectivity
|
||||
)
|
||||
let allReasons = Object.assign({}, reasonsGeneral, reasonsSupplies, reasonsMedia, reasonsParts, reasonsErrors, reasonsService, reasonsConnectivity)
|
||||
|
||||
let basReason = reason
|
||||
let suffix = ""
|
||||
|
||||
Reference in New Issue
Block a user