~iwarford/do-plugins/fart-plugin-fwiw

« back to all changes in this revision

Viewing changes to SqueezeCenter/src/ItemSource.cs

  • Committer: Jason Jones
  • Date: 2008-12-24 04:45:02 UTC
  • mfrom: (335.1.9 do-plugins)
  • Revision ID: jasonedwardjones@gmail.com-20081224044502-ra56ym06cp1iqs7t
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
5
//
 
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.
 
10
//
 
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/>.
 
13
 
 
14
using System;
 
15
using System.IO;
 
16
using System.Collections.Generic;
 
17
using System.Threading;
 
18
 
 
19
 
 
20
using Do.Universe;
 
21
using Do.Platform.Linux;
 
22
 
 
23
namespace SqueezeCenter
 
24
{
 
25
        
 
26
        public class ItemSource : Do.Universe.ItemSource,  IConfigurable
 
27
        {
 
28
                List<Item> items;               
 
29
                List<AlbumMusicItem> albums;
 
30
                List<ArtistMusicItem> artists;
 
31
                
 
32
                public ItemSource ()
 
33
                {       
 
34
                        items = new List<Item> ();
 
35
                        albums = new List<AlbumMusicItem>();
 
36
                        artists = new List<ArtistMusicItem>();
 
37
                        UpdateItems ();
 
38
                }
 
39
                
 
40
                public Gtk.Bin GetConfiguration ()
 
41
                {                       
 
42
                        return new Configuration ();
 
43
                }
 
44
 
 
45
                public override string Name { get { return "SqueezeCenter"; } }
 
46
                public override string Description { get { return "Artists, albums and radio."; } }
 
47
                public override string Icon { get { return "SB on.png@" + this.GetType ().Assembly.FullName; } }                
 
48
 
 
49
                public override IEnumerable<Type> SupportedItemTypes {
 
50
                        get {
 
51
                                return new Type[] {
 
52
                                        typeof (MusicItem),
 
53
                                        typeof (RadioItem),
 
54
                                        typeof (BrowseMusicItem),
 
55
                                        typeof (IApplicationItem),
 
56
                                };
 
57
                        }
 
58
                }
 
59
 
 
60
                public override IEnumerable<Item> Items 
 
61
                { 
 
62
                        get 
 
63
                        {                       
 
64
                                return items; 
 
65
                        } 
 
66
                }
 
67
 
 
68
                public override IEnumerable<Item> ChildrenOfItem (Item parent)                  
 
69
                {
 
70
                        List<Item> children = new List<Item> ();
 
71
                        
 
72
                        if (parent is IApplicationItem && parent.Name == this.Name) {
 
73
                                children.Add (new BrowseAlbumsMusicItem ());
 
74
                                children.Add (new BrowseArtistsMusicItem ());
 
75
                        }
 
76
                        else if (parent is ArtistMusicItem) {
 
77
                                foreach (AlbumMusicItem album in albums)
 
78
                                        if(album.Artist == parent)
 
79
                                                children.Add (album);
 
80
                        }
 
81
                        else if (parent is BrowseAlbumsMusicItem) {
 
82
                                foreach (AlbumMusicItem album in albums)
 
83
                                        children.Add (album);
 
84
                        }
 
85
                        else if (parent is BrowseArtistsMusicItem) {
 
86
                                foreach (ArtistMusicItem album in artists)
 
87
                                        children.Add (album);
 
88
                        }
 
89
                        else if (parent is RadioItem) {
 
90
                                children.AddRange ((parent as RadioItem).Children);
 
91
                        }
 
92
                        
 
93
                        return children;
 
94
                }
 
95
 
 
96
                public override void UpdateItems ()
 
97
                {
 
98
                        items.Clear ();
 
99
 
 
100
                        // Add artists
 
101
                        albums.Clear();
 
102
                        albums.AddRange (Server.Instance.GetAlbums ());
 
103
 
 
104
                        // Add albums
 
105
                        artists.Clear();
 
106
                        artists.AddRange (Server.Instance.GetArtists ());
 
107
                                                
 
108
                        // Add radios and all children
 
109
                        foreach (RadioSuperItem r in Server.Instance.GetRadios ()) {
 
110
#if VERBOSE_OUTPUT
 
111
                                Console.WriteLine ("SQC: Adding radio:" + r.Name + "  Children: " + r.GetChildrenRecursive ().Length);
 
112
#endif
 
113
                                // items.Add (r);
 
114
                                items.AddRange (r.GetChildrenRecursive ());
 
115
                        }                       
 
116
 
 
117
                        // Add players
 
118
                        items.AddRange (Server.Instance.GetConnectedPlayersAsItem ());
 
119
 
 
120
                        // Add browse features
 
121
                        items.Add (new BrowseAlbumsMusicItem ());
 
122
                        items.Add (new BrowseArtistsMusicItem ());
 
123
 
 
124
                                                                                
 
125
                        // Add artists and albums to items
 
126
                        items.Capacity = Math.Max (items.Capacity, items.Count + albums.Count + artists.Count);
 
127
                        foreach (Item album in albums) items.Add (album);
 
128
                        foreach (Item artist in artists) items.Add (artist);
 
129
                }       
 
130
        }
 
131
}