diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellCoverArt.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellCoverArt.cs new file mode 100644 index 000000000..6254ac566 --- /dev/null +++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellCoverArt.cs @@ -0,0 +1,108 @@ +// +// ColumnCellCoverArt.cs +// +// Author: +// Nicholas Little +// +// Copyright (C) 2017 +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using Gtk; +using Cairo; + +using Hyena.Gui; +using Hyena.Gui.Theming; +using Hyena.Data.Gui; +using Hyena.Data.Gui.Accessibility; + +using Banshee.Gui; +using Banshee.ServiceStack; + +namespace Banshee.Collection.Gui +{ + public class ColumnCellCoverArt : ColumnCell + { + private static int image_spacing = 4; + private static int image_size = 48; + + private ArtworkManager artwork_manager; + + public ColumnCellCoverArt () : base (null, true) + { + artwork_manager = ServiceManager.Get (); + + FixedSize = new Hyena.Gui.Canvas.Size ( image_size, image_size ); + } + + private class ColumnCellCoverArtAccessible : ColumnCellAccessible + { + public ColumnCellCoverArtAccessible (object bound_object, ColumnCellCoverArt cell, ICellAccessibleParent parent) + : base (bound_object, cell as ColumnCell, parent) + { + var bound_album_info = bound_object as AlbumInfo; + if (bound_album_info != null) { + Name = String.Format ("{0} - {1}", + bound_album_info.DisplayTitle, + bound_album_info.DisplayArtistName); + } + } + } + + public override Atk.Object GetAccessible (ICellAccessibleParent parent) + { + return new ColumnCellCoverArtAccessible (BoundObject, this, parent); + } + + public override void Render (CellContext context, double cellWidth, double cellHeight) + { + if (BoundObject == null) { + return; + } + + TrackInfo track = BoundObject as TrackInfo; + AlbumInfo album = BoundObject as AlbumInfo; + + if (null == track && null == album) { + throw new InvalidCastException ("ColumnCellCoverArt can only bind to Track/AlbumInfo objects"); + } + + string artworkId = track?.ArtworkId ?? album?.ArtworkId; + + int image_render_size = (int) Math.Min(cellWidth, cellHeight); + + ImageSurface image = artwork_manager?.LookupScaleSurface (artworkId, image_render_size, true); + + var x = (cellWidth - image_render_size) / 2; + var y = (cellHeight - image_render_size) / 2; + + ArtworkRenderer.RenderThumbnail (context.Context, image, + dispose: false, + x: (int) x, + y: (int) y, + width: image_render_size, + height: image_render_size, + drawBorder: false, + radius: 0); + } + } +} diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DefaultColumnController.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DefaultColumnController.cs index 8e7e5c760..6612896a0 100644 --- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DefaultColumnController.cs +++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DefaultColumnController.cs @@ -68,6 +68,7 @@ public void AddDefaultColumns () AddRange ( IndicatorColumn, TrackColumn, + CoverArtColumn, TitleColumn, ArtistColumn, AlbumColumn, @@ -106,7 +107,10 @@ private void CreateDefaultColumns () // Visible-by-default column track_column = Create (BansheeQuery.TrackNumberField, 0.10, true, new ColumnCellTrackNumber (null, true)); - track_column.Title = String.Empty; // don't show any text in the header for this column, so it can be smaller + track_column.Title = String.Empty; // don't show any text in the header for this column, so it can be smaller + + var cover_art_desc = new Hyena.Data.ColumnDescription(null, "Cover Art", 0.10); + cover_art_column = new Column(cover_art_desc, new ColumnCellCoverArt()) { Id = "cover_art", Title = string.Empty }; title_column = CreateText (BansheeQuery.TitleField, 0.25, true); artist_column = CreateText (BansheeQuery.ArtistField, 0.225, true); @@ -350,6 +354,11 @@ public SortableColumn LicenseUriColumn { get { return license_uri_column; } } + private Column cover_art_column; + public Column CoverArtColumn { + get { return cover_art_column; } + } + #endregion } diff --git a/src/Core/Banshee.ThickClient/Makefile.am b/src/Core/Banshee.ThickClient/Makefile.am index 1d40be6de..0037ff560 100644 --- a/src/Core/Banshee.ThickClient/Makefile.am +++ b/src/Core/Banshee.ThickClient/Makefile.am @@ -17,6 +17,7 @@ SOURCES = \ Banshee.Collection.Gui/BaseTrackListView.cs \ Banshee.Collection.Gui/ColumnCellAlbum.cs \ Banshee.Collection.Gui/ColumnCellArtistText.cs \ + Banshee.Collection.Gui/ColumnCellCoverArt.cs \ Banshee.Collection.Gui/ColumnCellCreativeCommons.cs \ Banshee.Collection.Gui/ColumnCellDateTime.cs \ Banshee.Collection.Gui/ColumnCellDiscAndCount.cs \ diff --git a/src/Hyena b/src/Hyena index c72e52086..f7cb3b9f3 160000 --- a/src/Hyena +++ b/src/Hyena @@ -1 +1 @@ -Subproject commit c72e5208632f8b1c2b27bd853e22acbb1d06d9fd +Subproject commit f7cb3b9f38551175a09b4d5b7c3d5554f99bdd53