Skip to content

Commit

Permalink
Add new tray icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Jun 7, 2024
1 parent 7ab59a3 commit 8d3c4c5
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/mumble/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ set(MUMBLE_SOURCES
"widgets/SearchDialogTree.h"
"widgets/SemanticSlider.cpp"
"widgets/SemanticSlider.h"
"widgets/TrayIcon.cpp"
"widgets/TrayIcon.h"


"${SHARED_SOURCE_DIR}/ACL.cpp"
Expand Down
1 change: 1 addition & 0 deletions src/mumble/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void Global::migrateDataDir(const QDir &toDir) {

Global::Global(const QString &qsConfigPath) {
mw = 0;
trayIcon = 0;
db = 0;
pluginManager = 0;
nam = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/mumble/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class OverlayClient;
class LogEmitter;
class DeveloperConsole;
class TalkingUI;
class TrayIcon;

class QNetworkAccessManager;

Expand All @@ -50,6 +51,7 @@ struct Global Q_DECL_FINAL {
static Global &get();

MainWindow *mw;
TrayIcon *trayIcon;
Settings s;
boost::shared_ptr< ServerHandler > sh;
boost::shared_ptr< AudioInput > ai;
Expand Down
23 changes: 17 additions & 6 deletions src/mumble/Log_unix.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
// Copyright 2012-2023 The Mumble Developers. All rights reserved.
// Copyright 2012-2024 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "Log.h"
#include "MainWindow.h"
#include "Settings.h"

#include <QDBusInterface>
#include "Global.h"
#include "widgets/TrayIcon.h"

void Log::postNotification(MsgType mt, const QString &plain) {
// FIXME
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().trayIcon->showMessage(msgName(mt), plain, msgIcon);
}
19 changes: 17 additions & 2 deletions src/mumble/Log_win.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
// Copyright 2012-2023 The Mumble Developers. All rights reserved.
// Copyright 2012-2024 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "Log.h"
#include "Global.h"
#include "widgets/TrayIcon.h"

void Log::postNotification(MsgType mt, const QString &plain) {
// FIXME
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().trayIcon->showMessage(msgName(mt), plain, msgIcon);
}
3 changes: 3 additions & 0 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include <QtWidgets/QWhatsThis>

#include "widgets/SemanticSlider.h"
#include "widgets/TrayIcon.h"

#ifdef Q_OS_WIN
# include <dbt.h>
Expand Down Expand Up @@ -2536,6 +2537,8 @@ void MainWindow::updateMenuPermissions() {
}

void MainWindow::userStateChanged() {
Global::get().trayIcon->updateIcon();

ClientUser *user = ClientUser::get(Global::get().uiSession);
if (!user) {
Global::get().bAttenuateOthers = false;
Expand Down
4 changes: 4 additions & 0 deletions src/mumble/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#include "VersionCheck.h"
#include "Global.h"

#include "widgets/TrayIcon.h"

#include <QLocale>
#include <QScreen>
#include <QtCore/QProcess>
Expand Down Expand Up @@ -684,6 +686,8 @@ int main(int argc, char **argv) {
Global::get().mw = new MainWindow(nullptr);
Global::get().mw->show();

Global::get().trayIcon = new TrayIcon(Global::get().mw);

Global::get().talkingUI = new TalkingUI();

// Set TalkingUI's position
Expand Down
75 changes: 75 additions & 0 deletions src/mumble/widgets/TrayIcon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2024 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "TrayIcon.h"

#include "../ClientUser.h"
#include "../Global.h"
#include "../MainWindow.h"

#include <QDebug>

TrayIcon::TrayIcon(QObject *parent) : QSystemTrayIcon(parent), m_statusIcon(nullptr) {
setIcon(Global::get().mw->qiIcon);
setToolTip("Mumble");
show();
}

void TrayIcon::updateIcon() {
QIcon *newIcon = nullptr;

ClientUser *p = ClientUser::get(Global::get().uiSession);

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

if (newIcon != m_statusIcon) {
m_statusIcon = newIcon;
setIcon(*m_statusIcon);
}
}

void TrayIcon::on_icon_clicked(QSystemTrayIcon::ActivationReason reason) {
qDebug() << reason;
switch (reason) {
case QSystemTrayIcon::Unknown:
case QSystemTrayIcon::Context:
case QSystemTrayIcon::DoubleClick:
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::MiddleClick:
default:
break;
}
}
25 changes: 25 additions & 0 deletions src/mumble/widgets/TrayIcon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#ifndef MUMBLE_MUMBLE_WIDGETS_TRAYICCON_H_
#define MUMBLE_MUMBLE_WIDGETS_TRAYICCON_H_

#include <QtWidgets/QSystemTrayIcon>

class TrayIcon : public QSystemTrayIcon {
Q_OBJECT

public:
TrayIcon(QObject *parent);

void updateIcon();

private:
QIcon *m_statusIcon;

void on_icon_clicked(QSystemTrayIcon::ActivationReason reason);
};

#endif // MUMBLE_MUMBLE_WIDGETS_TRAYICCON_H_

0 comments on commit 8d3c4c5

Please sign in to comment.