Skip to content

Commit

Permalink
Merge PR #6466: Complete rewrite of the tray icon implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt authored Jan 8, 2025
2 parents 8f6cbfa + cdab9ec commit 2aeb6cb
Show file tree
Hide file tree
Showing 61 changed files with 3,413 additions and 5,255 deletions.
6 changes: 2 additions & 4 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 Expand Up @@ -578,7 +580,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 +664,6 @@ else()
PRIVATE
"GlobalShortcut_unix.cpp"
"GlobalShortcut_unix.h"
"Log_unix.cpp"
"os_unix.cpp"
)

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

Expand Down Expand Up @@ -1116,7 +1115,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
13 changes: 7 additions & 6 deletions src/mumble/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ void Global::migrateDataDir(const QDir &toDir) {
}

Global::Global(const QString &qsConfigPath) {
mw = 0;
db = 0;
pluginManager = 0;
nam = 0;
c = 0;
talkingUI = 0;
mw = nullptr;
trayIcon = nullptr;
db = nullptr;
pluginManager = nullptr;
nam = nullptr;
c = nullptr;
talkingUI = nullptr;
uiSession = 0;
uiDoublePush = 1000000;
iPushToTalk = 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
71 changes: 49 additions & 22 deletions src/mumble/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ Log::Log(QObject *p) : QObject(p) {
#endif
uiLastId = 0;
qdDate = QDate::currentDate();

QObject::connect(this, &Log::highlightSpawned, Global::get().mw, &MainWindow::highlightWindow);
}

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

// 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]")));
plain = plain.replace("\xEF\xBF\xBC", tr("[embedded content]"));

QSystemTrayIcon::MessageIcon msgIcon = QSystemTrayIcon::NoIcon;
switch (mt) {
case DebugInfo:
case CriticalError:
msgIcon = QSystemTrayIcon::Critical;
break;
case Warning:
msgIcon = QSystemTrayIcon::Warning;
break;
case TextMessage:
case PrivateTextMessage:
msgIcon = QSystemTrayIcon::NoIcon;
break;
case Information:
case ServerConnected:
case ServerDisconnected:
case UserJoin:
case UserLeave:
case Recording:
case YouKicked:
case UserKicked:
case SelfMute:
case OtherSelfMute:
case YouMuted:
case YouMutedOther:
case OtherMutedOther:
case ChannelJoin:
case ChannelLeave:
case PermissionDenied:
case SelfUnmute:
case SelfDeaf:
case SelfUndeaf:
case UserRenamed:
case SelfChannelJoin:
case SelfChannelJoinOther:
case ChannelJoinConnect:
case ChannelLeaveDisconnect:
case ChannelListeningAdd:
case ChannelListeningRemove:
case PluginMessage:
msgIcon = QSystemTrayIcon::Information;
break;
}
emit notificationSpawned(msgName(mt), plain, msgIcon);
}
}

Expand Down Expand Up @@ -913,26 +960,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
10 changes: 8 additions & 2 deletions src/mumble/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef MUMBLE_MUMBLE_LOG_H_
#define MUMBLE_MUMBLE_LOG_H_

#include <QSystemTrayIcon>
#include <QtCore/QDate>
#include <QtCore/QMutex>
#include <QtCore/QVector>
Expand Down Expand Up @@ -133,8 +134,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 All @@ -158,6 +157,13 @@ public slots:
const QString &overrideTTS = QString(), bool ignoreTTS = false);
/// Logs LogMessages that have been deferred so far
void processDeferredLogs();

signals:
/// Signal emitted when there was a message received whose type was configured to spawn a notification
void notificationSpawned(QString title, QString body, QSystemTrayIcon::MessageIcon icon);

/// Signal emitted when there was a message received whose type was configured to highlight the application
void highlightSpawned();
};

class LogMessage {
Expand Down
63 changes: 0 additions & 63 deletions src/mumble/Log_macx.mm

This file was deleted.

68 changes: 0 additions & 68 deletions src/mumble/Log_unix.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions src/mumble/Log_win.cpp

This file was deleted.

11 changes: 8 additions & 3 deletions src/mumble/LookConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "SearchDialog.h"
#include "Global.h"

#include <QSystemTrayIcon>
#include <QtCore/QFileSystemWatcher>
#include <QtCore/QStack>
#include <QtCore/QTimer>
Expand All @@ -27,10 +28,14 @@ static ConfigRegistrar registrar(1100, LookConfigNew);
LookConfig::LookConfig(Settings &st) : ConfigWidget(st) {
setupUi(this);

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

#ifdef Q_OS_MAC
// Qt can not hide the window via the native macOS hide function. This should be re-evaluated with new Qt versions.
qcbHideTray->hide();
#endif

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

0 comments on commit 2aeb6cb

Please sign in to comment.