[gnome-music/wip/merge: 122/343] make albumcache work (with default icons only)



commit 304a54fc1415e6a37b2208236873f7dccb7822e9
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Mon Jul 15 18:19:23 2013 +0200

    make albumcache work (with default icons only)

 gnomemusic/albumArtCache.py |   73 ++++++++++++++++++++++++++++++++++++++++--
 gnomemusic/view.py          |    8 +++--
 gnomemusic/widgets.py       |    6 ++-
 3 files changed, 78 insertions(+), 9 deletions(-)
---
diff --git a/gnomemusic/albumArtCache.py b/gnomemusic/albumArtCache.py
index 3fceea1..51ef792 100644
--- a/gnomemusic/albumArtCache.py
+++ b/gnomemusic/albumArtCache.py
@@ -1,4 +1,6 @@
-from gi.repository import GdkPixbuf, Gio, GLib, Grl
+from gi.repository import GdkPixbuf, Gio, GLib, Grl, Gdk
+import cairo
+from math import pi
 
 import os
 import re
@@ -17,9 +19,6 @@ class AlbumArtCache:
             self.instance = AlbumArtCache()
         return self.instance
 
-    def makeDefaultIcon(self, width, height):
-        pass
-
     def __init__(self):
         self.logLookupErrors = False
         self.requested_uris = {}
@@ -39,6 +38,72 @@ class AlbumArtCache:
         except:
             pass
 
+    def makeDefaultIcon(self, width, height):
+        path = "/usr/share/icons/gnome/scalable/places/folder-music-symbolic.svg"
+        # get a small pixbuf with the given path
+        icon = GdkPixbuf.Pixbuf.new_from_file_at_scale(path, 
+                    -1 if width < 0 else width/4,
+                    -1 if height < 0 else height/4,
+                    True)
+
+        # create an empty pixbuf with the requested size
+        result = GdkPixbuf.Pixbuf.new(icon.get_colorspace(),
+                True,
+                icon.get_bits_per_sample(),
+                icon.get_width()*4,
+                icon.get_height()*4)
+        result.fill(0xffffffff)
+        icon.composite(result,
+                        icon.get_width()*3/2,
+                        icon.get_height()*3/2,
+                        icon.get_width(),
+                        icon.get_height(),
+                        icon.get_width()*3/2,
+                        icon.get_height()*3/2,
+                        1, 1,
+                        GdkPixbuf.InterpType.NEAREST, 0xff)
+        return self.makeIconFrame(result)
+
+    def makeIconFrame(self, pixbuf):
+        border = 1.5
+        pixbuf = pixbuf.scale_simple(pixbuf.get_width() - border * 2,
+                                     pixbuf.get_height() - border * 2,
+                                     0)
+
+        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
+                                     int(pixbuf.get_width() + border * 2),
+                                     int(pixbuf.get_height() + border * 2))
+        ctx = cairo.Context(surface)
+        self.drawRoundedPath(ctx, 0, 0,
+                             pixbuf.get_width()  + border * 2,
+                             pixbuf.get_height()  + border * 2,
+                             3)
+        result = Gdk.pixbuf_get_from_surface(surface, 0, 0,
+                                             pixbuf.get_width() + border * 2,
+                                             pixbuf.get_height() + border * 2)
+
+        pixbuf.copy_area(border, border,
+                        pixbuf.get_width() - border * 2,
+                        pixbuf.get_height() - border * 2,
+                        result,
+                        border * 2, border * 2)
+
+        return result
+
+    def drawRoundedPath(self, ctx, x, y, width, height, radius):
+            degrees = pi / 180;
+            ctx.new_sub_path()
+            ctx.arc(x + width - radius, y + radius, radius - 0.5, -90 * degrees, 0 * degrees)
+            ctx.arc(x + width - radius, y + height - radius, radius - 0.5, 0 * degrees, 90 * degrees)
+            ctx.arc(x + radius, y + height - radius, radius - 0.5, 90 * degrees, 180 * degrees)
+            ctx.arc(x + radius, y + radius, radius - 0.5, 180 * degrees, 270 * degrees)
+            ctx.close_path()
+            ctx.set_line_width(0.6)
+            ctx.set_source_rgb(0.2, 0.2, 0.2)
+            ctx.stroke_preserve()
+            ctx.set_source_rgb(1, 1, 1)
+            ctx.fill()
+
     def _tryLoad(self, size, artist, album, i, format, callback):
         if i >= self._keybuilder_funcs.length:
             if format == 'jpeg':
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 4f78016..7871862 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -75,7 +75,8 @@ class ViewContainer(Gtk.Stack):
         self._items = []
         self._loadMore.widget.hide()
         self._connectView()
-        self._symbolicIcon = albumArtCache.makeDefaultIcon(self, self._iconHeight, self._iconWidth)
+        self.cache = albumArtCache.getDefault()
+        self._symbolicIcon = self.cache.makeDefaultIcon(self._iconHeight, self._iconWidth)
 
         self._init = False
         grilo.connect('ready', self._onGriloReady)
@@ -182,7 +183,7 @@ class ViewContainer(Gtk.Stack):
                 self._model.set(iter,
                                 [0, 1, 2, 3, 4, 5, 7, 8, 9, 10],
                                 [str(item.get_id()), "", item.get_title(), artist, self._symbolicIcon, item, 
-1, self.errorIconName, False, True])
-            GLib.idle_add(300, lambda item, iter: self._updateAlbumArt, item, iter)
+            GLib.idle_add(300, self._updateAlbumArt, item, iter)
 
     def _getRemainingItemCount(self):
         count = -1
@@ -261,7 +262,8 @@ class Songs(ViewContainer):
         self.view.get_generic_view().get_style_context().add_class("songs-list")
         self._iconHeight = 32
         self._iconWidth = 32
-        self._symbolicIcon = albumArtCache.makeDefaultIcon(self, self._iconHeight, self._iconWidth)
+        self.cache = albumArtCache.getDefault()
+        self._symbolicIcon = self.cache.makeDefaultIcon(self._iconHeight, self._iconWidth)
         self._addListRenderers()
         self.player = player
         self.player.connect('playlist-item-changed', self.updateModel)
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index c580e98..a9f3527 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -60,7 +60,8 @@ class AlbumWidget(Gtk.EventBox):
         self.player = player
         self.hbox = Gtk.HBox()
         self.iterToClean = None
-        self._symbolicIcon = ALBUM_ART_CACHE.makeDefaultIcon(256, 256)
+        self.cache = AlbumArtCache.getDefault()
+        self._symbolicIcon = self.cache.makeDefaultIcon(256, 256)
 
         self.ui = Gtk.Builder()
         self.ui.add_from_resource('/org/gnome/music/AlbumWidget.ui')
@@ -426,7 +427,8 @@ class ArtistAlbumWidget(Gtk.HBox):
         self.ui = Gtk.Builder()
         self.ui.add_from_resource('/org/gnome/music/ArtistAlbumWidget.ui')
 
-        pixbuf = ALBUM_ART_CACHE.makeDefaultIcon(128, 128)
+        self.cache = AlbumArtCache.getDefault()
+        pixbuf = self.cache.makeDefaultIcon(128, 128)
         GLib.idle_add(300, self._updateAlbumArt)
 
         self.ui.get_object("cover").set_from_pixbuf(pixbuf)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]