diff --git a/Tomighty.Core/IMutableUserPreferences.cs b/Tomighty.Core/IMutableUserPreferences.cs index cc97d4c..bfba7de 100644 --- a/Tomighty.Core/IMutableUserPreferences.cs +++ b/Tomighty.Core/IMutableUserPreferences.cs @@ -11,6 +11,7 @@ public interface IMutableUserPreferences : IUserPreferences { void SetIntervalDuration(IntervalType intervalType, Duration duration); new bool ShowToastNotifications { get; set; } + new bool PlaySoundNotifications { get; set; } new int MaxPomodoroCount { get; set; } } } diff --git a/Tomighty.Core/IUserPreferences.cs b/Tomighty.Core/IUserPreferences.cs index dd88191..0c1fca1 100644 --- a/Tomighty.Core/IUserPreferences.cs +++ b/Tomighty.Core/IUserPreferences.cs @@ -14,6 +14,7 @@ public interface IUserPreferences Duration GetIntervalDuration(IntervalType intervalType); int MaxPomodoroCount { get; } bool ShowToastNotifications { get; } + bool PlaySoundNotifications { get; } void Update(Action action); } diff --git a/Tomighty.Windows/Notifications/SoundNotificationPlayer.cs b/Tomighty.Windows/Notifications/SoundNotificationPlayer.cs new file mode 100644 index 0000000..4b70fd0 --- /dev/null +++ b/Tomighty.Windows/Notifications/SoundNotificationPlayer.cs @@ -0,0 +1,25 @@ +using System.Media; +using Tomighty.Events; + +namespace Tomighty.Windows.Notifications +{ + public class SoundNotificationPlayer + { + private readonly IUserPreferences userPreferences; + private readonly SoundPlayer intervalCompletedNotification = new SoundPlayer(Properties.Resources.audio_deskbell); + + public SoundNotificationPlayer(IUserPreferences userPreferences, IEventHub eventHub) + { + this.userPreferences = userPreferences; + eventHub.Subscribe(OnTimerStopped); + } + + private void OnTimerStopped(TimerStopped @event) + { + if (@event.IsIntervalCompleted && userPreferences.PlaySoundNotifications) + { + intervalCompletedNotification.Play(); + } + } + } +} diff --git a/Tomighty.Windows/Preferences/UserPreferences.cs b/Tomighty.Windows/Preferences/UserPreferences.cs index e69fabd..e688420 100644 --- a/Tomighty.Windows/Preferences/UserPreferences.cs +++ b/Tomighty.Windows/Preferences/UserPreferences.cs @@ -40,7 +40,8 @@ private static Values GetDefaultValues() ShortBreakDuration = Duration.InMinutes(5).Seconds, LongBreakDuration = Duration.InMinutes(15).Seconds, MaxPomodoroCount = 4, - ShowToastNotifications = true + ShowToastNotifications = true, + PlaySoundNotifications = true }; } @@ -80,6 +81,12 @@ public bool ShowToastNotifications set { values.ShowToastNotifications = value; } } + public bool PlaySoundNotifications + { + get { return values.PlaySoundNotifications; } + set { values.PlaySoundNotifications = value; } + } + public void Update(Action action) { action(this); @@ -94,6 +101,7 @@ private class Values public int LongBreakDuration { get; set; } public int MaxPomodoroCount { get; set; } public bool ShowToastNotifications { get; set; } + public bool PlaySoundNotifications { get; set; } } } } diff --git a/Tomighty.Windows/Preferences/UserPreferencesForm.Designer.cs b/Tomighty.Windows/Preferences/UserPreferencesForm.Designer.cs index 1667159..96d0bac 100644 --- a/Tomighty.Windows/Preferences/UserPreferencesForm.Designer.cs +++ b/Tomighty.Windows/Preferences/UserPreferencesForm.Designer.cs @@ -55,6 +55,7 @@ private void InitializeComponent() this.tabPage2 = new System.Windows.Forms.TabPage(); this.label8 = new System.Windows.Forms.Label(); this.toastNotification = new System.Windows.Forms.CheckBox(); + this.soundNotifications = new System.Windows.Forms.CheckBox(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.longBreakDurationTextBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.shortBreakDurationTextBox)).BeginInit(); @@ -304,6 +305,7 @@ private void InitializeComponent() // // tabPage2 // + this.tabPage2.Controls.Add(this.soundNotifications); this.tabPage2.Controls.Add(this.toastNotification); this.tabPage2.Controls.Add(this.label8); this.tabPage2.Location = new System.Drawing.Point(4, 22); @@ -333,6 +335,16 @@ private void InitializeComponent() this.toastNotification.Text = "Show a toast notification"; this.toastNotification.UseVisualStyleBackColor = true; // + // soundNotifications + // + this.soundNotifications.AutoSize = true; + this.soundNotifications.Location = new System.Drawing.Point(16, 59); + this.soundNotifications.Name = "soundNotifications"; + this.soundNotifications.Size = new System.Drawing.Size(87, 17); + this.soundNotifications.TabIndex = 2; + this.soundNotifications.Text = "Play a sound"; + this.soundNotifications.UseVisualStyleBackColor = true; + // // UserPreferencesForm // this.AcceptButton = this.okButton; @@ -387,5 +399,6 @@ private void InitializeComponent() private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.Label label8; private System.Windows.Forms.CheckBox toastNotification; + private System.Windows.Forms.CheckBox soundNotifications; } } \ No newline at end of file diff --git a/Tomighty.Windows/Preferences/UserPreferencesForm.cs b/Tomighty.Windows/Preferences/UserPreferencesForm.cs index 1435333..18308c9 100644 --- a/Tomighty.Windows/Preferences/UserPreferencesForm.cs +++ b/Tomighty.Windows/Preferences/UserPreferencesForm.cs @@ -24,6 +24,7 @@ public UserPreferencesForm(IUserPreferences userPreferences) longBreakDurationTextBox.Value = userPreferences.GetIntervalDuration(IntervalType.LongBreak).Minutes; maxPomodoroCountTextBox.Value = userPreferences.MaxPomodoroCount; toastNotification.Checked = userPreferences.ShowToastNotifications; + soundNotifications.Checked = userPreferences.PlaySoundNotifications; } private void OnCancelButtonClick(object sender, System.EventArgs e) @@ -40,6 +41,7 @@ private void OnOkButtonClick(object sender, System.EventArgs e) newPreferences.SetIntervalDuration(IntervalType.LongBreak, Duration.InMinutes((int)longBreakDurationTextBox.Value)); newPreferences.MaxPomodoroCount = (int)maxPomodoroCountTextBox.Value; newPreferences.ShowToastNotifications = toastNotification.Checked; + newPreferences.PlaySoundNotifications = soundNotifications.Checked; }); Close(); diff --git a/Tomighty.Windows/Properties/Resources.Designer.cs b/Tomighty.Windows/Properties/Resources.Designer.cs index a71a959..0dc5c10 100644 --- a/Tomighty.Windows/Properties/Resources.Designer.cs +++ b/Tomighty.Windows/Properties/Resources.Designer.cs @@ -60,6 +60,15 @@ internal Resources() { } } + /// + /// Looks up a localized resource of type System.IO.UnmanagedMemoryStream similar to System.IO.MemoryStream. + /// + internal static System.IO.UnmanagedMemoryStream audio_deskbell { + get { + return ResourceManager.GetStream("audio_deskbell", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// diff --git a/Tomighty.Windows/Properties/Resources.resx b/Tomighty.Windows/Properties/Resources.resx index 8de566d..38f50b0 100644 --- a/Tomighty.Windows/Properties/Resources.resx +++ b/Tomighty.Windows/Properties/Resources.resx @@ -172,4 +172,7 @@ ..\Resources\Toasts\interval-completed.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + ..\Resources\Audio\deskbell.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/Tomighty.Windows/Resources/Audio/deskbell.wav b/Tomighty.Windows/Resources/Audio/deskbell.wav new file mode 100644 index 0000000..2837ba9 Binary files /dev/null and b/Tomighty.Windows/Resources/Audio/deskbell.wav differ diff --git a/Tomighty.Windows/Tomighty.Windows.csproj b/Tomighty.Windows/Tomighty.Windows.csproj index 35c90f1..850e595 100644 --- a/Tomighty.Windows/Tomighty.Windows.csproj +++ b/Tomighty.Windows/Tomighty.Windows.csproj @@ -88,6 +88,7 @@ + @@ -153,6 +154,7 @@ + diff --git a/Tomighty.Windows/TomightyApplication.cs b/Tomighty.Windows/TomightyApplication.cs index 5e0943f..f85d741 100644 --- a/Tomighty.Windows/TomightyApplication.cs +++ b/Tomighty.Windows/TomightyApplication.cs @@ -31,6 +31,7 @@ public TomightyApplication() new TrayIconController(trayIcon, timerWindowPresenter, eventHub); new TrayMenuController(trayMenu, this, pomodoroEngine, eventHub); new NotificationsPresenter(pomodoroEngine, userPreferences, eventHub); + new SoundNotificationPlayer(userPreferences, eventHub); var aboutWindowPresenter = new AboutWindowPresenter(); var userPreferencesPresenter = new UserPreferencesPresenter(userPreferences);