mirror of
https://github.com/kbumsik/VirtScreen.git
synced 2025-03-09 15:40:18 +00:00
QML: better password control
This commit is contained in:
parent
05f95f842d
commit
b75cd4ed2b
2 changed files with 92 additions and 31 deletions
69
main.qml
69
main.qml
|
@ -21,9 +21,10 @@ ApplicationWindow {
|
||||||
Material.accent: Material.Teal
|
Material.accent: Material.Teal
|
||||||
// Material.background: Material.Grey
|
// Material.background: Material.Grey
|
||||||
|
|
||||||
property int margin: 8
|
|
||||||
width: 380
|
width: 380
|
||||||
height: 525
|
height: 525
|
||||||
|
property int margin: 8
|
||||||
|
property int popupWidth: width - 26
|
||||||
|
|
||||||
// hide screen when loosing focus
|
// hide screen when loosing focus
|
||||||
property bool autoClose: true
|
property bool autoClose: true
|
||||||
|
@ -193,7 +194,7 @@ ApplicationWindow {
|
||||||
focus: true
|
focus: true
|
||||||
x: (parent.width - width) / 2
|
x: (parent.width - width) / 2
|
||||||
y: (parent.width - height) / 2 //(window.height) / 2
|
y: (parent.width - height) / 2 //(window.height) / 2
|
||||||
width: window.width - 26
|
width: popupWidth
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
@ -237,6 +238,44 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dialog {
|
||||||
|
id: passwordDialog
|
||||||
|
title: "New password"
|
||||||
|
focus: true
|
||||||
|
modal: true
|
||||||
|
standardButtons: Dialog.Ok | Dialog.Cancel
|
||||||
|
x: (parent.width - width) / 2
|
||||||
|
y: (parent.width - height) / 2 //(window.height) / 2
|
||||||
|
width: popupWidth
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id: passwordFIeld
|
||||||
|
focus: true
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
|
||||||
|
placeholderText: "New Password";
|
||||||
|
echoMode: TextInput.Password;
|
||||||
|
}
|
||||||
|
|
||||||
|
Keys.onPressed: {
|
||||||
|
event.accepted = true;
|
||||||
|
if (event.key == Qt.Key_Return || event.key == Qt.Key_Enter) {
|
||||||
|
passwordDialog.accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onAccepted: {
|
||||||
|
backend.createVNCPassword(passwordFIeld.text);
|
||||||
|
passwordFIeld.text = "";
|
||||||
|
}
|
||||||
|
onRejected: passwordFIeld.text = ""
|
||||||
|
}
|
||||||
|
|
||||||
StackLayout {
|
StackLayout {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
anchors.top: tabBar.bottom
|
anchors.top: tabBar.bottom
|
||||||
|
@ -458,18 +497,22 @@ ApplicationWindow {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
|
||||||
Label { id: passwordLabel; text: "Password" }
|
Label { text: "Password"; Layout.fillWidth: true }
|
||||||
TextField {
|
|
||||||
anchors.left: passwordLabel.right
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.margins: margin
|
|
||||||
|
|
||||||
placeholderText: "Password";
|
Button {
|
||||||
text: backend.vncPassword;
|
text: "Delete"
|
||||||
echoMode: TextInput.Password;
|
font.capitalization: Font.MixedCase
|
||||||
onTextEdited: {
|
highlighted: false
|
||||||
backend.vncPassword = text;
|
enabled: backend.vncUsePassword
|
||||||
}
|
onClicked: backend.deleteVNCPassword()
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: "New"
|
||||||
|
font.capitalization: Font.MixedCase
|
||||||
|
highlighted: true
|
||||||
|
enabled: !backend.vncUsePassword
|
||||||
|
onClicked: passwordDialog.open()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -354,7 +354,7 @@ class Backend(QObject):
|
||||||
_virtScreenIndex: int
|
_virtScreenIndex: int
|
||||||
# VNC server properties
|
# VNC server properties
|
||||||
_vncPort: int
|
_vncPort: int
|
||||||
_vncPassword: str = ""
|
_vncUsePassword: bool = False
|
||||||
_vncState: VNCState
|
_vncState: VNCState
|
||||||
_vncAutoStart: bool
|
_vncAutoStart: bool
|
||||||
_ipAddresses: List[str] = []
|
_ipAddresses: List[str] = []
|
||||||
|
@ -367,6 +367,7 @@ class Backend(QObject):
|
||||||
# Signals
|
# Signals
|
||||||
onVirtScreenCreatedChanged = pyqtSignal(bool)
|
onVirtScreenCreatedChanged = pyqtSignal(bool)
|
||||||
onVirtScreenIndexChanged = pyqtSignal(int)
|
onVirtScreenIndexChanged = pyqtSignal(int)
|
||||||
|
onVncUsePasswordChanged = pyqtSignal(bool)
|
||||||
onVncStateChanged = pyqtSignal(VNCState)
|
onVncStateChanged = pyqtSignal(VNCState)
|
||||||
onVncAutoStartChanged = pyqtSignal(bool)
|
onVncAutoStartChanged = pyqtSignal(bool)
|
||||||
onIPAddressesChanged = pyqtSignal()
|
onIPAddressesChanged = pyqtSignal()
|
||||||
|
@ -453,12 +454,18 @@ class Backend(QObject):
|
||||||
def vncPort(self, port):
|
def vncPort(self, port):
|
||||||
self._vncPort = port
|
self._vncPort = port
|
||||||
|
|
||||||
@pyqtProperty(str)
|
@pyqtProperty(bool, notify=onVncUsePasswordChanged)
|
||||||
def vncPassword(self):
|
def vncUsePassword(self):
|
||||||
return self._vncPassword
|
if os.path.isfile(X11VNC_PASSWORD_PATH):
|
||||||
@vncPassword.setter
|
self._vncUsePassword = True
|
||||||
def vncPassword(self, vncPassword):
|
else:
|
||||||
self._vncPassword = vncPassword
|
if self._vncUsePassword:
|
||||||
|
self.vncUsePassword = False
|
||||||
|
return self._vncUsePassword
|
||||||
|
@vncUsePassword.setter
|
||||||
|
def vncUsePassword(self, use):
|
||||||
|
self._vncUsePassword = use
|
||||||
|
self.onVncUsePasswordChanged.emit(use)
|
||||||
|
|
||||||
@pyqtProperty(VNCState, notify=onVncStateChanged)
|
@pyqtProperty(VNCState, notify=onVncStateChanged)
|
||||||
def vncState(self):
|
def vncState(self):
|
||||||
|
@ -514,6 +521,27 @@ class Backend(QObject):
|
||||||
self.xrandr.delete_virtual_screen()
|
self.xrandr.delete_virtual_screen()
|
||||||
self.virtScreenCreated = False
|
self.virtScreenCreated = False
|
||||||
|
|
||||||
|
@pyqtSlot(str)
|
||||||
|
def createVNCPassword(self, password):
|
||||||
|
if password:
|
||||||
|
p = SubprocessWrapper()
|
||||||
|
try:
|
||||||
|
p.run(f"x11vnc -storepasswd {password} {X11VNC_PASSWORD_PATH}")
|
||||||
|
except:
|
||||||
|
print("Failed creating password")
|
||||||
|
return
|
||||||
|
self.vncUsePassword = True
|
||||||
|
else:
|
||||||
|
print("Empty password")
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def deleteVNCPassword(self):
|
||||||
|
if os.path.isfile(X11VNC_PASSWORD_PATH):
|
||||||
|
os.remove(X11VNC_PASSWORD_PATH)
|
||||||
|
self.vncUsePassword = False
|
||||||
|
else:
|
||||||
|
print("Failed deleting the password file")
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def startVNC(self):
|
def startVNC(self):
|
||||||
# Check if a virtual screen created
|
# Check if a virtual screen created
|
||||||
|
@ -538,23 +566,13 @@ class Backend(QObject):
|
||||||
print("VNC Exited.")
|
print("VNC Exited.")
|
||||||
self.vncState = self.VNCState.OFF
|
self.vncState = self.VNCState.OFF
|
||||||
atexit.unregister(self.stopVNC)
|
atexit.unregister(self.stopVNC)
|
||||||
# Set password
|
|
||||||
password = False
|
|
||||||
if self.vncPassword:
|
|
||||||
print("There is password. Creating.")
|
|
||||||
password = True
|
|
||||||
p = SubprocessWrapper()
|
|
||||||
try:
|
|
||||||
p.run(f"x11vnc -storepasswd {self.vncPassword} {X11VNC_PASSWORD_PATH}")
|
|
||||||
except:
|
|
||||||
password = False
|
|
||||||
logfile = open(X11VNC_LOG_PATH, "wb")
|
logfile = open(X11VNC_LOG_PATH, "wb")
|
||||||
self.vncServer = ProcessProtocol(_onConnected, _onReceived, _onReceived, _onEnded, logfile)
|
self.vncServer = ProcessProtocol(_onConnected, _onReceived, _onReceived, _onEnded, logfile)
|
||||||
port = self.vncPort
|
port = self.vncPort
|
||||||
virt = self.xrandr.get_virtual_screen()
|
virt = self.xrandr.get_virtual_screen()
|
||||||
clip = f"{virt.width}x{virt.height}+{virt.x_offset}+{virt.y_offset}"
|
clip = f"{virt.width}x{virt.height}+{virt.x_offset}+{virt.y_offset}"
|
||||||
arg = f"x11vnc -multiptr -repeat -rfbport {port} -clip {clip}"
|
arg = f"x11vnc -multiptr -repeat -rfbport {port} -clip {clip}"
|
||||||
if password:
|
if self.vncUsePassword:
|
||||||
arg += f" -rfbauth {X11VNC_PASSWORD_PATH}"
|
arg += f" -rfbauth {X11VNC_PASSWORD_PATH}"
|
||||||
self.vncServer.run(arg)
|
self.vncServer.run(arg)
|
||||||
# auto stop on exit
|
# auto stop on exit
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue