Compare commits
No commits in common. "345e7697ff99192f98790e74344a2dd5b01ca90e" and "099adbab8c0742912176ca9d97a6e090c9b75f20" have entirely different histories.
345e7697ff
...
099adbab8c
6 changed files with 49 additions and 76 deletions
|
|
@ -221,14 +221,10 @@
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="vexpand">true</property>
|
|
||||||
<property name="hexpand">true</property>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkPicture">
|
<object class="GtkPicture">
|
||||||
<property name="content-fit">contain</property>
|
<property name="content-fit">contain</property>
|
||||||
<property name="can-shrink">false</property>
|
<property name="can-shrink">false</property>
|
||||||
<property name="vexpand">true</property>
|
|
||||||
<property name="hexpand">true</property>
|
|
||||||
<binding name="tooltip-markup">
|
<binding name="tooltip-markup">
|
||||||
<lookup name="tooltip" type="GridItem">
|
<lookup name="tooltip" type="GridItem">
|
||||||
<lookup name="item">GtkListItem</lookup>
|
<lookup name="item">GtkListItem</lookup>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
project('mcg',
|
project('mcg',
|
||||||
version: '4.0.2',
|
version: '4.0.1',
|
||||||
meson_version: '>= 0.59.0',
|
meson_version: '>= 0.59.0',
|
||||||
default_options: [
|
default_options: [
|
||||||
'warning_level=2',
|
'warning_level=2',
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,6 @@ class CoverPanel(Gtk.Overlay):
|
||||||
pixbuf = self._cover_pixbuf
|
pixbuf = self._cover_pixbuf
|
||||||
# Check pixelbuffer
|
# Check pixelbuffer
|
||||||
if pixbuf is None:
|
if pixbuf is None:
|
||||||
self.cover_default.set_pixel_size(min(size_width, size_height)/2)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Skalierungswert für Breite und Höhe ermitteln
|
# Skalierungswert für Breite und Höhe ermitteln
|
||||||
|
|
@ -252,5 +251,4 @@ class CoverPanel(Gtk.Overlay):
|
||||||
return
|
return
|
||||||
self.cover_image.set_from_pixbuf(
|
self.cover_image.set_from_pixbuf(
|
||||||
pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER))
|
pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER))
|
||||||
self.cover_image.set_pixel_size(min(width, height))
|
|
||||||
self.cover_image.show()
|
self.cover_image.show()
|
||||||
|
|
|
||||||
|
|
@ -293,13 +293,15 @@ class LibraryPanel(Adw.Bin):
|
||||||
|
|
||||||
def set_albumart(self, album, data):
|
def set_albumart(self, album, data):
|
||||||
if album in self._selected_albums:
|
if album in self._selected_albums:
|
||||||
self._standalone_pixbuf = None
|
|
||||||
if data:
|
if data:
|
||||||
# Load image and draw it
|
# Load image and draw it
|
||||||
try:
|
try:
|
||||||
self._standalone_pixbuf = Utils.load_pixbuf(data)
|
self._standalone_pixbuf = Utils.load_pixbuf(data)
|
||||||
except Exception:
|
except Exception:
|
||||||
self._logger.exception("Failed to set albumart")
|
self._logger.exception("Failed to set albumart")
|
||||||
|
self._standalone_pixbuf = self._get_default_image()
|
||||||
|
else:
|
||||||
|
self._standalone_pixbuf = self._get_default_image()
|
||||||
# Show image
|
# Show image
|
||||||
GObject.idle_add(self._show_image)
|
GObject.idle_add(self._show_image)
|
||||||
|
|
||||||
|
|
@ -333,24 +335,23 @@ class LibraryPanel(Adw.Bin):
|
||||||
self._grid_pixbufs.clear()
|
self._grid_pixbufs.clear()
|
||||||
for album_id in albums.keys():
|
for album_id in albums.keys():
|
||||||
album = albums[album_id]
|
album = albums[album_id]
|
||||||
grid_item = GridItem(album)
|
|
||||||
|
|
||||||
pixbuf = None
|
pixbuf = None
|
||||||
try:
|
try:
|
||||||
pixbuf = Utils.load_thumbnail(cache, self._client, album, size)
|
pixbuf = Utils.load_thumbnail(cache, self._client, album, size)
|
||||||
except client.CommandException:
|
except client.CommandException:
|
||||||
# Exception is handled by client
|
# Exception is handled by client
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception as e:
|
||||||
self._logger.exception("Failed to load albumart")
|
self._logger.exception("Failed to load albumart", e)
|
||||||
if pixbuf is None:
|
if pixbuf is None:
|
||||||
icon = self._get_default_icon(self._item_size, self._item_size)
|
pixbuf = self._icon_theme.lookup_icon(
|
||||||
grid_item.set_icon(icon)
|
Utils.STOCK_ICON_DEFAULT, None, self._item_size,
|
||||||
else:
|
self._item_size, Gtk.TextDirection.LTR,
|
||||||
|
Gtk.IconLookupFlags.FORCE_SYMBOLIC)
|
||||||
|
if pixbuf is not None:
|
||||||
self._grid_pixbufs[album.get_id()] = pixbuf
|
self._grid_pixbufs[album.get_id()] = pixbuf
|
||||||
grid_item.set_cover(pixbuf)
|
GObject.idle_add(self._library_grid_model.append,
|
||||||
|
GridItem(album, pixbuf))
|
||||||
GObject.idle_add(self._library_grid_model.append, grid_item)
|
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
GObject.idle_add(self.progress_bar.set_fraction, i / n)
|
GObject.idle_add(self.progress_bar.set_fraction, i / n)
|
||||||
|
|
@ -439,26 +440,27 @@ class LibraryPanel(Adw.Bin):
|
||||||
pixbuf = self._standalone_pixbuf
|
pixbuf = self._standalone_pixbuf
|
||||||
# Check pixelbuffer
|
# Check pixelbuffer
|
||||||
if pixbuf is None:
|
if pixbuf is None:
|
||||||
icon = self._get_default_icon(size_width, size_height)
|
|
||||||
self.standalone_image.set_from_paintable(icon)
|
|
||||||
self.standalone_image.set_pixel_size(min(size_width, size_height)/2)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
(width, height) = Utils.calculate_size(pixbuf.get_width(),
|
# Skalierungswert für Breite und Höhe ermitteln
|
||||||
pixbuf.get_height(), size_width,
|
ratio_w = float(size_width) / float(pixbuf.get_width())
|
||||||
size_height)
|
ratio_h = float(size_height) / float(pixbuf.get_height())
|
||||||
|
# Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren
|
||||||
|
ratio = min(ratio_w, ratio_h)
|
||||||
|
ratio = min(ratio, 1)
|
||||||
|
# Neue Breite und Höhe berechnen
|
||||||
|
width = int(math.floor(pixbuf.get_width() * ratio))
|
||||||
|
height = int(math.floor(pixbuf.get_height() * ratio))
|
||||||
if width <= 0 or height <= 0:
|
if width <= 0 or height <= 0:
|
||||||
return
|
return
|
||||||
# Pixelpuffer auf Oberfläche zeichnen
|
# Pixelpuffer auf Oberfläche zeichnen
|
||||||
self.standalone_image.set_from_pixbuf(
|
self.standalone_image.set_from_pixbuf(
|
||||||
pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER))
|
pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER))
|
||||||
self.standalone_image.set_pixel_size(min(width, height))
|
|
||||||
self.standalone_image.show()
|
self.standalone_image.show()
|
||||||
|
|
||||||
def _get_default_icon(self, width, height):
|
def _get_default_image(self):
|
||||||
return self._icon_theme.lookup_icon(Utils.STOCK_ICON_DEFAULT, None,
|
return self._icon_theme.lookup_icon(Utils.STOCK_ICON_DEFAULT, None,
|
||||||
width, height,
|
512, 512, Gtk.TextDirection.LTR,
|
||||||
Gtk.TextDirection.LTR,
|
|
||||||
Gtk.IconLookupFlags.FORCE_SYMBOLIC)
|
Gtk.IconLookupFlags.FORCE_SYMBOLIC)
|
||||||
|
|
||||||
def _get_selected_albums(self):
|
def _get_selected_albums(self):
|
||||||
|
|
|
||||||
|
|
@ -171,13 +171,15 @@ class PlaylistPanel(Adw.Bin):
|
||||||
|
|
||||||
def set_albumart(self, album, data):
|
def set_albumart(self, album, data):
|
||||||
if album in self._selected_albums:
|
if album in self._selected_albums:
|
||||||
self._standalone_pixbuf = None
|
|
||||||
if data:
|
if data:
|
||||||
# Load image and draw it
|
# Load image and draw it
|
||||||
try:
|
try:
|
||||||
self._standalone_pixbuf = Utils.load_pixbuf(data)
|
self._standalone_pixbuf = Utils.load_pixbuf(data)
|
||||||
except Exception:
|
except Exception:
|
||||||
self._logger.exception("Failed to set albumart")
|
self._logger.exception("Failed to set albumart")
|
||||||
|
self._cover_pixbuf = self._get_default_image()
|
||||||
|
else:
|
||||||
|
self._cover_pixbuf = self._get_default_image()
|
||||||
# Show image
|
# Show image
|
||||||
GObject.idle_add(self._show_image)
|
GObject.idle_add(self._show_image)
|
||||||
|
|
||||||
|
|
@ -195,8 +197,6 @@ class PlaylistPanel(Adw.Bin):
|
||||||
|
|
||||||
cache = client.MCGCache(host, size)
|
cache = client.MCGCache(host, size)
|
||||||
for album in playlist:
|
for album in playlist:
|
||||||
grid_item = GridItem(album)
|
|
||||||
|
|
||||||
pixbuf = None
|
pixbuf = None
|
||||||
# Load albumart thumbnail
|
# Load albumart thumbnail
|
||||||
try:
|
try:
|
||||||
|
|
@ -207,12 +207,12 @@ class PlaylistPanel(Adw.Bin):
|
||||||
except Exception:
|
except Exception:
|
||||||
self._logger.exception("Failed to load albumart")
|
self._logger.exception("Failed to load albumart")
|
||||||
if pixbuf is None:
|
if pixbuf is None:
|
||||||
icon = self._get_default_icon(self._item_size, self._item_size)
|
pixbuf = self._icon_theme.lookup_icon(
|
||||||
grid_item.set_icon(icon)
|
Utils.STOCK_ICON_DEFAULT, None, self._item_size,
|
||||||
else:
|
self._item_size, Gtk.TextDirection.LTR,
|
||||||
grid_item.set_cover(pixbuf)
|
Gtk.IconLookupFlags.FORCE_SYMBOLIC)
|
||||||
|
if pixbuf is not None:
|
||||||
GObject.idle_add(self._playlist_grid_model.append, grid_item)
|
self._playlist_grid_model.append(GridItem(album, pixbuf))
|
||||||
|
|
||||||
if self._playlist_stop.is_set():
|
if self._playlist_stop.is_set():
|
||||||
self._playlist_lock.release()
|
self._playlist_lock.release()
|
||||||
|
|
@ -247,26 +247,27 @@ class PlaylistPanel(Adw.Bin):
|
||||||
pixbuf = self._standalone_pixbuf
|
pixbuf = self._standalone_pixbuf
|
||||||
# Check pixelbuffer
|
# Check pixelbuffer
|
||||||
if pixbuf is None:
|
if pixbuf is None:
|
||||||
icon = self._get_default_icon(size_width, size_height)
|
|
||||||
self.standalone_image.set_from_paintable(icon)
|
|
||||||
self.standalone_image.set_pixel_size(min(size_width, size_height)/2)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
(width, height) = Utils.calculate_size(pixbuf.get_width(),
|
# Skalierungswert für Breite und Höhe ermitteln
|
||||||
pixbuf.get_height(), size_width,
|
ratio_w = float(size_width) / float(pixbuf.get_width())
|
||||||
size_height)
|
ratio_h = float(size_height) / float(pixbuf.get_height())
|
||||||
|
# Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren
|
||||||
|
ratio = min(ratio_w, ratio_h)
|
||||||
|
ratio = min(ratio, 1)
|
||||||
|
# Neue Breite und Höhe berechnen
|
||||||
|
width = int(math.floor(pixbuf.get_width() * ratio))
|
||||||
|
height = int(math.floor(pixbuf.get_height() * ratio))
|
||||||
if width <= 0 or height <= 0:
|
if width <= 0 or height <= 0:
|
||||||
return
|
return
|
||||||
# Pixelpuffer auf Oberfläche zeichnen
|
# Pixelpuffer auf Oberfläche zeichnen
|
||||||
self.standalone_image.set_from_pixbuf(
|
self.standalone_image.set_from_pixbuf(
|
||||||
pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER))
|
pixbuf.scale_simple(width, height, GdkPixbuf.InterpType.HYPER))
|
||||||
self.standalone_image.set_pixel_size(min(width, height))
|
|
||||||
self.standalone_image.show()
|
self.standalone_image.show()
|
||||||
|
|
||||||
def _get_default_icon(self, width, height):
|
def _get_default_image(self):
|
||||||
return self._icon_theme.lookup_icon(Utils.STOCK_ICON_DEFAULT, None,
|
return self._icon_theme.lookup_icon(Utils.STOCK_ICON_DEFAULT, None,
|
||||||
width, height,
|
512, 512, Gtk.TextDirection.LTR,
|
||||||
Gtk.TextDirection.LTR,
|
|
||||||
Gtk.IconLookupFlags.FORCE_SYMBOLIC)
|
Gtk.IconLookupFlags.FORCE_SYMBOLIC)
|
||||||
|
|
||||||
def _get_selected_albums(self):
|
def _get_selected_albums(self):
|
||||||
|
|
|
||||||
34
src/utils.py
34
src/utils.py
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
import hashlib
|
import hashlib
|
||||||
import math
|
|
||||||
import locale
|
import locale
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
gi.require_version('Gtk', '4.0')
|
gi.require_version('Gtk', '4.0')
|
||||||
|
|
@ -37,17 +35,9 @@ class Utils:
|
||||||
if albumart:
|
if albumart:
|
||||||
pixbuf = Utils.load_pixbuf(albumart)
|
pixbuf = Utils.load_pixbuf(albumart)
|
||||||
if pixbuf is not None:
|
if pixbuf is not None:
|
||||||
(width, height) = Utils.calculate_size(pixbuf.get_width(),
|
pixbuf = pixbuf.scale_simple(size, size,
|
||||||
pixbuf.get_height(),
|
|
||||||
size, size)
|
|
||||||
pixbuf = pixbuf.scale_simple(width, height,
|
|
||||||
GdkPixbuf.InterpType.HYPER)
|
GdkPixbuf.InterpType.HYPER)
|
||||||
try:
|
pixbuf.savev(cache_url, 'jpeg', [], [])
|
||||||
pixbuf.savev(cache_url, 'jpeg', [], [])
|
|
||||||
except Exception as e:
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logger.warning("Failed to save thumbnail for album\"%s\": "
|
|
||||||
"%s", album.get_title(), e)
|
|
||||||
return pixbuf
|
return pixbuf
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -82,19 +72,6 @@ class Utils:
|
||||||
m.update(value.encode('utf-8'))
|
m.update(value.encode('utf-8'))
|
||||||
return m.hexdigest()
|
return m.hexdigest()
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def calculate_size(src_width, src_height, dest_width, dest_height):
|
|
||||||
ratio_w = float(dest_width) / float(src_width)
|
|
||||||
ratio_h = float(dest_height) / float(src_height)
|
|
||||||
ratio = min(min(ratio_w, ratio_h), 1)
|
|
||||||
if ratio == 1:
|
|
||||||
return (src_width, src_height)
|
|
||||||
|
|
||||||
width = int(math.floor(src_width * ratio))
|
|
||||||
height = int(math.floor(src_height * ratio))
|
|
||||||
|
|
||||||
return (width, height)
|
|
||||||
|
|
||||||
|
|
||||||
class SortOrder:
|
class SortOrder:
|
||||||
ARTIST = 0
|
ARTIST = 0
|
||||||
|
|
@ -109,9 +86,11 @@ class GridItem(GObject.GObject):
|
||||||
tooltip = GObject.Property(type=str, default=None)
|
tooltip = GObject.Property(type=str, default=None)
|
||||||
cover = GObject.Property(type=Gdk.Paintable, default=None)
|
cover = GObject.Property(type=Gdk.Paintable, default=None)
|
||||||
|
|
||||||
def __init__(self, album):
|
def __init__(self, album, cover):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._album = album
|
self._album = album
|
||||||
|
if cover:
|
||||||
|
self.cover = Gdk.Texture.new_for_pixbuf(cover)
|
||||||
self.tooltip = GObject.markup_escape_text("\n".join([
|
self.tooltip = GObject.markup_escape_text("\n".join([
|
||||||
album.get_title(), ', '.join(album.get_dates()),
|
album.get_title(), ', '.join(album.get_dates()),
|
||||||
Utils.create_artists_label(album),
|
Utils.create_artists_label(album),
|
||||||
|
|
@ -124,9 +103,6 @@ class GridItem(GObject.GObject):
|
||||||
def set_cover(self, cover):
|
def set_cover(self, cover):
|
||||||
self.cover = Gdk.Texture.new_for_pixbuf(cover)
|
self.cover = Gdk.Texture.new_for_pixbuf(cover)
|
||||||
|
|
||||||
def set_icon(self, icon):
|
|
||||||
self.cover = icon
|
|
||||||
|
|
||||||
|
|
||||||
class SearchFilter(Gtk.Filter):
|
class SearchFilter(Gtk.Filter):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue