From 84d4d8fbba32ade66ae5dcf86f15984f7c4d5570 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Thu, 14 Nov 2024 12:19:20 +0100 Subject: [PATCH] Add dialog for montly active contributor limit --- app/qml/CMakeLists.txt | 1 + .../MMMonthlyContributorsLimitDialog.qml | 34 +++++++++++++++++++ app/qml/main.qml | 12 +++++++ app/synchronizationerror.cpp | 5 +++ app/synchronizationerror.h | 1 + app/synchronizationmanager.cpp | 3 ++ app/synchronizationmanager.h | 1 + gallery/qml.qrc | 1 + gallery/qml/pages/DrawerPage.qml | 18 ++++++++++ 9 files changed, 76 insertions(+) create mode 100644 app/qml/dialogs/MMMonthlyContributorsLimitDialog.qml diff --git a/app/qml/CMakeLists.txt b/app/qml/CMakeLists.txt index ccf99a8d5..9caf23291 100644 --- a/app/qml/CMakeLists.txt +++ b/app/qml/CMakeLists.txt @@ -59,6 +59,7 @@ set(MM_QML dialogs/MMDownloadProjectDialog.qml dialogs/MMMigrateToMerginDialog.qml dialogs/MMMissingAuthDialog.qml + dialogs/MMMonthlyContributorsLimitDialog.qml dialogs/MMNoPermissionsDialog.qml dialogs/MMPositionTrackingDialog.qml dialogs/MMProjectLimitDialog.qml diff --git a/app/qml/dialogs/MMMonthlyContributorsLimitDialog.qml b/app/qml/dialogs/MMMonthlyContributorsLimitDialog.qml new file mode 100644 index 000000000..ad96563d7 --- /dev/null +++ b/app/qml/dialogs/MMMonthlyContributorsLimitDialog.qml @@ -0,0 +1,34 @@ +/*************************************************************************** + * * + * 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 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +import QtQuick + +import "../components" as MMComponents + + +MMComponents.MMDrawerDialog { + id: root + + required property bool apiSupportsSubscription + + signal manageAccountClicked() + + title: qsTr("You've reached the maximum number of active monthly contributors for your current subscription.") + imageSource: __style.reachedDataLimitImage + + description: qsTr( "Upgrade your subscription or wait until next month for the limit to reset." ) + + primaryButton.text: apiSupportsSubscription ? qsTr("Manage account") : "" + secondaryButton.text: qsTr("Cancel") + + onPrimaryButtonClicked: { + root.manageAccountClicked() + close() + } +} diff --git a/app/qml/main.qml b/app/qml/main.qml index d6b7ea116..0ec6e33eb 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -715,6 +715,14 @@ ApplicationWindow { onManageAccountClicked: Qt.openUrlExternally(__inputHelp.merginSubscriptionLink) } + MMMonthlyContributorsLimitDialog { + id: monthlyContributorsLimitDialog + + apiSupportsSubscription: __merginApi.apiSupportsSubscriptions + + onManageAccountClicked: Qt.openUrlExternally(__inputHelp.merginSubscriptionLink) + } + MMProjectLimitDialog { id: projectLimitDialog @@ -874,6 +882,10 @@ ApplicationWindow { } } } + + function onMonthlyContributorsLimitReached( uploadSize ) { + monthlyContributorsLimitDialog.open() + } } Connections { diff --git a/app/synchronizationerror.cpp b/app/synchronizationerror.cpp index f21b38c53..2c09b1d85 100644 --- a/app/synchronizationerror.cpp +++ b/app/synchronizationerror.cpp @@ -37,6 +37,11 @@ SynchronizationError::ErrorType SynchronizationError::errorType( int errorCode, // Project no longer exists / is on different server return ErrorType::ProjectNotFound; } + else if ( errorCode == 422 ) + { + // Hit the maximun number of contributor per month + return ErrorType::MonthlyContributorsLimitHit; + } else if ( errorCode >= 500 ) { // Exceptions in server code or maintenance mode diff --git a/app/synchronizationerror.h b/app/synchronizationerror.h index 86e41515f..a239cf8ac 100644 --- a/app/synchronizationerror.h +++ b/app/synchronizationerror.h @@ -31,6 +31,7 @@ class SynchronizationError ProjectNotFound, VersionMismatch, ServerError, + MonthlyContributorsLimitHit, UnknownError }; Q_ENUMS( ErrorType ); diff --git a/app/synchronizationmanager.cpp b/app/synchronizationmanager.cpp index 100040040..4bbcf3307 100644 --- a/app/synchronizationmanager.cpp +++ b/app/synchronizationmanager.cpp @@ -286,6 +286,9 @@ void SynchronizationManager::onProjectSyncFailure( } else { + if (error == SynchronizationError::MonthlyContributorsLimitHit){ + emit monthlyContributorsLimitReached(""); + } mSyncProcesses.remove( projectFullName ); emit syncFinished( projectFullName, false, -1, false ); diff --git a/app/synchronizationmanager.h b/app/synchronizationmanager.h index ba3d02448..62cab4496 100644 --- a/app/synchronizationmanager.h +++ b/app/synchronizationmanager.h @@ -64,6 +64,7 @@ class SynchronizationManager : public QObject void syncFinished( const QString &projectFullName, bool success, int newVersion, bool reloadNeeded ); void syncError( const QString &projectFullName, int errorType, bool willRetry = false, const QString &errorMessage = QLatin1String() ); + void monthlyContributorsLimitReached( const QString &message ); public slots: diff --git a/gallery/qml.qrc b/gallery/qml.qrc index b54c2ff92..d19fa58e4 100644 --- a/gallery/qml.qrc +++ b/gallery/qml.qrc @@ -30,6 +30,7 @@ ../app/qml/dialogs/MMStreamingModeDialog.qml ../app/qml/dialogs/MMPositionTrackingDialog.qml ../app/qml/dialogs/MMStorageLimitDialog.qml + ../app/qml/dialogs/MMMonthlyContributorsLimitDialog.qml ../app/qml/dialogs/MMCloseAccountDialog.qml ../app/qml/dialogs/MMRemoveProjectDialog.qml ../app/qml/dialogs/MMDownloadProjectDialog.qml diff --git a/gallery/qml/pages/DrawerPage.qml b/gallery/qml/pages/DrawerPage.qml index e3400a423..f5cac7ddb 100644 --- a/gallery/qml/pages/DrawerPage.qml +++ b/gallery/qml/pages/DrawerPage.qml @@ -38,6 +38,11 @@ Page { onClicked: storageLimitDialog.open() } + Button { + text: "MMMonthlyContributorsLimitDialog" + onClicked: monthlyContributorsLimitDialog.open() + } + Button { text: "MMCloseAccountDialog" onClicked: closeAccountDialog.open() @@ -289,6 +294,19 @@ Page { } } + MMMonthlyContributorsLimitDialog { + id: monthlyContributorsLimitDialog + + dataToSync: "643.8 MB" + dataUsing: "9.23 MB / 10.0 MB" + usedData: 0.923 + apiSupportsSubscription: true + + onPrimaryButtonClicked: { + console.log("Manage workspace clicked") + } + } + MMSyncFailedDialog { id: syncFailedDialog }