Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

[WIP] feat: Add username to tray menu #5943

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Chiitoo
Copy link
Contributor

@Chiitoo Chiitoo commented Dec 2, 2019

This is a 'first try' at displaying the user name in the tray menu.

Updating the name only happens when restarting the client, and truncating too long ones is not there yet.


This change is Reviewable

@Chiitoo
Copy link
Contributor Author

Chiitoo commented Dec 2, 2019

Something like this might be a bit cleaner:

diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp
index 956ab0fd..14a14558 100644
--- a/src/widget/widget.cpp
+++ b/src/widget/widget.cpp
@@ -2249,7 +2249,12 @@ void Widget::onTryCreateTrayIcon()
             icon = std::unique_ptr<QSystemTrayIcon>(new QSystemTrayIcon);
             updateIcons();
             trayMenu = new QMenu(this);
+            trayUser = new QWidgetAction(trayMenu);

+            trayUser->setText(getUsername());
+
+            trayMenu->addAction(trayUser);
+            trayMenu->addSeparator();
             // adding activate to the top, avoids accidentally clicking quit
             trayMenu->addAction(actionShow);
             trayMenu->addSeparator();
diff --git a/src/widget/widget.h b/src/widget/widget.h
index 23f10a63..29a80334 100644
--- a/src/widget/widget.h
+++ b/src/widget/widget.h
@@ -26,6 +26,7 @@
 #include <QMainWindow>
 #include <QPointer>
 #include <QSystemTrayIcon>
+#include <QWidgetAction>

 #include "genericchatitemwidget.h"

@@ -286,6 +287,8 @@ private:
     QAction* actionQuit;
     QAction* actionShow;

+    QWidgetAction* trayUser;
+
     QMenu* filterMenu;

     QActionGroup* filterGroup;

@Chiitoo
Copy link
Contributor Author

Chiitoo commented Dec 3, 2019

Or even:

diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp
index 956ab0fd..24957923 100644
--- a/src/widget/widget.cpp
+++ b/src/widget/widget.cpp
@@ -167,6 +167,8 @@ void Widget::init()

     icon_size = 15;

+    trayUser = new QAction(this);
+
     actionShow = new QAction(this);
     connect(actionShow, &QAction::triggered, this, &Widget::forceShow);

@@ -2249,7 +2251,12 @@ void Widget::onTryCreateTrayIcon()
             icon = std::unique_ptr<QSystemTrayIcon>(new QSystemTrayIcon);
             updateIcons();
             trayMenu = new QMenu(this);

+            trayMenu->addAction(trayUser);
+            trayMenu->addSeparator();
             // adding activate to the top, avoids accidentally clicking quit
             trayMenu->addAction(actionShow);
             trayMenu->addSeparator();
@@ -2642,6 +2649,7 @@ void Widget::retranslateUi()
     actionLogout->setText(tr("Logout", "Tray action menu to logout user"));
     actionQuit->setText(tr("Exit", "Tray action menu to exit Tox"));
     actionShow->setText(tr("Show", "Tray action menu to show qTox window"));
+    trayUser->setText(getUsername());

     if (!settings.getSeparateWindow() && (settingsWidget && settingsWidget->isShown())) {
         setWindowTitle(fromDialogType(DialogType::SettingDialog));
diff --git a/src/widget/widget.h b/src/widget/widget.h
index 23f10a63..ed1545ed 100644
--- a/src/widget/widget.h
+++ b/src/widget/widget.h
@@ -285,6 +286,7 @@ private:
     QAction* actionLogout;
     QAction* actionQuit;
     QAction* actionShow;
+    QAction* trayUser;

     QMenu* filterMenu;

I also wonder if it were intuitive at all to simply rename 'Show' into 'username'.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant