Skip to content

Commit

Permalink
REFAC(client): Remove old tray icon code
Browse files Browse the repository at this point in the history
The existing code for the tray icon was ancient,
buggy and possibly entirely broken in more than one place.

This commit removes all tray related code, such that it can
be completely written from scratch.
  • Loading branch information
Hartmnt committed Jan 2, 2025
1 parent 7aeb37a commit 4bcbcad
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 222 deletions.
4 changes: 0 additions & 4 deletions src/mumble/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ if(WIN32)
target_sources(mumble_client_object_lib PRIVATE
"GlobalShortcut_win.cpp"
"GlobalShortcut_win.h"
"Log_win.cpp"
"SharedMemory_win.cpp"
"TaskList.cpp"
"UserLockFile_win.cpp"
Expand Down Expand Up @@ -663,7 +662,6 @@ else()
PRIVATE
"GlobalShortcut_unix.cpp"
"GlobalShortcut_unix.h"
"Log_unix.cpp"
"os_unix.cpp"
)

Expand All @@ -687,7 +685,6 @@ else()
"AppNap.mm"
"GlobalShortcut_macx.h"
"GlobalShortcut_macx.mm"
"Log_macx.mm"
"os_macx.mm"
)

Expand Down Expand Up @@ -1116,7 +1113,6 @@ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
set_source_files_properties(
"AppNap.mm"
"GlobalShortcut_macx.mm"
"Log_macx.mm"
"os_macx.mm"
"TextToSpeech_macx.mm"
"Overlay_macx.mm"
Expand Down
22 changes: 1 addition & 21 deletions src/mumble/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ void Log::log(MsgType mt, const QString &console, const QString &terse, bool own
// Message notification with balloon tooltips
if (flags & Settings::LogBalloon) {
// Replace any instances of a "Object Replacement Character" from QTextDocumentFragment::toPlainText
postNotification(mt, plain.replace("\xEF\xBF\xBC", tr("[embedded content]")));
// FIXME
}
}

Expand Down Expand Up @@ -913,26 +913,6 @@ void Log::processDeferredLogs() {
}
}

// Post a notification using the MainWindow's QSystemTrayIcon.
void Log::postQtNotification(MsgType mt, const QString &plain) {
if (Global::get().mw->qstiIcon->isSystemTrayAvailable() && Global::get().mw->qstiIcon->supportsMessages()) {
QSystemTrayIcon::MessageIcon msgIcon;
switch (mt) {
case DebugInfo:
case CriticalError:
msgIcon = QSystemTrayIcon::Critical;
break;
case Warning:
msgIcon = QSystemTrayIcon::Warning;
break;
default:
msgIcon = QSystemTrayIcon::Information;
break;
}
Global::get().mw->qstiIcon->showMessage(msgName(mt), plain, msgIcon);
}
}

