From 7be46a47402be596a8a1f8925c09ef26f9445fc3 Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Thu, 9 Mar 2023 12:16:17 +0100 Subject: [PATCH] fix(GODT-2467): elide long email adresses in 'bad event' QML notification dialog. --- .../bridge-gui/bridge-gui/QMLBackend.cpp | 3 ++- .../bridge-gui/bridgepp/bridgepp/BridgeUtils.cpp | 16 ++++++++++++++++ .../bridge-gui/bridgepp/bridgepp/BridgeUtils.h | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp index 1584c09f..5ba5d2c6 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #define HANDLE_EXCEPTION(x) try { x } \ @@ -1033,7 +1034,7 @@ void QMLBackend::displayBadEventDialog(QString const &userID) { emit userBadEvent(userID, tr("Bridge ran into an internal error and it is not able to proceed with the account %1. Synchronize your local database now or logout" - " to do it later. Synchronization time depends on the size of your mailbox.").arg(user->primaryEmailOrUsername())); + " to do it later. Synchronization time depends on the size of your mailbox.").arg(elideLongString(user->primaryEmailOrUsername(), 30))); emit selectUser(userID); emit showMainWindow(); ) diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/BridgeUtils.cpp b/internal/frontend/bridge-gui/bridgepp/bridgepp/BridgeUtils.cpp index 0bc71232..3b4b9289 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/BridgeUtils.cpp +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/BridgeUtils.cpp @@ -280,4 +280,20 @@ bool onWindows() { } +//**************************************************************************************************************************************************** +/// Elision is performed by inserting '...' around the (maxLen / 2) - 2 left-most and right-most characters of the string. +/// +/// \return The elided string, or the original string if its length does not exceed maxLength. +//**************************************************************************************************************************************************** +QString elideLongString(QString const &str, qint32 maxLength) { + qint32 const len = str.length(); + if (len <= maxLength) { + return str; + } + + qint32 const hLen = qMax(0, (maxLength / 2) - 2); + return str.left(hLen) + "..." + str.right(hLen); +} + + } // namespace bridgepp diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/BridgeUtils.h b/internal/frontend/bridge-gui/bridgepp/bridgepp/BridgeUtils.h index 47d5e894..5964b986 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/BridgeUtils.h +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/BridgeUtils.h @@ -49,6 +49,7 @@ OS os(); ///< Return the operating system. bool onLinux(); ///< Check if the OS is Linux. bool onMacOS(); ///< Check if the OS is macOS. bool onWindows(); ///< Check if the OS in Windows. +QString elideLongString(QString const &str, qint32 maxLength); ///< Elide a string in the middle if its length exceed maxLength. } // namespace