Commit | Line | Data |
---|---|---|
f017f3c4 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
4 | * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. | |
5 | * libCEC(R) is an original work, containing original code. | |
6 | * | |
7 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
8 | * | |
9 | * This program is dual-licensed; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | * | |
23 | * | |
24 | * Alternatively, you can license this library under a commercial license, | |
25 | * please contact Pulse-Eight Licensing for more information. | |
26 | * | |
27 | * For more information contact: | |
28 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
29 | * http://www.pulse-eight.com/ | |
30 | * http://www.pulse-eight.net/ | |
31 | */ | |
32 | ||
33 | using System.Windows.Forms; | |
34 | using CecSharp; | |
35 | using LibCECTray.Properties; | |
36 | ||
37 | namespace LibCECTray.settings | |
38 | { | |
39 | /// <summary> | |
40 | /// A setting of type CecDeviceType that can be persisted in the registry | |
41 | /// </summary> | |
42 | class CECSettingDeviceType : CECSettingNumeric | |
43 | { | |
44 | public CECSettingDeviceType(string keyName, string friendlyName, CecDeviceType defaultValue, SettingChangedHandler changedHandler) : | |
45 | base(CECSettingType.DeviceType, keyName, friendlyName, (int)defaultValue, changedHandler, OnFormat) | |
46 | { | |
47 | LowerLimit = (int) CecDeviceType.Tv; | |
48 | UpperLimit = (int) CecDeviceType.AudioSystem; | |
49 | } | |
50 | ||
51 | private static void OnFormat(object sender, ListControlConvertEventArgs listControlConvertEventArgs) | |
52 | { | |
53 | int iValue; | |
54 | if (int.TryParse((string)listControlConvertEventArgs.Value, out iValue)) | |
55 | listControlConvertEventArgs.Value = FormatValue(iValue); | |
56 | } | |
57 | ||
58 | public new CecDeviceType Value | |
59 | { | |
60 | get { return base.Value >= (int)CecDeviceType.Tv && base.Value <= (int)CecDeviceType.AudioSystem ? (CecDeviceType)base.Value : CecDeviceType.Reserved; } | |
61 | set | |
62 | { | |
63 | base.Value = (int)value; | |
64 | if (Form == null) return; | |
65 | switch (value) | |
66 | { | |
67 | case CecDeviceType.RecordingDevice: | |
68 | Form.SetControlText(ValueControl, Resources.device_recorder); | |
69 | break; | |
70 | case CecDeviceType.PlaybackDevice: | |
71 | Form.SetControlText(ValueControl, Resources.device_playbackdevice); | |
72 | break; | |
73 | case CecDeviceType.Tuner: | |
74 | Form.SetControlText(ValueControl, Resources.device_tuner); | |
75 | break; | |
76 | default: | |
77 | Form.SetControlText(ValueControl, Resources.device_recorder); | |
78 | break; | |
79 | } | |
80 | } | |
81 | } | |
82 | ||
83 | public new CecDeviceType DefaultValue | |
84 | { | |
85 | get { return base.DefaultValue >= (int)CecDeviceType.Tv && base.DefaultValue <= (int)CecDeviceType.AudioSystem ? (CecDeviceType)base.DefaultValue : CecDeviceType.Reserved; } | |
86 | set { base.DefaultValue = (int)value; } | |
87 | } | |
88 | ||
89 | private static string FormatValue(int value) | |
90 | { | |
91 | switch ((CecDeviceType)value) | |
92 | { | |
93 | case CecDeviceType.Tv: | |
94 | return Resources.device_tv; | |
95 | case CecDeviceType.PlaybackDevice: | |
96 | return Resources.device_playbackdevice; | |
97 | case CecDeviceType.AudioSystem: | |
98 | return Resources.device_audiosystem; | |
99 | case CecDeviceType.RecordingDevice: | |
100 | return Resources.device_recorder; | |
101 | case CecDeviceType.Tuner: | |
102 | return Resources.device_tuner; | |
103 | case CecDeviceType.Reserved: | |
104 | return Resources.device_reserved; | |
105 | } | |
106 | return Resources.unknown; | |
107 | } | |
108 | ||
109 | protected override bool AllowedValue(int value) | |
110 | { | |
111 | if ((CecDeviceType)value == CecDeviceType.Reserved) | |
112 | return false; | |
113 | for (var i = 0; i < _allowedTypeMask.Types.Length; i++) | |
114 | { | |
115 | if (_allowedTypeMask.Types[i] == (CecDeviceType) value) | |
116 | return true; | |
117 | } | |
118 | return false; | |
119 | } | |
120 | ||
121 | private CecDeviceTypeList _allowedTypeMask; | |
122 | public CecDeviceTypeList AllowedTypeMask | |
123 | { | |
124 | get | |
125 | { | |
126 | return _allowedTypeMask ?? (_allowedTypeMask = new CecDeviceTypeList | |
127 | { | |
128 | Types = | |
129 | new[] | |
130 | { | |
131 | CecDeviceType.Tv, CecDeviceType.PlaybackDevice, | |
132 | CecDeviceType.RecordingDevice, | |
133 | CecDeviceType.AudioSystem, CecDeviceType.Tuner | |
134 | } | |
135 | }); | |
136 | } | |
137 | set | |
138 | { | |
139 | _allowedTypeMask = value; | |
140 | ResetItems(true); | |
141 | } | |
142 | } | |
143 | } | |
144 | } |