Skip to content

Commit

Permalink
Allow muting notifications for a window
Browse files Browse the repository at this point in the history
In the chat options. Turns off sound effects, net status popups and
attention demands of the window.
  • Loading branch information
askmeaboutlo0m committed Aug 11, 2023
1 parent 9e71085 commit 4ec27d6
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Unreleased Version 2.2.0-pre
* Feature: Mark window when a chat message is received. On Windows, this makes the icon in the task bar orange. On macOS, it supposedly bounces an icon somewhere. On other platforms it probably does something similar, indicating which window is the one that got a message ready. Thanks Radio for suggesting.
* Fix: Don't add current color to the palette when creating it. Thanks xxxx for reporting.
* Fix: Make exported palettes not start using the exported location to save changes to. Thanks xxxx for reporting.
* Feature: Allow muting notifications for a window. Thanks Blozzom for suggesting.

2023-07-31 Version 2.2.0-beta.6
* Fix: Don't forget account password when entering a wrong session password.
Expand Down
1 change: 1 addition & 0 deletions src/desktop/chat/chatbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ ChatBox::ChatBox(Document *doc, QWidget *parent)
emit expandPlease();
}
});
connect(m_chatWidget, &ChatWidget::muteChanged, this, &ChatBox::muteChanged);

connect(doc, &Document::canvasChanged, this, &ChatBox::onCanvasChanged);
connect(doc, &Document::serverLoggedIn, this, &ChatBox::onServerLogin);
Expand Down
2 changes: 2 additions & 0 deletions src/desktop/chat/chatbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ private slots:
//! Detached chat box should be re-attached and reparented (or it will be destroyed)
void reattachNowPlease();

void muteChanged(bool muted);

protected:
void resizeEvent(QResizeEvent *event) override;

Expand Down
20 changes: 16 additions & 4 deletions src/desktop/chat/chatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "desktop/chat/chatwidget.h"
#include "libclient/utils/html.h"
#include "libclient/utils/funstuff.h"
#include "desktop/notifications.h"
#include "desktop/main.h"

#include "libclient/canvas/userlist.h"
Expand Down Expand Up @@ -86,6 +85,7 @@ struct ChatWidget::Private {
QAction *compactAction = nullptr;
QAction *attachAction = nullptr;
QAction *detachAction = nullptr;
QAction *muteAction = nullptr;

QList<int> announcedUsers;
canvas::UserListModel *userlist = nullptr;
Expand Down Expand Up @@ -200,6 +200,11 @@ ChatWidget::ChatWidget(QWidget *parent)
tr("Detach"), this, &ChatWidget::detachRequested);
}

d->muteAction = d->externalMenu->addAction(
tr("Mute notifications"), this, &ChatWidget::muteChanged);
d->muteAction->setStatusTip(tr("Toggle notifications for this window"));
d->muteAction->setCheckable(true);

connect(d->externalMenu, &QMenu::aboutToShow, this, &ChatWidget::contextMenuAboutToShow);

setPreserveMode(false);
Expand Down Expand Up @@ -551,7 +556,7 @@ void ChatWidget::userJoined(int id, const QString &name)
d->scrollChatToEnd(id);
}

notification::playSound(notification::Event::LOGIN);
playSound(notification::Event::LOGIN);
}

void ChatWidget::userParted(int id)
Expand All @@ -571,7 +576,7 @@ void ChatWidget::userParted(int id)

d->announcedUsers.removeAll(id);

notification::playSound(notification::Event::LOGOUT);
playSound(notification::Event::LOGOUT);
}

void ChatWidget::kicked(const QString &kickedBy)
Expand Down Expand Up @@ -630,7 +635,7 @@ void ChatWidget::receiveMessage(int sender, int recipient, uint8_t tflags, uint8
}

if(!d->myline->hasFocus() || chatId != d->currentChat || isValidAlert)
notification::playSound(notification::Event::CHAT);
playSound(notification::Event::CHAT);

if(wasAtEnd || isValidAlert) {
d->scrollChatToEnd(chatId);
Expand Down Expand Up @@ -875,4 +880,11 @@ void ChatWidget::resizeEvent(QResizeEvent *)
}
}

void ChatWidget::playSound(notification::Event event)
{
if(!d->muteAction->isChecked()) {
notification::playSound(event);
}
}

}
4 changes: 4 additions & 0 deletions src/desktop/chat/chatwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef CHATWIDGET_H
#define CHATWIDGET_H

#include "desktop/notifications.h"
#include <QWidget>

class QMenu;
Expand Down Expand Up @@ -82,6 +83,7 @@ private slots:
void message(const drawdance::Message &msg);
void detachRequested();
void expandRequested();
void muteChanged(bool muted);

