aboutsummaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorxiphon <xiphon@protonmail.com>2020-04-04 13:22:25 +0000
committerxiphon <xiphon@protonmail.com>2020-04-06 16:59:33 +0000
commit6ed7fcec67109602a6b1dbe390b4274b9467931e (patch)
tree4d983c69547036bc1c883d525ceb5d8e0425e3b7 /components
parentdf54439972b885476ccc13b468b17508493521c7 (diff)
downloadmonzero-gui-6ed7fcec67109602a6b1dbe390b4274b9467931e.tar.gz
monzero-gui-6ed7fcec67109602a6b1dbe390b4274b9467931e.tar.xz
monzero-gui-6ed7fcec67109602a6b1dbe390b4274b9467931e.zip
UpdateDialog: implement update download functionality
Diffstat (limited to 'components')
-rw-r--r--components/Notifier.qml85
-rw-r--r--components/StandardButton.qml16
-rw-r--r--components/Style.qml3
-rw-r--r--components/UpdateDialog.qml200
4 files changed, 216 insertions, 88 deletions
diff --git a/components/Notifier.qml b/components/Notifier.qml
deleted file mode 100644
index 127de390..00000000
--- a/components/Notifier.qml
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright (c) 2017-2018, The Monero Project
-//
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification, are
-// permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of
-// conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-// of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be
-// used to endorse or promote products derived from this software without specific
-// prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import QtQuick 2.9
-import QtQuick.Controls 1.4
-import moneroComponents.Wallet 1.0
-import "." as MoneroComponents
-
-Item {
- id: item
- property string message: ""
- property bool active: false
- height: 180
- width: 320
- property int margin: 15
- x: parent.width - width - margin
- y: parent.height - height * scale.yScale - margin * scale.yScale
-
- Rectangle {
- color: "#FF6C3C"
- border.color: "black"
- anchors.fill: parent
-
- TextArea {
- id:versionText
- readOnly: true
- backgroundVisible: false
- textFormat: TextEdit.AutoText
- anchors.fill: parent
- font.family: MoneroComponents.Style.fontRegular.name
- font.pixelSize: 12
- textMargin: 20
- textColor: "white"
- text: item.message
- wrapMode: Text.WrapAnywhere
- }
- }
-
- transform: Scale {
- id: scale
- yScale: item.active ? 1 : 0
-
- Behavior on yScale {
- NumberAnimation { duration: 500; easing.type: Easing.InOutCubic }
- }
- }
-
- Timer {
- id: hider
- interval: 30000; running: false; repeat: false
- onTriggered: { item.active = false }
- }
-
- function show(message) {
- item.visible = true
- item.message = message
- item.active = true
- hider.running = true
- }
-}
diff --git a/components/StandardButton.qml b/components/StandardButton.qml
index 77cd2dad..5b4e2279 100644
--- a/components/StandardButton.qml
+++ b/components/StandardButton.qml
@@ -33,11 +33,17 @@ import "../components" as MoneroComponents
Item {
id: button
+ property bool primary: true
property string rightIcon: ""
property string rightIconInactive: ""
- property string textColor: button.enabled? MoneroComponents.Style.buttonTextColor: MoneroComponents.Style.buttonTextColorDisabled
+ property color textColor: !button.enabled
+ ? MoneroComponents.Style.buttonTextColorDisabled
+ : primary
+ ? MoneroComponents.Style.buttonTextColor
+ : MoneroComponents.Style.buttonSecondaryTextColor;
property bool small: false
property alias text: label.text
+ property alias fontBold: label.font.bold
property int fontSize: {
if(small) return 14;
else return 16;
@@ -70,7 +76,9 @@ Item {
when: buttonArea.containsMouse || button.focus
PropertyChanges {
target: buttonRect
- color: MoneroComponents.Style.buttonBackgroundColorHover
+ color: primary
+ ? MoneroComponents.Style.buttonBackgroundColorHover
+ : MoneroComponents.Style.buttonSecondaryBackgroundColorHover
}
},
State {
@@ -78,7 +86,9 @@ Item {
when: button.enabled
PropertyChanges {
target: buttonRect
- color: MoneroComponents.Style.buttonBackgroundColor
+ color: primary
+ ? MoneroComponents.Style.buttonBackgroundColor
+ : MoneroComponents.Style.buttonSecondaryBackgroundColor
}
},
State {
diff --git a/components/Style.qml b/components/Style.qml
index fc840244..7b9f31ee 100644
--- a/components/Style.qml
+++ b/components/Style.qml
@@ -43,6 +43,9 @@ QtObject {
property string buttonInlineBackgroundColor: blackTheme ? _b_buttonInlineBackgroundColor : _w_buttonInlineBackgroundColor
property string buttonTextColor: blackTheme ? _b_buttonTextColor : _w_buttonTextColor
property string buttonTextColorDisabled: blackTheme ? _b_buttonTextColorDisabled : _w_buttonTextColorDisabled
+ property string buttonSecondaryBackgroundColor: "#d9d9d9"
+ property string buttonSecondaryBackgroundColorHover: "#a6a6a6"
+ property string buttonSecondaryTextColor: "#4d4d4d"
property string dividerColor: blackTheme ? _b_dividerColor : _w_dividerColor
property real dividerOpacity: blackTheme ? _b_dividerOpacity : _w_dividerOpacity
diff --git a/components/UpdateDialog.qml b/components/UpdateDialog.qml
new file mode 100644
index 00000000..74c62516
--- /dev/null
+++ b/components/UpdateDialog.qml
@@ -0,0 +1,200 @@
+// Copyright (c) 2020, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import QtQuick 2.9
+import QtQuick.Controls 2.2
+import QtQuick.Layouts 1.1
+
+import moneroComponents.Downloader 1.0
+
+import "../components" as MoneroComponents
+
+Popup {
+ id: updateDialog
+
+ property bool allowed: true
+ property string error: ""
+ property string filename: ""
+ property double progress: url && downloader.total > 0 ? downloader.loaded * 100 / downloader.total : 0
+ property bool active: false
+ property string url: ""
+ property bool valid: false
+ property string version: ""
+
+ background: Rectangle {
+ border.color: MoneroComponents.Style.appWindowBorderColor
+ border.width: 1
+ color: MoneroComponents.Style.middlePanelBackgroundColor
+ }
+ closePolicy: Popup.NoAutoClose
+ padding: 20
+ visible: active && allowed
+
+ function show(version, url) {
+ updateDialog.error = "";
+ updateDialog.url = url;
+ updateDialog.valid = false;
+ updateDialog.version = version;
+ updateDialog.active = true;
+ }
+
+ ColumnLayout {
+ id: mainLayout
+ spacing: updateDialog.padding
+
+ Text {
+ color: MoneroComponents.Style.defaultFontColor
+ font.bold: true
+ font.family: MoneroComponents.Style.fontRegular.name
+ font.pixelSize: 18
+ text: qsTr("New Monero version v%1 is available.").arg(updateDialog.version)
+ }
+
+ Text {
+ id: errorText
+ color: "red"
+ font.family: MoneroComponents.Style.fontRegular.name
+ font.pixelSize: 18
+ text: updateDialog.error
+ visible: text
+ }
+
+ Text {
+ id: statusText
+ color: MoneroComponents.Style.defaultFontColor
+ font.family: MoneroComponents.Style.fontRegular.name
+ font.pixelSize: 18
+ visible: !errorText.visible
+
+ text: {
+ if (!updateDialog.url) {
+ return qsTr("Please visit getmonero.org for details") + translationManager.emptyString;
+ }
+ if (downloader.active) {
+ return "%1 (%2%)"
+ .arg(qsTr("Downloading"))
+ .arg(updateDialog.progress.toFixed(1))
+ + translationManager.emptyString;
+ }
+ if (updateDialog.valid) {
+ return qsTr("Download finished") + translationManager.emptyString;
+ }
+ return qsTr("Do you want to download new version?") + translationManager.emptyString;
+ }
+ }
+
+ Rectangle {
+ id: progressBar
+ color: MoneroComponents.Style.lightGreyFontColor
+ height: 3
+ Layout.fillWidth: true
+ visible: updateDialog.valid || downloader.active
+
+ Rectangle {
+ color: MoneroComponents.Style.buttonBackgroundColor
+ height: parent.height
+ width: parent.width * updateDialog.progress / 100
+ }
+ }
+
+ RowLayout {
+ Layout.alignment: Qt.AlignRight
+ spacing: parent.spacing
+
+ MoneroComponents.StandardButton {
+ id: cancelButton
+ fontBold: false
+ primary: !updateDialog.url
+ text: {
+ if (!updateDialog.url) {
+ return qsTr("Ok") + translationManager.emptyString;
+ }
+ if (updateDialog.valid || downloader.active || errorText.visible) {
+ return qsTr("Cancel") + translationManager.emptyString;
+ }
+ return qsTr("Download later") + translationManager.emptyString;
+ }
+
+ onClicked: {
+ downloader.cancel();
+ updateDialog.active = false;
+ }
+ }
+
+ MoneroComponents.StandardButton {
+ id: downloadButton
+ KeyNavigation.tab: cancelButton
+ fontBold: false
+ text: (updateDialog.error ? qsTr("Retry") : qsTr("Download")) + translationManager.emptyString
+ visible: updateDialog.url && !updateDialog.valid && !downloader.active
+
+ onClicked: {
+ updateDialog.error = "";
+ updateDialog.filename = updateDialog.url.replace(/^.*\//, '');
+ const downloadingStarted = downloader.get(updateDialog.url, function(error) {
+ if (error) {
+ updateDialog.error = qsTr("Download failed") + translationManager.emptyString;
+ } else {
+ updateDialog.valid = true;
+ }
+ });
+ if (!downloadingStarted) {
+ updateDialog.error = qsTr("Failed to start download") + translationManager.emptyString;
+ }
+ }
+ }
+
+ MoneroComponents.StandardButton {
+ id: saveButton
+ KeyNavigation.tab: cancelButton
+ fontBold: false
+ onClicked: {
+ const fullPath = oshelper.openSaveFileDialog(
+ qsTr("Save as") + translationManager.emptyString,
+ oshelper.downloadLocation(),
+ updateDialog.filename);
+ if (!fullPath) {
+ return;
+ }
+ if (downloader.saveToFile(fullPath)) {
+ cancelButton.clicked();
+ oshelper.openContainingFolder(fullPath);
+ } else {
+ updateDialog.error = qsTr("Save operation failed") + translationManager.emptyString;
+ }
+ }
+ text: qsTr("Save to file") + translationManager.emptyString
+ visible: updateDialog.valid
+ }
+ }
+ }
+
+ Downloader {
+ id: downloader
+ }
+}