LogMessage::LogMessage(Log::MsgType mt, const QString &console, const QString &terse, bool ownMessage,
const QString &overrideTTS, bool ignoreTTS)
: mt(mt), console(console), terse(terse), ownMessage(ownMessage), overrideTTS(overrideTTS), ignoreTTS(ignoreTTS) {
Expand Down
2 changes: 0 additions & 2 deletions src/mumble/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ class Log : public QObject {
unsigned int uiLastId;
QDate qdDate;
static const QStringList allowedSchemes();
void postNotification(MsgType mt, const QString &plain);
void postQtNotification(MsgType mt, const QString &plain);

public:
Log(QObject *p = nullptr);
Expand Down
5 changes: 0 additions & 5 deletions src/mumble/LookConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ static ConfigRegistrar registrar(1100, LookConfigNew);
LookConfig::LookConfig(Settings &st) : ConfigWidget(st) {
setupUi(this);

#ifndef Q_OS_MAC
if (!QSystemTrayIcon::isSystemTrayAvailable())
#endif
qgbTray->hide();

qcbLanguage->addItem(tr("System default"));
QDir d(QLatin1String(":"), QLatin1String("mumble_*.qm"), QDir::Name, QDir::Files);
foreach (const QString &key, d.entryList()) {
Expand Down
159 changes: 1 addition & 158 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ MainWindow::MainWindow(QWidget *p)
connect(qteChat, &ChatbarTextEdit::ctrlEnterPressed, [this](const QString &msg) { sendChatbarText(msg, true); });
connect(qteChat, SIGNAL(pastedImage(QString)), this, SLOT(sendChatbarMessage(QString)));

// Tray
connect(qstiIcon, SIGNAL(messageClicked()), this, SLOT(showRaiseWindow()));
connect(qaShow, SIGNAL(triggered()), this, SLOT(showRaiseWindow()));

QObject::connect(this, &MainWindow::transmissionModeChanged, this, &MainWindow::updateTransmitModeComboBox);

// Explicitly add actions to mainwindow so their shortcuts are available
Expand Down Expand Up @@ -271,10 +267,6 @@ void MainWindow::createActions() {
new GlobalShortcut(this, GlobalShortcutType::VolumeDown, tr("Volume Down (-10%)", "Global Shortcut"));
gsVolumeDown->setObjectName(QLatin1String("VolumeDown"));

qstiIcon = new QSystemTrayIcon(qiIcon, this);
qstiIcon->setToolTip(tr("Mumble -- %1").arg(Version::getRelease()));
qstiIcon->setObjectName(QLatin1String("Icon"));

gsWhisper = new GlobalShortcut(this, GlobalShortcutType::Whisper_Shout, tr("Whisper/Shout"),
QVariant::fromValue(ShortcutTarget()));
gsWhisper->setObjectName(QLatin1String("gsWhisper"));
Expand Down Expand Up @@ -423,10 +415,6 @@ void MainWindow::createActions() {
tr("Toggle positional audio", "Global Shortcut"));
gsTogglePositionalAudio->setObjectName("gsTogglePositionalAudio");
gsTogglePositionalAudio->qsWhatsThis = tr("This will toggle positional audio on/off");

#ifndef Q_OS_MAC
qstiIcon->show();
#endif
}

void MainWindow::setupGui() {
Expand Down Expand Up @@ -555,13 +543,6 @@ void MainWindow::setupGui() {

setupView(false);

qmTray = new QMenu(this);
connect(qmTray, SIGNAL(aboutToShow()), this, SLOT(trayAboutToShow()));
trayAboutToShow();
qstiIcon->setContextMenu(qmTray);

updateTrayIcon();

#ifdef Q_OS_MAC
setWindowOpacity(1.0f);
#endif
Expand Down Expand Up @@ -711,43 +692,16 @@ void MainWindow::hideEvent(QHideEvent *e) {
e->ignore();
return;
}
#endif
#ifndef Q_OS_MAC
# ifdef Q_OS_UNIX
if (!qApp->activeModalWidget() && !qApp->activePopupWidget())
# endif
if (Global::get().s.bHideInTray && qstiIcon->isSystemTrayAvailable() && e->spontaneous())
QMetaObject::invokeMethod(this, "hide", Qt::QueuedConnection);
#endif
QMainWindow::hideEvent(e);
}

void MainWindow::showEvent(QShowEvent *e) {
#ifndef Q_OS_MAC
# ifdef Q_OS_UNIX
if (!qApp->activeModalWidget() && !qApp->activePopupWidget())
# endif
if (Global::get().s.bHideInTray && qstiIcon->isSystemTrayAvailable() && e->spontaneous())
QMetaObject::invokeMethod(this, "show", Qt::QueuedConnection);
#endif
QMainWindow::showEvent(e);
}

void MainWindow::changeEvent(QEvent *e) {
QWidget::changeEvent(e);

#ifdef Q_OS_MAC
// On modern macOS/Qt combinations, the code below causes Mumble's
// MainWindow to not be interactive after returning from being minimized.
// (See issue mumble-voip/mumble#2171)
// So, let's not do it on macOS.

#else
if (isMinimized() && qstiIcon->isSystemTrayAvailable() && Global::get().s.bHideInTray) {
// Workaround https://forum.qt.io/topic/4327/minimizing-application-to-tray/24
QTimer::singleShot(0, this, SLOT(hide()));
}
#endif
}

void MainWindow::keyPressEvent(QKeyEvent *e) {
Expand Down Expand Up @@ -809,43 +763,6 @@ void MainWindow::updateAudioToolTips() {
qaAudioDeaf->setToolTip(tr("Deafen yourself"));
}

void MainWindow::updateTrayIcon() {
ClientUser *p = ClientUser::get(Global::get().uiSession);

if (Global::get().s.bDeaf) {
qstiIcon->setIcon(qiIconDeafSelf);
} else if (p && p->bDeaf) {
qstiIcon->setIcon(qiIconDeafServer);
} else if (Global::get().s.bMute) {
qstiIcon->setIcon(qiIconMuteSelf);
} else if (p && p->bMute) {
qstiIcon->setIcon(qiIconMuteServer);
} else if (p && p->bSuppress) {
qstiIcon->setIcon(qiIconMuteSuppressed);
} else if (Global::get().s.bStateInTray && Global::get().bPushToMute) {
qstiIcon->setIcon(qiIconMutePushToMute);
} else if (p && Global::get().s.bStateInTray) {
switch (p->tsState) {
case Settings::Talking:
case Settings::MutedTalking:
qstiIcon->setIcon(qiTalkingOn);
break;
case Settings::Whispering:
qstiIcon->setIcon(qiTalkingWhisper);
break;
case Settings::Shouting:
qstiIcon->setIcon(qiTalkingShout);
break;
case Settings::Passive:
default:
qstiIcon->setIcon(qiTalkingOff);
break;
}
} else {
qstiIcon->setIcon(qiIcon);
}
}

void MainWindow::updateUserModel() {
UserModel *um = static_cast< UserModel * >(qtvUsers->model());
um->forceVisualUpdate();
Expand Down Expand Up @@ -1610,13 +1527,6 @@ void MainWindow::on_qmServer_aboutToShow() {
qmServer->addAction(qaServerUserList);
qmServer->addAction(qaServerBanList);
qmServer->addSeparator();
#if !defined(Q_OS_MAC)
// Don't add qaHide on macOS.
// There is no way to bring the window back (no 'tray' for Mumble on macOS),
// and the system has built-in hide functionality via Cmd-H.
if (qstiIcon->isSystemTrayAvailable())
qmServer->addAction(qaHide);
#endif
qmServer->addAction(qaQuit);

qaServerBanList->setEnabled(Global::get().pPermissions & (ChanACL::Ban | ChanACL::Write));
Expand Down Expand Up @@ -2129,10 +2039,6 @@ void MainWindow::on_qaUserInformation_triggered() {
Global::get().sh->requestUserStats(p->uiSession, false);
}

void MainWindow::on_qaHide_triggered() {
hide();
}

void MainWindow::on_qaQuit_triggered() {
forceQuit = true;
this->close();
Expand Down Expand Up @@ -2623,10 +2529,6 @@ void MainWindow::updateMenuPermissions() {
}

void MainWindow::userStateChanged() {
if (Global::get().s.bStateInTray) {
updateTrayIcon();
}

ClientUser *user = ClientUser::get(Global::get().uiSession);
if (!user) {
Global::get().bAttenuateOthers = false;
Expand Down Expand Up @@ -2697,7 +2599,6 @@ void MainWindow::on_qaAudioMute_triggered() {
}

updateAudioToolTips();
updateTrayIcon();
}

void MainWindow::setAudioMute(bool mute) {
Expand Down Expand Up @@ -2742,7 +2643,6 @@ void MainWindow::on_qaAudioDeaf_triggered() {
}

updateAudioToolTips();
updateTrayIcon();
}

void MainWindow::setAudioDeaf(bool deaf) {
Expand Down Expand Up @@ -2854,7 +2754,6 @@ void MainWindow::pttReleased() {

void MainWindow::on_PushToMute_triggered(bool down, QVariant) {
Global::get().bPushToMute = down;
updateTrayIcon();
updateUserModel();
}

Expand Down Expand Up @@ -3136,13 +3035,7 @@ void MainWindow::on_gsCycleTransmitMode_triggered(bool down, QVariant) {
}

void MainWindow::on_gsToggleMainWindowVisibility_triggered(bool down, QVariant) {
if (down) {
if (Global::get().mw->isVisible()) {
Global::get().mw->hide();
} else {
Global::get().mw->show();
}
}
// FIXME
}

void MainWindow::on_gsListenChannel_triggered(bool down, QVariant scdata) {
Expand Down Expand Up @@ -3477,7 +3370,6 @@ void MainWindow::serverDisconnected(QAbstractSocket::SocketError err, QString re
qaServerBanList->setEnabled(false);
qtvUsers->setCurrentIndex(QModelIndex());
qteChat->setEnabled(false);
updateTrayIcon();

#ifdef Q_OS_MAC
// Remove App Nap suppression now that we're disconnected.
Expand Down Expand Up @@ -3686,7 +3578,6 @@ void MainWindow::serverDisconnected(QAbstractSocket::SocketError err, QString re
}
}
}
qstiIcon->setToolTip(tr("Mumble -- %1").arg(Version::getRelease()));
AudioInput::setMaxBandwidth(-1);

if (Global::get().s.bMinimalView) {
Expand All @@ -3709,38 +3600,6 @@ void MainWindow::resolverError(QAbstractSocket::SocketError, QString reason) {
}
}

void MainWindow::trayAboutToShow() {
bool top = false;

QPoint p = qstiIcon->geometry().center();
if (p.isNull()) {
p = QCursor::pos();
}

QScreen *screen = Mumble::Screen::screenAt(p);
if (screen) {
QRect qr = screen->geometry();

if (p.y() < (qr.height() / 2))
top = true;

qmTray->clear();
if (top) {
qmTray->addAction(qaQuit);
qmTray->addAction(qaShow);
qmTray->addSeparator();
qmTray->addAction(qaAudioDeaf);
qmTray->addAction(qaAudioMute);
} else {
qmTray->addAction(qaAudioMute);
qmTray->addAction(qaAudioDeaf);
qmTray->addSeparator();
qmTray->addAction(qaShow);
qmTray->addAction(qaQuit);
}
}
}

void MainWindow::showRaiseWindow() {
if (isMinimized()) {
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
Expand All @@ -3751,21 +3610,6 @@ void MainWindow::showRaiseWindow() {
activateWindow();
}

void MainWindow::on_Icon_activated(QSystemTrayIcon::ActivationReason reason) {
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
case QSystemTrayIcon::MiddleClick:
if (isMinimized()) {
showRaiseWindow();
} else {
showMinimized();
}
default:
break;
}
}

void MainWindow::on_qaTalkingUIToggle_triggered() {
if (!Global::get().talkingUI) {
qCritical("MainWindow: Attempting to show Talking UI before it has been created!");
Expand Down Expand Up @@ -4140,7 +3984,6 @@ void MainWindow::openConfigDialog() {
if (dlg->exec() == QDialog::Accepted) {
setupView(false);
updateTransmitModeComboBox(Global::get().s.atTransmit);
updateTrayIcon();
updateUserModel();

if (Global::get().s.requireRestartToApply) {
Expand Down
Loading

0 comments on commit 4bcbcad

Please sign in to comment.