From e9f9730364cb81296503494e4f0307293cde9246 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 26 Jul 2022 16:36:38 +0200 Subject: [PATCH] Don't show context menu button if it is empty It will likely be empty for guest accounts on networks where the administrator is the only one with rights to access other people's prints. Contributes to issue CURA-9220. --- .../resources/qml/MonitorContextMenu.qml | 171 ++++++++++-------- .../resources/qml/MonitorPrintJobCard.qml | 6 +- .../resources/qml/MonitorPrinterCard.qml | 9 +- 3 files changed, 104 insertions(+), 82 deletions(-) diff --git a/plugins/UM3NetworkPrinting/resources/qml/MonitorContextMenu.qml b/plugins/UM3NetworkPrinting/resources/qml/MonitorContextMenu.qml index 11cb55d42d..cf7d5fe932 100644 --- a/plugins/UM3NetworkPrinting/resources/qml/MonitorContextMenu.qml +++ b/plugins/UM3NetworkPrinting/resources/qml/MonitorContextMenu.qml @@ -13,10 +13,94 @@ import Cura 1.6 as Cura */ Item { + id: monitorContextMenu property alias target: popUp.target property var printJob: null + //Everything in the pop-up only gets evaluated when showing the pop-up. + //However we want to show the button for showing the pop-up only if there is anything visible inside it. + //So compute here the visibility of the menu items, so that we can use it for the visibility of the button. + property bool sendToTopVisible: + { + if (printJob && (printJob.state == "queued" || printJob.state == "error") && !isAssigned(printJob)) { + if (OutputDevice && OutputDevice.queuedPrintJobs[0] && OutputDevice.canWriteOthersPrintJobs) { + return OutputDevice.queuedPrintJobs[0].key != printJob.key; + } + } + return false; + } + property bool deleteVisible: + { + if(!printJob) + { + return false; + } + if(printJob.isMine) + { + if(!OutputDevice.canWriteOwnPrintJobs) + { + return false; + } + } + else + { + if(!OutputDevice.canWriteOthersPrintJobs) + { + return false; + } + } + var states = ["queued", "error", "sent_to_printer"]; + return states.indexOf(printJob.state) !== -1; + } + property bool pauseVisible: + { + if(!printJob) + { + return false; + } + if(printJob.isMine) + { + if(!OutputDevice.canWriteOwnPrintJobs) + { + return false; + } + } + else + { + if(!OutputDevice.canWriteOthersPrintJobs) + { + return false; + } + } + var states = ["printing", "pausing", "paused", "resuming"]; + return states.indexOf(printJob.state) !== -1; + } + property bool abortVisible: + { + if(!printJob) + { + return false; + } + if(printJob.isMine) + { + if(!OutputDevice.canWriteOwnPrintJobs) + { + return false; + } + } + else + { + if(!OutputDevice.canWriteOthersPrintJobs) + { + return false; + } + } + var states = ["pre_print", "printing", "pausing", "paused", "resuming"]; + return states.indexOf(printJob.state) !== -1; + } + property bool hasItems: sendToTopVisible || deleteVisible || pauseVisible || abortVisible + GenericPopUp { id: popUp @@ -46,20 +130,15 @@ Item spacing: Math.floor(UM.Theme.getSize("default_margin").height / 2) - PrintJobContextMenuItem { - onClicked: { + PrintJobContextMenuItem + { + onClicked: + { sendToTopConfirmationDialog.visible = true; popUp.close(); } text: catalog.i18nc("@label", "Move to top"); - visible: { - if (printJob && (printJob.state == "queued" || printJob.state == "error") && !isAssigned(printJob)) { - if (OutputDevice && OutputDevice.queuedPrintJobs[0] && OutputDevice.canWriteOthersPrintJobs) { - return OutputDevice.queuedPrintJobs[0].key != printJob.key; - } - } - return false; - } + visible: monitorContextMenu.sendToTopVisible } PrintJobContextMenuItem @@ -70,29 +149,7 @@ Item popUp.close(); } text: catalog.i18nc("@label", "Delete"); - visible: - { - if(!printJob) - { - return false; - } - if(printJob.isMine) - { - if(!OutputDevice.canWriteOwnPrintJobs) - { - return false; - } - } - else - { - if(!OutputDevice.canWriteOthersPrintJobs) - { - return false; - } - } - var states = ["queued", "error", "sent_to_printer"]; - return states.indexOf(printJob.state) !== -1; - } + visible: monitorContextMenu.deleteVisible } PrintJobContextMenuItem @@ -131,29 +188,7 @@ Item catalog.i18nc("@label", "Pause"); } } - visible: - { - if(!printJob) - { - return false; - } - if(printJob.isMine) - { - if(!OutputDevice.canWriteOwnPrintJobs) - { - return false; - } - } - else - { - if(!OutputDevice.canWriteOthersPrintJobs) - { - return false; - } - } - var states = ["printing", "pausing", "paused", "resuming"]; - return states.indexOf(printJob.state) !== -1; - } + visible: monitorContextMenu.pauseVisible } PrintJobContextMenuItem @@ -165,29 +200,7 @@ Item popUp.close(); } text: printJob && printJob.state == "aborting" ? catalog.i18nc("@label", "Aborting...") : catalog.i18nc("@label", "Abort"); - visible: - { - if (!printJob) - { - return false; - } - if(printJob.isMine) - { - if(!OutputDevice.canWriteOwnPrintJobs) - { - return false; - } - } - else - { - if(!OutputDevice.canWriteOthersPrintJobs) - { - return false; - } - } - var states = ["pre_print", "printing", "pausing", "paused", "resuming"]; - return states.indexOf(printJob.state) !== -1; - } + visible: monitorContextMenu.abortVisible } } } diff --git a/plugins/UM3NetworkPrinting/resources/qml/MonitorPrintJobCard.qml b/plugins/UM3NetworkPrinting/resources/qml/MonitorPrintJobCard.qml index 2974e5ce6b..64aa4e7a9c 100644 --- a/plugins/UM3NetworkPrinting/resources/qml/MonitorPrintJobCard.qml +++ b/plugins/UM3NetworkPrinting/resources/qml/MonitorPrintJobCard.qml @@ -206,7 +206,11 @@ Item onClicked: enabled ? contextMenu.switchPopupState() : {} visible: { - if (!printJob) + if(!printJob) + { + return false; + } + if(!contextMenu.hasItems) { return false; } diff --git a/plugins/UM3NetworkPrinting/resources/qml/MonitorPrinterCard.qml b/plugins/UM3NetworkPrinting/resources/qml/MonitorPrinterCard.qml index 0069d017f6..67f308a64e 100644 --- a/plugins/UM3NetworkPrinting/resources/qml/MonitorPrinterCard.qml +++ b/plugins/UM3NetworkPrinting/resources/qml/MonitorPrinterCard.qml @@ -209,8 +209,13 @@ Item onClicked: enabled ? contextMenu.switchPopupState() : {} visible: { - if (!printer || !printer.activePrintJob) { - return false + if(!printer || !printer.activePrintJob) + { + return false; + } + if(!contextMenu.hasItems) + { + return false; } var states = ["queued", "error", "sent_to_printer", "pre_print", "printing", "pausing", "paused", "resuming"] return states.indexOf(printer.activePrintJob.state) !== -1