From b1f79c292550c6a1742de6e2761420a9b2ecf2b0 Mon Sep 17 00:00:00 2001 From: lx-s Date: Wed, 28 Oct 2020 11:58:49 +0100 Subject: [PATCH] Added option to disable notifications. --- WinMute/QuietHoursDlg.cpp | 11 ++++++++++- WinMute/Settings.cpp | 3 +++ WinMute/Settings.h | 1 + WinMute/WinMute.cpp | 33 ++++++++++++++++++++++++--------- WinMute/WinMute.h | 1 + WinMute/res.rc | 9 +++++---- WinMute/resource.h | 2 ++ 7 files changed, 46 insertions(+), 14 deletions(-) diff --git a/WinMute/QuietHoursDlg.cpp b/WinMute/QuietHoursDlg.cpp index 7b3bad9..d9a9138 100644 --- a/WinMute/QuietHoursDlg.cpp +++ b/WinMute/QuietHoursDlg.cpp @@ -56,6 +56,7 @@ static bool SaveQuietHours( Settings *settings, const int enabled, const int forceUnmute, + const int showNotifications, const LPSYSTEMTIME start, const LPSYSTEMTIME end) { @@ -80,6 +81,7 @@ static bool SaveQuietHours( if (!settings->SetValue(SettingsKey::QUIETHOURS_ENABLE, enabled) || !settings->SetValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, forceUnmute) || + !settings->SetValue(SettingsKey::QUIETHOURS_NOTIFICATIONS, showNotifications) || !settings->SetValue(SettingsKey::QUIETHOURS_START, setStart) || !settings->SetValue(SettingsKey::QUIETHOURS_END, setEnd)) { TaskDialog( @@ -104,6 +106,7 @@ INT_PTR CALLBACK QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP case WM_INITDIALOG: { HWND hEnable = GetDlgItem(hDlg, IDC_ENABLEQUIETHOURS); HWND hForce = GetDlgItem(hDlg, IDC_FORCEUNMUTE); + HWND hNotify = GetDlgItem(hDlg, IDC_SHOWNOTIFICATIONS); HWND hStart = GetDlgItem(hDlg, IDC_QUIETHOURS_START); HWND hEnd = GetDlgItem(hDlg, IDC_QUIETHOURS_END); Settings *settings = reinterpret_cast(lParam); @@ -116,7 +119,11 @@ INT_PTR CALLBACK QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP DWORD qhForceUnmute = !!settings->QueryValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, FALSE); Button_SetCheck(hForce, qhForceUnmute ? BST_CHECKED : BST_UNCHECKED); + DWORD qhNotifications = !!settings->QueryValue(SettingsKey::QUIETHOURS_NOTIFICATIONS, FALSE); + Button_SetCheck(hNotify, qhNotifications ? BST_CHECKED : BST_UNCHECKED); + EnableWindow(hForce, qhEnabled); + EnableWindow(hNotify, qhEnabled); EnableWindow(hStart, qhEnabled); EnableWindow(hEnd, qhEnabled); @@ -146,6 +153,7 @@ INT_PTR CALLBACK QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP case WM_COMMAND: { HWND hEnable = GetDlgItem(hDlg, IDC_ENABLEQUIETHOURS); HWND hForce = GetDlgItem(hDlg, IDC_FORCEUNMUTE); + HWND hNotify = GetDlgItem(hDlg, IDC_SHOWNOTIFICATIONS); HWND hStart = GetDlgItem(hDlg, IDC_QUIETHOURS_START); HWND hEnd = GetDlgItem(hDlg, IDC_QUIETHOURS_END); if (LOWORD(wParam) == IDOK) { @@ -154,10 +162,11 @@ INT_PTR CALLBACK QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP Settings *settings = reinterpret_cast(GetWindowLongPtr(hDlg, GWLP_USERDATA)); int qhEnabled = Button_GetCheck(hEnable) == BST_CHECKED; int qhForceUnmute = Button_GetCheck(hForce) == BST_CHECKED; + int qhNotifications = Button_GetCheck(hNotify) == BST_CHECKED; DateTime_GetSystemtime(hStart, &start); DateTime_GetSystemtime(hEnd, &end); settings->SetValue(SettingsKey::QUIETHOURS_ENABLE, qhEnabled); - if (SaveQuietHours(settings, qhEnabled, qhForceUnmute, &start, &end)) { + if (SaveQuietHours(settings, qhEnabled, qhForceUnmute, qhNotifications, &start, &end)) { SendMessage(GetParent(hDlg), WM_WINMUTE_QUIETHOURS_CHANGE, 0, 0); EndDialog(hDlg, 0); } diff --git a/WinMute/Settings.cpp b/WinMute/Settings.cpp index aaf8a1f..22bda63 100644 --- a/WinMute/Settings.cpp +++ b/WinMute/Settings.cpp @@ -65,6 +65,9 @@ static LPCWSTR KeyToStr(SettingsKey key) case SettingsKey::QUIETHOURS_FORCEUNMUTE: keyStr = _T("QuietHoursForceUnmute"); break; + case SettingsKey::QUIETHOURS_NOTIFICATIONS: + keyStr = _T("QuietHoursNotifications"); + break; case SettingsKey::QUIETHOURS_START: keyStr = _T("QuietHoursStart"); break; diff --git a/WinMute/Settings.h b/WinMute/Settings.h index 56c213e..2a96321 100644 --- a/WinMute/Settings.h +++ b/WinMute/Settings.h @@ -44,6 +44,7 @@ enum class SettingsKey { , MUTE_ON_LOGOUT , QUIETHOURS_ENABLE , QUIETHOURS_FORCEUNMUTE + , QUIETHOURS_NOTIFICATIONS , QUIETHOURS_START , QUIETHOURS_END }; diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index f0c159d..3f81290 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -71,6 +71,7 @@ WinMute::MuteConfig::MuteConfig() this->quietHours.enabled = false; this->quietHours.forceUnmute = false; + this->quietHours.notifications = false; this->quietHours.start = 0; this->quietHours.end = 0; } @@ -223,6 +224,8 @@ bool WinMute::LoadDefaults() settings_.QueryValue(SettingsKey::QUIETHOURS_ENABLE, 0) != 0; muteConfig_.quietHours.forceUnmute = settings_.QueryValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, 0) != 0; + muteConfig_.quietHours.notifications = + settings_.QueryValue(SettingsKey::QUIETHOURS_NOTIFICATIONS, 0) != 0; muteConfig_.quietHours.start = settings_.QueryValue(SettingsKey::QUIETHOURS_START, 0); muteConfig_.quietHours.end = @@ -385,21 +388,27 @@ LRESULT CALLBACK WinMute::WindowProc( case WM_WINMUTE_QUIETHOURS_START: wsAlreadyMuted_ = audio_->IsMuted(); audio_->Mute(); - trayIcon_.ShowPopup( - _T("WinMute: Quiet hours started"), - _T("Your workstation audio is now muted")); + if (muteConfig_.quietHours.notifications) { + trayIcon_.ShowPopup( + _T("WinMute: Quiet hours started"), + _T("Your workstation audio is now muted")); + } return 0; case WM_WINMUTE_QUIETHOURS_END: if (wsAlreadyMuted_ && muteConfig_.quietHours.forceUnmute || !wsAlreadyMuted_) { audio_->UnMute(); - trayIcon_.ShowPopup( - _T("WinMute: Quiet Hours ended"), - _T("Your workstation audio has been restored.")); + if (muteConfig_.quietHours.notifications) { + trayIcon_.ShowPopup( + _T("WinMute: Quiet Hours ended"), + _T("Your workstation audio has been restored.")); + } } else { - trayIcon_.ShowPopup( - _T("WinMute: Quiet Hours ended"), - _T("Quiet hours ended, your workstation remains muted.")); + if (muteConfig_.quietHours.notifications) { + trayIcon_.ShowPopup( + _T("WinMute: Quiet Hours ended"), + _T("Quiet hours ended, your workstation remains muted.")); + } } return 0; case WM_WINMUTE_MUTE: { @@ -415,6 +424,12 @@ LRESULT CALLBACK WinMute::WindowProc( muteConfig_.quietHours.enabled = settings_.QueryValue( SettingsKey::QUIETHOURS_ENABLE, 0); + muteConfig_.quietHours.forceUnmute = settings_.QueryValue( + SettingsKey::QUIETHOURS_FORCEUNMUTE, + 0); + muteConfig_.quietHours.notifications = settings_.QueryValue( + SettingsKey::QUIETHOURS_NOTIFICATIONS, + 0); CheckMenuItem( hTrayMenu_, ID_TRAYMENU_CONFIGUREQUIETHOURS, diff --git a/WinMute/WinMute.h b/WinMute/WinMute.h index e53d5a8..e95ca37 100644 --- a/WinMute/WinMute.h +++ b/WinMute/WinMute.h @@ -75,6 +75,7 @@ private: struct { bool enabled; bool forceUnmute; + bool notifications; time_t start; time_t end; } quietHours; diff --git a/WinMute/res.rc b/WinMute/res.rc index 6484b81..ea20a9f 100644 --- a/WinMute/res.rc +++ b/WinMute/res.rc @@ -96,7 +96,7 @@ BEGIN "SysLink",WS_TABSTOP,119,35,36,13 END -IDD_QUIETHOURS DIALOGEX 0, 0, 201, 190 +IDD_QUIETHOURS DIALOGEX 0, 0, 201, 205 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Configure Quiet Hours" FONT 8, "MS Shell Dlg", 400, 0, 0x1 @@ -105,12 +105,13 @@ BEGIN CONTROL "",IDC_QUIETHOURS_START,"SysDateTimePick32",DTS_RIGHTALIGN | DTS_UPDOWN | WS_TABSTOP | 0x8,79,58,54,15 CONTROL "",IDC_QUIETHOURS_END,"SysDateTimePick32",DTS_RIGHTALIGN | DTS_UPDOWN | WS_TABSTOP | 0x8,79,80,54,15 CONTROL "Force unmute",IDC_FORCEUNMUTE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,31,102,60,10 - DEFPUSHBUTTON "Save",IDOK,63,165,50,14 - PUSHBUTTON "Cancel",IDCANCEL,123,165,50,14 + DEFPUSHBUTTON "Save",IDOK,63,174,50,14 + PUSHBUTTON "Cancel",IDCANCEL,123,174,50,14 LTEXT "If force unmute is enabled, WinMute will unmute your workstation when quiet hours end and not take into account if your workstation was already muted before quiet hours started.",IDC_STATIC,32,115,162,38 LTEXT "Start time:",IDC_STATIC,31,60,42,12 LTEXT "End time:",IDC_STATIC,31,82,43,12 LTEXT "During Quiet Hours WinMute automatically mutes your PC volumes and unmutes it afterwards.",IDC_STATIC,14,15,180,24 + CONTROL "Show notifications",IDC_SHOWNOTIFICATIONS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,32,153,74,10 END @@ -136,7 +137,7 @@ BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 194 TOPMARGIN, 7 - BOTTOMMARGIN, 183 + BOTTOMMARGIN, 198 END END #endif // APSTUDIO_INVOKED diff --git a/WinMute/resource.h b/WinMute/resource.h index cd00b1f..c8aaade 100644 --- a/WinMute/resource.h +++ b/WinMute/resource.h @@ -15,6 +15,8 @@ #define IDC_ENABLEQUIETHOURS 1003 #define IDC_QUIETHOURS_END 1004 #define IDC_FORCEUNMUTE 1005 +#define IDC_FORCEUNMUTE2 1006 +#define IDC_SHOWNOTIFICATIONS 1006 #define ID_TRAYMENU_INFO 40001 #define ID_TRAYMENU_EXIT 40002 #define ID_TRAYMENU_MUTEONLOCK 40003 -- 2.43.0