Commit | Line | Data |
---|---|---|
16f47961 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
4 | * libCEC(R) is Copyright (C) 2011-2013 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 | ||
f017f3c4 LOK |
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 CecLogicalAddress that can be persisted in the registry | |
41 | /// </summary> | |
42 | class CECSettingLogicalAddress : CECSettingNumeric | |
43 | { | |
44 | public CECSettingLogicalAddress(string keyName, string friendlyName, CecLogicalAddress defaultValue, SettingChangedHandler changedHandler) : | |
45 | base(CECSettingType.LogicalAddress, keyName, friendlyName, (int)defaultValue, changedHandler, OnFormat) | |
46 | { | |
47 | LowerLimit = (int) CecLogicalAddress.Tv; | |
48 | UpperLimit = (int) CecLogicalAddress.Broadcast; | |
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 CecLogicalAddress Value | |
59 | { | |
60 | get { return base.Value >= (int)CecLogicalAddress.Tv && base.Value <= (int)CecLogicalAddress.Broadcast ? (CecLogicalAddress)base.Value : CecLogicalAddress.Unknown; } | |
61 | set { base.Value = (int)value; } | |
62 | } | |
63 | ||
64 | public new CecLogicalAddress DefaultValue | |
65 | { | |
66 | get { return base.DefaultValue >= (int)CecLogicalAddress.Tv && base.DefaultValue <= (int)CecLogicalAddress.Broadcast ? (CecLogicalAddress)base.DefaultValue : CecLogicalAddress.Unknown; } | |
67 | set { base.DefaultValue = (int)value; } | |
68 | } | |
69 | ||
70 | private static string FormatValue(int value) | |
71 | { | |
72 | switch ((CecLogicalAddress)value) | |
73 | { | |
74 | case CecLogicalAddress.AudioSystem: | |
75 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_audiosystem : CECSettings.VendorNames[value] + " " + Resources.device_audiosystem; | |
76 | case CecLogicalAddress.Broadcast: | |
77 | return Resources.device_broadcast; | |
78 | case CecLogicalAddress.FreeUse: | |
79 | return Resources.device_free_use; | |
80 | case CecLogicalAddress.PlaybackDevice1: | |
81 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_playbackdevice + " 1" : CECSettings.VendorNames[value] + " " + Resources.device_playbackdevice + " 1"; | |
82 | case CecLogicalAddress.PlaybackDevice2: | |
83 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_playbackdevice + " 2" : CECSettings.VendorNames[value] + " " + Resources.device_playbackdevice + " 2"; | |
84 | case CecLogicalAddress.PlaybackDevice3: | |
85 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_playbackdevice + " 3" : CECSettings.VendorNames[value] + " " + Resources.device_playbackdevice + " 3"; | |
86 | case CecLogicalAddress.RecordingDevice1: | |
87 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_recorder + " 1" : CECSettings.VendorNames[value] + " " + Resources.device_recorder + " 1"; | |
88 | case CecLogicalAddress.RecordingDevice2: | |
89 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_recorder + " 2" : CECSettings.VendorNames[value] + " " + Resources.device_recorder + " 2"; | |
90 | case CecLogicalAddress.RecordingDevice3: | |
91 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_recorder + " 3" : CECSettings.VendorNames[value] + " " + Resources.device_recorder + " 3"; | |
92 | case CecLogicalAddress.Reserved1: | |
93 | return Resources.device_reserved + " 1"; | |
94 | case CecLogicalAddress.Reserved2: | |
95 | return Resources.device_reserved + " 2"; | |
96 | case CecLogicalAddress.Tuner1: | |
97 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_tuner + " 1" : CECSettings.VendorNames[value] + " " + Resources.device_tuner + " 1"; | |
98 | case CecLogicalAddress.Tuner2: | |
99 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_tuner + " 2" : CECSettings.VendorNames[value] + " " + Resources.device_tuner + " 2"; | |
100 | case CecLogicalAddress.Tuner3: | |
101 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_tuner + " 3" : CECSettings.VendorNames[value] + " " + Resources.device_tuner + " 3"; | |
102 | case CecLogicalAddress.Tuner4: | |
103 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_tuner + " 4" : CECSettings.VendorNames[value] + " " + Resources.device_tuner + " 4"; | |
104 | case CecLogicalAddress.Tv: | |
105 | return CECSettings.VendorNames[value] == null || CECSettings.VendorNames[value].Length == 0 ? Resources.device_tv : CECSettings.VendorNames[value] + " " + Resources.device_tv; | |
106 | default: | |
107 | return Resources.unknown; | |
108 | } | |
109 | } | |
110 | ||
111 | protected override bool AllowedValue(int value) | |
112 | { | |
113 | return AllowedAddressMask.IsSet((CecLogicalAddress)value); | |
114 | } | |
115 | ||
116 | private CecLogicalAddresses _allowedAddressMask; | |
117 | public CecLogicalAddresses AllowedAddressMask | |
118 | { | |
119 | get | |
120 | { | |
121 | if (_allowedAddressMask == null) | |
122 | { | |
123 | _allowedAddressMask = new CecLogicalAddresses(); | |
124 | for (int iPtr = 0; iPtr < 16; iPtr++) | |
125 | _allowedAddressMask.Set((CecLogicalAddress)iPtr); | |
126 | } | |
127 | return _allowedAddressMask; | |
128 | } | |
129 | set | |
130 | { | |
131 | _allowedAddressMask = value; | |
132 | ResetItems(true); | |
133 | } | |
134 | } | |
135 | } | |
136 | ||
137 | } |