Skip to content

Commit

Permalink
Add Device Icons into Settings. Fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Aflalo committed Aug 26, 2015
1 parent b8cf52b commit 108d73b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 35 deletions.
57 changes: 37 additions & 20 deletions SoundSwitch/Forms/Settings.Designer.cs

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

46 changes: 31 additions & 15 deletions SoundSwitch/Forms/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Windows.Forms;
using AudioEndPointControllerWrapper;
using SoundSwitch.Framework;
using SoundSwitch.Properties;
using SoundSwitch.Util;

namespace SoundSwitch.Forms
Expand All @@ -40,6 +41,7 @@ public Settings(Main main)


RunAtStartup.Checked = _main.RunAtStartup;
//TODO: test.SmallImageList.Images.Add("test", Resources.GreenCheck);
PopulateAudioList();
}

Expand Down Expand Up @@ -99,37 +101,51 @@ private void PopulateAudioList()
var selected = _main.SelectedDevicesList;
var audioDeviceWrappers = AudioController.getAllAudioDevices()
.Where(wrapper => !string.IsNullOrEmpty(wrapper.FriendlyName))
.Select(wrapper => wrapper.FriendlyName)
.OrderBy(s => s);
foreach (
var item in
audioDeviceWrappers.Where(name => selected.Contains(name)))
.OrderBy(s => s.FriendlyName);
deviceListView.SmallImageList = new ImageList();

deviceListView.Columns.Add("Device", -3, HorizontalAlignment.Center);
foreach (var device in audioDeviceWrappers)
{
lstDevices.Items.Add(item, true);
}

foreach (
var item in
audioDeviceWrappers.Where(name => !selected.Contains(name)))
{
lstDevices.Items.Add(item, false);
deviceListView.SmallImageList.Images.Add(device.FriendlyName, IconExtractor.ExtractIconFromAudioDevice(device, false));
if (selected.Contains(device.FriendlyName))
{
deviceListView.Items.Add(new ListViewItem
{
Text = device.FriendlyName,
Checked = true,
Group = deviceListView.Groups["selectedGroup"],
ImageKey = device.FriendlyName
});
}
else
{
deviceListView.Items.Add(new ListViewItem
{
Text = device.FriendlyName,
Checked = false,
Group = deviceListView.Groups["unSelectedGroup"],
ImageKey = device.FriendlyName
});
}
}

}
catch (Exception e)
{
MessageBox.Show(@"Error: " + e.Message);
}
finally
{
lstDevices.ItemCheck += LstDevicesItemChecked;
deviceListView.ItemCheck += LstDevicesItemChecked;
}
}

private void LstDevicesItemChecked(object sender, ItemCheckEventArgs e)
{
try
{
_main.AddRemoveDevice(lstDevices.Items[e.Index].ToString());
_main.AddRemoveDevice(deviceListView.Items[e.Index].ToString());
}
catch (Exception)
{
Expand Down

0 comments on commit 108d73b

Please sign in to comment.