From f4bb504fb4ad62f21abd481c7986f5612a0c8650 Mon Sep 17 00:00:00 2001 From: Adam Blackburn Date: Fri, 20 Nov 2015 20:20:32 -0800 Subject: [PATCH] Allow enable/disable display of notifications Add checkbox to enable/disable display of notifications --- .gitignore | 3 + .../ISoundSwitchConfiguration.cs | 1 + .../Configuration/SoundSwitchConfiguration.cs | 3 + SoundSwitch/Model/AppModel.cs | 10 ++ SoundSwitch/Model/IAppModel.cs | 6 + SoundSwitch/SoundSwitch.csproj | 3 + SoundSwitch/UI/Forms/Settings.Designer.cs | 37 ++++-- SoundSwitch/UI/Forms/Settings.cs | 8 ++ SoundSwitch/UI/Forms/Settings.resx | 120 ++++++++++++++++++ SoundSwitch/Util/TrayIcon.cs | 12 +- 10 files changed, 190 insertions(+), 13 deletions(-) create mode 100644 SoundSwitch/UI/Forms/Settings.resx diff --git a/.gitignore b/.gitignore index ef4f2aec74..340fbb4680 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,6 @@ ipch/ *.sdf Final GenerateChangelog.bat + +# nuget +packages/ \ No newline at end of file diff --git a/SoundSwitch/Framework/Configuration/ISoundSwitchConfiguration.cs b/SoundSwitch/Framework/Configuration/ISoundSwitchConfiguration.cs index 7fec8e4f57..a167d6146c 100644 --- a/SoundSwitch/Framework/Configuration/ISoundSwitchConfiguration.cs +++ b/SoundSwitch/Framework/Configuration/ISoundSwitchConfiguration.cs @@ -27,5 +27,6 @@ public interface ISoundSwitchConfiguration : IConfiguration HotKeys RecordingHotKeys { get; set; } bool ChangeCommunications { get; set; } uint UpdateCheckInterval { get; set; } + bool DisplayNotifications { get; set; } } } \ No newline at end of file diff --git a/SoundSwitch/Framework/Configuration/SoundSwitchConfiguration.cs b/SoundSwitch/Framework/Configuration/SoundSwitchConfiguration.cs index a149ec3766..0dd6ae91ff 100644 --- a/SoundSwitch/Framework/Configuration/SoundSwitchConfiguration.cs +++ b/SoundSwitch/Framework/Configuration/SoundSwitchConfiguration.cs @@ -24,6 +24,7 @@ public SoundSwitchConfiguration() { FirstRun = true; ChangeCommunications = false; + DisplayNotifications = true; SelectedPlaybackDeviceList = new HashSet(); SelectedRecordingDeviceList = new HashSet(); PlaybackHotKeys = new HotKeys(Keys.F11, HotKeys.ModifierKeys.Alt | HotKeys.ModifierKeys.Control); @@ -50,6 +51,8 @@ public HotKeys HotKeysCombinaison public HotKeys RecordingHotKeys { get; set; } public bool ChangeCommunications { get; set; } public uint UpdateCheckInterval { get; set; } + public bool DisplayNotifications { get; set; } + //Needed by Interface public string FileLocation { get; set; } diff --git a/SoundSwitch/Model/AppModel.cs b/SoundSwitch/Model/AppModel.cs index edded7626d..8a570faf92 100644 --- a/SoundSwitch/Model/AppModel.cs +++ b/SoundSwitch/Model/AppModel.cs @@ -104,6 +104,16 @@ public bool RunAtStartup } } + public bool DisplayNotifications + { + get { return AppConfigs.Configuration.DisplayNotifications; } + set + { + AppConfigs.Configuration.DisplayNotifications = value; + AppConfigs.Configuration.Save(); + } + } + public IAudioDeviceLister ActiveAudioDeviceLister { get; set; } #endregion diff --git a/SoundSwitch/Model/IAppModel.cs b/SoundSwitch/Model/IAppModel.cs index f9ce1362b5..b366ead1a3 100644 --- a/SoundSwitch/Model/IAppModel.cs +++ b/SoundSwitch/Model/IAppModel.cs @@ -54,6 +54,12 @@ public interface IAppModel /// If the application runs at windows startup /// bool RunAtStartup { get; set; } + + /// + /// If notifications are displayed when the devices are changed + /// + bool DisplayNotifications { get; set; } + /// /// List the active audio devices /// diff --git a/SoundSwitch/SoundSwitch.csproj b/SoundSwitch/SoundSwitch.csproj index b98203cfee..3469eaae15 100644 --- a/SoundSwitch/SoundSwitch.csproj +++ b/SoundSwitch/SoundSwitch.csproj @@ -305,6 +305,9 @@ ResXFileCodeGenerator UpdateFormStrings.Designer.cs + + Settings.cs + diff --git a/SoundSwitch/UI/Forms/Settings.Designer.cs b/SoundSwitch/UI/Forms/Settings.Designer.cs index 1bcf2fb6aa..f2e080b22c 100644 --- a/SoundSwitch/UI/Forms/Settings.Designer.cs +++ b/SoundSwitch/UI/Forms/Settings.Designer.cs @@ -30,8 +30,8 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup(global::SoundSwitch.Properties.SettingsString.selected, System.Windows.Forms.HorizontalAlignment.Center); - System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup(global::SoundSwitch.Properties.SettingsString.selected, System.Windows.Forms.HorizontalAlignment.Center); + System.Windows.Forms.ListViewGroup listViewGroup3 = new System.Windows.Forms.ListViewGroup(global::SoundSwitch.Properties.SettingsString.selected, System.Windows.Forms.HorizontalAlignment.Center); + System.Windows.Forms.ListViewGroup listViewGroup4 = new System.Windows.Forms.ListViewGroup(global::SoundSwitch.Properties.SettingsString.selected, System.Windows.Forms.HorizontalAlignment.Center); this.RunAtStartup = new System.Windows.Forms.CheckBox(); this.closeButton = new System.Windows.Forms.Button(); this.communicationCheckbox = new System.Windows.Forms.CheckBox(); @@ -42,6 +42,7 @@ private void InitializeComponent() this.recordingListView = new System.Windows.Forms.ListView(); this.hotkeyTextBox = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); + this.notificationsCheckbox = new System.Windows.Forms.CheckBox(); this.tabControl.SuspendLayout(); this.playbackPage.SuspendLayout(); this.recordingPage.SuspendLayout(); @@ -75,7 +76,7 @@ private void InitializeComponent() // this.communicationCheckbox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.communicationCheckbox.AutoSize = true; - this.communicationCheckbox.Location = new System.Drawing.Point(165, 265); + this.communicationCheckbox.Location = new System.Drawing.Point(113, 265); this.communicationCheckbox.Name = "communicationCheckbox"; this.communicationCheckbox.Size = new System.Drawing.Size(140, 17); this.communicationCheckbox.TabIndex = 12; @@ -114,11 +115,11 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.playbackListView.CheckBoxes = true; - listViewGroup1.Header = global::SoundSwitch.Properties.SettingsString.selected; - listViewGroup1.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center; - listViewGroup1.Name = "selectedGroup"; + listViewGroup3.Header = global::SoundSwitch.Properties.SettingsString.selected; + listViewGroup3.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center; + listViewGroup3.Name = "selectedGroup"; this.playbackListView.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { - listViewGroup1}); + listViewGroup3}); this.playbackListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; this.playbackListView.Location = new System.Drawing.Point(-4, 0); this.playbackListView.Name = "playbackListView"; @@ -145,11 +146,11 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.recordingListView.CheckBoxes = true; - listViewGroup2.Header = global::SoundSwitch.Properties.SettingsString.selected; - listViewGroup2.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center; - listViewGroup2.Name = "selectedGroup"; + listViewGroup4.Header = global::SoundSwitch.Properties.SettingsString.selected; + listViewGroup4.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center; + listViewGroup4.Name = "selectedGroup"; this.recordingListView.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { - listViewGroup2}); + listViewGroup4}); this.recordingListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; this.recordingListView.Location = new System.Drawing.Point(-2, 0); this.recordingListView.Name = "recordingListView"; @@ -176,12 +177,25 @@ private void InitializeComponent() this.label2.TabIndex = 14; this.label2.Text = "Hotkeys"; // + // notificationsCheckbox + // + this.notificationsCheckbox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.notificationsCheckbox.AutoSize = true; + this.notificationsCheckbox.Location = new System.Drawing.Point(259, 265); + this.notificationsCheckbox.Name = "notificationsCheckbox"; + this.notificationsCheckbox.Size = new System.Drawing.Size(121, 17); + this.notificationsCheckbox.TabIndex = 16; + this.notificationsCheckbox.Text = "Display Notifications"; + this.notificationsCheckbox.UseVisualStyleBackColor = true; + this.notificationsCheckbox.CheckedChanged += new System.EventHandler(this.notificationsCheckbox_CheckedChanged); + // // Settings // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.closeButton; this.ClientSize = new System.Drawing.Size(505, 286); + this.Controls.Add(this.notificationsCheckbox); this.Controls.Add(this.hotkeyTextBox); this.Controls.Add(this.label2); this.Controls.Add(this.tabControl); @@ -210,5 +224,6 @@ private void InitializeComponent() private System.Windows.Forms.ListView recordingListView; private System.Windows.Forms.TextBox hotkeyTextBox; private System.Windows.Forms.Label label2; + private System.Windows.Forms.CheckBox notificationsCheckbox; } } \ No newline at end of file diff --git a/SoundSwitch/UI/Forms/Settings.cs b/SoundSwitch/UI/Forms/Settings.cs index 0cbf32b388..995e867059 100644 --- a/SoundSwitch/UI/Forms/Settings.cs +++ b/SoundSwitch/UI/Forms/Settings.cs @@ -45,6 +45,8 @@ public Settings() RunAtStartup.Checked = AppModel.Instance.RunAtStartup; communicationCheckbox.Checked = AppModel.Instance.SetCommunications; + notificationsCheckbox.Checked = AppModel.Instance.DisplayNotifications; + var audioDeviceLister = new AudioDeviceLister(DeviceState.All); PopulateAudioList(playbackListView, AppModel.Instance.SelectedPlaybackDevicesList, audioDeviceLister.GetPlaybackDevices()); @@ -264,5 +266,11 @@ private void tabControl_SelectedIndexChanged(object sender, EventArgs e) hotkeyTextBox.Tag = AudioDeviceType.Recording; } } + + private void notificationsCheckbox_CheckedChanged(object sender, EventArgs e) + { + var checkboxSender = (CheckBox) sender; + AppModel.Instance.DisplayNotifications = checkboxSender.Checked; + } } } \ No newline at end of file diff --git a/SoundSwitch/UI/Forms/Settings.resx b/SoundSwitch/UI/Forms/Settings.resx new file mode 100644 index 0000000000..1af7de150c --- /dev/null +++ b/SoundSwitch/UI/Forms/Settings.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SoundSwitch/Util/TrayIcon.cs b/SoundSwitch/Util/TrayIcon.cs index ddb2bfa611..fc95f3dc2b 100644 --- a/SoundSwitch/Util/TrayIcon.cs +++ b/SoundSwitch/Util/TrayIcon.cs @@ -322,12 +322,20 @@ private void DeviceClicked(object sender, EventArgs e) private void ShowPlaybackChanged(string deviceName) { - _trayIcon.ShowBalloonTip(500, string.Format(TrayIconStrings.playbackChanged, Application.ProductName), deviceName, ToolTipIcon.Info); + if (AppModel.Instance.DisplayNotifications) + { + _trayIcon.ShowBalloonTip(500, string.Format(TrayIconStrings.playbackChanged, Application.ProductName), + deviceName, ToolTipIcon.Info); + } } private void ShowRecordingChanged(string deviceName) { - _trayIcon.ShowBalloonTip(500, string.Format(TrayIconStrings.recordingChanged, Application.ProductName), deviceName, ToolTipIcon.Info); + if (AppModel.Instance.DisplayNotifications) + { + _trayIcon.ShowBalloonTip(500, string.Format(TrayIconStrings.recordingChanged, Application.ProductName), + deviceName, ToolTipIcon.Info); + } } ///