From f7ed91f709eadb4823e310b4853f30001e08db70 Mon Sep 17 00:00:00 2001 From: Khang Yeen Lee Date: Mon, 25 May 2015 10:30:40 +0800 Subject: [PATCH] #16. Sound notification can now be disabled and have all notification settings saved.. --- .../ConfigurationService.cs | 11 +++ .../BusinessComponents/NotificationService.cs | 25 ++++--- .../Entities/NotificationSettings.cs | 5 +- .../NotificationsSettingsControl.Designer.cs | 72 +++++++++++-------- .../Controls/NotificationsSettingsControl.cs | 20 +++++- HudsonTrayTracker/UI/SettingsForm.Designer.cs | 38 +--------- HudsonTrayTracker/UI/SettingsForm.cs | 6 +- 7 files changed, 97 insertions(+), 80 deletions(-) diff --git a/HudsonTrayTracker/BusinessComponents/ConfigurationService.cs b/HudsonTrayTracker/BusinessComponents/ConfigurationService.cs index 3dbb31e..c928c89 100644 --- a/HudsonTrayTracker/BusinessComponents/ConfigurationService.cs +++ b/HudsonTrayTracker/BusinessComponents/ConfigurationService.cs @@ -197,6 +197,11 @@ public bool IsTreadUnstableAsFailed() return NotificationSettings.TreatUnstableAsFailed; } + public bool IsSoundNotificationsEnabled() + { + return NotificationSettings.SoundNotifications; + } + public void SetTreadUnstableAsFailed(bool value) { NotificationSettings.TreatUnstableAsFailed = value; @@ -220,5 +225,11 @@ public void SetIntegrateWithClaimPlugin(bool value) GeneralSettings.IntegrateWithClaimPlugin = value; SaveConfiguration(); } + + public void SetSoundNotifications(bool value) + { + NotificationSettings.SoundNotifications = value; + SaveConfiguration(); + } } } diff --git a/HudsonTrayTracker/BusinessComponents/NotificationService.cs b/HudsonTrayTracker/BusinessComponents/NotificationService.cs index 7372d2c..2e184c9 100644 --- a/HudsonTrayTracker/BusinessComponents/NotificationService.cs +++ b/HudsonTrayTracker/BusinessComponents/NotificationService.cs @@ -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) diff --git a/HudsonTrayTracker/Entities/NotificationSettings.cs b/HudsonTrayTracker/Entities/NotificationSettings.cs index 588da25..6d00678 100644 --- a/HudsonTrayTracker/Entities/NotificationSettings.cs +++ b/HudsonTrayTracker/Entities/NotificationSettings.cs @@ -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; } @@ -19,4 +22,4 @@ public class NotificationSettings [JsonProperty("treatUnstableAsFailed")] public bool TreatUnstableAsFailed { get; set; } } -} \ No newline at end of file +} diff --git a/HudsonTrayTracker/UI/Controls/NotificationsSettingsControl.Designer.cs b/HudsonTrayTracker/UI/Controls/NotificationsSettingsControl.Designer.cs index b6ba888..234ff63 100644 --- a/HudsonTrayTracker/UI/Controls/NotificationsSettingsControl.Designer.cs +++ b/HudsonTrayTracker/UI/Controls/NotificationsSettingsControl.Designer.cs @@ -29,16 +29,18 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.groupControl1 = new DevExpress.XtraEditors.GroupControl(); - this.enableSoundCheckBox = new DevExpress.XtraEditors.CheckEdit(); this.notificationSettingsControl1 = new Hudson.TrayTracker.UI.Controls.NotificationSettingsControl(); this.notificationSettingsControl2 = new Hudson.TrayTracker.UI.Controls.NotificationSettingsControl(); this.notificationSettingsControl3 = new Hudson.TrayTracker.UI.Controls.NotificationSettingsControl(); this.notificationSettingsControl4 = new Hudson.TrayTracker.UI.Controls.NotificationSettingsControl(); + this.enableSoundCheckBox = new DevExpress.XtraEditors.CheckEdit(); + this.groupControl1 = new DevExpress.XtraEditors.GroupControl(); + this.treatUnstableAsFailedCheckBox = new DevExpress.XtraEditors.CheckEdit(); this.tableLayoutPanel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.enableSoundCheckBox.Properties)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.groupControl1)).BeginInit(); this.groupControl1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.enableSoundCheckBox.Properties)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.treatUnstableAsFailedCheckBox.Properties)).BeginInit(); this.SuspendLayout(); // // tableLayoutPanel1 @@ -50,11 +52,13 @@ private void InitializeComponent() this.tableLayoutPanel1.Controls.Add(this.notificationSettingsControl3, 0, 3); this.tableLayoutPanel1.Controls.Add(this.notificationSettingsControl4, 0, 4); this.tableLayoutPanel1.Controls.Add(this.enableSoundCheckBox, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.treatUnstableAsFailedCheckBox, 0, 6); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(2, 25); this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 7; + this.tableLayoutPanel1.RowCount = 8; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); @@ -65,29 +69,6 @@ private void InitializeComponent() this.tableLayoutPanel1.Size = new System.Drawing.Size(552, 391); this.tableLayoutPanel1.TabIndex = 0; // - // groupControl1 - // - this.groupControl1.AppearanceCaption.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold); - this.groupControl1.AppearanceCaption.Options.UseFont = true; - this.groupControl1.Controls.Add(this.tableLayoutPanel1); - this.groupControl1.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupControl1.Location = new System.Drawing.Point(0, 0); - this.groupControl1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.groupControl1.Name = "groupControl1"; - this.groupControl1.Size = new System.Drawing.Size(556, 418); - this.groupControl1.TabIndex = 1; - this.groupControl1.Text = "Configure sound notifications"; - // - // enableSoundCheckBox - // - this.enableSoundCheckBox.Location = new System.Drawing.Point(3, 4); - this.enableSoundCheckBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.enableSoundCheckBox.Name = "enableSoundCheckBox"; - this.enableSoundCheckBox.Properties.Caption = "&Enable sound notifications"; - this.enableSoundCheckBox.Size = new System.Drawing.Size(175, 21); - this.enableSoundCheckBox.TabIndex = 0; - this.enableSoundCheckBox.CheckedChanged += new System.EventHandler(this.enableSoundCheckBox_CheckedChanged); - // // notificationSettingsControl1 // this.notificationSettingsControl1.AutoSize = true; @@ -140,6 +121,39 @@ private void InitializeComponent() this.notificationSettingsControl4.Status = "Succeeded"; this.notificationSettingsControl4.TabIndex = 3; // + // enableSoundCheckBox + // + this.enableSoundCheckBox.Location = new System.Drawing.Point(3, 4); + this.enableSoundCheckBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.enableSoundCheckBox.Name = "enableSoundCheckBox"; + this.enableSoundCheckBox.Properties.Caption = "&Enable sound notifications"; + this.enableSoundCheckBox.Size = new System.Drawing.Size(175, 21); + this.enableSoundCheckBox.TabIndex = 0; + this.enableSoundCheckBox.CheckedChanged += new System.EventHandler(this.enableSoundCheckBox_CheckedChanged); + // + // groupControl1 + // + this.groupControl1.AppearanceCaption.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold); + this.groupControl1.AppearanceCaption.Options.UseFont = true; + this.groupControl1.Controls.Add(this.tableLayoutPanel1); + this.groupControl1.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupControl1.Location = new System.Drawing.Point(0, 0); + this.groupControl1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupControl1.Name = "groupControl1"; + this.groupControl1.Size = new System.Drawing.Size(556, 418); + this.groupControl1.TabIndex = 1; + this.groupControl1.Text = "Configure sound notifications"; + // + // treatUnstableAsFailedCheckBox + // + this.treatUnstableAsFailedCheckBox.Location = new System.Drawing.Point(3, 313); + this.treatUnstableAsFailedCheckBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.treatUnstableAsFailedCheckBox.Name = "treatUnstableAsFailedCheckBox"; + this.treatUnstableAsFailedCheckBox.Properties.Caption = "&Treat unstable as failed"; + this.treatUnstableAsFailedCheckBox.Size = new System.Drawing.Size(162, 21); + this.treatUnstableAsFailedCheckBox.TabIndex = 9; + this.treatUnstableAsFailedCheckBox.CheckedChanged += new System.EventHandler(this.treatUnstableAsFailedCheckBox_CheckedChanged); + // // NotificationsSettingsControl // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); @@ -150,9 +164,10 @@ private void InitializeComponent() this.Size = new System.Drawing.Size(556, 418); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.enableSoundCheckBox.Properties)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.groupControl1)).EndInit(); this.groupControl1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.enableSoundCheckBox.Properties)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.treatUnstableAsFailedCheckBox.Properties)).EndInit(); this.ResumeLayout(false); } @@ -166,5 +181,6 @@ private void InitializeComponent() private NotificationSettingsControl notificationSettingsControl4; private DevExpress.XtraEditors.GroupControl groupControl1; private DevExpress.XtraEditors.CheckEdit enableSoundCheckBox; + private DevExpress.XtraEditors.CheckEdit treatUnstableAsFailedCheckBox; } } diff --git a/HudsonTrayTracker/UI/Controls/NotificationsSettingsControl.cs b/HudsonTrayTracker/UI/Controls/NotificationsSettingsControl.cs index 73f231b..87f8b4c 100644 --- a/HudsonTrayTracker/UI/Controls/NotificationsSettingsControl.cs +++ b/HudsonTrayTracker/UI/Controls/NotificationsSettingsControl.cs @@ -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() @@ -49,5 +62,10 @@ public void InvalidateData() notificationSettingsControl3.InvalidateData(); notificationSettingsControl4.InvalidateData(); } + + private void treatUnstableAsFailedCheckBox_CheckedChanged(object sender, EventArgs e) + { + configurationService.SetTreadUnstableAsFailed(treatUnstableAsFailedCheckBox.Checked); + } } } diff --git a/HudsonTrayTracker/UI/SettingsForm.Designer.cs b/HudsonTrayTracker/UI/SettingsForm.Designer.cs index eed47fa..a0cac3e 100644 --- a/HudsonTrayTracker/UI/SettingsForm.Designer.cs +++ b/HudsonTrayTracker/UI/SettingsForm.Designer.cs @@ -46,8 +46,6 @@ private void InitializeComponent() this.updateMainWindowIconCheckEdit = new DevExpress.XtraEditors.CheckEdit(); this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); this.integrateWithClaimPluginCheckEdit = new DevExpress.XtraEditors.CheckEdit(); - this.tableLayoutPanel6 = new System.Windows.Forms.TableLayoutPanel(); - this.treatUnstableAsFailedCheckBox = new DevExpress.XtraEditors.CheckEdit(); ((System.ComponentModel.ISupportInitialize)(this.tabControl)).BeginInit(); this.tabControl.SuspendLayout(); this.serversTabPage.SuspendLayout(); @@ -64,8 +62,6 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.updateMainWindowIconCheckEdit.Properties)).BeginInit(); this.tableLayoutPanel4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.integrateWithClaimPluginCheckEdit.Properties)).BeginInit(); - this.tableLayoutPanel6.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.treatUnstableAsFailedCheckBox.Properties)).BeginInit(); this.SuspendLayout(); // // tabControl @@ -146,7 +142,6 @@ private void InitializeComponent() // this.tableLayoutPanel2.ColumnCount = 1; this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel6, 0, 4); this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel5, 0, 3); this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel1, 0, 0); this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel3, 0, 1); @@ -155,13 +150,13 @@ private void InitializeComponent() this.tableLayoutPanel2.Location = new System.Drawing.Point(2, 25); this.tableLayoutPanel2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.tableLayoutPanel2.Name = "tableLayoutPanel2"; - this.tableLayoutPanel2.RowCount = 6; - this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel2.RowCount = 5; this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel2.Size = new System.Drawing.Size(834, 472); this.tableLayoutPanel2.TabIndex = 4; // @@ -292,31 +287,6 @@ private void InitializeComponent() this.integrateWithClaimPluginCheckEdit.Size = new System.Drawing.Size(265, 21); this.integrateWithClaimPluginCheckEdit.TabIndex = 0; // - // tableLayoutPanel6 - // - this.tableLayoutPanel6.AutoSize = true; - this.tableLayoutPanel6.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.tableLayoutPanel6.ColumnCount = 1; - this.tableLayoutPanel6.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel6.Controls.Add(this.treatUnstableAsFailedCheckBox, 0, 0); - this.tableLayoutPanel6.Dock = System.Windows.Forms.DockStyle.Fill; - this.tableLayoutPanel6.Location = new System.Drawing.Point(3, 153); - this.tableLayoutPanel6.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.tableLayoutPanel6.Name = "tableLayoutPanel6"; - this.tableLayoutPanel6.RowCount = 1; - this.tableLayoutPanel6.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel6.Size = new System.Drawing.Size(828, 29); - this.tableLayoutPanel6.TabIndex = 9; - // - // treatUnstableAsFailedCheckBox - // - this.treatUnstableAsFailedCheckBox.Location = new System.Drawing.Point(3, 4); - this.treatUnstableAsFailedCheckBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.treatUnstableAsFailedCheckBox.Name = "treatUnstableAsFailedCheckBox"; - this.treatUnstableAsFailedCheckBox.Properties.Caption = "&Treat unstable as failed"; - this.treatUnstableAsFailedCheckBox.Size = new System.Drawing.Size(162, 21); - this.treatUnstableAsFailedCheckBox.TabIndex = 8; - // // SettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); @@ -348,8 +318,6 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.updateMainWindowIconCheckEdit.Properties)).EndInit(); this.tableLayoutPanel4.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.integrateWithClaimPluginCheckEdit.Properties)).EndInit(); - this.tableLayoutPanel6.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.treatUnstableAsFailedCheckBox.Properties)).EndInit(); this.ResumeLayout(false); } @@ -373,8 +341,6 @@ private void InitializeComponent() private DevExpress.XtraEditors.CheckEdit integrateWithClaimPluginCheckEdit; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel5; private DevExpress.XtraEditors.CheckEdit checkEdit1; - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel6; - private DevExpress.XtraEditors.CheckEdit treatUnstableAsFailedCheckBox; } } \ No newline at end of file diff --git a/HudsonTrayTracker/UI/SettingsForm.cs b/HudsonTrayTracker/UI/SettingsForm.cs index 18d9a7b..c3457bb 100644 --- a/HudsonTrayTracker/UI/SettingsForm.cs +++ b/HudsonTrayTracker/UI/SettingsForm.cs @@ -52,7 +52,6 @@ private void SettingsForm_Load(object sender, EventArgs e) refreshSpinEdit.Value = ConfigurationService.GeneralSettings.RefreshIntervalInSeconds; updateMainWindowIconCheckEdit.Checked = ConfigurationService.GeneralSettings.UpdateMainWindowIcon; integrateWithClaimPluginCheckEdit.Checked = ConfigurationService.GeneralSettings.IntegrateWithClaimPlugin; - treatUnstableAsFailedCheckBox.Checked = ConfigurationService.IsTreadUnstableAsFailed(); } private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e) @@ -61,8 +60,9 @@ private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e) ConfigurationService.SetRefreshIntervalInSeconds(refreshInterval); ConfigurationService.SetUpdateMainWindowIcon(updateMainWindowIconCheckEdit.Checked); ConfigurationService.SetIntegrateWithClaimPlugin(integrateWithClaimPluginCheckEdit.Checked); - ConfigurationService.SetTreadUnstableAsFailed(treatUnstableAsFailedCheckBox.Checked); + ConfigurationService.SetTreadUnstableAsFailed(notificationsSettingsControl.TreadUnstableAsFailed()); + ConfigurationService.SetSoundNotifications(notificationsSettingsControl.SoundNotificationsEnabled()); notificationsSettingsControl.InvalidateData(); } } -} \ No newline at end of file +}