From b2efed71d3c589828b48bcaea48ff2030a179f64 Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Wed, 12 Oct 2022 09:42:52 +0200 Subject: [PATCH] GODT-1344: notifications for ApiCertError and NoActiveKeyForRecipient. Phase 1: added the two event in bridge-gui-tester. Phase 2: implemented QML notifications. --- .../bridge-gui-tester/Tabs/SettingsTab.cpp | 3 + .../bridge-gui-tester/Tabs/SettingsTab.ui | 51 ++++++++------- .../bridge-gui/qml/NotificationDialog.qml | 1 + .../bridge-gui/qml/NotificationPopups.qml | 10 +++ .../qml/Notifications/Notifications.qml | 63 ++++++++++++++++++- .../bridgepp/bridgepp/GRPC/GRPCClient.cpp | 7 ++- 6 files changed, 106 insertions(+), 29 deletions(-) diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.cpp b/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.cpp index 6d381434..784d45d8 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.cpp +++ b/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.cpp @@ -43,6 +43,9 @@ SettingsTab::SettingsTab(QWidget *parent) connect(ui_.buttonInternetOn, &QPushButton::clicked, []() { app().grpc().sendEvent(newInternetStatusEvent(true)); }); connect(ui_.buttonInternetOff, &QPushButton::clicked, []() { app().grpc().sendEvent(newInternetStatusEvent(false)); }); connect(ui_.buttonShowMainWindow, &QPushButton::clicked, []() { app().grpc().sendEvent(newShowMainWindowEvent()); }); + connect(ui_.buttonAPICertIssue, &QPushButton::clicked, []() {app().grpc().sendEvent(newApiCertIssueEvent()); }); + connect(ui_.buttonNoActiveKeyForRecipient, &QPushButton::clicked, [&]() {app().grpc().sendEvent( + newNoActiveKeyForRecipientEvent(ui_.editNoActiveKeyForRecipient->text())); }); connect(ui_.checkNextCacheChangeWillSucceed, &QCheckBox::toggled, this, &SettingsTab::updateGUIState); this->resetUI(); this->updateGUIState(); diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.ui b/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.ui index d67c0671..3b45527b 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.ui +++ b/internal/frontend/bridge-gui/bridge-gui-tester/Tabs/SettingsTab.ui @@ -703,19 +703,6 @@ - - - - Qt::Horizontal - - - - 0 - 10 - - - - @@ -723,19 +710,6 @@ - - - - Qt::Horizontal - - - - 0 - 10 - - - - @@ -743,6 +717,31 @@ + + + + API cert. Issue + + + + + + + + + + + No Active Key For Recipient + + + + + + + dummy.user@proton.me + + + diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/NotificationDialog.qml b/internal/frontend/bridge-gui/bridge-gui/qml/NotificationDialog.qml index 3af8f070..e729e19f 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/NotificationDialog.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/NotificationDialog.qml @@ -68,6 +68,7 @@ Dialog { Label { Layout.alignment: Qt.AlignHCenter + horizontalAlignment: Text.AlignHCenter Layout.bottomMargin: 8 colorScheme: root.colorScheme text: root.notification.title diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/NotificationPopups.qml b/internal/frontend/bridge-gui/bridge-gui/qml/NotificationPopups.qml index 65f27b9d..f4aee23b 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/NotificationPopups.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/NotificationPopups.qml @@ -128,4 +128,14 @@ Item { colorScheme: root.colorScheme notification: root.notifications.rebuildKeychain } + + NotificationDialog { + colorScheme: root.colorScheme + notification: root.notifications.apiCertIssue + } + + NotificationDialog { + colorScheme: root.colorScheme + notification: root.notifications.noActiveKeyForRecipient + } } diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml b/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml index d3204b9a..d638ac4c 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml @@ -77,7 +77,9 @@ QtObject { root.deleteAccount, root.noKeychain, root.rebuildKeychain, - root.addressChanged + root.addressChanged, + root.apiCertIssue, + root.noActiveKeyForRecipient ] // Connection @@ -1051,4 +1053,63 @@ QtObject { } ] } + + property Notification apiCertIssue: Notification { + title: qsTr("Unable to establish a \nsecure connection to \nProton servers") + description: qsTr("Bridge cannot verify the authenticity of Proton servers on your current network due to a TLS certificate error. " + + "Start Bridge again after ensuring your connection is secure and/or connecting to a VPN. Learn more about TLS pinning " + + "here.") + + brief: title + icon: "./icons/ic-exclamation-circle-filled.svg" + type: Notification.NotificationType.Danger + group: Notifications.Group.Dialogs | Notifications.Group.Connection + + Connections { + target: Backend + + function onApiCertIssue() { + root.apiCertIssue.active = true + } + } + + action: [ + Action { + text: qsTr("Quit Bridge") + + onTriggered: { + root.apiCertIssue.active = false; + Backend.quit() + } + } + ] + } + + property Notification noActiveKeyForRecipient: Notification { + title: qsTr("Unable to send \nencrypted message") + description: "#PlaceholderText#" + icon: "./icons/ic-exclamation-circle-filled.svg" + type: Notification.NotificationType.Danger + group: Notifications.Group.Dialogs | Notifications.Group.Connection + + Connections { + target: Backend + + function onNoActiveKeyForRecipient(email) { + root.noActiveKeyForRecipient.description = qsTr("There are no active keys to encrypt your message to %1. "+ + "Please update the setting for this contact.").arg(email) + root.noActiveKeyForRecipient.active = true + } + } + + action: [ + Action { + text: qsTr("OK") + + onTriggered: { + root.noActiveKeyForRecipient.active = false + } + } + ] + } } diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp index 2178486e..54e96aea 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp @@ -1382,9 +1382,12 @@ void GRPCClient::processMailEvent(MailEvent const &event) switch (event.event_case()) { case MailEvent::kNoActiveKeyForRecipientEvent: - this->logTrace("Mail event received: kNoActiveKeyForRecipientEvent."); - emit noActiveKeyForRecipient(QString::fromStdString(event.noactivekeyforrecipientevent().email())); + { + QString const email = QString::fromStdString(event.noactivekeyforrecipientevent().email()); + this->logTrace(QString("Mail event received: NoActiveKeyForRecipient (email = %1).").arg(email)); + emit noActiveKeyForRecipient(email); break; + } case MailEvent::kAddressChanged: this->logTrace("Mail event received: AddressChanged."); emit addressChanged(QString::fromStdString(event.addresschanged().address()));