From 0ae04b4ef593c225d00317d91e9fb7775d0481d1 Mon Sep 17 00:00:00 2001 From: Martin Burchell Date: Thu, 28 Mar 2024 22:10:54 +0000 Subject: [PATCH] Option to enable network log on network failure --- docs/source/changelog.rst | 3 ++ tablet_qt/core/camcopsapp.cpp | 60 ++++++++++++++++++++++++++++------- tablet_qt/core/camcopsapp.h | 13 +++++++- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 019d78c3f..8db3fa4bd 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -3883,3 +3883,6 @@ Current C++/SQLite client, Python/SQLAlchemy server - Additional optional LGPL licensing for some Qt height-for-width layout code to make it suitable for inclusion in libraries elsewhere. + +- Make it easier to turn on error logging in the event of a network operation failure. + https://github.com/ucam-department-of-psychiatry/camcops/issues/336 diff --git a/tablet_qt/core/camcopsapp.cpp b/tablet_qt/core/camcopsapp.cpp index 94d3cf3b3..b130badc5 100644 --- a/tablet_qt/core/camcopsapp.cpp +++ b/tablet_qt/core/camcopsapp.cpp @@ -508,12 +508,8 @@ void CamcopsApp::patientRegistrationFailed( break; } - uifunc::alert( - QString("%1\n\n%2").arg(base_message, additional_message), - tr("Error") - ); - - recreateMainMenu(); + maybeRetryNetworkOperation(base_message, additional_message, + NetworkOperation::RegisterPatient); } @@ -543,7 +539,8 @@ void CamcopsApp::updateTaskSchedulesFailed( handleNetworkFailure( error_code, error_string, - tr("There was a problem updating your task schedules.") + tr("There was a problem updating your task schedules."), + NetworkOperation::UpdateTaskSchedules ); } @@ -569,7 +566,8 @@ void CamcopsApp::uploadFailed(const NetworkManager::ErrorCode error_code, handleNetworkFailure( error_code, error_string, - tr("There was a problem sending your completed tasks to the server.") + tr("There was a problem sending your completed tasks to the server."), + NetworkOperation::Upload ); } @@ -623,7 +621,8 @@ void CamcopsApp::retryUpload() void CamcopsApp::handleNetworkFailure(const NetworkManager::ErrorCode error_code, const QString& error_string, - const QString& base_message) + const QString& base_message, + CamcopsApp::NetworkOperation operation) { QString additional_message = ""; @@ -651,14 +650,51 @@ void CamcopsApp::handleNetworkFailure(const NetworkManager::ErrorCode error_code break; } - uifunc::alert( + maybeRetryNetworkOperation(base_message, additional_message, operation); +} + + +void CamcopsApp::maybeRetryNetworkOperation(const QString base_message, + const QString additional_message, + CamcopsApp::NetworkOperation operation) +{ + bool try_again_with_log = uifunc::confirm( QString("%1\n\n%2").arg(base_message, additional_message), - tr("Error") + tr("Error"), + tr("Try again with error log"), + tr("Dismiss") ); - recreateMainMenu(); + if (!try_again_with_log) { + recreateMainMenu(); + + return; + } + + enableNetworkLogging(); + + switch (operation) { + case NetworkOperation::RegisterPatient: + registerPatientWithServer(); + break; + + case NetworkOperation::UpdateTaskSchedules: + // it doesn't matter if we pass alert_unfinished_tasks as True or False + // here. We wouldn't be here if there were unfinished tasks. + updateTaskSchedules(); + break; + + case NetworkOperation::Upload: + upload(); + break; + + default: + // Shouldn't get here + break; + } } + TaskSchedulePtrList CamcopsApp::getTaskSchedules() { TaskSchedulePtrList task_schedules; diff --git a/tablet_qt/core/camcopsapp.h b/tablet_qt/core/camcopsapp.h index 414cbddb4..dbbb5ec73 100644 --- a/tablet_qt/core/camcopsapp.h +++ b/tablet_qt/core/camcopsapp.h @@ -237,9 +237,20 @@ class CamcopsApp : public QApplication // For single user mode, register patient if not already done so void maybeRegisterPatient(); + enum class NetworkOperation { + RegisterPatient, + UpdateTaskSchedules, + Upload + }; + void handleNetworkFailure(const NetworkManager::ErrorCode error_code, const QString& error_string, - const QString& base_message); + const QString& base_message, + CamcopsApp::NetworkOperation operation); + + void maybeRetryNetworkOperation(const QString base_message, + const QString additional_message, + CamcopsApp::NetworkOperation operation); bool userConfirmedRetryPassword() const; bool userConfirmedDeleteDatabases() const;