diff --git a/virtscreen/assets/AppWindow.qml b/virtscreen/assets/AppWindow.qml index 0ad5f83..992eb8c 100644 --- a/virtscreen/assets/AppWindow.qml +++ b/virtscreen/assets/AppWindow.qml @@ -209,8 +209,7 @@ ApplicationWindow { TextField { id: passwordFIeld focus: true - anchors.left: parent.left - anchors.right: parent.right + Layout.fillWidth: true placeholderText: "New Password"; echoMode: TextInput.Password; } diff --git a/virtscreen/assets/VncOptionsDialog.qml b/virtscreen/assets/VncOptionsDialog.qml index e047a36..be50f76 100644 --- a/virtscreen/assets/VncOptionsDialog.qml +++ b/virtscreen/assets/VncOptionsDialog.qml @@ -12,7 +12,7 @@ Dialog { x: (window.width - width) / 2 y: (window.width - height) / 2 width: popupWidth - height: 300 + height: 350 Component.onCompleted: { var request = new XMLHttpRequest(); @@ -33,24 +33,44 @@ Dialog { ColumnLayout { anchors.fill: parent - - Repeater { - id: vncOptionsRepeater - RowLayout { - enabled: modelData.available - Label { - Layout.fillWidth: true - text: modelData.description + ' (' + modelData.value + ')' + RowLayout { + TextField { + id: vncCustomArgsTextField + enabled: vncCustomArgsCheckbox.checked + Layout.fillWidth: true + placeholderText: "Custom x11vnc arguments" + onTextEdited: { + settings.customX11vncArgs.value = text; } - Switch { - checked: modelData.available ? modelData.enabled : false - onCheckedChanged: { - settings.x11vncOptions[modelData.value].enabled = checked; + text: vncCustomArgsCheckbox.checked ? settings.customX11vncArgs.value : "" + } + CheckBox { + id: vncCustomArgsCheckbox + checked: settings.customX11vncArgs.enabled + onToggled: { + settings.customX11vncArgs.enabled = checked; + } + } + } + ColumnLayout { + enabled: !vncCustomArgsCheckbox.checked + Repeater { + id: vncOptionsRepeater + RowLayout { + enabled: modelData.available + Label { + Layout.fillWidth: true + text: modelData.description + ' (' + modelData.value + ')' + } + Switch { + checked: modelData.available ? modelData.enabled : false + onCheckedChanged: { + settings.x11vncOptions[modelData.value].enabled = checked; + } } } } } - RowLayout { // Empty layout Layout.fillHeight: true diff --git a/virtscreen/assets/config.default.json b/virtscreen/assets/config.default.json index f592c1e..3c018c2 100644 --- a/virtscreen/assets/config.default.json +++ b/virtscreen/assets/config.default.json @@ -1,5 +1,5 @@ { - "version": "0.2.0", + "version": "0.3.0", "x11vncVersion": "0.9.15", "theme_color": 8, "virt": { @@ -31,5 +31,9 @@ "arg": null } }, + "customX11vncArgs": { + "enabled": false, + "value": "" + }, "presets": [] } \ No newline at end of file diff --git a/virtscreen/assets/data.json b/virtscreen/assets/data.json index 30c5938..70c2f33 100644 --- a/virtscreen/assets/data.json +++ b/virtscreen/assets/data.json @@ -1,5 +1,5 @@ { - "version": "0.2.0", + "version": "0.3.0", "x11vncOptions": { "-ncache": { "value": "-ncache", diff --git a/virtscreen/assets/main.qml b/virtscreen/assets/main.qml index 1760b2f..c2c1f74 100644 --- a/virtscreen/assets/main.qml +++ b/virtscreen/assets/main.qml @@ -11,6 +11,11 @@ Item { property var settings: JSON.parse(backend.settings) property bool autostart: settings.vnc.autostart + function saveSettings () { + settings.vnc.autostart = autostart; + backend.settings = JSON.stringify(settings, null, 4); + } + function createVirtScreen () { backend.createVirtScreen(settings.virt.device, settings.virt.width, settings.virt.height, settings.virt.portrait, @@ -18,18 +23,8 @@ Item { } function startVNC () { - var options = ''; - var data = settings.x11vncOptions; - for (var key in data) { - if(data[key].available && data[key].enabled) { - options += key + ' '; - if(data[key].arg !== null) { - options += data[key].arg.toString() + ' '; - } - } - } - console.log('options: ', options); - backend.startVNC(settings.vnc.port, options); + saveSettings(); + backend.startVNC(settings.vnc.port); } function stopVNC () { @@ -234,8 +229,7 @@ Item { id: quitAction text: qsTr("&Quit") onTriggered: { - settings.vnc.autostart = autostart; - backend.settings = JSON.stringify(settings, null, 4); + saveSettings(); backend.quitProgram(); } } diff --git a/virtscreen/virtscreen.py b/virtscreen/virtscreen.py index 91c866e..324f78f 100755 --- a/virtscreen/virtscreen.py +++ b/virtscreen/virtscreen.py @@ -457,7 +457,7 @@ class Backend(QObject): value["available"] = True else: value["available"] = False - # 2. Default Display settings app for a Desktop Environment + # Default Display settings app for a Desktop Environment desktop_environ = os.environ['XDG_CURRENT_DESKTOP'].lower() for key, value in data['displaySettingApps'].items(): for de in value['XDG_CURRENT_DESKTOP']: @@ -569,8 +569,8 @@ class Backend(QObject): else: self.onError.emit("Failed deleting the password file") - @pyqtSlot(int, str) - def startVNC(self, port, options=''): + @pyqtSlot(int) + def startVNC(self, port): # Check if a virtual screen created if not self.virtScreenCreated: self.onError.emit("Virtual Screen not crated.") @@ -606,7 +606,19 @@ class Backend(QObject): self.vncState = self.VNCState.OFF print("VNC Exited.") atexit.unregister(self.stopVNC) - + # load settings + with open(CONFIG_PATH, 'r') as f: + config = json.load(f) + options = '' + if config['customX11vncArgs']['enabled']: + options = config['customX11vncArgs']['value'] + else: + for key, value in config['x11vncOptions'].items(): + if value['available'] and value['enabled']: + options += key + ' ' + if value['arg'] is not None: + options += str(value['arg']) + ' ' + # Sart x11vnc, turn settings object into VNC arguments format logfile = open(X11VNC_LOG_PATH, "wb") self.vncServer = ProcessProtocol(_onConnected, _onReceived, _onReceived, _onEnded, logfile) try: @@ -856,13 +868,6 @@ def main_cli(args: argparse.Namespace): for key, value in tmp_args.items(): if value: position = key - # Turn settings object into VNC arguments format - vnc_option = '' - for key, value in config['x11vncOptions'].items(): - if value['available'] and value['enabled']: - vnc_option += key + ' ' - if value['arg'] is not None: - vnc_option += str(value['arg']) + ' ' # Create virtscreen and Start VNC def handle_error(msg): print('Error: ', msg) @@ -876,7 +881,7 @@ def main_cli(args: argparse.Namespace): sys.exit(0) backend.onVncStateChanged.connect(handle_vnc_changed) from twisted.internet import reactor # pylint: disable=E0401 - backend.startVNC(config['vnc']['port'], vnc_option) + backend.startVNC(config['vnc']['port']) reactor.run() if __name__ == '__main__':