Commit | Line | Data |
---|---|---|
f017f3c4 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
16f47961 | 4 | * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved. |
f017f3c4 LOK |
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.Collections.Generic; | |
34 | using CecSharp; | |
35 | using LibCECTray.settings; | |
324a4cb1 | 36 | using System; |
f017f3c4 LOK |
37 | |
38 | namespace LibCECTray.controller.applications | |
39 | { | |
40 | class CecButtonConfigItem : CECSettingString | |
41 | { | |
42 | public CecButtonConfigItem(ApplicationController controller, CecKeypress key) : | |
43 | base(CECSettingType.Button, null, ButtonName(key.Keycode), ApplicationInput.DefaultValue(controller, key).AsString(), null) | |
44 | { | |
45 | Key = key; | |
46 | } | |
47 | ||
48 | public new ApplicationInput Value | |
49 | { | |
50 | get | |
51 | { | |
52 | return base.Value != null | |
53 | ? ApplicationInput.FromString(Controller, base.Value) | |
54 | : new ApplicationInput(Controller); | |
55 | } | |
56 | set | |
57 | { | |
58 | base.Value = value == null ? null : value.AsString(); | |
59 | } | |
60 | } | |
61 | ||
62 | public new ApplicationInput DefaultValue | |
63 | { | |
64 | get { return base.DefaultValue != null ? ApplicationInput.FromString(Controller, base.DefaultValue) : null; } | |
65 | set { base.DefaultValue = value.AsString(); } | |
66 | } | |
67 | ||
68 | public string MappedButtonName | |
69 | { | |
70 | get { return Value == null ? string.Empty : Value.AsFriendlyString(); } | |
71 | set { base.Value = value; } | |
72 | } | |
73 | ||
74 | public new bool Enabled | |
75 | { | |
76 | get | |
77 | { | |
78 | return _enabled || !string.IsNullOrEmpty(base.Value); | |
79 | } | |
80 | set | |
81 | { | |
82 | _enabled = value; | |
83 | } | |
84 | } | |
85 | private bool _enabled; | |
86 | ||
87 | public string CecButtonName | |
88 | { | |
89 | get { return ButtonName(Key.Keycode); } | |
90 | } | |
91 | ||
92 | public void SetController(ApplicationController controller) | |
93 | { | |
94 | Controller = controller; | |
95 | KeyName = string.Format("{0}_key_{1}", controller.ProcessName, (int)Key.Keycode); | |
96 | } | |
97 | ||
98 | public static string ButtonName(CecUserControlCode key) | |
99 | { | |
100 | switch (key) | |
101 | { | |
102 | case CecUserControlCode.Select: | |
103 | return "Select"; | |
104 | case CecUserControlCode.Up: | |
105 | return "Up"; | |
106 | case CecUserControlCode.Down: | |
107 | return "Down"; | |
108 | case CecUserControlCode.Left: | |
109 | return "Left"; | |
110 | case CecUserControlCode.Right: | |
111 | return "Right"; | |
112 | case CecUserControlCode.RightUp: | |
113 | return "Right+Up"; | |
114 | case CecUserControlCode.RightDown: | |
115 | return "Right+Down"; | |
116 | case CecUserControlCode.LeftUp: | |
117 | return "Left+Up"; | |
118 | case CecUserControlCode.LeftDown: | |
119 | return "Left+Down"; | |
120 | case CecUserControlCode.RootMenu: | |
121 | return "Root menu"; | |
122 | case CecUserControlCode.SetupMenu: | |
123 | return "Setup menu"; | |
124 | case CecUserControlCode.ContentsMenu: | |
125 | return "Contents menu"; | |
126 | case CecUserControlCode.FavoriteMenu: | |
127 | return "Favourite menu"; | |
128 | case CecUserControlCode.Exit: | |
129 | return "Exit"; | |
130 | case CecUserControlCode.Number0: | |
131 | return "0"; | |
132 | case CecUserControlCode.Number1: | |
133 | return "1"; | |
134 | case CecUserControlCode.Number2: | |
135 | return "2"; | |
136 | case CecUserControlCode.Number3: | |
137 | return "3"; | |
138 | case CecUserControlCode.Number4: | |
139 | return "4"; | |
140 | case CecUserControlCode.Number5: | |
141 | return "5"; | |
142 | case CecUserControlCode.Number6: | |
143 | return "6"; | |
144 | case CecUserControlCode.Number7: | |
145 | return "7"; | |
146 | case CecUserControlCode.Number8: | |
147 | return "8"; | |
148 | case CecUserControlCode.Number9: | |
149 | return "9"; | |
150 | case CecUserControlCode.Dot: | |
151 | return "."; | |
152 | case CecUserControlCode.Enter: | |
153 | return "Enter"; | |
154 | case CecUserControlCode.Clear: | |
155 | return "Clear"; | |
156 | case CecUserControlCode.NextFavorite: | |
157 | return "Next favourite"; | |
158 | case CecUserControlCode.ChannelUp: | |
159 | return "Channel up"; | |
160 | case CecUserControlCode.ChannelDown: | |
161 | return "Channel down"; | |
162 | case CecUserControlCode.PreviousChannel: | |
163 | return "Previous channel"; | |
164 | case CecUserControlCode.SoundSelect: | |
165 | return "Sound select"; | |
166 | case CecUserControlCode.InputSelect: | |
167 | return "Input select"; | |
168 | case CecUserControlCode.DisplayInformation: | |
169 | return "Display information"; | |
170 | case CecUserControlCode.Help: | |
171 | return "Help"; | |
172 | case CecUserControlCode.PageUp: | |
173 | return "Page up"; | |
174 | case CecUserControlCode.PageDown: | |
175 | return "Page down"; | |
176 | case CecUserControlCode.Power: | |
177 | return "Power"; | |
178 | case CecUserControlCode.VolumeUp: | |
179 | return "Volume up"; | |
180 | case CecUserControlCode.VolumeDown: | |
181 | return "Volume down"; | |
182 | case CecUserControlCode.Mute: | |
183 | return "Mute"; | |
184 | case CecUserControlCode.Play: | |
185 | return "Play"; | |
186 | case CecUserControlCode.Stop: | |
187 | return "Stop"; | |
188 | case CecUserControlCode.Pause: | |
189 | return "Pause"; | |
190 | case CecUserControlCode.Record: | |
191 | return "Record"; | |
192 | case CecUserControlCode.Rewind: | |
193 | return "Rewind"; | |
194 | case CecUserControlCode.FastForward: | |
195 | return "Fast forward"; | |
196 | case CecUserControlCode.Eject: | |
197 | return "Eject"; | |
198 | case CecUserControlCode.Forward: | |
199 | return "Forward"; | |
200 | case CecUserControlCode.Backward: | |
201 | return "Backward"; | |
202 | case CecUserControlCode.StopRecord: | |
203 | return "Stop record"; | |
204 | case CecUserControlCode.PauseRecord: | |
205 | return "Pause record"; | |
206 | case CecUserControlCode.Angle: | |
207 | return "Angle"; | |
208 | case CecUserControlCode.SubPicture: | |
209 | return "Sub picture"; | |
210 | case CecUserControlCode.VideoOnDemand: | |
211 | return "Video on demand"; | |
212 | case CecUserControlCode.ElectronicProgramGuide: | |
213 | return "Electronic program guide"; | |
214 | case CecUserControlCode.TimerProgramming: | |
215 | return "Timer programming"; | |
216 | case CecUserControlCode.InitialConfiguration: | |
217 | return "Initial configuration"; | |
218 | case CecUserControlCode.PlayFunction: | |
219 | return "Play (function)"; | |
220 | case CecUserControlCode.PausePlayFunction: | |
221 | return "Pause play (function)"; | |
222 | case CecUserControlCode.RecordFunction: | |
223 | return "Record (function)"; | |
224 | case CecUserControlCode.PauseRecordFunction: | |
225 | return "Pause record (function)"; | |
226 | case CecUserControlCode.StopFunction: | |
227 | return "Stop (function)"; | |
228 | case CecUserControlCode.MuteFunction: | |
229 | return "Mute (function)"; | |
230 | case CecUserControlCode.RestoreVolumeFunction: | |
231 | return "Restore volume"; | |
232 | case CecUserControlCode.TuneFunction: | |
233 | return "Tune"; | |
234 | case CecUserControlCode.SelectMediaFunction: | |
235 | return "Select media"; | |
236 | case CecUserControlCode.SelectAVInputFunction: | |
237 | return "Select AV input"; | |
238 | case CecUserControlCode.SelectAudioInputFunction: | |
239 | return "Select audio input"; | |
240 | case CecUserControlCode.PowerToggleFunction: | |
241 | return "Power toggle"; | |
242 | case CecUserControlCode.PowerOffFunction: | |
243 | return "Power off"; | |
244 | case CecUserControlCode.PowerOnFunction: | |
245 | return "Power on"; | |
246 | case CecUserControlCode.F1Blue: | |
247 | return "F1 (blue)"; | |
248 | case CecUserControlCode.F2Red: | |
249 | return "F2 (red)"; | |
250 | case CecUserControlCode.F3Green: | |
251 | return "F3 (green)"; | |
252 | case CecUserControlCode.F4Yellow: | |
253 | return "F4 (yellow)"; | |
254 | case CecUserControlCode.F5: | |
255 | return "F5"; | |
256 | case CecUserControlCode.Data: | |
257 | return "Data"; | |
258 | case CecUserControlCode.SamsungReturn: | |
259 | return "Return (Samsung)"; | |
260 | } | |
261 | return "Unknown"; | |
262 | } | |
263 | ||
264 | public CecKeypress Key { get; private set; } | |
265 | public ApplicationController Controller { get; private set; } | |
266 | } | |
267 | ||
268 | internal class CecButtonConfig : List<CecButtonConfigItem> | |
269 | { | |
270 | public CecButtonConfig(ApplicationController controller) | |
271 | { | |
272 | _controller = controller; | |
324a4cb1 LOK |
273 | |
274 | foreach (CecUserControlCode key in Enum.GetValues(typeof(CecUserControlCode))) | |
275 | AddConfigItem(new CecButtonConfigItem(controller, (new CecKeypress { Keycode = key }))); | |
276 | ||
277 | Load(); | |
278 | } | |
279 | ||
280 | private void AddConfigItem(CecButtonConfigItem item) | |
281 | { | |
282 | if (!HasItem(item) && item.Key.Keycode != CecUserControlCode.Unknown) | |
283 | Add(item); | |
284 | } | |
285 | ||
286 | public bool HasItem(CecButtonConfigItem item) | |
287 | { | |
288 | foreach (var entry in this) | |
289 | { | |
290 | if (item.Key.Keycode == entry.Key.Keycode) | |
291 | return true; | |
292 | } | |
293 | return false; | |
f017f3c4 LOK |
294 | } |
295 | ||
296 | public void Load() | |
297 | { | |
298 | foreach (var item in this) | |
299 | { | |
300 | item.SetController(_controller); | |
301 | _controller.Settings[item.KeyName] = item; | |
302 | _controller.Settings.Load(item); | |
303 | } | |
304 | } | |
305 | ||
306 | public CecButtonConfigItem this[CecKeypress key] | |
307 | { | |
308 | get | |
309 | { | |
310 | foreach (var item in this) | |
311 | { | |
312 | if (item.Key.Keycode == key.Keycode) | |
313 | return item; | |
314 | } | |
315 | return null; | |
316 | } | |
317 | } | |
318 | ||
319 | private readonly ApplicationController _controller; | |
320 | } | |
321 | } |