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;
37 namespace LibCECTray.controller.applications
39 class CecButtonConfigItem : CECSettingString
41 public CecButtonConfigItem(ApplicationController controller, CecKeypress key) :
42 base(CECSettingType.Button, null, ButtonName(key.Keycode), ApplicationInput.DefaultValue(controller, key).AsString(), null)
47 public new ApplicationInput Value
51 return base.Value != null
52 ? ApplicationInput.FromString(Controller, base.Value)
53 : new ApplicationInput(Controller);
57 base.Value = value == null ? null : value.AsString();
61 public new ApplicationInput DefaultValue
63 get { return base.DefaultValue != null ? ApplicationInput.FromString(Controller, base.DefaultValue) : null; }
64 set { base.DefaultValue = value.AsString(); }
67 public string MappedButtonName
69 get { return Value == null ? string.Empty : Value.AsFriendlyString(); }
70 set { base.Value = value; }
73 public new bool Enabled
77 return _enabled || !string.IsNullOrEmpty(base.Value);
84 private bool _enabled;
86 public string CecButtonName
88 get { return ButtonName(Key.Keycode); }
91 public void SetController(ApplicationController controller)
93 Controller = controller;
94 KeyName = string.Format("{0}_key_{1}", controller.ProcessName, (int)Key.Keycode);
97 public static string ButtonName(CecUserControlCode key)
101 case CecUserControlCode.Select:
103 case CecUserControlCode.Up:
105 case CecUserControlCode.Down:
107 case CecUserControlCode.Left:
109 case CecUserControlCode.Right:
111 case CecUserControlCode.RightUp:
113 case CecUserControlCode.RightDown:
115 case CecUserControlCode.LeftUp:
117 case CecUserControlCode.LeftDown:
119 case CecUserControlCode.RootMenu:
121 case CecUserControlCode.SetupMenu:
123 case CecUserControlCode.ContentsMenu:
124 return "Contents menu";
125 case CecUserControlCode.FavoriteMenu:
126 return "Favourite menu";
127 case CecUserControlCode.Exit:
129 case CecUserControlCode.Number0:
131 case CecUserControlCode.Number1:
133 case CecUserControlCode.Number2:
135 case CecUserControlCode.Number3:
137 case CecUserControlCode.Number4:
139 case CecUserControlCode.Number5:
141 case CecUserControlCode.Number6:
143 case CecUserControlCode.Number7:
145 case CecUserControlCode.Number8:
147 case CecUserControlCode.Number9:
149 case CecUserControlCode.Dot:
151 case CecUserControlCode.Enter:
153 case CecUserControlCode.Clear:
155 case CecUserControlCode.NextFavorite:
156 return "Next favourite";
157 case CecUserControlCode.ChannelUp:
159 case CecUserControlCode.ChannelDown:
160 return "Channel down";
161 case CecUserControlCode.PreviousChannel:
162 return "Previous channel";
163 case CecUserControlCode.SoundSelect:
164 return "Sound select";
165 case CecUserControlCode.InputSelect:
166 return "Input select";
167 case CecUserControlCode.DisplayInformation:
168 return "Display information";
169 case CecUserControlCode.Help:
171 case CecUserControlCode.PageUp:
173 case CecUserControlCode.PageDown:
175 case CecUserControlCode.Power:
177 case CecUserControlCode.VolumeUp:
179 case CecUserControlCode.VolumeDown:
180 return "Volume down";
181 case CecUserControlCode.Mute:
183 case CecUserControlCode.Play:
185 case CecUserControlCode.Stop:
187 case CecUserControlCode.Pause:
189 case CecUserControlCode.Record:
191 case CecUserControlCode.Rewind:
193 case CecUserControlCode.FastForward:
194 return "Fast forward";
195 case CecUserControlCode.Eject:
197 case CecUserControlCode.Forward:
199 case CecUserControlCode.Backward:
201 case CecUserControlCode.StopRecord:
202 return "Stop record";
203 case CecUserControlCode.PauseRecord:
204 return "Pause record";
205 case CecUserControlCode.Angle:
207 case CecUserControlCode.SubPicture:
208 return "Sub picture";
209 case CecUserControlCode.VideoOnDemand:
210 return "Video on demand";
211 case CecUserControlCode.ElectronicProgramGuide:
212 return "Electronic program guide";
213 case CecUserControlCode.TimerProgramming:
214 return "Timer programming";
215 case CecUserControlCode.InitialConfiguration:
216 return "Initial configuration";
217 case CecUserControlCode.PlayFunction:
218 return "Play (function)";
219 case CecUserControlCode.PausePlayFunction:
220 return "Pause play (function)";
221 case CecUserControlCode.RecordFunction:
222 return "Record (function)";
223 case CecUserControlCode.PauseRecordFunction:
224 return "Pause record (function)";
225 case CecUserControlCode.StopFunction:
226 return "Stop (function)";
227 case CecUserControlCode.MuteFunction:
228 return "Mute (function)";
229 case CecUserControlCode.RestoreVolumeFunction:
230 return "Restore volume";
231 case CecUserControlCode.TuneFunction:
233 case CecUserControlCode.SelectMediaFunction:
234 return "Select media";
235 case CecUserControlCode.SelectAVInputFunction:
236 return "Select AV input";
237 case CecUserControlCode.SelectAudioInputFunction:
238 return "Select audio input";
239 case CecUserControlCode.PowerToggleFunction:
240 return "Power toggle";
241 case CecUserControlCode.PowerOffFunction:
243 case CecUserControlCode.PowerOnFunction:
245 case CecUserControlCode.F1Blue:
247 case CecUserControlCode.F2Red:
249 case CecUserControlCode.F3Green:
251 case CecUserControlCode.F4Yellow:
252 return "F4 (yellow)";
253 case CecUserControlCode.F5:
255 case CecUserControlCode.Data:
257 case CecUserControlCode.SamsungReturn:
258 return "Return (Samsung)";
263 public CecKeypress Key { get; private set; }
264 public ApplicationController Controller { get; private set; }
267 internal class CecButtonConfig : List<CecButtonConfigItem>
269 public CecButtonConfig(ApplicationController controller)
271 _controller = controller;
276 foreach (var item in this)
278 item.SetController(_controller);
279 _controller.Settings[item.KeyName] = item;
280 _controller.Settings.Load(item);
284 public CecButtonConfigItem this[CecKeypress key]
288 foreach (var item in this)
290 if (item.Key.Keycode == key.Keycode)
297 private readonly ApplicationController _controller;