feat(GODT-3121): suggestions are transferred to QML.

This commit is contained in:
Xavier Michelon
2023-11-29 17:43:50 +01:00
parent 2e2648fcd5
commit cfd07cf893
6 changed files with 18 additions and 6 deletions

View File

@ -360,11 +360,11 @@ Status GRPCService::SetMainExecutable(ServerContext *, StringValue const *reques
//**************************************************************************************************************************************************** //****************************************************************************************************************************************************
grpc::Status GRPCService::RequestKnowledgeBaseSuggestions(ServerContext*, StringValue const* request, Empty*) { grpc::Status GRPCService::RequestKnowledgeBaseSuggestions(ServerContext*, StringValue const* request, Empty*) {
app().log().info(QString("RequestKnowledgeBaseSuggestions: %1").arg(QString::fromStdString(request->value()).left(10) + "...")); app().log().info(QString("RequestKnowledgeBaseSuggestions: %1").arg(QString::fromStdString(request->value()).left(10) + "..."));
QList<bridgepp::KnowledgeBaseSuggestion> suggestions(3); QList<bridgepp::KnowledgeBaseSuggestion> suggestions;
for (qsizetype i = 0; i < 3; ++i) { for (qsizetype i = 1; i <= 3; ++i) {
suggestions.push_back( { suggestions.push_back( {
.title = QString("Suggested link %1").arg(i), .title = QString("Suggested link %1").arg(i),
.url = "https://proton.me/support/bridge" .url = QString("https://proton.me/support/bridge#%1").arg(i),
}); });
} }
qtProxy_.sendDelayedEvent(newKnowledgeBaseSuggestionsEvent(suggestions)); qtProxy_.sendDelayedEvent(newKnowledgeBaseSuggestionsEvent(suggestions));

View File

@ -1315,6 +1315,7 @@ void QMLBackend::connectGrpcEvents() {
connect(client, &GRPCClient::certificateInstallCanceled, this, &QMLBackend::certificateInstallCanceled); connect(client, &GRPCClient::certificateInstallCanceled, this, &QMLBackend::certificateInstallCanceled);
connect(client, &GRPCClient::certificateInstallFailed, this, &QMLBackend::certificateInstallFailed); connect(client, &GRPCClient::certificateInstallFailed, this, &QMLBackend::certificateInstallFailed);
connect(client, &GRPCClient::showMainWindow, [&]() { this->showMainWindow("gRPC showMainWindow event"); }); connect(client, &GRPCClient::showMainWindow, [&]() { this->showMainWindow("gRPC showMainWindow event"); });
connect(client, &GRPCClient::knowledgeBasSuggestionsReceived, this, &QMLBackend::receivedKnowledgeBaseSuggestions);
// cache events // cache events
connect(client, &GRPCClient::cantMoveDiskCache, this, &QMLBackend::cantMoveDiskCache); connect(client, &GRPCClient::cantMoveDiskCache, this, &QMLBackend::cantMoveDiskCache);

View File

@ -279,6 +279,7 @@ signals: // Signals received from the Go backend, to be forwarded to QML
void selectUser(QString const& userID, bool forceShowWindow); ///< Signal emitted in order to selected a user with a given ID in the list. void selectUser(QString const& userID, bool forceShowWindow); ///< Signal emitted in order to selected a user with a given ID in the list.
void genericError(QString const &title, QString const &description); ///< Signal for the 'genericError' gRPC stream event. void genericError(QString const &title, QString const &description); ///< Signal for the 'genericError' gRPC stream event.
void imapLoginWhileSignedOut(QString const& username); ///< Signal for the notification of IMAP login attempt on a signed out account. void imapLoginWhileSignedOut(QString const& username); ///< Signal for the notification of IMAP login attempt on a signed out account.
void receivedKnowledgeBaseSuggestions(QList<bridgepp::KnowledgeBaseSuggestion> const& suggestions); ///< Signal for the reception of knowledgebase article suggestions.
// This signal is emitted when an exception is intercepted is calls triggered by QML. QML engine would intercept the exception otherwise. // This signal is emitted when an exception is intercepted is calls triggered by QML. QML engine would intercept the exception otherwise.
void fatalError(bridgepp::Exception const& e) const; ///< Signal emitted when an fatal error occurs. void fatalError(bridgepp::Exception const& e) const; ///< Signal emitted when an fatal error occurs.

View File

@ -155,7 +155,12 @@ SettingsView {
function onReportBugFinished() { function onReportBugFinished() {
sendButton.loading = false; sendButton.loading = false;
} }
function onReceivedKnowledgeBaseSuggestions(suggestions) {
console.error("QML: onReceivedKnowledgeBaseSuggestions() - len = %1".arg(suggestions.length))
console.error("QML: %1: %2".arg(suggestions[0].title).arg(suggestions[0].url))
console.error("QML: %1: %2".arg(suggestions[1].title).arg(suggestions[1].url))
console.error("QML: %1: %2".arg(suggestions[2].title).arg(suggestions[2].url))
}
target: Backend target: Backend
} }
} }

View File

@ -1182,7 +1182,7 @@ void GRPCClient::processAppEvent(AppEvent const &event) {
.title = QString::fromUtf8(suggestion.title()) .title = QString::fromUtf8(suggestion.title())
}); });
} }
emit knowledgeBasSuggestions(suggestions); emit knowledgeBasSuggestionsReceived(suggestions);
break; break;
} }
default: default:

View File

@ -46,6 +46,11 @@ typedef std::unique_ptr<grpc::ClientContext> UPClientContext;
/// \brief A struct for knowledge base suggestion. /// \brief A struct for knowledge base suggestion.
//**************************************************************************************************************************************************** //****************************************************************************************************************************************************
struct KnowledgeBaseSuggestion { struct KnowledgeBaseSuggestion {
// The following lines make the type transmissible to QML (but not instanciable there)
Q_GADGET
Q_PROPERTY(QString url MEMBER url)
Q_PROPERTY(QString title MEMBER title)
public:
QString url; ///< The URL of the knowledge base article QString url; ///< The URL of the knowledge base article
QString title; ///< The title of the knowledge base article. QString title; ///< The title of the knowledge base article.
}; };
@ -116,7 +121,7 @@ signals: // app related signals
void certificateInstallCanceled(); void certificateInstallCanceled();
void certificateInstallFailed(); void certificateInstallFailed();
void showMainWindow(); void showMainWindow();
void knowledgeBasSuggestions(QList<KnowledgeBaseSuggestion> const& suggestions); void knowledgeBasSuggestionsReceived(QList<KnowledgeBaseSuggestion> const& suggestions);
public: // cache related calls public: // cache related calls