2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
33 using System.Collections.Generic;
35 using LibCECTray.settings;
38 namespace LibCECTray.controller.applications
40 class CecButtonConfigItem : CECSettingString
42 public CecButtonConfigItem(ApplicationController controller, CecKeypress key) :
43 base(CECSettingType.Button, null, ButtonName(key.Keycode), ApplicationInput.DefaultValue(controller, key).AsString(), null)
48 public new ApplicationInput Value
52 return base.Value != null
53 ? ApplicationInput.FromString(Controller, base.Value)
54 : new ApplicationInput(Controller);
58 base.Value = value == null ? null : value.AsString();
62 public new ApplicationInput DefaultValue
64 get { return base.DefaultValue != null ? ApplicationInput.FromString(Controller, base.DefaultValue) : null; }
65 set { base.DefaultValue = value.AsString(); }
68 public string MappedButtonName
70 get { return Value == null ? string.Empty : Value.AsFriendlyString(); }
71 set { base.Value = value; }
74 public new bool Enabled
78 return _enabled || !string.IsNullOrEmpty(base.Value);
85 private bool _enabled;
87 public string CecButtonName
89 get { return ButtonName(Key.Keycode); }
92 public void SetController(ApplicationController controller)
94 Controller = controller;
95 KeyName = string.Format("{0}_key_{1}", controller.ProcessName, (int)Key.Keycode);
98 public static string ButtonName(CecUserControlCode key)
102 case CecUserControlCode.Select:
104 case CecUserControlCode.Up:
106 case CecUserControlCode.Down:
108 case CecUserControlCode.Left:
110 case CecUserControlCode.Right:
112 case CecUserControlCode.RightUp:
114 case CecUserControlCode.RightDown:
116 case CecUserControlCode.LeftUp:
118 case CecUserControlCode.LeftDown:
120 case CecUserControlCode.RootMenu:
122 case CecUserControlCode.SetupMenu:
124 case CecUserControlCode.ContentsMenu:
125 return "Contents menu";
126 case CecUserControlCode.FavoriteMenu:
127 return "Favourite menu";
128 case CecUserControlCode.Exit:
130 case CecUserControlCode.Number0:
132 case CecUserControlCode.Number1:
134 case CecUserControlCode.Number2:
136 case CecUserControlCode.Number3:
138 case CecUserControlCode.Number4:
140 case CecUserControlCode.Number5:
142 case CecUserControlCode.Number6:
144 case CecUserControlCode.Number7:
146 case CecUserControlCode.Number8:
148 case CecUserControlCode.Number9:
150 case CecUserControlCode.Dot:
152 case CecUserControlCode.Enter:
154 case CecUserControlCode.Clear:
156 case CecUserControlCode.NextFavorite:
157 return "Next favourite";
158 case CecUserControlCode.ChannelUp:
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:
172 case CecUserControlCode.PageUp:
174 case CecUserControlCode.PageDown:
176 case CecUserControlCode.Power:
178 case CecUserControlCode.VolumeUp:
180 case CecUserControlCode.VolumeDown:
181 return "Volume down";
182 case CecUserControlCode.Mute:
184 case CecUserControlCode.Play:
186 case CecUserControlCode.Stop:
188 case CecUserControlCode.Pause:
190 case CecUserControlCode.Record:
192 case CecUserControlCode.Rewind:
194 case CecUserControlCode.FastForward:
195 return "Fast forward";
196 case CecUserControlCode.Eject:
198 case CecUserControlCode.Forward:
200 case CecUserControlCode.Backward:
202 case CecUserControlCode.StopRecord:
203 return "Stop record";
204 case CecUserControlCode.PauseRecord:
205 return "Pause record";
206 case CecUserControlCode.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:
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:
244 case CecUserControlCode.PowerOnFunction:
246 case CecUserControlCode.F1Blue:
248 case CecUserControlCode.F2Red:
250 case CecUserControlCode.F3Green:
252 case CecUserControlCode.F4Yellow:
253 return "F4 (yellow)";
254 case CecUserControlCode.F5:
256 case CecUserControlCode.Data:
258 case CecUserControlCode.SamsungReturn:
259 return "Return (Samsung)";
264 public CecKeypress Key { get; private set; }
265 public ApplicationController Controller { get; private set; }
268 internal class CecButtonConfig : List<CecButtonConfigItem>
270 public CecButtonConfig(ApplicationController controller)
272 _controller = controller;
274 foreach (CecUserControlCode key in Enum.GetValues(typeof(CecUserControlCode)))
275 AddConfigItem(new CecButtonConfigItem(controller, (new CecKeypress { Keycode = key })));
280 private void AddConfigItem(CecButtonConfigItem item)
282 if (!HasItem(item) && item.Key.Keycode != CecUserControlCode.Unknown)
286 public bool HasItem(CecButtonConfigItem item)
288 foreach (var entry in this)
290 if (item.Key.Keycode == entry.Key.Keycode)
298 foreach (var item in this)
300 item.SetController(_controller);
301 _controller.Settings[item.KeyName] = item;
302 _controller.Settings.Load(item);
306 public CecButtonConfigItem this[CecKeypress key]
310 foreach (var item in this)
312 if (item.Key.Keycode == key.Keycode)
319 private readonly ApplicationController _controller;