From 7205fa4ed8e6eebe700189481cf95b94e3ac961d Mon Sep 17 00:00:00 2001 From: Akira Ohgaki <akiraohgaki@gmail.com> Date: Wed, 1 Mar 2017 12:53:52 +0900 Subject: [PATCH] Use custom dialog --- app/qml/main.qml | 190 +++++++++++++++++++++-------------------------- 1 file changed, 86 insertions(+), 104 deletions(-) diff --git a/app/qml/main.qml b/app/qml/main.qml index 810065b..25568f3 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -1,105 +1,26 @@ -import QtQuick 2.3 +// Still support Qt 5.2, so doesn't use QtQuick.Dialogs 1.2 +import QtQuick 2.0 import QtQuick.Window 2.0 -import QtQuick.Controls 1.2 -import QtQuick.Dialogs 1.2 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 1.0 + +import "ui" as Ui import "scripts/Utility.js" as Utility Window { id: app - title: Qt.application.name + + title: configHandler.getAppConfigApplication().name width: 400 height: 200 minimumWidth: 400 minimumHeight: 200 maximumWidth: 800 maximumHeight: 400 + visible: true - MessageDialog { - id: confirmDialog - title: app.title - icon: StandardIcon.Question - text: "" - informativeText: "" - detailedText: "" - standardButtons: StandardButton.Ok | StandardButton.Cancel - onAccepted: ocsUrlHandler.process() - onRejected: Qt.quit() - } - - MessageDialog { - id: infoDialog - title: app.title - icon: StandardIcon.Information - text: "" - informativeText: "" - detailedText: "" - standardButtons: StandardButton.Open | StandardButton.Close - onAccepted: { - ocsUrlHandler.openDestination(); - Qt.quit(); - } - onRejected: Qt.quit() - } - - MessageDialog { - id: errorDialog - title: app.title - icon: StandardIcon.Warning - text: "" - informativeText: "" - detailedText: "" - standardButtons: StandardButton.Close - onRejected: Qt.quit() - } - - Dialog { - id: progressDialog - title: app.title - property alias primaryLabel: primaryLabel - property alias informativeLabel: informativeLabel - property alias progressBar: progressBar - property alias progressLabel: progressLabel - contentItem: Item { - implicitWidth: 400 - implicitHeight: 150 - Column { - anchors.fill: parent - anchors.margins: 12 - spacing: 8 - Label { - id: primaryLabel - text: " " - font.bold: true - } - Label { - id: informativeLabel - text: " " - } - ProgressBar { - id: progressBar - maximumValue: 1 - minimumValue: 0 - value: 0 - anchors.left: parent.left - anchors.right: parent.right - } - Label { - id: progressLabel - text: " " - anchors.right: parent.right - } - Button { - id: cancelButton - text: qsTr("Cancel") - anchors.right: parent.right - onClicked: Qt.quit() - } - } - } - } - - Component.onCompleted: { + function init() { var metadata = ocsUrlHandler.metadata(); var primaryMessages = { "success_download": qsTr("Download successfull"), @@ -111,50 +32,111 @@ Window { }; ocsUrlHandler.started.connect(function() { + confirmDialog.close(); progressDialog.open(); }); ocsUrlHandler.finishedWithSuccess.connect(function(result) { progressDialog.close(); - infoDialog.text = primaryMessages[result.status]; + infoDialog.primaryText = primaryMessages[result.status]; infoDialog.informativeText = metadata.filename; - infoDialog.detailedText = result.message; + //infoDialog.detailedText = result.message; infoDialog.open(); }); ocsUrlHandler.finishedWithError.connect(function(result) { progressDialog.close(); - errorDialog.text = primaryMessages[result.status]; + errorDialog.primaryText = primaryMessages[result.status]; errorDialog.informativeText = metadata.filename; - errorDialog.detailedText = result.message; + //errorDialog.detailedText = result.message; errorDialog.open(); }); ocsUrlHandler.downloadProgress.connect(function(id, bytesReceived, bytesTotal) { - progressDialog.primaryLabel.text = qsTr("Downloading"); - progressDialog.informativeLabel.text = metadata.filename; - progressDialog.progressBar.value = bytesReceived / bytesTotal; - progressDialog.progressLabel.text = Utility.convertByteToHumanReadable(bytesReceived) - + " / " + Utility.convertByteToHumanReadable(bytesTotal) + progressDialog.primaryText = qsTr("Downloading"); + progressDialog.informativeText = metadata.filename; + progressDialog.progress = bytesReceived / bytesTotal; + progressDialog.progressText + = Utility.convertByteToHumanReadable(bytesReceived) + + " / " + Utility.convertByteToHumanReadable(bytesTotal); }); if (ocsUrlHandler.isValid()) { if (metadata.command === "download") { - confirmDialog.text = qsTr("Do you want to download?"); + confirmDialog.primaryText = qsTr("Do you want to download?"); } else if (metadata.command === "install") { - confirmDialog.text = qsTr("Do you want to install?"); + confirmDialog.primaryText = qsTr("Do you want to install?"); } confirmDialog.informativeText = metadata.filename; - confirmDialog.detailedText = qsTr("URL") + ": " + metadata.url + "\n\n" + /* + confirmDialog.detailedText + = qsTr("URL") + ": " + metadata.url + "\n\n" + qsTr("File") + ": " + metadata.filename + "\n\n" - + qsTr("Type") + ": " + metadata.type; + + qsTr("Type") + ": " + configHandler.getAppConfigInstallTypes()[metadata.type].name; + */ confirmDialog.open(); } else { - errorDialog.text = qsTr("Validation error"); - errorDialog.detailedText = qsTr("Invalid OCS-URL"); + errorDialog.primaryText = primaryMessages["error_validation"]; + errorDialog.informativeText = qsTr("Invalid OCS-URL"); errorDialog.open(); } } + + Ui.Dialog { + id: confirmDialog + //icon: StandardIcon.Question + acceptButton.text: qsTr("OK") + acceptButton.onClicked: ocsUrlHandler.process() + rejectButton.text: qsTr("Cancel") + rejectButton.onClicked: Qt.quit() + } + + Ui.Dialog { + id: infoDialog + //icon: StandardIcon.Information + acceptButton.text: qsTr("Open") + acceptButton.onClicked: { + ocsUrlHandler.openDestination(); + Qt.quit(); + } + rejectButton.text: qsTr("Close") + rejectButton.onClicked: Qt.quit() + } + + Ui.Dialog { + id: errorDialog + //icon: StandardIcon.Warning + rejectButton.text: qsTr("Close") + rejectButton.onClicked: Qt.quit() + } + + Ui.Dialog { + id: progressDialog + //icon: StandardIcon.Warning + rejectButton.text: qsTr("Cancel") + rejectButton.onClicked: Qt.quit() + property alias progress: progressBar.value + property alias progressText: progressText.text + content: ColumnLayout { + spacing: 8 + ProgressBar { + id: progressBar + minimumValue: 0 + maximumValue: 1 + value: 0 + Layout.fillWidth: true + } + Label { + id: progressText + text: "" + anchors.right: parent.right + } + } + } + + Component.onCompleted: { + app.init(); + } } -- GitLab