2022-11-24 13:11:09 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2023-01-30 19:11:23 +01:00
|
|
|
* Copyright (C) 2022-2023 Tom Zander <tom@flowee.org>
|
2022-11-24 13:11:09 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2022-11-23 19:04:03 +01:00
|
|
|
import QtQuick
|
|
|
|
|
import Flowee.org.pay;
|
2023-03-23 20:03:39 +01:00
|
|
|
import "../Flowee" as Flowee
|
2022-11-23 19:04:03 +01:00
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: root
|
2023-03-23 20:03:39 +01:00
|
|
|
height: indicator.height + 3 + (uptodate ? 0 : progressbar.height + 10)
|
2022-11-23 19:04:03 +01:00
|
|
|
property QtObject account: null
|
2022-12-19 11:57:04 +01:00
|
|
|
property bool uptodate: false
|
2022-11-24 13:11:09 +01:00
|
|
|
property int startPos: account.initialBlockHeight
|
2022-12-19 11:57:04 +01:00
|
|
|
onAccountChanged: checkIfDone();
|
|
|
|
|
function checkIfDone() {
|
2022-11-24 13:11:09 +01:00
|
|
|
let startPos = account.initialBlockHeight;
|
|
|
|
|
if (startPos === -2) {
|
|
|
|
|
// special number, the account is just created and waits for transactions.
|
2022-12-19 11:57:04 +01:00
|
|
|
uptodate = true;
|
2022-11-24 13:11:09 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let end = Pay.expectedChainHeight;
|
|
|
|
|
let currentPos = account.lastBlockSynched;
|
|
|
|
|
// only show the progress-circle when its more than 2 days behind
|
|
|
|
|
// and we are not synched
|
2022-12-19 11:57:04 +01:00
|
|
|
uptodate = end - startPos < 300 || end - currentPos <= 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: account
|
|
|
|
|
function onLastBlockSynchedChanged() { checkIfDone(); }
|
2022-11-23 19:04:03 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-23 20:03:39 +01:00
|
|
|
// The progressbar
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: progressbar
|
|
|
|
|
y: 10 // top spacing of widget, only when doing progress report
|
|
|
|
|
x: 10
|
|
|
|
|
width: parent.width - 20
|
|
|
|
|
height: 40 // percentLabel.height + 10
|
|
|
|
|
color: "#00000000"
|
|
|
|
|
border.width: 2
|
|
|
|
|
border.color: palette.midlight
|
|
|
|
|
radius: 10
|
2022-12-19 11:57:04 +01:00
|
|
|
visible: !root.uptodate
|
2022-11-23 19:04:03 +01:00
|
|
|
|
2023-03-23 20:03:39 +01:00
|
|
|
property double progress: {
|
|
|
|
|
let startPos = root.startPos;
|
|
|
|
|
let end = Pay.expectedChainHeight
|
|
|
|
|
if (startPos == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
let currentPos = root.account.lastBlockSynched;
|
|
|
|
|
let totalDistance = end - startPos;
|
|
|
|
|
if (totalDistance <= 6)
|
|
|
|
|
return 100; // uptodate
|
|
|
|
|
let ourProgress = currentPos - startPos;
|
|
|
|
|
return ourProgress / totalDistance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
width: Math.min(10, parent.width * parent.progress)
|
|
|
|
|
y: 2
|
|
|
|
|
height: parent.height - 4
|
|
|
|
|
color: palette.highlight
|
|
|
|
|
radius: 10
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: bar
|
|
|
|
|
x: 5
|
|
|
|
|
y: 2
|
|
|
|
|
width: {
|
|
|
|
|
var full = progressbar.width;
|
|
|
|
|
var w = full * progressbar.progress
|
|
|
|
|
w = Math.min(w, full - 5) // the right max
|
|
|
|
|
w -= 5; // our X offset
|
|
|
|
|
Math.max(0, w);
|
|
|
|
|
}
|
|
|
|
|
height: parent.height - 4
|
|
|
|
|
color: palette.highlight
|
|
|
|
|
clip: true
|
|
|
|
|
Flowee.Label {
|
|
|
|
|
id: percentLabel
|
|
|
|
|
text: (100 * progressbar.progress).toFixed(0) + "%"
|
|
|
|
|
y: 5
|
|
|
|
|
x: progressbar.width / 2 - 10 - width / 2
|
|
|
|
|
color: palette.highlightedText
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Rectangle {
|
|
|
|
|
width: {
|
|
|
|
|
// just the last 10 pixels.
|
|
|
|
|
var full = progressbar.width;
|
|
|
|
|
return Math.max(0, full * progressbar.progress - (full - 10));
|
|
|
|
|
}
|
|
|
|
|
x: progressbar.width - 10
|
|
|
|
|
y: 2
|
|
|
|
|
height: parent.height - 4
|
|
|
|
|
color: palette.highlight
|
|
|
|
|
radius: 10
|
|
|
|
|
}
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: groove
|
|
|
|
|
y: 2
|
|
|
|
|
height: parent.height - 4
|
|
|
|
|
color: palette.light
|
|
|
|
|
clip: true
|
|
|
|
|
x: {
|
|
|
|
|
var full = progressbar.width;
|
|
|
|
|
var distance = progressbar.progress * full;
|
|
|
|
|
distance = Math.min(distance, full - 5); // and right
|
|
|
|
|
distance = Math.max(5, distance); // avoid the left rounding area
|
|
|
|
|
return distance;
|
|
|
|
|
}
|
|
|
|
|
width: {
|
|
|
|
|
var full = progressbar.width;
|
|
|
|
|
var w = full - progressbar.progress * full;
|
|
|
|
|
w -= 5;
|
|
|
|
|
w = Math.min(w, full - 10); // the rounded corners
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
Flowee.Label {
|
|
|
|
|
text: percentLabel.text
|
|
|
|
|
y: 5
|
|
|
|
|
x: progressbar.width / 2 - 5 - width / 2 - parent.x
|
|
|
|
|
// color: palette.highlightedText
|
2022-11-23 19:04:03 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Flowee.Label {
|
|
|
|
|
id: indicator
|
|
|
|
|
width: parent.width
|
2023-03-23 20:03:39 +01:00
|
|
|
y: root.uptodate ? 0 : progressbar.height + 13
|
2022-11-23 19:04:03 +01:00
|
|
|
wrapMode: Text.Wrap
|
|
|
|
|
text: {
|
|
|
|
|
if (isLoading)
|
2023-01-30 19:11:23 +01:00
|
|
|
return "";
|
2022-11-23 19:04:03 +01:00
|
|
|
var account = portfolio.current;
|
|
|
|
|
if (account === null)
|
2023-01-30 19:11:23 +01:00
|
|
|
return "";
|
2022-11-23 19:04:03 +01:00
|
|
|
if (account.needsPinToOpen && !account.isDecrypted)
|
2023-01-30 19:11:23 +01:00
|
|
|
return qsTr("Status: Offline");
|
|
|
|
|
return account.timeBehind;
|
2022-11-23 19:04:03 +01:00
|
|
|
}
|
|
|
|
|
font.italic: true
|
2022-11-24 13:11:09 +01:00
|
|
|
Behavior on y { NumberAnimation { duration: 100 } }
|
2022-11-23 19:04:03 +01:00
|
|
|
}
|
2022-11-24 13:11:09 +01:00
|
|
|
Behavior on height { NumberAnimation { duration: 100 } }
|
2022-11-23 19:04:03 +01:00
|
|
|
}
|