From f486588c48f299ef19752e0e28ddd95de0b5ebf0 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Wed, 18 Aug 2021 20:19:11 -0500 Subject: [PATCH] Add system beeps for message/mention receiving --- application/AppConstants.h | 3 +++ application/Conversation.cpp | 10 ++++++++++ .../preferences/PreferencesNotifications.cpp | 19 +++++++++++++++---- .../preferences/PreferencesNotifications.h | 6 +++++- application/windows/MainWindow.cpp | 4 ++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/application/AppConstants.h b/application/AppConstants.h index 62e7ca6..70080a0 100644 --- a/application/AppConstants.h +++ b/application/AppConstants.h @@ -19,6 +19,9 @@ const rgb_color APP_BLACK_COLOR = {0, 0, 0, 255}; const rgb_color APP_SELSTART_COLOR = {254, 150, 57}; const rgb_color APP_SELEND_COLOR = {230, 113, 9}; +#define APP_MENTION_BEEP "Chat-o-Matic mention" +#define APP_MESSAGE_BEEP "Chat-o-Matic message" + /** * Miscellaneous. */ diff --git a/application/Conversation.cpp b/application/Conversation.cpp index 44dcef0..a12e8f7 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -5,12 +5,14 @@ #include "Conversation.h" +#include #include #include #include #include #include +#include "AppConstants.h" #include "AppPreferences.h" #include "Cardie.h" #include "ChatProtocolMessages.h" @@ -94,6 +96,14 @@ Conversation::ImMessage(BMessage* msg) && text.IFindFirst(contact->GetName()) != B_ERROR) || (text.IFindFirst(contact->GetId()) != B_ERROR)); + // Sound the bell, if appropriate + if (mentioned == true && winFocused == false + && AppPreferences::Get()->SoundOnMention == true) + system_beep(APP_MENTION_BEEP); + else if (winFocused == false && (fUsers.CountItems() <= 2) + && AppPreferences::Get()->SoundOnMessageReceived == true) + system_beep(APP_MESSAGE_BEEP); + // Send a notification, if appropriate if (winFocused == false && AppPreferences::Get()->NotifyNewMessage && (fUsers.CountItems() <= 2 || mentioned == true)) diff --git a/application/preferences/PreferencesNotifications.cpp b/application/preferences/PreferencesNotifications.cpp index f58a47b..2cd4f51 100644 --- a/application/preferences/PreferencesNotifications.cpp +++ b/application/preferences/PreferencesNotifications.cpp @@ -8,10 +8,12 @@ #include "PreferencesNotifications.h" #include +#include #include #include #include #include +#include #include "AppPreferences.h" @@ -25,6 +27,7 @@ const uint32 kNotifyContactStatus = 'NTcl'; const uint32 kNotifyNewMessage = 'NTms'; const uint32 kSoundOnMessageReceived = 'Fmsn'; const uint32 kSoundOnMention = 'FMsn'; +const uint32 kEditSounds = 'HKsn'; PreferencesNotifications::PreferencesNotifications() @@ -50,12 +53,15 @@ PreferencesNotifications::PreferencesNotifications() soundsBox->SetLabel(B_TRANSLATE("Sounds")); fSoundOnMessageReceived = new BCheckBox("SoundOnMessageReceived", - B_TRANSLATE("Sound on message received"), NULL); - fSoundOnMessageReceived->SetEnabled(false); // wow that's a lot + B_TRANSLATE("Sound on message received"), + new BMessage(kSoundOnMessageReceived)); fSoundOnMention = new BCheckBox("SoundOnMention", - B_TRANSLATE("Sound when mentioned"), NULL); - fSoundOnMention->SetEnabled(false); // wow that's a lot + B_TRANSLATE("Sound when mentioned"), + new BMessage(kSoundOnMention)); + + fSoundsButton = new BButton("EditSoundsButton", + B_TRANSLATE("Edit sounds" B_UTF8_ELLIPSIS), new BMessage(kEditSounds)); const float spacing = be_control_look->DefaultItemSpacing(); @@ -71,6 +77,7 @@ PreferencesNotifications::PreferencesNotifications() .SetInsets(spacing, spacing * 2, spacing, spacing) .Add(fSoundOnMessageReceived) .Add(fSoundOnMention) + .Add(fSoundsButton) .End(); BLayoutBuilder::Group<>(this, B_VERTICAL) @@ -90,6 +97,7 @@ PreferencesNotifications::AttachedToWindow() fNotifyNewMessage->SetTarget(this); fSoundOnMessageReceived->SetTarget(this); fSoundOnMention->SetTarget(this); + fSoundsButton->SetTarget(this); fNotifyProtocols->SetValue( AppPreferences::Get()->NotifyProtocolStatus); @@ -128,6 +136,9 @@ PreferencesNotifications::MessageReceived(BMessage* message) AppPreferences::Get()->SoundOnMention = fSoundOnMention->Value(); break; + case kEditSounds: + BRoster().Launch("application/x-vnd.haiku-Sounds"); + break; default: BView::MessageReceived(message); } diff --git a/application/preferences/PreferencesNotifications.h b/application/preferences/PreferencesNotifications.h index 2adb983..0396651 100644 --- a/application/preferences/PreferencesNotifications.h +++ b/application/preferences/PreferencesNotifications.h @@ -1,6 +1,7 @@ /* * Copyright 2010, Oliver Ruiz Dorantes. All rights reserved. * Copyright 2012, Dario Casalinuovo. All rights reserved. + * Copyright 2021, Jaidyn Levesque. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _PREFERENCES_NOTIFICATIONS_H @@ -8,6 +9,7 @@ #include +class BButton; class BCheckBox; class PreferencesNotifications : public BView { @@ -23,6 +25,8 @@ private: BCheckBox* fNotifyNewMessage; BCheckBox* fSoundOnMessageReceived; BCheckBox* fSoundOnMention; + + BButton* fSoundsButton; }; -#endif // _PREFERENCES_BEHAVIOR_H +#endif // _PREFERENCES_NOTIFICATIONS_H diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index 60807bc..cf3547e 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -63,6 +64,9 @@ MainWindow::MainWindow() _InitInterface(); + add_system_beep_event(APP_MENTION_BEEP); + add_system_beep_event(APP_MESSAGE_BEEP); + //TODO check for errors here ReplicantStatusView::InstallReplicant(); }