[vlc-devel] [PATCH 2/2] qml/Dialogs: Update error handling with the global object

Benjamin Arnaud benjamin.arnaud at videolabs.io
Tue Mar 16 09:32:58 UTC 2021


---
 .../gui/qt/dialogs/dialogs/qml/Dialogs.qml    | 137 ++++++++++--------
 1 file changed, 77 insertions(+), 60 deletions(-)

diff --git a/modules/gui/qt/dialogs/dialogs/qml/Dialogs.qml b/modules/gui/qt/dialogs/dialogs/qml/Dialogs.qml
index d85cdb0a61..ae1828c510 100644
--- a/modules/gui/qt/dialogs/dialogs/qml/Dialogs.qml
+++ b/modules/gui/qt/dialogs/dialogs/qml/Dialogs.qml
@@ -30,10 +30,80 @@ Item {
     signal restoreFocus();
     property var bgContent: undefined
 
+    //---------------------------------------------------------------------------------------------
+    // Events
+    //---------------------------------------------------------------------------------------------
+
+    Component.onDestruction: {
+        if (questionDialog.dialogId !== undefined) {
+            dialogModel.dismiss(questionDialog.dialogId)
+            questionDialog.dialogId = undefined
+        } if (loginDialog.dialogId !== undefined) {
+            dialogModel.dismiss(loginDialog.dialogId)
+            loginDialog.dialogId = undefined
+        }
+    }
+
+    //---------------------------------------------------------------------------------------------
+    // Functions
+    //---------------------------------------------------------------------------------------------
+
     function ask(text, acceptCb, rejectCb, buttons) {
         customDialog.ask(text, acceptCb, rejectCb, buttons)
     }
 
+    //---------------------------------------------------------------------------------------------
+    // Connections
+    //---------------------------------------------------------------------------------------------
+
+    Connections
+    {
+        target: dialogModel
+
+        onLogin: {
+            loginDialog.dialogId = dialogId
+            loginDialog.title = title
+            loginDialog.defaultUsername = defaultUsername
+            loginDialog.open()
+        }
+
+        onQuestion: {
+            questionDialog.dialogId = dialogId
+            questionDialog.title = title
+            questionDialog.text = text
+            questionDialog.cancelTxt = cancel
+            questionDialog.action1Txt = action1
+            questionDialog.action2Txt = action2
+            questionDialog.open()
+        }
+
+        onProgress: {
+            console.warn("onProgressUpdated is not implemented")
+        }
+
+        onProgressUpdated: {
+            console.warn("onProgressUpdated is not implemented")
+        }
+
+        onCancelled: {
+            if (questionDialog.dialogId === dialogId) {
+                questionDialog.close()
+                questionDialog.dialogId = undefined
+                dialogModel.dismiss(dialogId)
+            } else if (loginDialog.dialogId === dialogId)  {
+                loginDialog.close()
+                loginDialog.dialogId = undefined
+                dialogModel.dismiss(dialogId)
+            } else {
+                dialogModel.dismiss(dialogId)
+            }
+        }
+    }
+
+    //---------------------------------------------------------------------------------------------
+    // Childs
+    //---------------------------------------------------------------------------------------------
+
     Widgets.DrawerExt {
         id: errorPopup
         anchors {
@@ -44,9 +114,14 @@ Item {
         width: parent.width * 0.8
         z: 10
 
-        property alias messageModel: messages
-        ListModel {
+        DialogErrorModel {
             id: messages
+
+            model: dialogModel
+
+            onModelChanged: if (count) errorPopup.state = "visible"
+
+            onCountChanged: errorPopup.state = "visible"
         }
 
         component: Rectangle {
@@ -283,62 +358,4 @@ Item {
         rootWindow: root.bgContent
         onAboutToHide: restoreFocus()
     }
-
-    DialogModel {
-        id: dialogModel
-        mainCtx: mainctx
-        onLoginDisplayed: {
-            loginDialog.dialogId = dialogId
-            loginDialog.title = title
-            loginDialog.defaultUsername = defaultUsername
-            loginDialog.open()
-        }
-
-        onErrorDisplayed: {
-            errorPopup.messageModel.append({title: title, text: text })
-            errorPopup.state = "visible"
-        }
-
-        onProgressDisplayed: {
-            console.warn("onProgressUpdated is not implemented")
-        }
-
-        onProgressUpdated: {
-            console.warn("onProgressUpdated is not implemented")
-        }
-
-        onQuestionDisplayed: {
-            questionDialog.dialogId = dialogId
-            questionDialog.title = title
-            questionDialog.text = text
-            questionDialog.cancelTxt = cancel
-            questionDialog.action1Txt = action1
-            questionDialog.action2Txt = action2
-            questionDialog.open()
-        }
-
-        onCancelled: {
-            if (questionDialog.dialogId === dialogId) {
-                questionDialog.close()
-                questionDialog.dialogId = undefined
-                dialogModel.dismiss(dialogId)
-            } else if (loginDialog.dialogId === dialogId)  {
-                loginDialog.close()
-                loginDialog.dialogId = undefined
-                dialogModel.dismiss(dialogId)
-            } else {
-                dialogModel.dismiss(dialogId)
-            }
-        }
-
-        Component.onDestruction: {
-            if (questionDialog.dialogId !== undefined) {
-                dialogModel.dismiss(questionDialog.dialogId)
-                questionDialog.dialogId = undefined
-            } if (loginDialog.dialogId !== undefined) {
-                dialogModel.dismiss(loginDialog.dialogId)
-                loginDialog.dialogId = undefined
-            }
-        }
-    }
 }
-- 
2.25.1



More information about the vlc-devel mailing list