Files

99 lines
3.3 KiB
QML
Raw Permalink Normal View History

2022-11-24 13:11:09 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2022-2024 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
2026-03-14 21:14:42 +01:00
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
2025-11-01 21:30:30 +01:00
implicitHeight: {
if (account.uptodate)
2026-03-14 21:14:42 +01:00
return 0
var h = indicator.height + 3
2025-11-01 21:30:30 +01:00
if (root.hasProgressbar)
2026-03-14 21:14:42 +01:00
h += progressbar.height + 10
return h
}
2022-11-23 19:04:03 +01:00
property QtObject account: null
2025-11-01 21:30:30 +01:00
property bool hasProgressbar: true
2022-11-24 13:11:09 +01:00
property int startPos: account.initialBlockHeight
2026-03-14 21:14:42 +01:00
onAccountChanged: checkIfDone()
function checkIfDone() {
2026-03-14 21:14:42 +01:00
let startPos = account.initialBlockHeight
2022-11-24 13:11:09 +01:00
if (startPos === -2) {
// special number, the account is just created and waits for transactions.
2026-03-14 21:14:42 +01:00
hasProgressbar = false
return
2022-11-24 13:11:09 +01:00
}
2026-03-14 21:14:42 +01:00
let end = Pay.expectedChainHeight
let currentPos = account.lastBlockSynched
2025-11-01 21:30:30 +01:00
// only show the progress-bar when its more than 2 days behind
2022-11-24 13:11:09 +01:00
// and we are not synched
2026-03-14 21:14:42 +01:00
hasProgressbar = end - startPos >= 300 && end - currentPos > 6
}
Connections {
2024-11-29 15:50:42 +01:00
target: root.account
2026-03-14 21:14:42 +01:00
function onLastBlockSynchedChanged() { checkIfDone() }
2022-11-23 19:04:03 +01:00
}
Flowee.Progressbar {
2023-03-23 20:03:39 +01:00
id: progressbar
x: 10
y: 10
2023-03-23 20:03:39 +01:00
width: parent.width - 20
2025-11-01 21:30:30 +01:00
visible: root.hasProgressbar
progress: {
2026-03-14 21:14:42 +01:00
let startPos = root.startPos
2023-03-23 20:03:39 +01:00
let end = Pay.expectedChainHeight
if (startPos == 0)
2026-03-14 21:14:42 +01:00
return 0
let currentPos = root.account.lastBlockSynched
let totalDistance = end - startPos
let ourProgress = currentPos - startPos
return ourProgress / totalDistance
2024-11-29 19:37:10 +01:00
}
progress2: {
2026-03-14 21:14:42 +01:00
let startPos = root.startPos
2024-11-29 19:37:10 +01:00
let end = Pay.expectedChainHeight
if (startPos == 0)
2026-03-14 21:14:42 +01:00
return 0
let currentPos = root.account.lastBlockSynched2
let totalDistance = end - startPos
let ourProgress = currentPos - startPos
return ourProgress / totalDistance
2023-03-23 20:03:39 +01:00
}
2022-11-23 19:04:03 +01:00
}
Flowee.Label {
id: indicator
2025-06-24 22:19:37 +02:00
anchors.horizontalCenter: parent.horizontalCenter
2025-11-01 21:30:30 +01:00
y: root.hasProgressbar ? progressbar.height + 13 : 0
2022-11-23 19:04:03 +01:00
wrapMode: Text.Wrap
text: {
2026-03-14 21:14:42 +01:00
let account = root.account
2025-11-01 21:30:30 +01:00
if (account === null || account.uptodate)
2026-03-14 21:14:42 +01:00
return ""
2025-02-26 14:04:58 +01:00
if (Pay.deviceOffline || (account.needsPinToOpen && !account.isDecrypted))
2026-03-14 21:14:42 +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
}
}