From bdc6542970d4d7148c6316a96f48aaa9ed06c64f Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Mon, 26 Jun 2023 11:03:49 +0200 Subject: [PATCH] feat(GODT-2678): When internet is off, do not display status dot icon for the user in the context menu. --- .../bridge-gui/bridge-gui/QMLBackend.cpp | 28 +++++++++++++++++-- .../bridge-gui/bridge-gui/QMLBackend.h | 6 ++-- .../bridge-gui/bridge-gui/TrayIcon.cpp | 5 +++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp index b7c884c2..03b4b256 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp @@ -109,6 +109,12 @@ UserList const &QMLBackend::users() const { return *users_; } +//**************************************************************************************************************************************************** +/// \return the if bridge considers internet is on. +//**************************************************************************************************************************************************** +bool QMLBackend::isInternetOn() const { + return isInternetOn_; +} //**************************************************************************************************************************************************** /// \return The build year as a string (e.g. 2023) @@ -874,7 +880,6 @@ void QMLBackend::sendBadEventUserFeedback(QString const &userID, bool doResync) if (!badEventDisplayQueue_.isEmpty()) { // we introduce a small delay here, so that the user notices the dialog disappear and pops up again. QTimer::singleShot(500, [&]() { this->displayBadEventDialog(badEventDisplayQueue_.front()); }); - } ) } @@ -923,6 +928,25 @@ void QMLBackend::setUpdateTrayIcon(QString const &stateString, QString const &st } +//**************************************************************************************************************************************************** +/// \param[in] isOn Does bridge consider internet as on. +//**************************************************************************************************************************************************** +void QMLBackend::internetStatusChanged(bool isOn) { + HANDLE_EXCEPTION( + if (isInternetOn_ == isOn) { + return; + } + + isInternetOn_ = isOn; + if (isOn) { + emit internetOn(); + } else { + emit internetOff(); + } + ) +} + + //**************************************************************************************************************************************************** /// \param[in] imapPort The IMAP port. /// \param[in] smtpPort The SMTP port. @@ -1086,7 +1110,7 @@ void QMLBackend::connectGrpcEvents() { GRPCClient *client = &app().grpc(); // app events - connect(client, &GRPCClient::internetStatus, this, [&](bool isOn) { if (isOn) { emit internetOn(); } else { emit internetOff(); }}); + connect(client, &GRPCClient::internetStatus, this, &QMLBackend::internetStatusChanged); connect(client, &GRPCClient::toggleAutostartFinished, this, &QMLBackend::toggleAutostartFinished); connect(client, &GRPCClient::resetFinished, this, &QMLBackend::onResetFinished); connect(client, &GRPCClient::reportBugFinished, this, &QMLBackend::reportBugFinished); diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h index c5b5c9c5..c2b77be6 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h @@ -45,6 +45,7 @@ public: // member functions. void init(GRPCConfig const &serviceConfig); ///< Initialize the backend. bool waitForEventStreamReaderToFinish(qint32 timeoutMs); ///< Wait for the event stream reader to finish. UserList const& users() const; ///< Return the list of users + bool isInternetOn() const; ///< Check if bridge considers internet as on. // invokable methods can be called from QML. They generally return a value, which slots cannot do. Q_INVOKABLE static QString buildYear(); ///< Return the application build year. @@ -85,7 +86,6 @@ public: // Qt/QML properties. Note that the NOTIFY-er signal is required even fo Q_PROPERTY(UserList *users MEMBER users_ NOTIFY usersChanged) Q_PROPERTY(bool dockIconVisible READ dockIconVisible WRITE setDockIconVisible NOTIFY dockIconVisibleChanged) - // Qt Property system setters & getters. bool showOnStartup() const; ///< Getter for the 'showOnStartup' property. void setShowSplashScreen(bool show); ///< Setter for the 'showSplashScreen' property. @@ -191,6 +191,7 @@ public slots: // slots for functions that need to be processed locally. void setUpdateTrayIcon(QString const& stateString, QString const &statusIcon); ///< Set the tray icon to 'update' state. public slots: // slot for signals received from gRPC that need transformation instead of simple forwarding + void internetStatusChanged(bool isOn); ///< Check if bridge considers internet as on. void onMailServerSettingsChanged(int imapPort, int smtpPort, bool useSSLForIMAP, bool useSSLForSMTP); ///< Slot for the ConnectionModeChanged gRPC event. void onGenericError(bridgepp::ErrorInfo const &info); ///< Slot for generic errors received from the gRPC service. void onLoginFinished(QString const &userID, bool wasSignedOut); ///< Slot for LoginFinished gRPC event. @@ -273,8 +274,9 @@ private: // data members int smtpPort_ { 0 }; ///< The cached value for the SMTP port. bool useSSLForIMAP_ { false }; ///< The cached value for useSSLForIMAP. bool useSSLForSMTP_ { false }; ///< The cached value for useSSLForSMTP. + bool isInternetOn_ { true }; ///< Does bridge consider internet as on? QList badEventDisplayQueue_; ///< THe queue for displaying 'bad event feedback request dialog'. - std::unique_ptr trayIcon_; + std::unique_ptr trayIcon_; ///< The tray icon for the application. friend class AppController; }; diff --git a/internal/frontend/bridge-gui/bridge-gui/TrayIcon.cpp b/internal/frontend/bridge-gui/bridge-gui/TrayIcon.cpp index 86ba6b0b..e5b32dbb 100644 --- a/internal/frontend/bridge-gui/bridge-gui/TrayIcon.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/TrayIcon.cpp @@ -344,6 +344,7 @@ void TrayIcon::refreshContextMenu() { return; } + bool const internetOn = app().backend().isInternetOn(); menu_->clear(); menu_->addAction(statusIcon_, stateString_, &app().backend(), &QMLBackend::showMainWindow); menu_->addSeparator(); @@ -355,7 +356,9 @@ void TrayIcon::refreshContextMenu() { User const &user = *users.get(i); UserState const state = user.state(); auto action = new QAction(user.primaryEmailOrUsername()); - action->setIcon((UserState::Connected == state) ? greenDot_ : (UserState::Locked == state ? orangeDot_ : greyDot_)); + if (internetOn) { + action->setIcon((UserState::Connected == state) ? greenDot_ : (UserState::Locked == state ? orangeDot_ : greyDot_)); + } action->setData(user.id()); connect(action, &QAction::triggered, this, &TrayIcon::onUserClicked); if ((i < 10) && onMac) {