Skip to content

Commit 7bb45a5

Browse files
authored
Merge pull request #6629 from opengisch/QF-6711_Whenever-a-HTTP-416-is-received
2 parents a2b7274 + 82ad1cb commit 7bb45a5

File tree

4 files changed

+69
-22
lines changed

4 files changed

+69
-22
lines changed

src/core/qfieldcloud/qfieldcloudproject.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,29 @@ void QFieldCloudProject::downloadFileConnections( const QString &fileKey )
12331233

12341234
if ( rawReply->error() != QNetworkReply::NoError )
12351235
{
1236+
const int httpStatus = rawReply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
1237+
if ( httpStatus == 416 && mDownloadFileTransfers[fileKey].retryCount < 3 )
1238+
{
1239+
mDownloadFileTransfers[fileKey].resumableDownload = false;
1240+
mDownloadFileTransfers[fileKey].retryCount++;
1241+
1242+
NetworkReply *newReply = downloadFile(
1243+
mDownloadFileTransfers[fileKey].projectId,
1244+
mDownloadFileTransfers[fileKey].fileName,
1245+
true,
1246+
true );
1247+
1248+
if ( newReply )
1249+
{
1250+
mDownloadFileTransfers[fileKey].networkReply = newReply;
1251+
newReply->setParent( reply );
1252+
downloadFileConnections( fileKey );
1253+
}
1254+
1255+
reply->abort();
1256+
return;
1257+
}
1258+
12361259
hasError = true;
12371260
errorMessageDetail = QFieldCloudConnection::errorString( rawReply );
12381261
errorMessage = tr( "Network error. Failed to download file `%1`." ).arg( fileKey );
@@ -1377,7 +1400,7 @@ NetworkReply *QFieldCloudProject::downloadFile( const QString &projectId, const
13771400
if ( partialFile.exists() )
13781401
{
13791402
qint64 partialSize = partialFile.size();
1380-
if ( partialSize < QFIELDCLOUD_MINIMUM_RANGE_HEADER_LENGTH || partialSize > fileTransfer.bytesTotal || ( partialSize == fileTransfer.bytesTotal ) && fileTransfer.etag != FileUtils::fileEtag( fileTransfer.partialFilePath ) )
1403+
if ( !fileTransfer.resumableDownload || partialSize < QFIELDCLOUD_MINIMUM_RANGE_HEADER_LENGTH || partialSize > fileTransfer.bytesTotal || ( partialSize == fileTransfer.bytesTotal ) && fileTransfer.etag != FileUtils::fileEtag( fileTransfer.partialFilePath ) )
13811404
{
13821405
// Invalid or dirty file; delete and re-download
13831406
partialFile.remove();

src/core/qfieldcloud/qfieldcloudproject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ class QFieldCloudProject : public QObject
454454
QNetworkReply::NetworkError error = QNetworkReply::NoError;
455455
int redirectsCount = 0;
456456
QUrl lastRedirectUrl;
457+
bool resumableDownload = true;
458+
int retryCount = 0;
457459
};
458460

459461
//! Tracks the job status (status, error etc) for a particular project. For now 1 project can have only 1 job of a type.

src/qml/QFieldCloudScreen.qml

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -764,37 +764,27 @@ Page {
764764
ColumnLayout {
765765
Layout.topMargin: 20
766766
Layout.bottomMargin: 20
767-
Layout.preferredWidth: projectDetailsCodeContainer.desiredWidth
767+
Layout.preferredWidth: projectDetailsCode.desiredWidth
768768
Layout.alignment: Qt.AlignHCenter
769769
spacing: 5
770770

771-
Rectangle {
772-
id: projectDetailsCodeContainer
773-
774-
property int desiredWidth: Math.min(mainWindow.width - 40, 250)
771+
Image {
772+
id: projectDetailsCode
775773
Layout.preferredWidth: desiredWidth
776774
Layout.preferredHeight: desiredWidth
775+
fillMode: Image.PreserveAspectFit
777776

778-
color: "transparent"
779-
radius: 4
780-
border.width: 1
781-
border.color: Theme.mainTextColor
782-
783-
Image {
784-
anchors.fill: parent
785-
fillMode: Image.PreserveAspectFit
786-
787-
sourceSize.width: projectDetailsCodeContainer.desiredWidth * Screen.devicePixelRatio
788-
sourceSize.height: projectDetailsCodeContainer.desiredWidth * Screen.devicePixelRatio
789-
source: projectDetails.cloudProject != undefined ? "image://barcode/?text=" + encodeURIComponent(UrlUtils.createActionUrl("qfield", "cloud", {
790-
"project": projectDetails.cloudProject.id
791-
})) + "&color=%2380cc28" : ""
792-
}
777+
sourceSize.width: desiredWidth * Screen.devicePixelRatio
778+
sourceSize.height: desiredWidth * Screen.devicePixelRatio
779+
source: projectDetails.cloudProject != undefined ? "image://barcode/?text=" + encodeURIComponent(UrlUtils.createActionUrl("qfield", "cloud", {
780+
"project": projectDetails.cloudProject.id
781+
})) + "&color=%2380cc28" : ""
782+
property int desiredWidth: Math.min(mainWindow.width - 40, 250)
793783
}
794784

795785
Text {
796786
id: projectDetailsCodeLabel
797-
Layout.preferredWidth: projectDetailsCodeContainer.desiredWidth - 20
787+
Layout.preferredWidth: projectDetailsCode.desiredWidth - 20
798788
font: Theme.tinyFont
799789
color: Theme.secondaryTextColor
800790
wrapMode: Text.WordWrap
@@ -810,6 +800,7 @@ Page {
810800
QfButton {
811801
id: downloadProjectBtn
812802
Layout.fillWidth: true
803+
progressValue: projectDetails.cloudProject ? projectDetails.cloudProject.downloadProgress : 0
813804
text: {
814805
if (projectDetails.cloudProject != undefined && projectDetails.cloudProject.status === QFieldCloudProject.ProjectStatus.Downloading) {
815806
if (projectDetails.cloudProject.packagingStatus === QFieldCloudProject.PackagingBusyStatus) {

src/qml/imports/Theme/QfButton.qml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Button {
1313
property alias radius: backgroundRectangle.radius
1414
property alias borderColor: backgroundRectangle.border.color
1515
property bool dropdown: false
16+
property real progressValue: 0.0
1617

1718
signal dropdownClicked
1819

@@ -35,6 +36,7 @@ Button {
3536
radius: 12
3637
border.width: 1
3738
border.color: !parent.enabled ? Theme.controlBackgroundDisabledColor : button.bgcolor != "#00000000" ? button.bgcolor : button.color
39+
clip: true
3840

3941
Ripple {
4042
clip: true
@@ -45,6 +47,35 @@ Button {
4547
active: button.down
4648
color: Theme.darkTheme ? "#22000000" : button.bgcolor == "#ffffff" || button.bgcolor == "#00000000" ? "#10000000" : "#22ffffff"
4749
}
50+
51+
Loader {
52+
active: progressValue != 0.0 && progressValue != 1.0
53+
sourceComponent: progressComponent
54+
}
55+
56+
Component {
57+
id: progressComponent
58+
Rectangle {
59+
width: backgroundRectangle.width * progressValue
60+
height: backgroundRectangle.height
61+
radius: backgroundRectangle.radius
62+
color: Theme.mainColor
63+
clip: true
64+
65+
Rectangle {
66+
width: Math.min(10, parent.width / 2)
67+
height: parent.height
68+
anchors.right: parent.right
69+
color: parent.color
70+
}
71+
72+
Behavior on width {
73+
NumberAnimation {
74+
duration: 200
75+
}
76+
}
77+
}
78+
}
4879
}
4980

5081
contentItem: IconLabel {

0 commit comments

Comments
 (0)