~ubuntu-branches/ubuntu/raring/banshee/raring

« back to all changes in this revision

Viewing changes to .pc/0011-Fix-FTBFS-involving-bad-cast-libgpod-forwardport.patch/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceTrackInfo.cs

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2012-01-23 23:16:49 UTC
  • mfrom: (6.3.22 experimental)
  • Revision ID: package-import@ubuntu.com-20120123231649-safm1f8eycltcgsf
Tags: 2.3.4.ds-1ubuntu1
* Merge from Debian Experimental, remaining changes:
  + Enable and recommend SoundMenu and Disable NotificationArea by default
  + Disable boo and karma extensions
  + Enable and suggest u1ms
  + Move desktop file for Meego UI to /usr/share/une/applications
  + Change the url for the Amazon store redirector
  + [08dea2c] Revert "Fix invalid cast causing ftbfs with libgpod"
* [b617fe0] Convert Ubuntu-specific patches to gbp-pq patches
* Also fixes Launchpad bugs:
  - Fixes race condition while starting (LP: #766303)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// AppleDeviceTrackInfo.cs
 
3
// 
 
4
// Author:
 
5
//   Alan McGovern <amcgovern@novell.com>
 
6
// 
 
7
// Copyright (c) 2010 Moonlight Team
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
 
 
29
using Banshee.Base;
 
30
using Banshee.Streaming;
 
31
using Banshee.Collection;
 
32
using Banshee.Collection.Database;
 
33
 
 
34
using Hyena;
 
35
 
 
36
namespace Banshee.Dap.AppleDevice
 
37
{
 
38
    public class AppleDeviceTrackInfo : DatabaseTrackInfo
 
39
    {
 
40
        internal GPod.Track IpodTrack {
 
41
            get; set;
 
42
        }
 
43
 
 
44
        private string mimetype;
 
45
        private string description; // Only used for podcasts.
 
46
 
 
47
        public AppleDeviceTrackInfo (GPod.Track track)
 
48
        {
 
49
            IpodTrack = track;
 
50
            LoadFromIpodTrack ();
 
51
            CanSaveToDatabase = true;
 
52
        }
 
53
 
 
54
        public AppleDeviceTrackInfo (TrackInfo track)
 
55
        {
 
56
            CanSaveToDatabase = true;
 
57
 
 
58
            if (track is AppleDeviceTrackInfo) {
 
59
                IpodTrack = ((AppleDeviceTrackInfo)track).IpodTrack;
 
60
                LoadFromIpodTrack ();
 
61
            } else {
 
62
                UpdateInfo (track);
 
63
            }
 
64
        }
 
65
 
 
66
        public void UpdateInfo (TrackInfo track)
 
67
        {
 
68
            if (track is AppleDeviceTrackInfo) {
 
69
                throw new ArgumentException ("Shouldn't update an AppleDeviceTrackInfo from an AppleDeviceTrackInfo");
 
70
            }
 
71
 
 
72
            IsCompilation = track.IsCompilation ;
 
73
            AlbumArtist = track.AlbumArtist;
 
74
            AlbumTitle = track.AlbumTitle;
 
75
            ArtistName = track.ArtistName;
 
76
            BitRate = track.BitRate;
 
77
            SampleRate = track.SampleRate;
 
78
            Bpm = track.Bpm;
 
79
            Comment = track.Comment;
 
80
            Composer = track.Composer;
 
81
            Conductor = track.Conductor;
 
82
            Copyright = track.Copyright;
 
83
            DateAdded = track.DateAdded;
 
84
            DiscCount = track.DiscCount;
 
85
            DiscNumber = track.DiscNumber;
 
86
            Duration = track.Duration;
 
87
            FileSize = track.FileSize;
 
88
            Genre = track.Genre;
 
89
            Grouping = track.Grouping;
 
90
            LastPlayed = track.LastPlayed;
 
91
            LastSkipped = track.LastSkipped;
 
92
            PlayCount = track.PlayCount;
 
93
            Rating = track.Rating;
 
94
            ReleaseDate = track.ReleaseDate;
 
95
            SkipCount = track.SkipCount;
 
96
            TrackCount = track.TrackCount;
 
97
            TrackNumber = track.TrackNumber;
 
98
            TrackTitle = track.TrackTitle;
 
99
            Year = track.Year;
 
100
            MediaAttributes = track.MediaAttributes;
 
101
 
 
102
            ArtistNameSort = track.ArtistNameSort;
 
103
            AlbumTitleSort = track.AlbumTitleSort;
 
104
            AlbumArtistSort = track.AlbumArtistSort;
 
105
            TrackTitleSort = track.TrackTitleSort;
 
106
 
 
107
            var podcast_info = track.ExternalObject as IPodcastInfo;
 
108
            if (podcast_info != null) {
 
109
                description = podcast_info.Description;
 
110
                ReleaseDate = podcast_info.ReleaseDate;
 
111
            }
 
112
 
 
113
            mimetype = track.MimeType;
 
114
        }
 
115
 
 
116
        private void LoadFromIpodTrack ()
 
117
        {
 
118
            var track = IpodTrack;
 
119
            try {
 
120
                Uri = new SafeUri (System.IO.Path.Combine (track.ITDB.Mountpoint, track.IpodPath.Replace (":", System.IO.Path.DirectorySeparatorChar.ToString ()).Substring (1)));
 
121
            } catch (Exception ex) {
 
122
                Log.Exception (ex);
 
123
                Uri = null;
 
124
            }
 
125
 
 
126
            ExternalId = (long) track.DBID;
 
127
 
 
128
            IsCompilation = track.Compilation;
 
129
            AlbumArtist = track.AlbumArtist;
 
130
            AlbumTitle = String.IsNullOrEmpty (track.Album) ? null : track.Album;
 
131
            ArtistName = String.IsNullOrEmpty (track.Artist) ? null : track.Artist;
 
132
            BitRate = track.Bitrate;
 
133
            SampleRate = track.Samplerate;
 
134
            Bpm = (int)track.BPM;
 
135
            Comment = track.Comment;
 
136
            Composer = track.Composer;
 
137
            DateAdded = track.TimeAdded;
 
138
            DiscCount = track.CDs;
 
139
            DiscNumber = track.CDNumber;
 
140
            Duration = TimeSpan.FromMilliseconds (track.TrackLength);
 
141
            FileSize = track.Size;
 
142
            Genre = String.IsNullOrEmpty (track.Genre) ? null : track.Genre;
 
143
            Grouping = track.Grouping;
 
144
            LastPlayed = track.TimePlayed;
 
145
            PlayCount = (int) track.PlayCount;
 
146
            TrackCount = track.Tracks;
 
147
            TrackNumber = track.TrackNumber;
 
148
            TrackTitle = String.IsNullOrEmpty (track.Title) ? null : track.Title;
 
149
            Year = track.Year;
 
150
            description = track.Description;
 
151
            ReleaseDate = track.TimeReleased;
 
152
            ArtistNameSort = track.SortArtist;
 
153
            AlbumTitleSort = track.SortAlbum;
 
154
            AlbumArtistSort = track.SortAlbumArtist;
 
155
            TrackTitleSort = track.SortTitle;
 
156
 
 
157
            rating = track.Rating > 5 ? 0 : (int) track.Rating;
 
158
 
 
159
            if (track.DRMUserID > 0) {
 
160
                PlaybackError = StreamPlaybackError.Drm;
 
161
            }
 
162
 
 
163
            MediaAttributes = TrackMediaAttributes.AudioStream;
 
164
            switch (track.MediaType) {
 
165
            case GPod.MediaType.Audio:
 
166
                MediaAttributes |= TrackMediaAttributes.Music;
 
167
                break;
 
168
            // This seems to cause audio files to show up in Banshee in the Videos section
 
169
            /*case GPod.MediaType.AudioVideo:
 
170
                MediaAttributes |= TrackMediaAttributes.VideoStream;
 
171
                break;*/
 
172
            case GPod.MediaType.MusicVideo:
 
173
                MediaAttributes |= TrackMediaAttributes.Music | TrackMediaAttributes.VideoStream;
 
174
                break;
 
175
            case GPod.MediaType.Movie:
 
176
                MediaAttributes |= TrackMediaAttributes.VideoStream | TrackMediaAttributes.Movie;
 
177
                break;
 
178
            case GPod.MediaType.TVShow:
 
179
                MediaAttributes |= TrackMediaAttributes.VideoStream | TrackMediaAttributes.TvShow;
 
180
                break;
 
181
            case GPod.MediaType.Podcast:
 
182
                MediaAttributes |= TrackMediaAttributes.Podcast;
 
183
                // FIXME: persist URL on the track (track.PodcastUrl)
 
184
                break;
 
185
            case GPod.MediaType.Audiobook:
 
186
                MediaAttributes |= TrackMediaAttributes.AudioBook;
 
187
                break;
 
188
            case GPod.MediaType.MusicTVShow:
 
189
                MediaAttributes |= TrackMediaAttributes.Music | TrackMediaAttributes.VideoStream | TrackMediaAttributes.TvShow;
 
190
                break;
 
191
            }
 
192
 
 
193
            // If it's just AudioStream, add Music to it as well so it'll show up in Music
 
194
            if (MediaAttributes == TrackMediaAttributes.AudioStream) {
 
195
                MediaAttributes |= TrackMediaAttributes.Music;
 
196
            }
 
197
        }
 
198
 
 
199
        public void CommitToIpod (GPod.ITDB database)
 
200
        {
 
201
            bool addTrack = IpodTrack == null;
 
202
            if (IpodTrack == null) {
 
203
                IpodTrack = new GPod.Track ();
 
204
            }
 
205
 
 
206
            var track = IpodTrack;
 
207
            track.Compilation = IsCompilation;
 
208
            track.AlbumArtist = AlbumArtist;
 
209
            track.Bitrate = BitRate;
 
210
            track.Samplerate= (ushort)SampleRate;
 
211
            track.BPM = (short)Bpm;
 
212
            track.Comment = Comment;
 
213
            track.Composer = Composer;
 
214
            track.TimeAdded = DateTime.Now;
 
215
            track.CDs = DiscCount;
 
216
            track.CDNumber = DiscNumber;
 
217
            track.TrackLength = (int) Duration.TotalMilliseconds;
 
218
            track.Size = (int)FileSize;
 
219
            track.Grouping = Grouping;
 
220
            try {
 
221
                track.TimePlayed = LastPlayed;
 
222
            } catch {
 
223
                Hyena.Log.InformationFormat ("Couldn't set TimePlayed to '{0}'", LastPlayed);
 
224
            }
 
225
            track.PlayCount = (uint) PlayCount;
 
226
            track.Tracks = TrackCount;
 
227
            track.TrackNumber = TrackNumber;
 
228
            track.Year = Year;
 
229
            try {
 
230
                track.TimeReleased = ReleaseDate;
 
231
            } catch {
 
232
                Hyena.Log.InformationFormat ("Couldn't set TimeReleased to '{0}'", ReleaseDate);
 
233
            }
 
234
            track.Album = AlbumTitle;
 
235
            track.Artist = ArtistName;
 
236
            track.Title = TrackTitle;
 
237
            track.Genre = Genre;
 
238
 
 
239
            track.SortArtist = ArtistNameSort;
 
240
            track.SortAlbum = AlbumTitleSort;
 
241
            track.SortAlbumArtist = AlbumArtistSort;
 
242
            track.SortTitle = TrackTitleSort;
 
243
 
 
244
            track.Rating = ((Rating >= 1) && (Rating <= 5)) ? (uint)Rating : 0;
 
245
 
 
246
            if (HasAttribute (TrackMediaAttributes.Podcast)) {
 
247
                track.Description = description;
 
248
                track.RememberPlaybackPosition = true;
 
249
                track.SkipWhenShuffling = true;
 
250
                track.Flag4 = (byte)1;
 
251
                track.MarkUnplayed = (track.PlayCount == 0);
 
252
            }
 
253
 
 
254
            track.MediaType = GPod.MediaType.Audio;
 
255
            if (HasAttribute (TrackMediaAttributes.VideoStream)) {
 
256
                if (HasAttribute (TrackMediaAttributes.Podcast)) {
 
257
                    track.MediaType = GPod.MediaType.Podcast | GPod.MediaType.Movie;
 
258
                } else if (HasAttribute (TrackMediaAttributes.Music)) {
 
259
                    if (HasAttribute (TrackMediaAttributes.TvShow)) {
 
260
                        track.MediaType = GPod.MediaType.MusicTVShow;
 
261
                    } else {
 
262
                        track.MediaType = GPod.MediaType.MusicVideo;
 
263
                    }
 
264
                } else if (HasAttribute (TrackMediaAttributes.Movie)) {
 
265
                    track.MediaType = GPod.MediaType.Movie;
 
266
                } else if (HasAttribute (TrackMediaAttributes.TvShow)) {
 
267
                    track.MediaType = GPod.MediaType.TVShow;
 
268
                } else {
 
269
                    // I dont' think AudioVideo should be used here; upon loading the tracks
 
270
                    // into Banshee, audio files often have AudioVideo (aka MediaType == 0) too.
 
271
                    //track.MediaType = GPod.MediaType.AudioVideo;
 
272
                    track.MediaType = GPod.MediaType.Movie;
 
273
                }
 
274
            } else {
 
275
                if (HasAttribute (TrackMediaAttributes.Podcast)) {
 
276
                    track.MediaType = GPod.MediaType.Podcast;
 
277
                } else if (HasAttribute (TrackMediaAttributes.AudioBook)) {
 
278
                    track.MediaType = GPod.MediaType.Audiobook;
 
279
                } else if (HasAttribute (TrackMediaAttributes.Music)) {
 
280
                    track.MediaType = GPod.MediaType.Audio;
 
281
                } else {
 
282
                    track.MediaType = GPod.MediaType.Audio;
 
283
                }
 
284
            }
 
285
 
 
286
            if (addTrack) {
 
287
                track.Filetype = mimetype;
 
288
 
 
289
                database.Tracks.Add (IpodTrack);
 
290
                database.MasterPlaylist.Tracks.Add (IpodTrack);
 
291
 
 
292
                if (HasAttribute (TrackMediaAttributes.Podcast) && database.Device.SupportsPodcast) {
 
293
                    database.PodcastsPlaylist.Tracks.Add (IpodTrack);
 
294
                }
 
295
 
 
296
                database.CopyTrackToIPod (track, Uri.LocalPath);
 
297
                Uri = new SafeUri (GPod.ITDB.GetLocalPath (database.Device, track));
 
298
                ExternalId = (long) IpodTrack.DBID;
 
299
            }
 
300
 
 
301
            if (CoverArtSpec.CoverExists (ArtworkId)) {
 
302
                string path = CoverArtSpec.GetPath (ArtworkId);
 
303
                if (!track.ThumbnailsSet (path)) {
 
304
                    Log.Error (String.Format ("Could not set cover art for {0}.", path));
 
305
                }
 
306
            } else {
 
307
                track.ThumbnailsRemoveAll ();
 
308
            }
 
309
        }
 
310
    }
 
311
}