[network/ruqola] src/widgets: Update systray status menu when we off -> on

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 5c83fcf203bb2358b3a0d5dc559a1a8a4cedc90e by Laurent Montel.
Committed on 14/08/2026 at 17:39.
Pushed by mlaurent into branch 'master'.

Update systray status menu when we off -> on

M  +8    -7    src/widgets/notifications/notificationmanager.cpp
M  +12   -0    src/widgets/ruqolamainwindow.cpp
M  +2    -0    src/widgets/ruqolamainwindow.h

https://invent.kde.org/network/ruqola/-/commit/5c83fcf203bb2358b3a0d5dc559a1a8a4cedc90e

diff --git a/src/widgets/notifications/notificationmanager.cpp b/src/widgets/notifications/notificationmanager.cpp
index 14f95375be..5f3ecab7ea 100644
--- a/src/widgets/notifications/notificationmanager.cpp
+++ b/src/widgets/notifications/notificationmanager.cpp
@@ -12,6 +12,8 @@
 #include <QApplication>
 #include <QMenu>
 
+#include <utility>
+
 NotificationManager::NotificationManager(KActionCollection *actionCollection, QObject *parent)
     : QObject(parent)
     , mActionCollection(actionCollection)
@@ -38,12 +40,13 @@ void NotificationManager::createSystemTray(QObject *parent)
         mNotification = new Notification(parent);
         auto trayMenu = mNotification->contextMenu();
 
-        mContextStatusMenu = mNotification->contextMenu()->addMenu(i18nc("@item:inmenu Instant message presence status", "Status"));
+        mContextStatusMenu = trayMenu->addMenu(i18nc("@item:inmenu Instant message presence status", "Status"));
         mContextStatusMenu->menuAction()->setVisible(false);
         trayMenu->addAction(mActionCollection->action(KStandardActions::name(KStandardActions::Preferences)));
         trayMenu->addAction(mActionCollection->action(KStandardActions::name(KStandardActions::ConfigureNotifications)));
         // Create systray to show notifications on Desktop
         connect(mNotification, &Notification::alert, this, &NotificationManager::alert);
+        createSystrayToolTip();
     }
 #endif
 }
@@ -83,12 +86,10 @@ void NotificationManager::createSystrayToolTip()
     QString str;
     bool hasAlert = false;
     int unreadMessage = 0;
-    for (const auto &[key, value] : mListTrayIcon.asKeyValueRange()) {
-        const Notification::TrayInfo trayInfo = value;
-        if (mNotification) {
-            if (trayInfo.hasAlert) {
-                hasAlert = trayInfo.hasAlert;
-            }
+    for (const auto &[key, value] : std::as_const(mListTrayIcon).asKeyValueRange()) {
+        const Notification::TrayInfo &trayInfo = value;
+        if (trayInfo.hasAlert) {
+            hasAlert = true;
         }
         if (trayInfo.unreadMessage != 0) {
             if (mNotification) {
diff --git a/src/widgets/ruqolamainwindow.cpp b/src/widgets/ruqolamainwindow.cpp
index edc6d674f3..43b03e5f30 100644
--- a/src/widgets/ruqolamainwindow.cpp
+++ b/src/widgets/ruqolamainwindow.cpp
@@ -916,6 +916,8 @@ void RuqolaMainWindow::slotConfigure()
 
         mAccountOverviewWidget->updateButtons();
         mNotificationManager->createSystemTray(this);
+        // Enabling the systray again creates a new (empty and hidden) status menu => fill it.
+        updateContextStatusMenu();
         Q_EMIT Ruqola::self()->translatorMenuChanged();
         Q_EMIT ColorsAndMessageViewStyle::self().needUpdateFontSize();
     }
@@ -1029,6 +1031,7 @@ void RuqolaMainWindow::slotMissingChannelPassword(const RocketChatRestApi::Chann
 
 void RuqolaMainWindow::slotDisableActions(bool loginPageActivated)
 {
+    mLoginPageActivated = loginPageActivated;
     const bool offline = mCurrentRocketChatAccount && mCurrentRocketChatAccount->offlineMode();
     mCreateNewChannel->setEnabled(!loginPageActivated && canCreateChannels() && !offline);
     mCreateDirectMessages->setEnabled(!loginPageActivated && canCreateDirectMessages() && !offline);
@@ -1203,6 +1206,15 @@ void RuqolaMainWindow::slotUpdateStatusMenu()
     }
 }
 
+void RuqolaMainWindow::updateContextStatusMenu()
+{
+    if (auto contextStatusMenu = mNotificationManager->contextStatusMenu()) {
+        contextStatusMenu->menuAction()->setVisible(!mLoginPageActivated);
+    }
+    slotUpdateCustomUserStatus();
+    slotUpdateStatusMenu();
+}
+
 void RuqolaMainWindow::slotUpdateCustomUserStatus()
 {
     mStatusProxyModel->sort(0);
diff --git a/src/widgets/ruqolamainwindow.h b/src/widgets/ruqolamainwindow.h
index ed71e0a958..a9085a39e0 100644
--- a/src/widgets/ruqolamainwindow.h
+++ b/src/widgets/ruqolamainwindow.h
@@ -136,8 +136,10 @@ private:
     LIBRUQOLAWIDGETS_NO_EXPORT void slotOfflineModeChanged();
     LIBRUQOLAWIDGETS_NO_EXPORT void updateOfflineAction();
     LIBRUQOLAWIDGETS_NO_EXPORT void slotShowNotifyNewRoom(const QString &accountName, const QByteArray &roomId);
+    LIBRUQOLAWIDGETS_NO_EXPORT void updateContextStatusMenu();
 
     bool mReallyClose{false};
+    bool mLoginPageActivated{true};
 
     RuqolaCentralWidget *const mMainWidget;
     QAction *mServerInfo = nullptr;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.