| 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 | |
| 33 | using System.Collections.Generic; |
| 34 | using System.Text; |
| 35 | using LibCECTray.controller.applications.@internal; |
| 36 | using LibCECTray.settings; |
| 37 | |
| 38 | namespace LibCECTray.controller.applications |
| 39 | { |
| 40 | class Applications : CECSettingString |
| 41 | { |
| 42 | private Applications() : |
| 43 | base("global_applications", "Applications", string.Empty, null) |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | public static ApplicationController Get(string key) |
| 48 | { |
| 49 | return (_instance != null && _instance.Value.ContainsKey(key)) |
| 50 | ? _instance.Value[key] |
| 51 | : null; |
| 52 | } |
| 53 | |
| 54 | public static List<ApplicationController> GetAll() |
| 55 | { |
| 56 | List<ApplicationController> retVal = new List<ApplicationController>(); |
| 57 | if (_instance != null) |
| 58 | { |
| 59 | foreach (var app in _instance.Value.Values) |
| 60 | retVal.Add(app); |
| 61 | } |
| 62 | return retVal; |
| 63 | } |
| 64 | |
| 65 | public new Dictionary<string, ApplicationController> Value |
| 66 | { |
| 67 | get |
| 68 | { |
| 69 | if (_controllers == null) |
| 70 | { |
| 71 | _controllers = DefaultValue; |
| 72 | var split = base.Value.Split('~'); |
| 73 | foreach (var item in split) |
| 74 | { |
| 75 | if (item.Length > 0) |
| 76 | { |
| 77 | var app = ApplicationController.FromString(_controller, _controller.Settings, item); |
| 78 | if (app != null) |
| 79 | _controllers.Add(app.ProcessName, app); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return _controllers; |
| 85 | } |
| 86 | |
| 87 | set |
| 88 | { |
| 89 | StringBuilder sb = new StringBuilder(); |
| 90 | foreach (var app in value.Values) |
| 91 | { |
| 92 | sb.AppendFormat("{0}~", app.AsString()); |
| 93 | } |
| 94 | base.Value = sb.ToString(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | public new Dictionary<string, ApplicationController> DefaultValue |
| 99 | { |
| 100 | get |
| 101 | { |
| 102 | var defaultValues = new Dictionary<string, ApplicationController>(); |
| 103 | WMCController wmcController = new WMCController(_controller); |
| 104 | defaultValues.Add(wmcController.ProcessName, wmcController); |
| 105 | XBMCController xbmcController = new XBMCController(_controller); |
| 106 | defaultValues.Add(xbmcController.ProcessName, xbmcController); |
| 107 | |
| 108 | return defaultValues; |
| 109 | } |
| 110 | |
| 111 | set |
| 112 | { |
| 113 | StringBuilder sb = new StringBuilder(); |
| 114 | foreach (var app in value.Values) |
| 115 | { |
| 116 | sb.AppendFormat("{0}~", app.AsString()); |
| 117 | } |
| 118 | base.DefaultValue = sb.ToString(); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | public static void Initialise(CECController controller) |
| 123 | { |
| 124 | _controller = controller; |
| 125 | _instance = new Applications(); |
| 126 | controller.Settings["global_applications"] = _instance; |
| 127 | controller.Settings.Load(_instance); |
| 128 | |
| 129 | foreach (var app in _instance.Value) |
| 130 | _controller.RegisterApplication(app.Value); |
| 131 | } |
| 132 | |
| 133 | private static Applications _instance; |
| 134 | private static CECController _controller; |
| 135 | private Dictionary<string, ApplicationController> _controllers; |
| 136 | } |
| 137 | } |