Skip to content

Commit

Permalink
#16. Sound notification can now be disabled and have all notification…
Browse files Browse the repository at this point in the history
… settings saved..
  • Loading branch information
zionyx committed May 25, 2015
1 parent 25f4f13 commit f7ed91f
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 80 deletions.
11 changes: 11 additions & 0 deletions HudsonTrayTracker/BusinessComponents/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public bool IsTreadUnstableAsFailed()
return NotificationSettings.TreatUnstableAsFailed;
}

public bool IsSoundNotificationsEnabled()
{
return NotificationSettings.SoundNotifications;
}

public void SetTreadUnstableAsFailed(bool value)
{
NotificationSettings.TreatUnstableAsFailed = value;
Expand All @@ -220,5 +225,11 @@ public void SetIntegrateWithClaimPlugin(bool value)
GeneralSettings.IntegrateWithClaimPlugin = value;
SaveConfiguration();
}

public void SetSoundNotifications(bool value)
{
NotificationSettings.SoundNotifications = value;
SaveConfiguration();
}
}
}
25 changes: 14 additions & 11 deletions HudsonTrayTracker/BusinessComponents/NotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ public void Execute()
{
allServersStatus.Update(ConfigurationService.Servers);

string fileToPlay = null;
if (allServersStatus.StillFailingProjects.Count > 0)
fileToPlay = ConfigurationService.NotificationSettings.StillFailingSoundPath;
else if (allServersStatus.FailingProjects.Count > 0)
fileToPlay = ConfigurationService.NotificationSettings.FailedSoundPath;
else if (allServersStatus.FixedProjects.Count > 0)
fileToPlay = ConfigurationService.NotificationSettings.FixedSoundPath;
else if (allServersStatus.SucceedingProjects.Count > 0)
fileToPlay = ConfigurationService.NotificationSettings.SucceededSoundPath;
if (fileToPlay != null)
SoundPlayer.PlayFile(fileToPlay);
if (ConfigurationService.NotificationSettings.SoundNotifications)
{
string fileToPlay = null;
if (allServersStatus.StillFailingProjects.Count > 0)
fileToPlay = ConfigurationService.NotificationSettings.StillFailingSoundPath;
else if (allServersStatus.FailingProjects.Count > 0)
fileToPlay = ConfigurationService.NotificationSettings.FailedSoundPath;
else if (allServersStatus.FixedProjects.Count > 0)
fileToPlay = ConfigurationService.NotificationSettings.FixedSoundPath;
else if (allServersStatus.SucceedingProjects.Count > 0)
fileToPlay = ConfigurationService.NotificationSettings.SucceededSoundPath;
if (fileToPlay != null)
SoundPlayer.PlayFile(fileToPlay);
}
}

private bool TreatAsFailure(BuildStatusEnum status)
Expand Down
5 changes: 4 additions & 1 deletion HudsonTrayTracker/Entities/NotificationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace Hudson.TrayTracker.Entities
[JsonObject(MemberSerialization.OptIn)]
public class NotificationSettings
{
[JsonProperty("soundNotifications")]
public bool SoundNotifications { get; set; }

[JsonProperty("failedSoundPath")]
public string FailedSoundPath { get; set; }

Expand All @@ -19,4 +22,4 @@ public class NotificationSettings
[JsonProperty("treatUnstableAsFailed")]
public bool TreatUnstableAsFailed { get; set; }
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion HudsonTrayTracker/UI/Controls/NotificationsSettingsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,30 @@ protected override void OnLoad(EventArgs e)
return;

configurationService = (ConfigurationService)ContextRegistry.GetContext().GetObject("ConfigurationService");

treatUnstableAsFailedCheckBox.Checked = configurationService.IsTreadUnstableAsFailed();
enableSoundCheckBox.Checked = configurationService.IsSoundNotificationsEnabled();
enableSoundCheckBox_CheckedChanged(null, null);
}

public bool SoundNotificationsEnabled()
{
return enableSoundCheckBox.Checked;
}

private void enableSoundCheckBox_CheckedChanged(object sender, EventArgs e)
{
notificationSettingsControl1.Enabled =
notificationSettingsControl2.Enabled =
notificationSettingsControl3.Enabled =
notificationSettingsControl4.Enabled =
treatUnstableAsFailedCheckBox.Enabled =
enableSoundCheckBox.Checked;
configurationService.SetSoundNotifications(enableSoundCheckBox.Checked);
}

public bool TreadUnstableAsFailed()
{
return treatUnstableAsFailedCheckBox.Checked;
}

public void InvalidateData()
Expand All @@ -49,5 +62,10 @@ public void InvalidateData()
notificationSettingsControl3.InvalidateData();
notificationSettingsControl4.InvalidateData();
}

private void treatUnstableAsFailedCheckBox_CheckedChanged(object sender, EventArgs e)
{
configurationService.SetTreadUnstableAsFailed(treatUnstableAsFailedCheckBox.Checked);
}
}
}
38 changes: 2 additions & 36 deletions HudsonTrayTracker/UI/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f7ed91f

Please sign in to comment.