1
// This program is free software: you can redistribute it and/or modify
2
// it under the terms of the GNU General Public License as published by
3
// the Free Software Foundation, either version 3 of the License, or
4
// (at your option) any later version.
6
// This program is distributed in the hope that it will be useful,
7
// but WITHOUT ANY WARRANTY; without even the implied warranty of
8
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
// GNU General Public License for more details.
11
// You should have received a copy of the GNU General Public License
12
// along with this program. If not, see <http://www.gnu.org/licenses/>.
15
using System.Collections.Generic;
20
namespace SqueezeCenter
23
public abstract class RadioItem : Item
25
protected RadioSubItem[] children;
27
public virtual RadioSubItem[] Children
29
get { return this.children; }
32
System.Threading.Interlocked.Exchange<RadioSubItem[]> (ref this.children, value);
36
public abstract RadioItem Parent {get;}
38
public override string Icon
40
get { return "radio.png@" + this.GetType ().Assembly.FullName; }
44
public class RadioSuperItem : RadioItem
46
readonly string cmd, name;
47
bool childrenSet = false;
49
public RadioSuperItem (string cmd, string name)
53
this.children = new RadioSubItem[0];
56
public string Command {
62
public override string Name {
68
public override string Description {
74
public override RadioSubItem[] Children {
75
get { return base.Children; }
78
base.Children = value;
79
this.childrenSet = true;
83
public bool IsLoadedRecursive
87
if (!this.childrenSet)
89
foreach (RadioSubItem rmi in this.children) {
90
if (!rmi.IsLoadedRecursive)
97
public override RadioItem Parent
102
public RadioSubItem[] GetChildrenRecursive ()
104
List<RadioSubItem> result = new List<RadioSubItem> ();
105
foreach (RadioSubItem rmi in children) {
107
rmi.CopyChildrenRecursive (result);
109
return result.ToArray ();
113
public class RadioSubItem : RadioItem
116
readonly RadioItem parent;
117
readonly string name;
118
readonly bool hasItems;
120
public RadioSubItem (RadioItem parent, int id, string name, bool hasItems)
122
this.parent = parent;
125
this.hasItems = hasItems;
126
this.children = new RadioSubItem[0];
129
public override string Name {
135
public override string Description {
137
RadioItem parent = this.parent;
138
string result = string.Empty;
139
while (parent != null) {
140
result = parent.Name + (result.Length == 0 ? string.Empty : " → " + result);
141
parent = parent.Parent;
147
public override RadioItem Parent
149
get { return this.parent; }
154
get { return this.id; }
159
get { return this.hasItems; }
162
public RadioSuperItem GetSuper ()
166
if (r is RadioSuperItem)
167
return r as RadioSuperItem;
176
if (! (this.parent is RadioSubItem)) {
177
return this.Id.ToString ();
179
return string.Format ("{0}.{1}", (this.parent as RadioSubItem).IdPath, this.Id);
183
public void CopyChildrenRecursive (List<RadioSubItem> target)
185
foreach (RadioSubItem rmi in children) {
187
rmi.CopyChildrenRecursive (target);
191
public bool IsLoadedRecursive
196
foreach (RadioSubItem rmi in this.children) {
197
if (!rmi.IsLoadedRecursive) {