Files
pay/guis/mobile/BackgroundSyncConfig.qml
T

161 lines
5.6 KiB
QML
Raw Permalink Normal View History

2025-03-02 19:35:00 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2025 Tom Zander <tom@flowee.org>
*
* 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/>.
*/
import QtQuick
2025-06-18 17:48:29 +02:00
import QtQuick.Controls.Basic as QQC2
2025-03-02 19:35:00 +01:00
import QtQuick.Layouts
import "../Flowee" as Flowee
Page {
2025-03-04 13:01:11 +01:00
headerText: qsTr("Background Synchronization")
2025-03-02 19:35:00 +01:00
id: root
2025-05-04 21:59:47 +02:00
property bool autoEnableAll: false
2025-03-02 19:35:00 +01:00
Column {
width: parent.width
spacing: 10
Flowee.Label {
width: parent.width
2025-03-04 13:01:11 +01:00
text: qsTr("Without background synchronization your wallets will not see new transactions until you open Flowee Pay")
2025-03-02 19:35:00 +01:00
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
Flowee.CheckBox {
id: checkbox
2025-03-04 13:01:11 +01:00
text: qsTr("Allow Background Synchronization")
2025-03-02 19:35:00 +01:00
checked: Pay.backgroundUpdates
2025-05-04 21:59:47 +02:00
onCheckedChanged: Pay.backgroundUpdates = checked
onToggled: {
if (checked && root.autoEnableAll)
Pay.externalNotifications = true;
}
// Make the user-enables-all action be nice and animated to make clear what is going on.
Timer {
running: root.autoEnableAll
interval: 400
repeat: false
onTriggered: if (!checkbox.checked) checkbox.toggle();
}
2025-03-02 19:35:00 +01:00
}
Item { width: 1; height: 10 } // spacer
QQC2.Slider {
id: slider
2025-04-02 10:50:58 +02:00
value: {
var ts = Pay.backgroundUpdateInterval
if (ts > 6) {
let s = 3;
while (ts > 6) {
s -= 1;
ts /= 2;
}
slider.value = s;
}
else {
slider.value = 6 - (ts - 3);
}
}
2025-03-02 19:35:00 +01:00
property int timeSpan: {
var i = slider.value;
if (i < 4) {
for (var h = 48; i > 0; --i) {
h = h / 2;
}
return h;
}
return 6 - (i - 3);
}
2025-04-02 10:50:58 +02:00
onTimeSpanChanged: Pay.backgroundUpdateInterval = timeSpan
2025-03-02 19:35:00 +01:00
2025-05-02 19:33:19 +02:00
opacity: checkbox.checked ? 1 : 0
2025-03-02 19:35:00 +01:00
width: parent.width
stepSize: 1
from: 0
to: 8
snapMode: QQC2.Slider.SnapAlways
2025-03-03 17:38:38 +01:00
background: Rectangle {
x: slider.leftPadding
y: slider.topPadding + slider.availableHeight / 2 - height / 2
implicitWidth: 200
implicitHeight: 4
width: slider.availableWidth
height: implicitHeight
radius: 2
color: palette.button
Repeater {
id: repeater
model: slider.to - slider.from - 1
Rectangle {
width: 1.8
height: 10
color: palette.button
x: {
var offset = slider.handle.implicitWidth
var totalWidth = slider.width - slider.leftPadding - slider.rightPadding - offset;
var unit = totalWidth / (slider.to - slider.from);
return offset / 2 + unit + unit * modelData
}
y: 10
}
}
}
handle: Rectangle {
x: slider.leftPadding + slider.visualPosition * (slider.availableWidth - width)
y: slider.topPadding + slider.availableHeight / 2 - height / 2
implicitWidth: slider.font.pixelSize
implicitHeight: implicitWidth
radius: implicitWidth / 2
color: Pay.useDarkSkin ? slider.palette.windowText : slider.palette.highlight
}
2025-05-02 19:33:19 +02:00
Behavior on opacity { NumberAnimation { } }
2025-03-02 19:35:00 +01:00
}
Flowee.Label {
2025-05-02 19:33:19 +02:00
opacity: slider.opacity
2025-03-02 19:35:00 +01:00
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Every %1 hours").arg(slider.timeSpan)
}
2025-05-02 19:33:19 +02:00
PageTitledBox {
title: qsTr("Notifications")
width: parent.width
Flowee.CheckBox {
2025-05-04 21:59:47 +02:00
id: notificationsCheckbox
2025-05-02 19:33:19 +02:00
width: parent.width
text: qsTr("On Payments", "in relation to notifications")
checked: Pay.externalNotifications
onCheckedChanged: Pay.externalNotifications = checked
2025-05-04 21:59:47 +02:00
// Make the user-enables-all only trigger this if the user accepted background sync
Timer {
running: root.autoEnableAll && checkbox.checked
interval: 400
repeat: false
onTriggered: {
if (checkbox.checked && !notificationsCheckbox.checked)
notificationsCheckbox.toggle();
}
}
2025-05-02 19:33:19 +02:00
}
}
2025-03-02 19:35:00 +01:00
}
}