Skip to content
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

translate server side error messages. #5505

Merged
merged 7 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 28 additions & 0 deletions src/core/utils/qfieldcloudutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ const QString QFieldCloudUtils::getProjectId( const QString &fileName )
return QString();
}

const QString QFieldCloudUtils::userFriendlyErrorString( const QString &errorMessage )
{
QString resultErrorMessage = errorMessage.startsWith( "[QF/" ) ? tr( "A server error has occured, please try again." ) : tr( "A network error has occured, please try again." );

const QString OVER_QUOTA( "over_quota" );
nirvn marked this conversation as resolved.
Show resolved Hide resolved

if ( errorMessage.contains( OVER_QUOTA ) )
{
resultErrorMessage = "Your account's available storage is full.";
nirvn marked this conversation as resolved.
Show resolved Hide resolved
}

return resultErrorMessage;
}

const QString QFieldCloudUtils::documentationFromErrorString( const QString &errorMessage )
{
QString linkToDocumentation;

const QString OVER_QUOTA( "over_quota" );

if ( errorMessage.contains( OVER_QUOTA ) )
{
linkToDocumentation = "https://docs.qfield.org/get-started/storage-qfc/";
nirvn marked this conversation as resolved.
Show resolved Hide resolved
}

return linkToDocumentation;
}

void QFieldCloudUtils::setProjectSetting( const QString &projectId, const QString &setting, const QVariant &value )
{
thread_local QgsSettings settings;
Expand Down
16 changes: 16 additions & 0 deletions src/core/utils/qfieldcloudutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ class QFieldCloudUtils : public QObject
*/
Q_INVOKABLE static const QString getProjectId( const QString &fileName );

/**
* Returns user-friendly message.
mohsenD98 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param errorMessage reveiced error message
* @return const QString
nirvn marked this conversation as resolved.
Show resolved Hide resolved
*/
Q_INVOKABLE static const QString userFriendlyErrorString( const QString &errorMessage );
mohsenD98 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns link to documentation page related to error message.
mohsenD98 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param errorMessage reveiced error message
* @return const QString
*/
Q_INVOKABLE static const QString documentationFromErrorString( const QString &errorMessage );

//! Sets a \a setting to a given \a value for project with given \a projectId to the permanent storage.
static void setProjectSetting( const QString &projectId, const QString &setting, const QVariant &value );

Expand Down
3 changes: 2 additions & 1 deletion src/qml/QFieldCloudPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ Popup {
detailsColor: Theme.secondaryTextColor
font: Theme.tipFont

titleText: detailsText.startsWith('[QF/') ? qsTr('A server error has occured, please try again.') : qsTr('A network error has occured, please try again.')
externalLink: QFieldCloudUtils.documentationFromErrorString(detailsText)
titleText: QFieldCloudUtils.userFriendlyErrorString(detailsText)
detailsText: ''

Connections {
Expand Down
55 changes: 36 additions & 19 deletions src/qml/imports/Theme/QfCollapsibleMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Theme 1.0

Item {
property bool collapsed: true
property string externalLink: ""
property alias color: titleText.color
property alias detailsColor: detailsText.color
property alias font: titleText.font
Expand All @@ -26,7 +27,6 @@ Item {
Rectangle {
id: background
anchors.fill: parent

color: "transparent"
border.color: titleText.color
border.width: 1
Expand All @@ -36,56 +36,73 @@ Item {

Text {
id: titleText

width: parent.width - 5
anchors.top: parent.top
anchors.left: parent.left
padding: 5
leftPadding: 8
topPadding: 10
bottomPadding: 10
clip: true

font: Theme.defaultFont
color: "black"

horizontalAlignment: Text.AlignHCenter
horizontalAlignment: Text.AlignLeft
wrapMode: Text.WordWrap
}

ToolButton {
id: externalLinkButton
z: mainMouseArea.z + 1
visible: externalLink !== ''
flat: false
text: "?"
anchors.verticalCenter: titleText.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 4
highlighted: true
Material.accent: Theme.mainBackgroundColor
font.bold: true
onClicked: {
Qt.openUrlExternally(externalLink);
}
background: Rectangle {
implicitWidth: 30
implicitHeight: 30
color: titleText.color
radius: background.radius
}
}

Rectangle {
id: separator

width: parent.width - 24
width: parent.width - 36
anchors.top: titleText.bottom
anchors.left: parent.left
anchors.leftMargin: 12

anchors.horizontalCenter: parent.horizontalCenter
height: 1
color: titleText.color
opacity: 0.25
}

Text {
id: detailsText

width: parent.width - 5
anchors.top: separator.bottom
anchors.left: parent.left
padding: 5
anchors.right: externalLinkButton.left
anchors.left: titleText.left
leftPadding: 8
topPadding: 10
bottomPadding: 10
clip: true

font.pointSize: titleText.font.pointSize / 1.5
font.weight: titleText.font.weight
font.italic: titleText.font.italic
font.family: titleText.font.family

color: titleText.color

horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
}

MouseArea {
id: mainMouseArea
anchors.fill: parent

onClicked: {
parent.collapsed = !parent.collapsed;
}
Expand Down
Loading