Skip to content

Commit

Permalink
Signal/Slot experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Jul 7, 2024
1 parent 9eba375 commit 1aa99c4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/mumble/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,7 @@ 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);
Global::get().trayIcon->highlight();
Global::get().mw->highlightWindow();
}

// Message notification with balloon tooltips
Expand Down
23 changes: 14 additions & 9 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ MainWindow::MainWindow(QWidget *p)
QObject::connect(this, &MainWindow::serverSynchronized, Global::get().pluginManager,
&PluginManager::on_serverSynchronized);

// Update tray icon when a server connection is established
// Set up initial client side talking state without the need for the user to do anything.
// This will, for example, make sure the correct status tray icon is used on connect.
QObject::connect(this, &MainWindow::serverSynchronized, this, &MainWindow::userStateChanged);

QAccessible::installFactory(AccessibleSlider::semanticSliderFactory);
Expand Down Expand Up @@ -721,7 +722,7 @@ void MainWindow::changeEvent(QEvent *e) {
// Unhighlight the tray icon when receiving focus
if (e->type() == QEvent::ActivationChange) {
if (isActiveWindow() && Global::get().trayIcon != nullptr) {
Global::get().trayIcon->unhighlight();
emit windowActivated();
}
return;
}
Expand Down Expand Up @@ -2554,7 +2555,7 @@ void MainWindow::updateMenuPermissions() {
}

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

ClientUser *user = ClientUser::get(Global::get().uiSession);
if (!user) {
Expand Down Expand Up @@ -2626,7 +2627,7 @@ void MainWindow::on_qaAudioMute_triggered() {
}

updateAudioToolTips();
Global::get().trayIcon->updateIcon();
emit talkingStatusChanged();
}

void MainWindow::setAudioMute(bool mute) {
Expand Down Expand Up @@ -2671,7 +2672,7 @@ void MainWindow::on_qaAudioDeaf_triggered() {
}

updateAudioToolTips();
Global::get().trayIcon->updateIcon();
emit talkingStatusChanged();
}

void MainWindow::setAudioDeaf(bool deaf) {
Expand Down Expand Up @@ -2784,7 +2785,7 @@ void MainWindow::pttReleased() {
void MainWindow::on_PushToMute_triggered(bool down, QVariant) {
Global::get().bPushToMute = down;
updateUserModel();
Global::get().trayIcon->updateIcon();
emit talkingStatusChanged();
}

void MainWindow::on_VolumeUp_triggered(bool down, QVariant) {
Expand Down Expand Up @@ -3394,7 +3395,6 @@ void MainWindow::serverDisconnected(QAbstractSocket::SocketError err, QString re
qaServerBanList->setEnabled(false);
qtvUsers->setCurrentIndex(QModelIndex());
qteChat->setEnabled(false);
Global::get().trayIcon->updateIcon();

#ifdef Q_OS_MAC
// Remove App Nap suppression now that we're disconnected.
Expand Down Expand Up @@ -3603,7 +3603,7 @@ void MainWindow::serverDisconnected(QAbstractSocket::SocketError err, QString re
qdwMinimalViewNote->show();
}

Global::get().trayIcon->updateIcon();
emit disconnectedFromServer();
}

void MainWindow::resolverError(QAbstractSocket::SocketError, QString reason) {
Expand Down Expand Up @@ -3631,6 +3631,11 @@ void MainWindow::showRaiseWindow() {
});
}

void MainWindow::highlightWindow() {
QApplication::alert(this);
emit windowHighlighted();
}

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 @@ -4007,7 +4012,7 @@ void MainWindow::openConfigDialog() {
showRaiseWindow();
updateTransmitModeComboBox(Global::get().s.atTransmit);
updateUserModel();
Global::get().trayIcon->updateIcon();
emit talkingStatusChanged();

if (Global::get().s.requireRestartToApply) {
if (Global::get().s.requireRestartToApply
Expand Down
10 changes: 10 additions & 0 deletions src/mumble/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindow {
void focusNextMainWidget();
QPair< QByteArray, QImage > openImageFile();

void highlightWindow();

void updateChatBar();
void openTextMessageDialog(ClientUser *p);
void openUserLocalNicknameDialog(const ClientUser &p);
Expand Down Expand Up @@ -390,6 +392,14 @@ public slots:
/// Signal emitted whenever a user removes a ChannelListener
void userRemovedChannelListener(ClientUser *user, Channel *channel);
void transmissionModeChanged(Settings::AudioTransmit newMode);
/// Signal emitted whenever the Mumble MainWindow regains the active state from the window manager
void windowActivated();
/// Signal emitted when the window manager is adviced to visually highlight the application
void windowHighlighted();
/// Signal emitted when the local user changes their talking status either actively or passively
void talkingStatusChanged();
/// Signal emitted when the connection was terminated and all cleanup code has been run
void disconnectedFromServer();

public:
MainWindow(QWidget *parent);
Expand Down
13 changes: 7 additions & 6 deletions src/mumble/widgets/TrayIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ TrayIcon::TrayIcon() : QSystemTrayIcon(Global::get().mw), m_statusIcon(Global::g

setToolTip("Mumble");

QObject::connect(Global::get().mw, &MainWindow::windowHighlighted, this, &TrayIcon::on_timer_triggered);
QObject::connect(Global::get().mw, &MainWindow::windowActivated, this, &TrayIcon::on_tray_unhighlight);
QObject::connect(Global::get().mw, &MainWindow::talkingStatusChanged, this, &TrayIcon::on_icon_update);
QObject::connect(Global::get().mw, &MainWindow::disconnectedFromServer, this, &TrayIcon::on_icon_update);

m_highlightTimer = new QTimer(this);
m_highlightTimer->setSingleShot(true);
QObject::connect(m_highlightTimer, &QTimer::timeout, this, &TrayIcon::on_timer_triggered);
Expand Down Expand Up @@ -44,7 +49,7 @@ TrayIcon::TrayIcon() : QSystemTrayIcon(Global::get().mw), m_statusIcon(Global::g
show();
}

void TrayIcon::updateIcon() {
void TrayIcon::on_icon_update() {
std::reference_wrapper< QIcon > newIcon = Global::get().mw->qiIcon;

ClientUser *p = ClientUser::get(Global::get().uiSession);
Expand Down Expand Up @@ -167,11 +172,7 @@ void TrayIcon::on_hideAction_triggered() {
updateContextMenu();
}

void TrayIcon::highlight() {
on_timer_triggered();
}

void TrayIcon::unhighlight() {
void TrayIcon::on_tray_unhighlight() {
if (m_highlightTimer == nullptr || !m_highlightTimer->isActive()) {
return;
}
Expand Down
7 changes: 3 additions & 4 deletions src/mumble/widgets/TrayIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ class TrayIcon : public QSystemTrayIcon {
public:
TrayIcon();

void updateIcon();
void toggleShowHide();
void highlight();
void unhighlight();

public slots:
void on_showAction_triggered();
void on_icon_update();
void on_tray_unhighlight();
void on_hideAction_triggered();
void on_showAction_triggered();

private:
std::reference_wrapper< QIcon > m_statusIcon;
Expand Down

0 comments on commit 1aa99c4

Please sign in to comment.