~karol-bedkowski/do-plugins/putty-fix-324282_load_parameter

« back to all changes in this revision

Viewing changes to Banshee/src/MediaItemSource.cs

  • Committer: Alex Launi
  • Date: 2009-01-23 02:23:36 UTC
  • mfrom: (276.4.12 bansheeplugin)
  • Revision ID: alex.launi@gmail.com-20090123022336-z0hf1ycf7pvg5i0d
Add full Banshee plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* MediaItemSource.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this
 
5
 * source distribution.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
 
 
22
using System;
 
23
using System.Collections.Generic;
 
24
 
 
25
using Mono.Unix;
 
26
 
 
27
using Do.Platform;
 
28
using Do.Universe;
 
29
 
 
30
namespace Banshee
 
31
{       
 
32
        public class MediaItemSource : ItemSource
 
33
        {
 
34
                List<Item> items;
 
35
                List<AlbumMusicItem> albums;
 
36
                List<ArtistMusicItem> artists;
 
37
                List<VideoItem> videos;
 
38
                List<PodcastItem> publishers;
 
39
                
 
40
                public MediaItemSource()
 
41
                {
 
42
                        if (!Util.VersionSupportsIndexing ()) {
 
43
                                Log<Banshee>.Error (Util.UnsupportedVersionMessage);
 
44
                                throw new Exception (Util.UnsupportedVersionMessage);
 
45
                        }
 
46
                                
 
47
                        items = new List<Item> ();
 
48
                }
 
49
                
 
50
                public override string Name {
 
51
                        get { return Catalog.GetString ("Banshee Media"); }
 
52
                }
 
53
                
 
54
                public override string Description {
 
55
                        get { return Catalog.GetString ("Indexes Media from Banshee Media Player"); }
 
56
                }
 
57
                
 
58
                public override string Icon {
 
59
                        get { return "music-player-banshee"; }
 
60
                }
 
61
                
 
62
                public override IEnumerable<Type> SupportedItemTypes {
 
63
                        get {
 
64
                                yield return typeof (MediaItem);
 
65
                                yield return typeof (BrowseMediaItem);
 
66
                                yield return typeof (IApplicationItem);
 
67
                        }
 
68
                }
 
69
                
 
70
                public override IEnumerable<Item> Items {
 
71
                        get { return items; }
 
72
                }
 
73
                
 
74
                public override IEnumerable<Item> ChildrenOfItem (Item parent)
 
75
                {
 
76
                        List<Item> children;
 
77
                        
 
78
                        children = new List<Item> ();
 
79
 
 
80
                        if (parent is IApplicationItem && (parent as IApplicationItem).Exec.Contains ("banshee-1")) {
 
81
                                if (albums != null && albums.Count > 0)
 
82
                                        children.Add (new BrowseAlbumsMusicItem ());
 
83
                                if (artists != null && artists.Count > 0)
 
84
                                        children.Add (new BrowseArtistMusicItem ());
 
85
                                if (videos != null && videos.Count > 0)
 
86
                                        children.Add (new BrowseVideoItem ());
 
87
                                if (publishers != null && publishers.Count > 0)
 
88
                                        children.Add (new BrowsePublisherPodcastItem ());
 
89
                        }
 
90
                        else if (parent is ArtistMusicItem) {
 
91
                                foreach (AlbumMusicItem album in Banshee.LoadAlbumsFor (parent as ArtistMusicItem, albums))
 
92
                                        children.Add (album);
 
93
                        }
 
94
                        else if (parent is AlbumMusicItem) {
 
95
                                foreach (SongMusicItem song in Banshee.LoadMedia (parent as AlbumMusicItem))
 
96
                                        children.Add (song);
 
97
                        }
 
98
                        else if (parent is PodcastPublisherItem) {
 
99
                                foreach (PodcastPodcastItem pc in Banshee.LoadMedia (parent as PodcastPublisherItem))
 
100
                                        children.Add (pc);
 
101
                        }
 
102
                        else if (parent is BrowsePublisherPodcastItem) {
 
103
                                foreach (PodcastItem podcast in publishers)
 
104
                                        children.Add (podcast);
 
105
                        }
 
106
                        else if (parent is BrowseVideoItem) {
 
107
                                foreach (VideoItem video in videos)
 
108
                                        children.Add (video);
 
109
                        }
 
110
                        else if (parent is BrowseAlbumsMusicItem) {
 
111
                                foreach (AlbumMusicItem album in albums)
 
112
                                        children.Add (album);
 
113
                        }
 
114
                        else if (parent is BrowseArtistMusicItem) {
 
115
                                foreach (ArtistMusicItem artist in artists)
 
116
                                        children.Add (artist);
 
117
                        }
 
118
                        
 
119
                        return children;
 
120
                }
 
121
                
 
122
                public override void UpdateItems ()
 
123
                {
 
124
                        items.Clear ();
 
125
                        Banshee.Index ();
 
126
 
 
127
                        Banshee.LoadVideos (out videos);
 
128
                        Banshee.LoadPodcasts (out publishers);
 
129
                        Banshee.LoadAlbumsAndArtists (out albums, out artists);
 
130
                        
 
131
                        foreach (Item video in videos) items.Add (video);
 
132
                        foreach (Item album in albums) items.Add (album);
 
133
                        foreach (Item artist in artists) items.Add (artist);
 
134
                        foreach (Item podcast in publishers) items.Add (podcast);
 
135
                }
 
136
        }
 
137
}