Skip to content

Show QFieldCloud current storage usage #6072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/qml/Nyuki.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QtQuick
import QtQuick.Controls
import Theme

/**
* \ingroup qml
Expand Down Expand Up @@ -66,7 +67,7 @@ Item {
id: nyukiLeft
width: 10
height: 10
color: "#4a6fae"
color: Theme.qfieldcloudBlue
x: 84
y: 84
radius: 5
Expand All @@ -91,7 +92,7 @@ Item {
id: nyukiRight
width: 10
height: 10
color: "#4a6fae"
color: Theme.qfieldcloudBlue
x: 106
y: 84
radius: 5
Expand Down
79 changes: 73 additions & 6 deletions src/qml/QFieldCloudScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ Page {
Layout.fillHeight: true
spacing: 2

RowLayout {
Item {
id: connectionInformation
spacing: 2
Layout.fillWidth: true
Layout.minimumHeight: cloudAvatarRect.height + (storageBar.visible * storageBar.height) + 8
Layout.leftMargin: 10
Layout.rightMargin: 10
Layout.topMargin: 12
visible: cloudConnection.status === QFieldCloudConnection.LoggedIn || table.count > 0

Label {
Layout.fillWidth: true
padding: 10
anchors.left: parent.left
opacity: projects.visible ? 1 : 0
text: switch (cloudConnection.status) {
case 0:
Expand All @@ -64,8 +66,7 @@ Page {

Rectangle {
id: cloudAvatarRect
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.margins: 10
anchors.right: parent.right
width: 48
height: 48
border.color: Theme.mainColor
Expand Down Expand Up @@ -123,6 +124,46 @@ Page {
}
}
}

Label {
id: storageText
anchors.bottom: storageBar.top
anchors.bottomMargin: 4
color: Theme.mainTextColor
font.italic: true
textFormat: Text.RichText
onLinkActivated: link => Qt.openUrlExternally(link)
}

ProgressBar {
id: storageBar
anchors.top: cloudAvatarRect.bottom
anchors.topMargin: 8
width: parent.width
visible: false
from: 0
to: 1
value: usage

// The `value` property is being animated, so we need the actual value at all times.
property double usage: 0.0

Material.accent: {
if (usage < 0.9) {
return Theme.qfieldcloudBlue;
} else if (usage < 0.975) {
return Theme.warningColor;
} else {
return Theme.bookmarkRed;
}
}

Behavior on value {
NumberAnimation {
duration: 1000
}
}
}
}

ColumnLayout {
Expand Down Expand Up @@ -620,10 +661,36 @@ Page {
} else {
projects.visible = true;
connectionSettings.visible = false;

// uncomment when storage bar api is ready
// showStorageBar()
}
} else
// uncomment when storage bar api is ready
// hideStorageBar()
{
}
}

function showStorageBar() {
const usedStorage = 1;
const totalStorage = 1;
storageBar.usage = usedStorage / totalStorage;
storageText.text = qsTr(`${usedStorage} GB of ${totalStorage} GB used`);
if (storageBar.usage >= 0.975) {
const upgradeStorageText = qsTr("upgrade to more storage here");
storageText.text += `; <a href="https://apps.qfield.cloud/plans">${upgradeStorageText}</a>`;
}
storageText.visible = true;
storageBar.visible = true;
}

function hideStorageBar() {
storageBar.usage = 0;
storageBar.visible = false;
storageText.visible = false;
}

Component.onCompleted: {
prepareCloudLogin();
}
Expand Down
1 change: 1 addition & 0 deletions src/qml/imports/Theme/Theme.qml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ QtObject {
property color bookmarkOrange: "orange"
property color bookmarkRed: "#c0392b"
property color bookmarkBlue: "#64b5f6"
property color qfieldcloudBlue: "#4a6fae"

property color vertexColor: "#FF0000"
property color vertexColorSemiOpaque: "#40FF0000"
Expand Down
Loading