private void HidePopup() { if (popup != null) { ArtworkManager.DisposePixbuf(popup.Image); popup.Destroy(); popup.EnterNotifyEvent -= OnPopupEnterNotifyEvent; popup.LeaveNotifyEvent -= OnPopupLeaveNotifyEvent; popup = null; } }
private bool UpdatePopup() { if (CurrentTrack == null || ArtworkManager == null || !in_thumbnail_region) { HidePopup(); return(false); } Gdk.Pixbuf pixbuf = ArtworkManager.LookupPixbuf(CurrentTrack.ArtworkId); if (pixbuf == null) { HidePopup(); return(false); } if (popup == null) { popup = new ArtworkPopup(); popup.EnterNotifyEvent += OnPopupEnterNotifyEvent; popup.LeaveNotifyEvent += OnPopupLeaveNotifyEvent; } popup.Label = String.Format("{0} - {1}", CurrentTrack.DisplayArtistName, CurrentTrack.DisplayAlbumTitle); if (popup.Image != null) { ArtworkManager.DisposePixbuf(popup.Image); } popup.Image = pixbuf; if (in_thumbnail_region) { popup.Show(); } return(true); }
protected override void AddTrackToDevice(DatabaseTrackInfo track, SafeUri fromUri) { if (track.PrimarySourceId == DbId) { return; } lock (mtp_device) { Track mtp_track = TrackInfoToMtpTrack(track, fromUri); bool video = track.HasAttribute(TrackMediaAttributes.VideoStream); Folder folder = GetFolderForTrack(track); mtp_device.UploadTrack(fromUri.LocalPath, mtp_track, folder, OnUploadProgress); // Add/update album art if (!video) { string key = MakeAlbumKey(track); if (!album_cache.ContainsKey(key)) { // LIBMTP 1.0.3 BUG WORKAROUND // In libmtp.c the 'LIBMTP_Create_New_Album' function invokes 'create_new_abstract_list'. // The latter calls strlen on the 'name' parameter without null checking. If AlbumTitle is // null, this causes a sigsegv. Lets be safe and always pass non-null values. Album album = new Album(mtp_device, track.AlbumTitle ?? "", track.AlbumArtist ?? "", track.Genre ?? "", track.Composer ?? ""); album.AddTrack(mtp_track); if (supports_jpegs && can_sync_albumart) { ArtworkManager art = ServiceManager.Get <ArtworkManager> (); Exception ex = null; Gdk.Pixbuf pic = null; byte[] bytes = null; uint width = 0, height = 0; ThreadAssist.BlockingProxyToMain(() => { try { pic = art.LookupScalePixbuf(track.ArtworkId, thumb_width); if (pic != null) { bytes = pic.SaveToBuffer("jpeg"); width = (uint)pic.Width; height = (uint)pic.Height; } } catch (Exception e) { ex = e; } }); try { if (ex != null) { throw ex; } if (bytes != null) { ArtworkManager.DisposePixbuf(pic); album.Save(bytes, width, height); album_cache [key] = Tuple.Create(album, folder); } } catch (Exception e) { Log.Debug("Failed to create MTP Album", e.Message); } } else { album.Save(); album_cache[key] = Tuple.Create(album, folder); } } else { Album album = album_cache[key].Item1; album.AddTrack(mtp_track); album.Save(); } } MtpTrackInfo new_track = new MtpTrackInfo(mtp_device, mtp_track); new_track.PrimarySource = this; new_track.Save(false); track_map[new_track.TrackId] = mtp_track; } }