Skip to content

Commit 2aeb6cb

Browse files
authored
Merge PR #6466: Complete rewrite of the tray icon implementation
2 parents 8f6cbfa + cdab9ec commit 2aeb6cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3413
-5255
lines changed

src/mumble/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ set(MUMBLE_SOURCES
309309
"widgets/SearchDialogTree.h"
310310
"widgets/SemanticSlider.cpp"
311311
"widgets/SemanticSlider.h"
312+
"widgets/TrayIcon.cpp"
313+
"widgets/TrayIcon.h"
312314

313315

314316
"${SHARED_SOURCE_DIR}/ACL.cpp"
@@ -578,7 +580,6 @@ if(WIN32)
578580
target_sources(mumble_client_object_lib PRIVATE
579581
"GlobalShortcut_win.cpp"
580582
"GlobalShortcut_win.h"
581-
"Log_win.cpp"
582583
"SharedMemory_win.cpp"
583584
"TaskList.cpp"
584585
"UserLockFile_win.cpp"
@@ -663,7 +664,6 @@ else()
663664
PRIVATE
664665
"GlobalShortcut_unix.cpp"
665666
"GlobalShortcut_unix.h"
666-
"Log_unix.cpp"
667667
"os_unix.cpp"
668668
)
669669

@@ -687,7 +687,6 @@ else()
687687
"AppNap.mm"
688688
"GlobalShortcut_macx.h"
689689
"GlobalShortcut_macx.mm"
690-
"Log_macx.mm"
691690
"os_macx.mm"
692691
)
693692