private:
#ifdef Q_OS_ANDROID
Expand All @@ -95,6 +97,8 @@ private slots:
static constexpr bool ALLOW_DETACH = true;
#endif

void playSound(notification::Event event);

struct Private;
Private *d;
};
Expand Down
20 changes: 15 additions & 5 deletions src/desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ MainWindow::MainWindow(bool restoreWindowPosition)
m_tempToolSwitchShortcut(nullptr),
m_titleBarsHidden(false),
m_wasSessionLocked(false),
m_notificationsMuted(false),
m_doc(nullptr),
m_exitAfterSave(false)
{
Expand Down Expand Up @@ -516,7 +517,7 @@ void MainWindow::onCanvasChanged(canvas::CanvasModel *canvas)
connect(canvas->paintEngine(), &canvas::PaintEngine::undoDepthLimitSet, this, &MainWindow::onUndoDepthLimitSet);

connect(canvas, &canvas::CanvasModel::chatMessageReceived, this, [this]() {
if(dpApp().settings().notificationChat()) {
if(dpApp().settings().notificationChat() && !m_notificationsMuted) {
// Demand attention if the window isn't focused.
QApplication::alert(this);
}
Expand Down Expand Up @@ -2037,10 +2038,12 @@ void MainWindow::updateLockWidget()
lock.setFlag(Lock::Canvas);
}

if(sessionLocked && !m_wasSessionLocked) {
notification::playSound(notification::Event::LOCKED);
} else if(!sessionLocked && m_wasSessionLocked) {
notification::playSound(notification::Event::UNLOCKED);
if(!m_notificationsMuted) {
if(sessionLocked && !m_wasSessionLocked) {
notification::playSound(notification::Event::LOCKED);
} else if(!sessionLocked && m_wasSessionLocked) {
notification::playSound(notification::Event::UNLOCKED);
}
}
m_wasSessionLocked = sessionLocked;

Expand Down Expand Up @@ -2287,6 +2290,12 @@ void MainWindow::setDockTitleBarsHidden(bool hidden)
}
}

void MainWindow::setNotificationsMuted(bool muted)
{
m_notificationsMuted = muted;
m_netstatus->setNotificationsMuted(muted);
}

/**
* User selected a tool
* @param tool action representing the tool
Expand Down Expand Up @@ -3242,6 +3251,7 @@ void MainWindow::setupActions()
m_splitter->setSizes(sizes);
m_saveSplitterDebounce.start();
});
connect(m_chatbox, &widgets::ChatBox::muteChanged, this, &MainWindow::setNotificationsMuted);

connect(moveleft, &QAction::triggered, m_view, [this] {
m_view->moveStep(widgets::CanvasView::Direction::Left);
Expand Down
2 changes: 2 additions & 0 deletions src/desktop/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ private slots:
void setFreezeDocks(bool freeze);
void setDocksHidden(bool hidden);
void setDockTitleBarsHidden(bool hidden);
void setNotificationsMuted(bool muted);

void updateTitle();

Expand Down Expand Up @@ -316,6 +317,7 @@ private slots:
ShortcutDetector *m_tempToolSwitchShortcut;
bool m_titleBarsHidden;
bool m_wasSessionLocked;
bool m_notificationsMuted;

Document *m_doc;
MainActions *m_ma;
Expand Down
7 changes: 4 additions & 3 deletions src/desktop/widgets/netstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,10 @@ void NetStatus::kicked(const QString& user)

void NetStatus::message(const QString &msg)
{
m_popup->showMessage(
mapToGlobal(m_label->pos() + QPoint(m_label->width()/2, 2)),
msg);
if(!m_notificationsMuted) {
m_popup->showMessage(
mapToGlobal(m_label->pos() + QPoint(m_label->width() / 2, 2)), msg);
}
}

void NetStatus::updateLabel()
Expand Down
4 changes: 4 additions & 0 deletions src/desktop/widgets/netstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Q_OBJECT
const QUrl &sessionUrl() const { return m_sessionUrl; }
QString joinPassword() const { return m_haveJoinPassword ? m_joinPassword : QString{}; }

void setNotificationsMuted(bool muted) { m_notificationsMuted = muted; }

signals:
void remoteAddressDiscovered();

Expand Down Expand Up @@ -113,6 +115,8 @@ private slots:
quint64 _sentbytes, _recvbytes, _lag;

QScopedPointer<const QSslCertificate> m_certificate;

bool m_notificationsMuted;
};

}
Expand Down

0 comments on commit 4ec27d6

Please sign in to comment.