From fb868a4f7f4924f06c4ed04d586bad3d3089d7f9 Mon Sep 17 00:00:00 2001 From: Bumsik Kim Date: Wed, 16 May 2018 07:04:16 -0400 Subject: [PATCH] Error message dialog added for X11VMC error --- main.qml | 23 ++++++++++++++++++++--- qml/AppWindow.qml | 23 +++++++++++++++++++++++ qml/preferenceDialog.qml | 2 +- virtscreen.py | 20 +++++++++----------- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/main.qml b/main.qml index 35840b0..fe261ca 100644 --- a/main.qml +++ b/main.qml @@ -29,6 +29,11 @@ Item { // virtscreen.py backend. Backend { id: backend + onVncStateChanged: { + if (backend.vncState == Backend.ERROR) { + autostart = false; + } + } } // Timer object and function @@ -128,12 +133,24 @@ Item { menu: Menu { MenuItem { id: vncStateText - text: !backend.virtScreenCreated ? "Enable Virtual Screen first." : - backend.vncState == Backend.OFF ? "Turn on VNC Server in the VNC tab." : + text: !backend.virtScreenCreated ? "Enable Virtual Screen first" : + backend.vncState == Backend.OFF ? "Turn on VNC Server in the VNC tab" : + backend.vncState == Backend.ERROR ? "Error occurred" : backend.vncState == Backend.WAITING ? "VNC Server is waiting for a client..." : - backend.vncState == Backend.CONNECTED ? "Connected." : + backend.vncState == Backend.CONNECTED ? "Connected" : "Server state error!" } + MenuItem { + id: errorText + visible: (text) + text: "" + Component.onCompleted : { + backend.onError.connect(function(errMsg) { + errorText.text = ""; + errorText.text = errMsg; + }); + } + } MenuItem { separator: true } diff --git a/qml/AppWindow.qml b/qml/AppWindow.qml index 0865c0f..82931f1 100644 --- a/qml/AppWindow.qml +++ b/qml/AppWindow.qml @@ -221,6 +221,29 @@ ApplicationWindow { onRejected: passwordFIeld.text = "" } + Dialog { + id: errorDialog + title: "Error" + focus: true + modal: true + standardButtons: Dialog.Ok + x: (parent.width - width) / 2 + y: (parent.width - height) / 2 //(window.height) / 2 + width: popupWidth + ColumnLayout { + anchors.fill: parent + Text { + horizontalAlignment: Text.AlignHCenter + text: errorText.text + onTextChanged: { + if (text) { + errorDialog.open(); + } + } + } + } + } + Loader { id: preferenceLoader active: false diff --git a/qml/preferenceDialog.qml b/qml/preferenceDialog.qml index e932714..45400f7 100644 --- a/qml/preferenceDialog.qml +++ b/qml/preferenceDialog.qml @@ -9,7 +9,7 @@ Dialog { focus: true modal: true visible: true - standardButtons: Dialog.Ok | Dialog.Cancel + standardButtons: Dialog.Ok x: (window.width - width) / 2 y: (window.width - height) / 2 width: popupWidth diff --git a/virtscreen.py b/virtscreen.py index e1cfcb3..73d1629 100755 --- a/virtscreen.py +++ b/virtscreen.py @@ -353,22 +353,20 @@ class Backend(QObject): class VNCState: """ Enum to indicate a state of the VNC server """ OFF = 0 - WAITING = 1 - CONNECTED = 2 + ERROR = 1 + WAITING = 2 + CONNECTED = 3 Q_ENUMS(VNCState) # Virtual screen properties - xrandr: XRandR + xrandr: XRandR = XRandR() _virtScreenCreated: bool = False - screens: List[DisplayProperty] - _virtScreenIndex: int + _virtScreenIndex: int = xrandr.virt_idx # VNC server properties _vncUsePassword: bool = False _vncState: VNCState = VNCState.OFF # Primary screen and mouse posistion _primaryProp: DisplayProperty - cursor_x: int - cursor_y: int vncServer: ProcessProtocol # Signals @@ -376,15 +374,12 @@ class Backend(QObject): onVirtScreenIndexChanged = pyqtSignal(int) onVncUsePasswordChanged = pyqtSignal(bool) onVncStateChanged = pyqtSignal(VNCState) - onVncAutoStartChanged = pyqtSignal(bool) onIPAddressesChanged = pyqtSignal() onDisplaySettingClosed = pyqtSignal() + onError = pyqtSignal(str) def __init__(self, parent=None): super(Backend, self).__init__(parent) - # create objects - self.xrandr = XRandR() - self._virtScreenIndex = self.xrandr.virt_idx # Qt properties @pyqtProperty(str, constant=True) @@ -534,6 +529,9 @@ class Backend(QObject): print("VNC disconnected.") self.vncState = self.VNCState.WAITING def _onEnded(exitCode): + if exitCode is not 0: + self.vncState = self.VNCState.ERROR + self.onError.emit('X11VNC: Error occurred.') print("VNC Exited.") self.vncState = self.VNCState.OFF atexit.unregister(self.stopVNC)