replaced cec-config-gui by libCEC tray
[deb_libcec.git] / src / LibCecTray / settings / CECSettingLogicalAddress.cs
CommitLineData
f017f3c4
LOK
1using System.Windows.Forms;
2using CecSharp;
3using LibCECTray.Properties;
4
5namespace LibCECTray.settings
6{
7 /// <summary>
8 /// A setting of type CecLogicalAddress that can be persisted in the registry
9 /// </summary>
10 class CECSettingLogicalAddress : CECSettingNumeric
11 {
12 public CECSettingLogicalAddress(string keyName, string friendlyName, CecLogicalAddress defaultValue, SettingChangedHandler changedHandler) :
13 base(CECSettingType.LogicalAddress, keyName, friendlyName, (int)defaultValue, changedHandler, OnFormat)
14 {
15 LowerLimit = (int) CecLogicalAddress.Tv;
16 UpperLimit = (int) CecLogicalAddress.Broadcast;
17 }
18
19 private static void OnFormat(object sender, ListControlConvertEventArgs listControlConvertEventArgs)
20 {
21 int iValue;
22 if (int.TryParse((string)listControlConvertEventArgs.Value, out iValue))
23 listControlConvertEventArgs.Value = FormatValue(iValue);
24 }
25
26 public new CecLogicalAddress Value
27 {
28 get { return base.Value >= (int)CecLogicalAddress.Tv && base.Value <= (int)CecLogicalAddress.Broadcast ? (CecLogicalAddress)base.Value : CecLogicalAddress.Unknown; }
29 set { base.Value = (int)value; }
30 }
31
32 public new CecLogicalAddress DefaultValue
33 {
34 get { return base.DefaultValue >= (int)CecLogicalAddress.Tv && base.DefaultValue <= (int)CecLogicalAddress.Broadcast ? (CecLogicalAddress)base.DefaultValue : CecLogicalAddress.Unknown; }
35 set { base.DefaultValue = (int)value; }
36 }
37
38 private static string FormatValue(int value)
39 {
40 switch ((CecLogicalAddress)value)
41 {
42 case CecLogicalAddress.AudioSystem:
43 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_audiosystem : CECSettings.VendorNames[value] + " " + Resources.device_audiosystem;
44 case CecLogicalAddress.Broadcast:
45 return Resources.device_broadcast;
46 case CecLogicalAddress.FreeUse:
47 return Resources.device_free_use;
48 case CecLogicalAddress.PlaybackDevice1:
49 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_playbackdevice + " 1" : CECSettings.VendorNames[value] + " " + Resources.device_playbackdevice + " 1";
50 case CecLogicalAddress.PlaybackDevice2:
51 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_playbackdevice + " 2" : CECSettings.VendorNames[value] + " " + Resources.device_playbackdevice + " 2";
52 case CecLogicalAddress.PlaybackDevice3:
53 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_playbackdevice + " 3" : CECSettings.VendorNames[value] + " " + Resources.device_playbackdevice + " 3";
54 case CecLogicalAddress.RecordingDevice1:
55 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_recorder + " 1" : CECSettings.VendorNames[value] + " " + Resources.device_recorder + " 1";
56 case CecLogicalAddress.RecordingDevice2:
57 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_recorder + " 2" : CECSettings.VendorNames[value] + " " + Resources.device_recorder + " 2";
58 case CecLogicalAddress.RecordingDevice3:
59 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_recorder + " 3" : CECSettings.VendorNames[value] + " " + Resources.device_recorder + " 3";
60 case CecLogicalAddress.Reserved1:
61 return Resources.device_reserved + " 1";
62 case CecLogicalAddress.Reserved2:
63 return Resources.device_reserved + " 2";
64 case CecLogicalAddress.Tuner1:
65 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_tuner + " 1" : CECSettings.VendorNames[value] + " " + Resources.device_tuner + " 1";
66 case CecLogicalAddress.Tuner2:
67 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_tuner + " 2" : CECSettings.VendorNames[value] + " " + Resources.device_tuner + " 2";
68 case CecLogicalAddress.Tuner3:
69 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_tuner + " 3" : CECSettings.VendorNames[value] + " " + Resources.device_tuner + " 3";
70 case CecLogicalAddress.Tuner4:
71 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_tuner + " 4" : CECSettings.VendorNames[value] + " " + Resources.device_tuner + " 4";
72 case CecLogicalAddress.Tv:
73 return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_tv : CECSettings.VendorNames[value] + " " + Resources.device_tv;
74 default:
75 return Resources.unknown;
76 }
77 }
78
79 protected override bool AllowedValue(int value)
80 {
81 return AllowedAddressMask.IsSet((CecLogicalAddress)value);
82 }
83
84 private CecLogicalAddresses _allowedAddressMask;
85 public CecLogicalAddresses AllowedAddressMask
86 {
87 get
88 {
89 if (_allowedAddressMask == null)
90 {
91 _allowedAddressMask = new CecLogicalAddresses();
92 for (int iPtr = 0; iPtr < 16; iPtr++)
93 _allowedAddressMask.Set((CecLogicalAddress)iPtr);
94 }
95 return _allowedAddressMask;
96 }
97 set
98 {
99 _allowedAddressMask = value;
100 ResetItems(true);
101 }
102 }
103 }
104
105}