import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.kirigami 2.12 as Kirigami import QtQuick 2.6 import QtQuick.Controls 2.6 import QtQuick.Layouts 1.12 import QtQuick.Dialogs 1.3 Rectangle{ color:"transparent" Text{ text:i18nd("lliurex-access-control","Restrict access by center") font.family: "Quattrocento Sans Bold" font.pointSize: 16 } GridLayout{ id:generalLayout rows:2 flow: GridLayout.TopToBottom rowSpacing:10 width:parent.width-10 anchors.left:parent.left Kirigami.InlineMessage { id: messageLabel visible:accessControlBridge.showSettingsCDCMessage[0] text:getMessageText(accessControlBridge.showSettingsCDCMessage[1]) type:getMessageType(accessControlBridge.showSettingsCDCMessage[2]) Layout.minimumWidth:490 Layout.fillWidth:true Layout.topMargin: 40 } GridLayout{ id: optionsGrid rows: 2 flow: GridLayout.TopToBottom rowSpacing:5 Layout.topMargin: messageLabel.visible?0:50 CheckBox { id:cdcControlCb text:i18nd("lliurex-access-control","Activated access control by center on this computer") checked:accessControlBridge.isAccessDenyCDCEnabled font.pointSize: 10 focusPolicy: Qt.NoFocus Keys.onReturnPressed: cdcControlCb.toggled() Keys.onEnterPressed: cdcControlCb.toggled() onToggled:{ accessControlBridge.manageCDCAccessControl(checked) } Layout.alignment:Qt.AlignLeft Layout.bottomMargin:15 } RowLayout { Layout.fillWidth: true Layout.alignment:Qt.AlignLeft Text{ id:cdcLabel text:i18nd("lliurex-access-control","Lock access to users who do not belong to the center:") font.pointSize:10 } TextField{ id:cdcEntry text:accessControlBridge.cdcCode enabled:cdcControlCb.checked maximumLength:8 font.pointSize:10 horizontalAlignment:TextInput.AlignLeft focus:true implicitWidth:75 onTextEdited:{ if ((cdcEntry.text=="")||(cdcEntry.text.length==8)){ wait(1000, function() { waitTimer.stop() accessControlBridge.manageCDCCodeChange(cdcEntry.text) }) } } } } } } RowLayout{ id:btnBox anchors.bottom: parent.bottom anchors.right:parent.right anchors.bottomMargin:15 anchors.rightMargin:10 spacing:10 Button { id:applyBtn visible:true focus:true display:AbstractButton.TextBesideIcon icon.name:"dialog-ok.svg" text:i18nd("lliurex-access-control","Apply") Layout.preferredHeight:40 enabled:accessControlBridge.settingsCDCChanged Keys.onReturnPressed: applyBtn.clicked() Keys.onEnterPressed: applyBtn.clicked() onClicked:{ applyChanges() accessControlBridge.applyCDCChanges() } } Button { id:cancelBtn visible:true focus:true display:AbstractButton.TextBesideIcon icon.name:"dialog-cancel.svg" text:i18nd("lliurex-access-control","Cancel") Layout.preferredHeight: 40 enabled:accessControlBridge.settingsCDCChanged Keys.onReturnPressed: cancelBtn.clicked() Keys.onEnterPressed: cancelBtn.clicked() onClicked:{ discardChanges() accessControlBridge.cancelCDCChanges() } } } ChangesDialog{ id:cdcChangesDialog dialogTitle:"Lliurex Access Control"+" - "+i18nd("lliurex-access-control","Control by center") dialogVisible:accessControlBridge.showCDCChangesDialog dialogMsg:i18nd("lliurex-access-control","The are pending changes to apply.\nDo you want apply the changes or discard them?") Connections{ target:cdcChangesDialog function onDialogApplyClicked(){ applyChanges() } function onDiscardDialogClicked(){ discardChanges() } } } CustomPopup{ id:synchronizePopup } Timer{ id:delayTimer } function delay(delayTime,cb){ delayTimer.interval=delayTime; delayTimer.repeat=true; delayTimer.triggered.connect(cb); delayTimer.start() } Timer{ id:waitTimer } function wait(delayTime,cb){ waitTimer.interval=delayTime; waitTimer.repeat=true; waitTimer.triggered.connect(cb); waitTimer.start() } function getMessageText(code){ var msg=""; switch (code){ case 10: msg=i18nd("lliurex-access-control","Changes applied successfully"); break; case -50: msg=i18nd("lliurex-access-control","It is not possible to deactive access control by center"); break; case -60: msg=i18nd("lliurex-access-control","Unable to update the center code"); break; case -90: msg=i18nd("lliurex-access-control","No center code has been indicated"); break; case -101: msg=i18nd("lliurex-access-control","Center code is not valid"); break; default: break; } return msg; } function getMessageType(type){ switch (type){ case "Info": return Kirigami.MessageType.Information case "Success": return Kirigami.MessageType.Positive case "Error": return Kirigami.MessageType.Error } } function applyChanges(){ synchronizePopup.open() synchronizePopup.popupMessage=i18nd("lliurex-access-control", "Apply changes. Wait a moment...") delayTimer.stop() delay(500, function() { if (accessControlBridge.closePopUp){ synchronizePopup.close(), delayTimer.stop() } }) } function discardChanges(){ synchronizePopup.open() synchronizePopup.popupMessage=i18nd("lliurex-access-control", "Restoring previous values. Wait a moment...") delayTimer.stop() delay(1000, function() { if (accessControlBridge.closePopUp){ synchronizePopup.close(), delayTimer.stop() } }) } }