Add system beeps for message/mention receiving

This commit is contained in:
Jaidyn Ann 2021-08-18 20:19:11 -05:00
parent 901f7a8e05
commit f486588c48
5 changed files with 37 additions and 5 deletions

View File

@ -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.
*/

View File

@ -5,12 +5,14 @@
#include "Conversation.h"
#include <Beep.h>
#include <Catalog.h>
#include <DateTimeFormat.h>
#include <Locale.h>
#include <Notification.h>
#include <StringFormat.h>
#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))

View File

@ -8,10 +8,12 @@
#include "PreferencesNotifications.h"
#include <Box.h>
#include <Button.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <ControlLook.h>
#include <LayoutBuilder.h>
#include <Roster.h>
#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);
}

View File

@ -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 <View.h>
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

View File

@ -12,6 +12,7 @@
#include <Application.h>
#include <Alert.h>
#include <Beep.h>
#include <Catalog.h>
#include <LayoutBuilder.h>
#include <MenuBar.h>
@ -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();
}