@@ -1116,7 +1115,6 @@ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
11161115
set_source_files_properties(
11171116
"AppNap.mm"
11181117
"GlobalShortcut_macx.mm"
1119-
"Log_macx.mm"
11201118
"os_macx.mm"
11211119
"TextToSpeech_macx.mm"
11221120
"Overlay_macx.mm"

src/mumble/Global.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,13 @@ void Global::migrateDataDir(const QDir &toDir) {
9292
}
9393

9494
Global::Global(const QString &qsConfigPath) {
95-
mw = 0;
96-
db = 0;
97-
pluginManager = 0;
98-
nam = 0;
99-
c = 0;
100-
talkingUI = 0;
95+
mw = nullptr;
96+
trayIcon = nullptr;
97+
db = nullptr;
98+
pluginManager = nullptr;
99+
nam = nullptr;
100+
c = nullptr;
101+
talkingUI = nullptr;
101102
uiSession = 0;
102103
uiDoublePush = 1000000;
103104
iPushToTalk = 0;

src/mumble/Global.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class OverlayClient;
3434
class LogEmitter;
3535
class DeveloperConsole;
3636
class TalkingUI;
37+
class TrayIcon;
3738

3839
class QNetworkAccessManager;
3940

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

5253
MainWindow *mw;
54+
TrayIcon *trayIcon;
5355
Settings s;
5456
boost::shared_ptr< ServerHandler > sh;
5557
boost::shared_ptr< AudioInput > ai;

src/mumble/Log.cpp

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ Log::Log(QObject *p) : QObject(p) {
421421
#endif
422422
uiLastId = 0;
423423
qdDate = QDate::currentDate();
424+
425+
QObject::connect(this, &Log::highlightSpawned, Global::get().mw, &MainWindow::highlightWindow);
424426
}
425427

426428
// Display order in settingsscreen, allows to insert new events without breaking config-compatibility with older
@@ -812,13 +814,58 @@ void Log::log(MsgType mt, const QString &console, const QString &terse, bool own
812814
if (!(Global::get().mw->isActiveWindow() && Global::get().mw->qdwLog->isVisible())) {
813815
// Message notification with window highlight
814816
if (flags & Settings::LogHighlight) {
815-
QApplication::alert(Global::get().mw);
817+
emit highlightSpawned();
816818
}
817819

818820
// Message notification with balloon tooltips
819821
if (flags & Settings::LogBalloon) {
820822
// Replace any instances of a "Object Replacement Character" from QTextDocumentFragment::toPlainText
821-
postNotification(mt, plain.replace("\xEF\xBF\xBC", tr("[embedded content]")));
823+
plain = plain.replace("\xEF\xBF\xBC", tr("[embedded content]"));
824+
825+
QSystemTrayIcon::MessageIcon msgIcon = QSystemTrayIcon::NoIcon;
826+
switch (mt) {
827+
case DebugInfo:
828+
case CriticalError:
829+
msgIcon = QSystemTrayIcon::Critical;
830+
break;
831+
case Warning:
832+
msgIcon = QSystemTrayIcon::Warning;
833+
break;
834+
case TextMessage:
835+
case PrivateTextMessage:
836+
msgIcon = QSystemTrayIcon::NoIcon;
837+
break;
838+
case Information:
839+
case ServerConnected:
840+
case ServerDisconnected:
841+
case UserJoin:
842+
case UserLeave:
843+
case Recording:
844+
case YouKicked:
845+
case UserKicked:
846+
case SelfMute:
847+
case OtherSelfMute:
848+
case YouMuted:
849+
case YouMutedOther:
850+
case OtherMutedOther:
851+
case ChannelJoin:
852+
case ChannelLeave:
853+
case PermissionDenied:
854+
case SelfUnmute:
855+
case SelfDeaf:
856+
case SelfUndeaf:
857+
case UserRenamed:
858+
case SelfChannelJoin:
859+
case SelfChannelJoinOther:
860+
case ChannelJoinConnect:
861+
case ChannelLeaveDisconnect:
862+
case ChannelListeningAdd:
863+
case ChannelListeningRemove:
864+
case PluginMessage:
865+
msgIcon = QSystemTrayIcon::Information;
866+
break;
867+
}
868+
emit notificationSpawned(msgName(mt), plain, msgIcon);
822869
}
823870
}
824871

@@ -913,26 +960,6 @@ void Log::processDeferredLogs() {
913960
}
914961
}
915962

916-
// Post a notification using the MainWindow's QSystemTrayIcon.
917-
void Log::postQtNotification(MsgType mt, const QString &plain) {
918-
if (Global::get().mw->qstiIcon->isSystemTrayAvailable() && Global::get().mw->qstiIcon->supportsMessages()) {
919-
QSystemTrayIcon::MessageIcon msgIcon;
920-
switch (mt) {
921-
case DebugInfo:
922-
case CriticalError:
923-
msgIcon = QSystemTrayIcon::Critical;
924-
break;
925-
case Warning:
926-
msgIcon = QSystemTrayIcon::Warning;
927-
break;
928-
default:
929-
msgIcon = QSystemTrayIcon::Information;
930-
break;
931-
}
932-
Global::get().mw->qstiIcon->showMessage(msgName(mt), plain, msgIcon);
933-
}
934-
}
935-
936963
LogMessage::LogMessage(Log::MsgType mt, const QString &console, const QString &terse, bool ownMessage,
937964
const QString &overrideTTS, bool ignoreTTS)
938965
: mt(mt), console(console), terse(terse), ownMessage(ownMessage), overrideTTS(overrideTTS), ignoreTTS(ignoreTTS) {

src/mumble/Log.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef MUMBLE_MUMBLE_LOG_H_
77
#define MUMBLE_MUMBLE_LOG_H_
88

9+
#include <QSystemTrayIcon>
910
#include <QtCore/QDate>
1011
#include <QtCore/QMutex>
1112
#include <QtCore/QVector>
@@ -133,8 +134,6 @@ class Log : public QObject {
133134
unsigned int uiLastId;
134135
QDate qdDate;
135136
static const QStringList allowedSchemes();
136-
void postNotification(MsgType mt, const QString &plain);
137-
void postQtNotification(MsgType mt, const QString &plain);
138137

139138
public:
140139
Log(QObject *p = nullptr);
@@ -158,6 +157,13 @@ public slots:
158157
const QString &overrideTTS = QString(), bool ignoreTTS = false);
159158
/// Logs LogMessages that have been deferred so far
160159
void processDeferredLogs();
160+
161+
signals:
162+
/// Signal emitted when there was a message received whose type was configured to spawn a notification
163+
void notificationSpawned(QString title, QString body, QSystemTrayIcon::MessageIcon icon);
164+
165+
/// Signal emitted when there was a message received whose type was configured to highlight the application
166+
void highlightSpawned();
161167
};
162168

163169
class LogMessage {

src/mumble/Log_macx.mm

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/mumble/Log_unix.cpp

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/mumble/Log_win.cpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/mumble/LookConfig.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "SearchDialog.h"
1313
#include "Global.h"
1414

15+
#include <QSystemTrayIcon>
1516
#include <QtCore/QFileSystemWatcher>
1617
#include <QtCore/QStack>
1718
#include <QtCore/QTimer>
@@ -27,10 +28,14 @@ static ConfigRegistrar registrar(1100, LookConfigNew);
2728
LookConfig::LookConfig(Settings &st) : ConfigWidget(st) {
2829
setupUi(this);
2930

30-
#ifndef Q_OS_MAC
31-
if (!QSystemTrayIcon::isSystemTrayAvailable())
32-
#endif
31+
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
3332
qgbTray->hide();
33+
}
34+
35+
#ifdef Q_OS_MAC
36+
// Qt can not hide the window via the native macOS hide function. This should be re-evaluated with new Qt versions.
37+
qcbHideTray->hide();
38+
#endif
3439

3540
qcbLanguage->addItem(tr("System default"));
3641
QDir d(QLatin1String(":"), QLatin1String("mumble_*.qm"), QDir::Name, QDir::Files);

0 commit comments

Comments
 (0)