~ubuntu-branches/debian/jessie/banshee-community-extensions/jessie

« back to all changes in this revision

Viewing changes to src/ClutterFlow/Banshee.ClutterFlow/ClutterFlowAlbum.cs

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2011-09-20 18:45:46 UTC
  • mfrom: (1.2.9 upstream) (5.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20110920184546-3ahue2qplydc4t0e
Tags: 2.2.0-1
* [4940fab] Imported Upstream version 2.2.0
  + Notable bug fixes:
    - Karaoke: Fix crash when switching to Now Playing
    - Lyrics: Fix crash when switching to Now Playing

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
using ClutterFlow;
36
36
 
37
37
namespace Banshee.ClutterFlow
38
 
{       
39
 
        /// <summary>
 
38
{
 
39
    /// <summary>
40
40
    /// A ClutterFlowAlbum is a subclass of the ClutterFlowActor class, containing
41
41
    /// banshee related Album art fetching code.
42
42
    /// </summary>
43
 
        public class ClutterFlowAlbum : ClutterFlowActor,  IEquatable<ClutterFlowAlbum>
44
 
        {
45
 
                #region Fields
46
 
                protected static ArtworkLookup lookup;
47
 
                public static ArtworkLookup Lookup {
48
 
                        get { return lookup; }
49
 
                        set { lookup = value; }
50
 
                }
51
 
 
52
 
                protected AlbumInfo album;
53
 
                public virtual AlbumInfo Album {
54
 
                        get { return album; }
55
 
                        set {
56
 
                                if (album!=value) {
57
 
                                        album = value;
58
 
                                        Lookup.Enqueue (this);
59
 
                                }
60
 
                        }
61
 
                }
62
 
        
63
 
                public virtual string PbId {
64
 
                        get { return Album!=null ? Album.ArtworkId : "NOT FOUND"; }
65
 
                }
66
 
 
67
 
                public override string CacheKey {
68
 
                        get { return CreateCacheKey(album); }
69
 
                        set {
70
 
                                throw new System.NotImplementedException ("CacheKey cannot be set directly in a ClutterFlowAlbum," +
71
 
                                                                          "derived from the Album property."); //TODO should use reflection here
72
 
                        }
73
 
                }
74
 
                public static string CreateCacheKey(AlbumInfo album) {
75
 
            return album!=null ? album.ArtistName + "\n" + album.Title : "";
76
 
                }
77
 
 
78
 
                public override string Label {
79
 
                        get { return album!=null ? album.ArtistName + "\n" + album.Title : ""; }
80
 
                        set {
81
 
                                throw new System.NotImplementedException ("Label cannot be set directly in a ClutterFlowAlbum, derived from the Album property.");
82
 
                        }
83
 
                }
 
43
    public class ClutterFlowAlbum : ClutterFlowActor, IEquatable<ClutterFlowAlbum>
 
44
    {
 
45
        #region Fields
 
46
        private static ArtworkLookup artwork_lookup;
 
47
 
 
48
        private AlbumInfo album;
 
49
        public AlbumInfo Album {
 
50
            get { return album; }
 
51
            set {
 
52
                if (album != value) {
 
53
                    album = value;
 
54
                    artwork_lookup.Enqueue (this);
 
55
                }
 
56
            }
 
57
        }
 
58
 
 
59
        public virtual string PbId {
 
60
            get { return Album != null ? Album.ArtworkId : "NOT FOUND"; }
 
61
        }
 
62
 
 
63
        public override string CacheKey {
 
64
            get { return CreateCacheKey (album); }
 
65
        }
 
66
        public static string CreateCacheKey (AlbumInfo album)
 
67
        {
 
68
            return album != null ? album.ArtistName + "\n" + album.Title : "";
 
69
        }
 
70
 
 
71
        public override string Label {
 
72
            get { return album != null ? album.ArtistName + "\n" + album.Title : ""; }
 
73
        }
84
74
 
85
75
        object sync = new object();
86
76
        bool enqueued = false;
88
78
            get { lock (sync) { return enqueued; } }
89
79
            internal set { lock (sync) { enqueued = value; } }
90
80
        }
91
 
                #endregion
92
 
 
93
 
                #region Initialization
94
 
                public ClutterFlowAlbum (AlbumInfo album, CoverManager coverManager) : base (coverManager, null)
95
 
                {
96
 
                        this.album = album;
97
 
                        Lookup.Enqueue(this);
98
 
                }
99
 
                protected override bool SetupStatics ()
100
 
                {
101
 
                        if (lookup==null) lookup = new ArtworkLookup (CoverManager);
102
 
                        return base.SetupStatics ();
103
 
                }
104
 
        protected override void DisposeStatics ()
105
 
        {
106
 
            if (lookup!=null) lookup.Dispose ();
107
 
            lookup = null;
108
 
            base.DisposeStatics ();
109
 
        }
110
 
                #endregion
111
 
                
112
 
                #region Texture Handling
113
 
                protected override Cairo.ImageSurface GetDefaultSurface ()
114
 
                {
115
 
                        Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, CoverManager.TextureSize, CoverManager.TextureSize);
116
 
                        Cairo.Context context = new Cairo.Context(surface);
117
 
                        Gdk.CairoHelper.SetSourcePixbuf(context, IconThemeUtils.LoadIcon (CoverManager.TextureSize, "media-optical", "browser-album-cover"), 0, 0);
118
 
                        context.Paint();
119
 
                        //((IDisposable) context.Target).Dispose();
120
 
                        ((IDisposable) context).Dispose();
121
 
                        return  surface;
122
 
                }       
123
 
 
124
 
                protected override void HandleTextureSizeChanged (object sender, System.EventArgs e)
125
 
                {
126
 
                        Lookup.Enqueue(this);
127
 
                }
128
 
                #endregion
129
 
                
130
 
                public virtual bool Equals (ClutterFlowAlbum other)
131
 
                {
132
 
                        return other.CacheKey==this.CacheKey;
133
 
                }
134
 
        }
 
81
        #endregion
 
82
 
 
83
        #region Initialization
 
84
        public ClutterFlowAlbum (AlbumInfo album, CoverManager coverManager) : base (coverManager)
 
85
        {
 
86
            this.album = album;
 
87
            if (artwork_lookup == null) {
 
88
                artwork_lookup = new ArtworkLookup (CoverManager);
 
89
            }
 
90
            artwork_lookup.Enqueue(this);
 
91
        }
 
92
 
 
93
        public override void Dispose ()
 
94
        {
 
95
            if (artwork_lookup != null) {
 
96
                artwork_lookup.Dispose ();
 
97
            }
 
98
            artwork_lookup = null;
 
99
            base.Dispose ();
 
100
        }
 
101
        #endregion
 
102
 
 
103
        public virtual bool Equals (ClutterFlowAlbum other)
 
104
        {
 
105
            return other.CacheKey == this.CacheKey;
 
106
        }
 
107
    }
135
108
}