| 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.Collections.Generic; |
| 34 | using CecSharp; |
| 35 | using LibCECTray.settings; |
| 36 | |
| 37 | namespace LibCECTray.controller.applications |
| 38 | { |
| 39 | class CecButtonConfigItem : CECSettingString |
| 40 | { |
| 41 | public CecButtonConfigItem(ApplicationController controller, CecKeypress key) : |
| 42 | base(CECSettingType.Button, null, ButtonName(key.Keycode), ApplicationInput.DefaultValue(controller, key).AsString(), null) |
| 43 | { |
| 44 | Key = key; |
| 45 | } |
| 46 | |
| 47 | public new ApplicationInput Value |
| 48 | { |
| 49 | get |
| 50 | { |
| 51 | return base.Value != null |
| 52 | ? ApplicationInput.FromString(Controller, base.Value) |
| 53 | : new ApplicationInput(Controller); |
| 54 | } |
| 55 | set |
| 56 | { |
| 57 | base.Value = value == null ? null : value.AsString(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | public new ApplicationInput DefaultValue |
| 62 | { |
| 63 | get { return base.DefaultValue != null ? ApplicationInput.FromString(Controller, base.DefaultValue) : null; } |
| 64 | set { base.DefaultValue = value.AsString(); } |
| 65 | } |
| 66 | |
| 67 | public string MappedButtonName |
| 68 | { |
| 69 | get { return Value == null ? string.Empty : Value.AsFriendlyString(); } |
| 70 | set { base.Value = value; } |
| 71 | } |
| 72 | |
| 73 | public new bool Enabled |
| 74 | { |
| 75 | get |
| 76 | { |
| 77 | return _enabled || !string.IsNullOrEmpty(base.Value); |
| 78 | } |
| 79 | set |
| 80 | { |
| 81 | _enabled = value; |
| 82 | } |
| 83 | } |
| 84 | private bool _enabled; |
| 85 | |
| 86 | public string CecButtonName |
| 87 | { |
| 88 | get { return ButtonName(Key.Keycode); } |
| 89 | } |
| 90 | |
| 91 | public void SetController(ApplicationController controller) |
| 92 | { |
| 93 | Controller = controller; |
| 94 | KeyName = string.Format("{0}_key_{1}", controller.ProcessName, (int)Key.Keycode); |
| 95 | } |
| 96 | |
| 97 | public static string ButtonName(CecUserControlCode key) |
| 98 | { |
| 99 | switch (key) |
| 100 | { |
| 101 | case CecUserControlCode.Select: |
| 102 | return "Select"; |
| 103 | case CecUserControlCode.Up: |
| 104 | return "Up"; |
| 105 | case CecUserControlCode.Down: |
| 106 | return "Down"; |
| 107 | case CecUserControlCode.Left: |
| 108 | return "Left"; |
| 109 | case CecUserControlCode.Right: |
| 110 | return "Right"; |
| 111 | case CecUserControlCode.RightUp: |
| 112 | return "Right+Up"; |
| 113 | case CecUserControlCode.RightDown: |
| 114 | return "Right+Down"; |
| 115 | case CecUserControlCode.LeftUp: |
| 116 | return "Left+Up"; |
| 117 | case CecUserControlCode.LeftDown: |
| 118 | return "Left+Down"; |
| 119 | case CecUserControlCode.RootMenu: |
| 120 | return "Root menu"; |
| 121 | case CecUserControlCode.SetupMenu: |
| 122 | return "Setup menu"; |
| 123 | case CecUserControlCode.ContentsMenu: |
| 124 | return "Contents menu"; |
| 125 | case CecUserControlCode.FavoriteMenu: |
| 126 | return "Favourite menu"; |
| 127 | case CecUserControlCode.Exit: |
| 128 | return "Exit"; |
| 129 | case CecUserControlCode.Number0: |
| 130 | return "0"; |
| 131 | case CecUserControlCode.Number1: |
| 132 | return "1"; |
| 133 | case CecUserControlCode.Number2: |
| 134 | return "2"; |
| 135 | case CecUserControlCode.Number3: |
| 136 | return "3"; |
| 137 | case CecUserControlCode.Number4: |
| 138 | return "4"; |
| 139 | case CecUserControlCode.Number5: |
| 140 | return "5"; |
| 141 | case CecUserControlCode.Number6: |
| 142 | return "6"; |
| 143 | case CecUserControlCode.Number7: |
| 144 | return "7"; |
| 145 | case CecUserControlCode.Number8: |
| 146 | return "8"; |
| 147 | case CecUserControlCode.Number9: |
| 148 | return "9"; |
| 149 | case CecUserControlCode.Dot: |
| 150 | return "."; |
| 151 | case CecUserControlCode.Enter: |
| 152 | return "Enter"; |
| 153 | case CecUserControlCode.Clear: |
| 154 | return "Clear"; |
| 155 | case CecUserControlCode.NextFavorite: |
| 156 | return "Next favourite"; |
| 157 | case CecUserControlCode.ChannelUp: |
| 158 | return "Channel up"; |
| 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: |
| 170 | return "Help"; |
| 171 | case CecUserControlCode.PageUp: |
| 172 | return "Page up"; |
| 173 | case CecUserControlCode.PageDown: |
| 174 | return "Page down"; |
| 175 | case CecUserControlCode.Power: |
| 176 | return "Power"; |
| 177 | case CecUserControlCode.VolumeUp: |
| 178 | return "Volume up"; |
| 179 | case CecUserControlCode.VolumeDown: |
| 180 | return "Volume down"; |
| 181 | case CecUserControlCode.Mute: |
| 182 | return "Mute"; |
| 183 | case CecUserControlCode.Play: |
| 184 | return "Play"; |
| 185 | case CecUserControlCode.Stop: |
| 186 | return "Stop"; |
| 187 | case CecUserControlCode.Pause: |
| 188 | return "Pause"; |
| 189 | case CecUserControlCode.Record: |
| 190 | return "Record"; |
| 191 | case CecUserControlCode.Rewind: |
| 192 | return "Rewind"; |
| 193 | case CecUserControlCode.FastForward: |
| 194 | return "Fast forward"; |
| 195 | case CecUserControlCode.Eject: |
| 196 | return "Eject"; |
| 197 | case CecUserControlCode.Forward: |
| 198 | return "Forward"; |
| 199 | case CecUserControlCode.Backward: |
| 200 | return "Backward"; |
| 201 | case CecUserControlCode.StopRecord: |
| 202 | return "Stop record"; |
| 203 | case CecUserControlCode.PauseRecord: |
| 204 | return "Pause record"; |
| 205 | case CecUserControlCode.Angle: |
| 206 | return "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: |
| 232 | return "Tune"; |
| 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: |
| 242 | return "Power off"; |
| 243 | case CecUserControlCode.PowerOnFunction: |
| 244 | return "Power on"; |
| 245 | case CecUserControlCode.F1Blue: |
| 246 | return "F1 (blue)"; |
| 247 | case CecUserControlCode.F2Red: |
| 248 | return "F2 (red)"; |
| 249 | case CecUserControlCode.F3Green: |
| 250 | return "F3 (green)"; |
| 251 | case CecUserControlCode.F4Yellow: |
| 252 | return "F4 (yellow)"; |
| 253 | case CecUserControlCode.F5: |
| 254 | return "F5"; |
| 255 | case CecUserControlCode.Data: |
| 256 | return "Data"; |
| 257 | case CecUserControlCode.SamsungReturn: |
| 258 | return "Return (Samsung)"; |
| 259 | } |
| 260 | return "Unknown"; |
| 261 | } |
| 262 | |
| 263 | public CecKeypress Key { get; private set; } |
| 264 | public ApplicationController Controller { get; private set; } |
| 265 | } |
| 266 | |
| 267 | internal class CecButtonConfig : List<CecButtonConfigItem> |
| 268 | { |
| 269 | public CecButtonConfig(ApplicationController controller) |
| 270 | { |
| 271 | _controller = controller; |
| 272 | } |
| 273 | |
| 274 | public void Load() |
| 275 | { |
| 276 | foreach (var item in this) |
| 277 | { |
| 278 | item.SetController(_controller); |
| 279 | _controller.Settings[item.KeyName] = item; |
| 280 | _controller.Settings.Load(item); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | public CecButtonConfigItem this[CecKeypress key] |
| 285 | { |
| 286 | get |
| 287 | { |
| 288 | foreach (var item in this) |
| 289 | { |
| 290 | if (item.Key.Keycode == key.Keycode) |
| 291 | return item; |
| 292 | } |
| 293 | return null; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | private readonly ApplicationController _controller; |
| 298 | } |
| 299 | } |