From 2e2648fcd5e13bab6f20aa144acba186e66db66c Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Tue, 28 Nov 2023 17:05:49 +0100 Subject: [PATCH] feat(GODT-3121): QML request suggestions. --- .../bridge-gui-tester/GRPCService.cpp | 17 +++++++++++++++++ .../bridge-gui/bridge-gui-tester/GRPCService.h | 1 + .../bridge-gui/bridge-gui/QMLBackend.cpp | 10 ++++++++++ .../frontend/bridge-gui/bridge-gui/QMLBackend.h | 1 + .../bridge-gui/bridge-gui/Resources.qrc | 10 +++++----- .../qml/{ => BugReport}/BugCategoryView.qml | 1 + .../qml/{ => BugReport}/BugQuestionView.qml | 1 + .../qml/{ => BugReport}/BugReportFlow.qml | 2 ++ .../qml/{ => BugReport}/BugReportView.qml | 1 + .../qml/{ => BugReport}/CategoryItem.qml | 1 + .../bridge-gui/qml/ContentWrapper.qml | 1 + .../bridge-gui/bridge-gui/qml/MainWindow.qml | 1 + .../bridgepp/bridgepp/GRPC/EventFactory.cpp | 16 ++++++++++++++++ .../bridgepp/bridgepp/GRPC/EventFactory.h | 2 ++ .../bridgepp/bridgepp/GRPC/GRPCClient.cpp | 2 +- .../bridgepp/bridgepp/GRPC/GRPCClient.h | 2 +- 16 files changed, 62 insertions(+), 7 deletions(-) rename internal/frontend/bridge-gui/bridge-gui/qml/{ => BugReport}/BugCategoryView.qml (99%) rename internal/frontend/bridge-gui/bridge-gui/qml/{ => BugReport}/BugQuestionView.qml (99%) rename internal/frontend/bridge-gui/bridge-gui/qml/{ => BugReport}/BugReportFlow.qml (97%) rename internal/frontend/bridge-gui/bridge-gui/qml/{ => BugReport}/BugReportView.qml (99%) rename internal/frontend/bridge-gui/bridge-gui/qml/{ => BugReport}/CategoryItem.qml (99%) diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.cpp b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.cpp index 8813789d..9c7e7aa6 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.cpp +++ b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.cpp @@ -354,6 +354,23 @@ Status GRPCService::SetMainExecutable(ServerContext *, StringValue const *reques return Status::OK; } +//**************************************************************************************************************************************************** +/// \param[in] request The request. +/// \return The status for the call. +//**************************************************************************************************************************************************** +grpc::Status GRPCService::RequestKnowledgeBaseSuggestions(ServerContext*, StringValue const* request, Empty*) { + app().log().info(QString("RequestKnowledgeBaseSuggestions: %1").arg(QString::fromStdString(request->value()).left(10) + "...")); + QList suggestions(3); + for (qsizetype i = 0; i < 3; ++i) { + suggestions.push_back( { + .title = QString("Suggested link %1").arg(i), + .url = "https://proton.me/support/bridge" + }); + } + qtProxy_.sendDelayedEvent(newKnowledgeBaseSuggestionsEvent(suggestions)); + return Status::OK; +} + //**************************************************************************************************************************************************** /// \param[in] request The request diff --git a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.h b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.h index 0e668a80..a044da4a 100644 --- a/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.h +++ b/internal/frontend/bridge-gui/bridge-gui-tester/GRPCService.h @@ -67,6 +67,7 @@ public: // member functions. grpc::Status ReportBug(::grpc::ServerContext *, ::grpc::ReportBugRequest const *request, ::google::protobuf::Empty *) override; grpc::Status ForceLauncher(::grpc::ServerContext *, ::google::protobuf::StringValue const *request, ::google::protobuf::Empty *) override; grpc::Status SetMainExecutable(::grpc::ServerContext *, ::google::protobuf::StringValue const *request, ::google::protobuf::Empty *) override; + grpc::Status RequestKnowledgeBaseSuggestions(::grpc::ServerContext *, ::google::protobuf::StringValue const *request, ::google::protobuf::Empty *) override; grpc::Status Login(::grpc::ServerContext *, ::grpc::LoginRequest const *request, ::google::protobuf::Empty *) override; grpc::Status Login2FA(::grpc::ServerContext *, ::grpc::LoginRequest const *request, ::google::protobuf::Empty *) override; grpc::Status Login2Passwords(::grpc::ServerContext *, ::grpc::LoginRequest const *request, ::google::protobuf::Empty *) override; diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp index 493178fb..54f552af 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp @@ -303,6 +303,16 @@ void QMLBackend::openExternalLink(QString const &url) { } +//**************************************************************************************************************************************************** +// +//**************************************************************************************************************************************************** +void QMLBackend::requestKnowledgeBaseSuggestions() const { + HANDLE_EXCEPTION( + app().grpc().requestKnowledgeBaseSuggestions("Test"); + ) +} + + //**************************************************************************************************************************************************** /// \return The value for the 'showOnStartup' property. //**************************************************************************************************************************************************** diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h index c295ede2..63392643 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h @@ -66,6 +66,7 @@ public: // member functions. Q_INVOKABLE void clearAnswers(); ///< Clear all collected answers. Q_INVOKABLE bool isTLSCertificateInstalled(); ///< Check if the bridge certificate is installed in the OS keychain. Q_INVOKABLE void openExternalLink(QString const & url = QString()); ///< Open a knowledge base article. + Q_INVOKABLE void requestKnowledgeBaseSuggestions() const; ///< Request knowledgebase article suggestions. public: // Qt/QML properties. Note that the NOTIFY-er signal is required even for read-only properties (QML warning otherwise) Q_PROPERTY(bool showOnStartup READ showOnStartup NOTIFY showOnStartupChanged) diff --git a/internal/frontend/bridge-gui/bridge-gui/Resources.qrc b/internal/frontend/bridge-gui/bridge-gui/Resources.qrc index 9403ac97..0d3c80b5 100644 --- a/internal/frontend/bridge-gui/bridge-gui/Resources.qrc +++ b/internal/frontend/bridge-gui/bridge-gui/Resources.qrc @@ -5,11 +5,6 @@ qml/AccountView.qml qml/Banner.qml qml/Bridge.qml - qml/BugCategoryView.qml - qml/BugQuestionView.qml - qml/BugReportFlow.qml - qml/BugReportView.qml - qml/CategoryItem.qml qml/Configuration.qml qml/ConfigurationItem.qml qml/ContentWrapper.qml @@ -89,6 +84,11 @@ qml/Notifications/Notifications.qml qml/Notifications/qmldir qml/PortSettings.qml + qml/BugReport/BugCategoryView.qml + qml/BugReport/BugQuestionView.qml + qml/BugReport/BugReportFlow.qml + qml/BugReport/BugReportView.qml + qml/BugReport/CategoryItem.qml qml/Proton/Action.qml qml/Proton/ApplicationWindow.qml qml/Proton/Button.qml diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/BugCategoryView.qml b/internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugCategoryView.qml similarity index 99% rename from internal/frontend/bridge-gui/bridge-gui/qml/BugCategoryView.qml rename to internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugCategoryView.qml index 07372080..1632c2cd 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/BugCategoryView.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugCategoryView.qml @@ -14,6 +14,7 @@ import QtQuick import QtQuick.Layouts import QtQuick.Controls import Proton +import ".." SettingsView { id: root diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/BugQuestionView.qml b/internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugQuestionView.qml similarity index 99% rename from internal/frontend/bridge-gui/bridge-gui/qml/BugQuestionView.qml rename to internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugQuestionView.qml index 7c01914b..d36eddec 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/BugQuestionView.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugQuestionView.qml @@ -14,6 +14,7 @@ import QtQuick import QtQuick.Layouts import QtQuick.Controls import Proton +import ".." SettingsView { id: root diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/BugReportFlow.qml b/internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugReportFlow.qml similarity index 97% rename from internal/frontend/bridge-gui/bridge-gui/qml/BugReportFlow.qml rename to internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugReportFlow.qml index 2e566399..5da1ca25 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/BugReportFlow.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugReportFlow.qml @@ -15,6 +15,7 @@ import QtQuick.Layouts import QtQuick.Controls import Proton import Notifications +import ".." Item { id: root @@ -77,6 +78,7 @@ Item { root.showBugCategory(); } onQuestionAnswered: { + Backend.requestKnowledgeBaseSuggestions(); root.showBugReport(); } } diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/BugReportView.qml b/internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugReportView.qml similarity index 99% rename from internal/frontend/bridge-gui/bridge-gui/qml/BugReportView.qml rename to internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugReportView.qml index e5029ecd..af3fd397 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/BugReportView.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/BugReport/BugReportView.qml @@ -14,6 +14,7 @@ import QtQuick import QtQuick.Layouts import QtQuick.Controls import Proton +import ".." SettingsView { id: root diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/CategoryItem.qml b/internal/frontend/bridge-gui/bridge-gui/qml/BugReport/CategoryItem.qml similarity index 99% rename from internal/frontend/bridge-gui/bridge-gui/qml/CategoryItem.qml rename to internal/frontend/bridge-gui/bridge-gui/qml/BugReport/CategoryItem.qml index 1e6342f2..2d4afae2 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/CategoryItem.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/BugReport/CategoryItem.qml @@ -14,6 +14,7 @@ import QtQuick import QtQuick.Layouts import QtQuick.Controls import Proton +import ".." Item { id: root diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml b/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml index 05336b6e..75f9f7c7 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml @@ -15,6 +15,7 @@ import QtQuick.Layouts import QtQuick.Controls import Proton import Notifications +import "BugReport" Item { id: root diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml b/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml index efd5c10d..a65ecfba 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml @@ -18,6 +18,7 @@ import QtQuick.Controls import Proton import Notifications import "SetupWizard" +import "BugReport" ApplicationWindow { id: root diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.cpp b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.cpp index d4e43d83..a27167e9 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.cpp +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.cpp @@ -247,6 +247,22 @@ SPStreamEvent newCertificateInstallFailedEvent() { } +//**************************************************************************************************************************************************** +/// \param[in] suggestions the suggestions +/// \return The event. +//**************************************************************************************************************************************************** +SPStreamEvent newKnowledgeBaseSuggestionsEvent(QList const& suggestions) { + auto event = new grpc::KnowledgeBaseSuggestionsEvent; + for (KnowledgeBaseSuggestion const &suggestion: suggestions) { + grpc::KnowledgeBaseSuggestion *s = event->add_suggestions(); + s->set_url(suggestion.url.toStdString()); + s->set_title(suggestion.title.toStdString()); + } + auto appEvent = new grpc::AppEvent; + appEvent->set_allocated_knowledgebasesuggestions(event); + return wrapAppEvent(appEvent); +} + //**************************************************************************************************************************************************** /// \return The event. //**************************************************************************************************************************************************** diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.h b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.h index 7bde721c..bb6e6d1e 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.h +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/EventFactory.h @@ -22,6 +22,7 @@ #include "bridge.grpc.pb.h" #include "GRPCUtils.h" +#include namespace bridgepp { @@ -39,6 +40,7 @@ SPStreamEvent newCertificateInstallSuccessEvent(); ///< Create a new Certificate SPStreamEvent newCertificateInstallCanceledEvent(); ///< Create a new CertificateInstallCanceledEvent event. SPStreamEvent newCertificateInstallFailedEvent(); ///< Create anew CertificateInstallFailedEvent event. SPStreamEvent newShowMainWindowEvent(); ///< Create a new ShowMainWindowEvent event. +SPStreamEvent newKnowledgeBaseSuggestionsEvent(QList const& suggestions); ///< Create a new KnowledgeBaseSuggestions event. // Login events SPStreamEvent newLoginError(grpc::LoginErrorType error, QString const &message); ///< Create a new LoginError event. diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp index 33746a03..eaaa45f6 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp @@ -571,7 +571,7 @@ grpc::Status GRPCClient::hostname(QString &outHostname) { //**************************************************************************************************************************************************** /// \param[in] input The user input to analyze. //**************************************************************************************************************************************************** -grpc::Status GRPCClient::RequestKnowledgeBaseSuggestions(QString const &input) { +grpc::Status GRPCClient::requestKnowledgeBaseSuggestions(QString const &input) { return this->logGRPCCallStatus(this->setString(&Bridge::Stub::RequestKnowledgeBaseSuggestions, input), __FUNCTION__); } diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h index d7bb31cf..84d79d9a 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h @@ -102,7 +102,7 @@ public: // member functions. grpc::Status releaseNotesPageLink(QUrl &outUrl); ///< Performs the 'releaseNotesPageLink' call. grpc::Status landingPageLink(QUrl &outUrl); ///< Performs the 'landingPageLink' call. grpc::Status hostname(QString &outHostname); ///< Performs the 'Hostname' call. - grpc::Status RequestKnowledgeBaseSuggestions(QString const &input); ///< Performs the 'RequestKnowledgeBaseSuggestions' call. + grpc::Status requestKnowledgeBaseSuggestions(QString const &input); ///< Performs the 'RequestKnowledgeBaseSuggestions' call. signals: // app related signals void internetStatus(bool isOn);