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.
This commit is contained in:
Ghostkeeper 2022-07-26 16:36:38 +02:00
parent 5eb340e3f0
commit e9f9730364
No known key found for this signature in database
GPG key ID: FFBC62A75981ED70
3 changed files with 104 additions and 82 deletions

View file

@ -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
}
}
}