Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// ColumnCellCoverArt.cs
//
// Author:
// Nicholas Little <arealityfarbetween@googlemail.com>
//
// 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<ArtworkManager> ();

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void AddDefaultColumns ()
AddRange (
IndicatorColumn,
TrackColumn,
CoverArtColumn,
TitleColumn,
ArtistColumn,
AlbumColumn,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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

}
Expand Down
1 change: 1 addition & 0 deletions src/Core/Banshee.ThickClient/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down