Ejemplo n.º 1
0
 def _update_album_art(self, item, _iter):
     albumArtCache.get_default().lookup(
         item,
         self._iconWidth,
         self._iconHeight,
         self._on_lookup_ready, _iter)
     return False
Ejemplo n.º 2
0
 def _insert_album_art(self, item, cb_item, itr, x=False):
     if item and cb_item and not item.get_thumbnail():
         if cb_item.get_thumbnail():
             item.set_thumbnail(cb_item.get_thumbnail())
         albumArtCache.get_default().lookup(item, self._iconWidth,
                                            self._iconHeight,
                                            self._on_lookup_ready, itr)
Ejemplo n.º 3
0
 def _insert_album_art(self, item, cb_item, itr, x=False):
     if item and cb_item and not item.get_thumbnail():
         if cb_item.get_thumbnail():
             item.set_thumbnail(cb_item.get_thumbnail())
         albumArtCache.get_default().lookup(
             item,
             self._iconWidth,
             self._iconHeight,
             self._on_lookup_ready, itr)
Ejemplo n.º 4
0
 def _update_album_art(self, item, _iter):
     albumArtCache.get_default().lookup_or_resolve(
         item,
         self._iconWidth,
         self._iconHeight,
         lambda icon, data: self._model.set_value(
             _iter, 4,
             albumArtCache.get_default()._make_icon_frame(icon)
             if icon else None))
     return False
Ejemplo n.º 5
0
    def __init__(self, player):
        super(Gtk.EventBox, self).__init__()
        self.player = player
        self.iterToClean = None
        self.cache = AlbumArtCache.get_default()

        self.ui = Gtk.Builder()
        self.ui.add_from_resource('/org/gnome/Music/AlbumWidget.ui')
        self._create_model()
        self.view = Gd.MainView(
            shadow_type=Gtk.ShadowType.NONE
        )
        self.view.set_view_type(Gd.MainViewType.LIST)
        self.album = None
        self.view.connect('item-activated', self._on_item_activated)
        self.monitors = []
        view_box = self.ui.get_object('view')
        self.ui.get_object('scrolledWindow').set_placement(Gtk.CornerType.
                                                           TOP_LEFT)
        child_view = self.view.get_children()[0]
        child_view.set_margin_top(64)
        child_view.set_margin_bottom(64)
        child_view.set_margin_right(32)
        self.view.remove(child_view)
        view_box.add(child_view)
        self.add(self.ui.get_object('AlbumWidget'))
        self._add_list_renderers()
        # TODO: make this work
        self.get_style_context().add_class('view')
        self.get_style_context().add_class('content-view')
        self.show_all()
Ejemplo n.º 6
0
    def __init__(self):
        GObject.GObject.__init__(self)
        self.playlist = None
        self.playlistType = None
        self.playlistId = None
        self.playlistField = None
        self.currentTrack = None
        self._lastState = Gst.State.PAUSED
        self.cache = AlbumArtCache.get_default()
        self._symbolicIcon = self.cache.get_default_icon(ART_SIZE, ART_SIZE)

        Gst.init(None)

        self.discoverer = GstPbutils.Discoverer()
        self.discoverer.connect('discovered', self._on_discovered)
        self.discoverer.start()
        self._discovering_urls = {}

        self.player = Gst.ElementFactory.make('playbin', 'player')
        self.bus = self.player.get_bus()
        self.bus.add_signal_watch()

        self._settings = Gio.Settings.new('org.gnome.Music')
        self._settings.connect('changed::repeat', self._on_settings_changed)
        self.repeat = self._settings.get_enum('repeat')

        self.bus.connect('message::state-changed', self._on_bus_state_changed)
        self.bus.connect('message::error', self._onBusError)
        self.bus.connect('message::eos', self._on_bus_eos)
        self._setup_view()

        self.playlist_insert_handler = 0
        self.playlist_delete_handler = 0
Ejemplo n.º 7
0
    def __init__(self, player):
        self._player = player

        self._notification = Notify.Notification()

        self._notification.set_category('x-gnome.music')
        self._notification.set_hint('action-icons', GLib.Variant('b', True))
        self._notification.set_hint('resident', GLib.Variant('b', True))
        self._notification.set_hint('desktop-entry', GLib.Variant('s', 'gnome-music'))

        self._isPlaying = False

        self._albumArtCache = AlbumArtCache.get_default()
        self._noArtworkIcon = self._albumArtCache.get_default_icon(IMAGE_SIZE, IMAGE_SIZE)

        rowStride = self._noArtworkIcon.get_rowstride()
        hasAlpha = self._noArtworkIcon.get_has_alpha()
        bitsPerSample = self._noArtworkIcon.get_bits_per_sample()
        nChannels = self._noArtworkIcon.get_n_channels()
        data = self._noArtworkIcon.get_pixels()

        self._noArtworkIconSerialized = GLib.Variant(
            '(iiibiiay)',
            (IMAGE_SIZE, IMAGE_SIZE, rowStride, hasAlpha, bitsPerSample, nChannels, data))

        self._player.connect('playing-changed', self._on_playing_changed)
        self._player.connect('current-changed', self._update_track)
        self._player.connect('thumbnail-updated', self._on_thumbnail_updated)
Ejemplo n.º 8
0
    def __init__(self, album, player, model):
        super(Gtk.HBox, self).__init__()
        self.player = player
        self.album = album
        self.artist = album.get_string(Grl.METADATA_KEY_ARTIST)
        self.model = model
        self.songs = []

        self.ui = Gtk.Builder()
        self.ui.add_from_resource('/org/gnome/Music/ArtistAlbumWidget.ui')

        self.cache = AlbumArtCache.get_default()
        pixbuf = self.cache.make_default_icon(128, 128)
        GLib.idle_add(self._update_album_art)

        self.ui.get_object("cover").set_from_pixbuf(pixbuf)
        self.ui.get_object("title").set_label(album.get_title())
        if album.get_creation_date():
            self.ui.get_object("year").set_markup(
                "<span color='grey'>(%s)</span>" %
                str(album.get_creation_date().get_year())
            )
        self.tracks = []
        GLib.idle_add(grilo.populate_album_songs,
                      album.get_id(), self.get_songs)
        self.pack_start(self.ui.get_object("ArtistAlbumWidget"), True, True, 0)
        self.show_all()
Ejemplo n.º 9
0
    def __init__(self):
        GObject.GObject.__init__(self)
        self.playlist = None
        self.playlistType = None
        self.playlistId = None
        self.playlistField = None
        self.currentTrack = None
        self._lastState = Gst.State.PAUSED
        self.cache = AlbumArtCache.get_default()
        self._symbolicIcon = self.cache.make_default_icon(ART_SIZE, ART_SIZE)

        Gst.init(None)

        self.discoverer = GstPbutils.Discoverer()
        self.discoverer.connect('discovered', self._on_discovered)
        self.discoverer.start()
        self._discovering_urls = {}

        self.player = Gst.ElementFactory.make('playbin', 'player')
        self.bus = self.player.get_bus()
        self.bus.add_signal_watch()

        self._settings = Gio.Settings.new('org.gnome.Music')
        self._settings.connect('changed::repeat', self._on_settings_changed)
        self.repeat = self._settings.get_enum('repeat')

        self.bus.connect('message::state-changed', self._on_bus_state_changed)
        self.bus.connect('message::error', self._onBusError)
        self.bus.connect('message::eos', self._on_bus_eos)
        self._setup_view()

        self.playlist_insert_handler = 0
        self.playlist_delete_handler = 0
Ejemplo n.º 10
0
    def __init__(self, artist, album, player, model):
        super(Gtk.HBox, self).__init__()
        self.player = player
        self.album = album
        self.artist = artist
        self.model = model
        self.songs = []
        self.monitors = []
        self.ui = Gtk.Builder()
        self.ui.add_from_resource('/org/gnome/Music/ArtistAlbumWidget.ui')

        self.cache = AlbumArtCache.get_default()
        pixbuf = self.cache.get_default_icon(128, 128)
        GLib.idle_add(self._update_album_art)

        self.ui.get_object('cover').set_from_pixbuf(pixbuf)
        self.ui.get_object('title').set_label(album.get_title())
        if album.get_creation_date():
            self.ui.get_object('year').set_markup(
                '<span color=\'grey\'>(%s)</span>' %
                str(album.get_creation_date().get_year())
            )
        self.tracks = []
        GLib.idle_add(grilo.populate_album_songs,
                      album.get_id(), self.get_songs)
        self.pack_start(self.ui.get_object('ArtistAlbumWidget'), True, True, 0)
        self.show_all()
Ejemplo n.º 11
0
    def __init__(self, player):
        self._player = player

        self._notification = Notify.Notification()

        self._notification.set_category('x-gnome.music')
        self._notification.set_hint('action-icons', GLib.Variant('b', True))
        self._notification.set_hint('resident', GLib.Variant('b', True))
        self._notification.set_hint('desktop-entry',
                                    GLib.Variant('s', 'gnome-music'))

        self._isPlaying = False

        self._albumArtCache = AlbumArtCache.get_default()
        self._noArtworkIcon = self._albumArtCache.get_default_icon(
            IMAGE_SIZE, IMAGE_SIZE)

        rowStride = self._noArtworkIcon.get_rowstride()
        hasAlpha = self._noArtworkIcon.get_has_alpha()
        bitsPerSample = self._noArtworkIcon.get_bits_per_sample()
        nChannels = self._noArtworkIcon.get_n_channels()
        data = self._noArtworkIcon.get_pixels()

        self._noArtworkIconSerialized = GLib.Variant(
            '(iiibiiay)', (IMAGE_SIZE, IMAGE_SIZE, rowStride, hasAlpha,
                           bitsPerSample, nChannels, data))

        self._player.connect('playing-changed', self._on_playing_changed)
        self._player.connect('current-changed', self._update_track)
        self._player.connect('thumbnail-updated', self._on_thumbnail_updated)
Ejemplo n.º 12
0
 def add_new_item():
     _iter = self._model.append(None)
     icon_name = self.nowPlayingIconName
     if item.get_url():
         try:
             self.player.discoverer.discover_uri(item.get_url())
         except:
             print('failed to discover url ' + item.get_url())
             icon_name = self.errorIconName
     self._model.set(_iter,
                     [0, 1, 2, 3, 4, 5, 7, 8, 9, 10],
                     [str(item.get_id()), '', title,
                      artist, self._symbolicIcon, item,
                      0, icon_name, False, icon_name == self.errorIconName])
     albumArtCache.get_default().lookup(
         item, self._iconWidth, self._iconHeight, self._on_lookup_ready,
         _iter, artist, title)
Ejemplo n.º 13
0
    def __init__(self, parent_window):
        GObject.GObject.__init__(self)
        self._parent_window = parent_window
        self.playlist = None
        self.playlistType = None
        self.playlistId = None
        self.playlistField = None
        self.currentTrack = None
        self.currentTrackUri = None
        self._lastState = Gst.State.PAUSED
        self.cache = AlbumArtCache.get_default()
        self._noArtworkIcon = self.cache.get_default_icon(ART_SIZE, ART_SIZE)
        self._loadingIcon = self.cache.get_default_icon(
            ART_SIZE, ART_SIZE, True)
        self._missingPluginMessages = []

        Gst.init(None)
        GstPbutils.pb_utils_init()

        self.discoverer = GstPbutils.Discoverer()
        self.discoverer.connect('discovered', self._on_discovered)
        self.discoverer.start()
        self._discovering_urls = {}

        self.player = Gst.ElementFactory.make('playbin', 'player')
        self.bus = self.player.get_bus()
        self.bus.add_signal_watch()
        self.setup_replaygain()

        self._settings = Gio.Settings.new('org.gnome.Music')
        self._settings.connect('changed::repeat',
                               self._on_repeat_setting_changed)
        self._settings.connect('changed::replaygain',
                               self._on_replaygain_setting_changed)
        self.repeat = self._settings.get_enum('repeat')
        self.replaygain = self._settings.get_value('replaygain') is not None
        self.toggle_replaygain(self.replaygain)

        self.bus.connect('message::state-changed', self._on_bus_state_changed)
        self.bus.connect('message::error', self._onBusError)
        self.bus.connect('message::element', self._on_bus_element)
        self.bus.connect('message::eos', self._on_bus_eos)
        self._setup_view()

        self.playlist_insert_handler = 0
        self.playlist_delete_handler = 0

        self._check_last_fm()
Ejemplo n.º 14
0
 def __init__(self, header_bar, selection_toolbar, player):
     ViewContainer.__init__(self, _("Songs"), header_bar, selection_toolbar, Gd.MainViewType.LIST)
     self.countQuery = Query.SONGS_COUNT
     self._items = {}
     self.isStarred = None
     self.iter_to_clean = None
     self.view.get_generic_view().get_style_context()\
         .add_class('songs-list')
     self._iconHeight = 32
     self._iconWidth = 32
     self.cache = albumArtCache.get_default()
     self._symbolicIcon = self.cache.get_default_icon(self._iconHeight,
                                                      self._iconWidth)
     self._add_list_renderers()
     self.player = player
     self.player.connect('playlist-item-changed', self.update_model)
Ejemplo n.º 15
0
    def __init__(self, player):
        self._player = player

        self._notification = Notify.Notification()

        self._notification.set_category('x-gnome.music')
        self._notification.set_hint('action-icons', GLib.Variant('b', True))
        self._notification.set_hint('resident', GLib.Variant('b', True))
        self._notification.set_hint('desktop-entry', GLib.Variant('s', 'gnome-music'))

        self._isPlaying = False

        self._albumArtCache = AlbumArtCache.get_default()
        self._symbolicIcon = self._albumArtCache.make_default_icon(IMAGE_SIZE, IMAGE_SIZE)

        self._player.connect('playing-changed', self._on_playing_changed)
        self._player.connect('current-changed', self._update_track)
Ejemplo n.º 16
0
    def __init__(self, player):
        self._player = player

        self._notification = Notify.Notification()

        self._notification.set_category('x-gnome.music')
        self._notification.set_hint('action-icons', GLib.Variant('b', True))
        self._notification.set_hint('resident', GLib.Variant('b', True))
        self._notification.set_hint('desktop-entry',
                                    GLib.Variant('s', 'gnome-music'))

        self._isPlaying = False

        self._albumArtCache = AlbumArtCache.get_default()
        self._noArtworkIcon = self._albumArtCache.get_default_icon(
            IMAGE_SIZE, IMAGE_SIZE)
        self._noArtworkIconSerialized = None
Ejemplo n.º 17
0
    def __init__(self, parent_window):
        GObject.GObject.__init__(self)
        self._parent_window = parent_window
        self.playlist = None
        self.playlistType = None
        self.playlistId = None
        self.playlistField = None
        self.currentTrack = None
        self.currentTrackUri = None
        self._lastState = Gst.State.PAUSED
        self.cache = AlbumArtCache.get_default()
        self._noArtworkIcon = self.cache.get_default_icon(ART_SIZE, ART_SIZE)
        self._loadingIcon = self.cache.get_default_icon(ART_SIZE, ART_SIZE, True)
        self._missingPluginMessages = []

        Gst.init(None)
        GstPbutils.pb_utils_init()

        self.discoverer = GstPbutils.Discoverer()
        self.discoverer.connect('discovered', self._on_discovered)
        self.discoverer.start()
        self._discovering_urls = {}

        self.player = Gst.ElementFactory.make('playbin', 'player')
        self.bus = self.player.get_bus()
        self.bus.add_signal_watch()
        self.setup_replaygain()

        self._settings = Gio.Settings.new('org.gnome.Music')
        self._settings.connect('changed::repeat', self._on_repeat_setting_changed)
        self._settings.connect('changed::replaygain', self._on_replaygain_setting_changed)
        self.repeat = self._settings.get_enum('repeat')
        self.replaygain = self._settings.get_value('replaygain') is not None
        self.toggle_replaygain(self.replaygain)

        self.bus.connect('message::state-changed', self._on_bus_state_changed)
        self.bus.connect('message::error', self._onBusError)
        self.bus.connect('message::element', self._on_bus_element)
        self.bus.connect('message::eos', self._on_bus_eos)
        self._setup_view()

        self.playlist_insert_handler = 0
        self.playlist_delete_handler = 0

        self._check_last_fm()
Ejemplo n.º 18
0
 def __init__(self, header_bar, selection_toolbar, player):
     ViewContainer.__init__(self, _("Songs"), header_bar, selection_toolbar)
     self.countQuery = Query.SONGS_COUNT
     self._items = {}
     self.monitors = []
     self.isStarred = None
     self.iter_to_clean = None
     self.view.set_view_type(Gd.MainViewType.LIST)
     self.view.get_generic_view().get_style_context()\
         .add_class('songs-list')
     self._iconHeight = 32
     self._iconWidth = 32
     self.cache = albumArtCache.get_default()
     self._symbolicIcon = self.cache.make_default_icon(
         self._iconHeight, self._iconWidth)
     self._add_list_renderers()
     self.player = player
     self.player.connect('playlist-item-changed', self.update_model)
Ejemplo n.º 19
0
    def __init__(self, player):
        super(Gtk.EventBox, self).__init__()
        self.player = player
        self.iterToClean = None
        self.cache = AlbumArtCache.get_default()
        self._symbolicIcon = self.cache.make_default_icon(256, 256)

        self.ui = Gtk.Builder()
        self.ui.add_from_resource('/org/gnome/Music/AlbumWidget.ui')
        self.model = Gtk.ListStore(
            GObject.TYPE_STRING,  # title
            GObject.TYPE_STRING,
            GObject.TYPE_STRING,
            GObject.TYPE_STRING,
            GdkPixbuf.Pixbuf,    # icon
            GObject.TYPE_OBJECT,  # song object
            GObject.TYPE_BOOLEAN,  # item selected
            GObject.TYPE_STRING,
            GObject.TYPE_BOOLEAN,
            GObject.TYPE_BOOLEAN,  # icon shown
        )

        self.view = Gd.MainView(
            shadow_type=Gtk.ShadowType.NONE
        )
        self.view.set_view_type(Gd.MainViewType.LIST)
        self.album = None
        self.view.connect('item-activated', self._on_item_activated)

        view_box = self.ui.get_object("view")
        self.ui.get_object("scrolledWindow").set_placement(Gtk.CornerType.
                                                           TOP_LEFT)
        child_view = self.view.get_children()[0]
        child_view.set_margin_top(64)
        child_view.set_margin_bottom(64)
        child_view.set_margin_right(32)
        self.view.remove(child_view)
        view_box.add(child_view)
        self.add(self.ui.get_object("AlbumWidget"))
        self._add_list_renderers()
        # TODO: make this work
        self.get_style_context().add_class("view")
        self.get_style_context().add_class("content-view")
        self.show_all()
Ejemplo n.º 20
0
    def __init__(self, player):
        self._player = player

        self._notification = Notify.Notification()

        self._notification.set_category('x-gnome.music')
        self._notification.set_hint('action-icons', GLib.Variant('b', True))
        self._notification.set_hint('resident', GLib.Variant('b', True))
        self._notification.set_hint('desktop-entry',
                                    GLib.Variant('s', 'gnome-music'))

        self._isPlaying = False

        self._albumArtCache = AlbumArtCache.get_default()
        self._symbolicIcon = self._albumArtCache.make_default_icon(
            IMAGE_SIZE, IMAGE_SIZE)

        self._player.connect('playing-changed', self._on_playing_changed)
        self._player.connect('current-changed', self._update_track)
Ejemplo n.º 21
0
# modify this code, you may extend this exception to your version of the
# code, but you are not obligated to do so.  If you do not wish to do so,
# delete this exception statement from your version.

from gi.repository import Gtk, Gdk, Gd, GLib, GObject, Pango, Gio
from gi.repository import GdkPixbuf, Grl
from gettext import gettext as _, ngettext
from gnomemusic.grilo import grilo
from gnomemusic.albumArtCache import AlbumArtCache
from gnomemusic.player import DiscoveryStatus
from gnomemusic.playlists import Playlists, StaticPlaylists
from gnomemusic import log
import logging
logger = logging.getLogger(__name__)

ALBUM_ART_CACHE = AlbumArtCache.get_default()
NOW_PLAYING_ICON_NAME = 'media-playback-start-symbolic'
ERROR_ICON_NAME = 'dialog-error-symbolic'

try:
    settings = Gio.Settings.new('org.gnome.Music')
    MAX_TITLE_WIDTH = settings.get_int('max-width-chars')
except Exception as e:
    MAX_TITLE_WIDTH = 20
    logger.error("Error on setting widget max-width-chars: %s", str(e))

playlists = Playlists.get_default()


class StarHandler():
    def __repr__(self):
Ejemplo n.º 22
0
    def __init__(self, title, header_bar, selection_toolbar, useStack=False):
        Stack.__init__(self,
                       transition_type=StackTransitionType.CROSSFADE)
        self._grid = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL)
        self._iconWidth = -1
        self._iconHeight = 128
        self._offset = 0
        self._adjustmentValueId = 0
        self._adjustmentChangedId = 0
        self._scrollbarVisibleId = 0
        self._model = Gtk.ListStore(
            GObject.TYPE_STRING,
            GObject.TYPE_STRING,
            GObject.TYPE_STRING,
            GObject.TYPE_STRING,
            GdkPixbuf.Pixbuf,
            GObject.TYPE_OBJECT,
            GObject.TYPE_BOOLEAN,
            GObject.TYPE_INT,
            GObject.TYPE_STRING,
            GObject.TYPE_BOOLEAN,
            GObject.TYPE_BOOLEAN
        )
        self.view = Gd.MainView(
            shadow_type=Gtk.ShadowType.NONE
        )
        self.view.set_view_type(Gd.MainViewType.ICON)
        self.view.set_model(self._model)
        self.selection_toolbar = selection_toolbar
        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        box.pack_start(self.view, True, True, 0)
        if useStack:
            self.stack = Stack(
                transition_type=StackTransitionType.SLIDE_RIGHT,
            )
            dummy = Gtk.Frame(visible=False)
            self.stack.add_named(dummy, 'dummy')
            self.stack.add_named(box, 'artists')
            self.stack.set_visible_child_name('dummy')
            self._grid.add(self.stack)
        else:
            self._grid.add(box)

        self._loadMore = Widgets.LoadMoreButton(self._get_remaining_item_count)
        box.pack_end(self._loadMore.widget, False, False, 0)
        self._loadMore.widget.connect('clicked', self._populate)
        self.view.connect('item-activated', self._on_item_activated)
        self._cursor = None
        self.header_bar = header_bar
        self.header_bar._select_button.connect(
            'toggled', self._on_header_bar_toggled)
        self.header_bar._cancel_button.connect(
            'clicked', self._on_cancel_button_clicked)

        self.title = title
        self.add(self._grid)

        self.show_all()
        self._items = []
        self._loadMore.widget.hide()
        self._connect_view()
        self.cache = albumArtCache.get_default()
        self._symbolicIcon = self.cache.make_default_icon(self._iconHeight,
                                                          self._iconWidth)

        self._init = False
        grilo.connect('ready', self._on_grilo_ready)
        self.header_bar.header_bar.connect('state-changed',
                                           self._on_state_changed)
        self.view.connect('view-selection-changed',
                          self._on_view_selection_changed)
Ejemplo n.º 23
0
 def _on_lookup_ready(self, icon, path, _iter):
     if icon:
         self._model.set_value(
             _iter, 4,
             albumArtCache.get_default()._make_icon_frame(icon))
Ejemplo n.º 24
0
class ArtistAlbumWidget(Gtk.Box):

    __gsignals__ = {
        'tracks-loaded': (GObject.SignalFlags.RUN_FIRST, None, ()),
    }

    loadingIcon = AlbumArtCache.get_default().get_default_icon(128, 128, True)
    noArtworkIcon = ALBUM_ART_CACHE.get_default_icon(128, 128, False)

    def __repr__(self):
        return '<ArtistAlbumWidget>'

    @log
    def __init__(self, artist, album, player, model, header_bar,
                 selectionModeAllowed):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
        self.player = player
        self.album = album
        self.artist = artist
        self.model = model
        self.model.connect('row-changed', self._model_row_changed)
        self.header_bar = header_bar
        self.selectionMode = False
        self.selectionModeAllowed = selectionModeAllowed
        self.songs = []
        self.ui = Gtk.Builder()
        self.ui.add_from_resource('/org/gnome/Music/ArtistAlbumWidget.ui')

        GLib.idle_add(self._update_album_art)

        self.cover = self.ui.get_object('cover')
        self.cover.set_from_pixbuf(self.loadingIcon)
        self.songsGrid = self.ui.get_object('grid1')
        self.ui.get_object('title').set_label(album.get_title())
        if album.get_creation_date():
            self.ui.get_object('year').set_markup(
                '<span color=\'grey\'>(%s)</span>' %
                str(album.get_creation_date().get_year()))
        self.tracks = []
        grilo.populate_album_songs(album, self.add_item)
        self.pack_start(self.ui.get_object('ArtistAlbumWidget'), True, True, 0)

    @log
    def add_item(self, source, prefs, track, remaining, data=None):
        if remaining == 0:
            self.songsGrid.show_all()
            self.emit("tracks-loaded")

        if track:
            self.tracks.append(track)
        else:
            for i, track in enumerate(self.tracks):
                ui = Gtk.Builder()
                ui.add_from_resource('/org/gnome/Music/TrackWidget.ui')
                song_widget = ui.get_object('eventbox1')
                self.songs.append(song_widget)
                ui.get_object('num')\
                    .set_markup('<span color=\'grey\'>%d</span>'
                                % len(self.songs))
                title = AlbumArtCache.get_media_title(track)
                ui.get_object('title').set_text(title)
                ui.get_object('title').set_alignment(0.0, 0.5)
                ui.get_object('title').set_max_width_chars(MAX_TITLE_WIDTH)

                self.songsGrid.attach(song_widget,
                                      int(i / (len(self.tracks) / 2)),
                                      int(i % (len(self.tracks) / 2)), 1, 1)
                track.song_widget = song_widget
                itr = self.model.append(None)
                song_widget._iter = itr
                song_widget.model = self.model
                song_widget.title = ui.get_object('title')
                song_widget.checkButton = ui.get_object('select')
                song_widget.checkButton.set_visible(self.selectionMode)
                song_widget.checkButton.connect('toggled',
                                                self._check_button_toggled,
                                                song_widget)
                self.model.set(itr, [0, 1, 2, 3, 5],
                               [title, '', '', False, track])
                song_widget.now_playing_sign = ui.get_object('image1')
                song_widget.now_playing_sign.set_from_icon_name(
                    NOW_PLAYING_ICON_NAME, Gtk.IconSize.SMALL_TOOLBAR)
                song_widget.now_playing_sign.set_no_show_all('True')
                song_widget.now_playing_sign.set_alignment(1, 0.6)
                song_widget.can_be_played = True
                song_widget.connect('button-release-event',
                                    self.track_selected)

    @log
    def _update_album_art(self):
        real_artist = self.album.get_string(Grl.METADATA_KEY_ARTIST)\
            or self.album.get_author()\
            or _("Unknown Artist")
        ALBUM_ART_CACHE.lookup(self.album, 128, 128, self._get_album_cover,
                               None, real_artist, self.album.get_title())

    @log
    def _get_album_cover(self, pixbuf, path, data=None):
        if not pixbuf:
            pixbuf = self.noArtworkIcon
        self.cover.set_from_pixbuf(pixbuf)

    @log
    def track_selected(self, widget, event):
        if not widget.can_be_played:
            return

        if not self.selectionMode and \
            (event.button == Gdk.BUTTON_SECONDARY or
                (event.button == 1 and event.state & Gdk.ModifierType.CONTROL_MASK)):
            if self.selectionModeAllowed:
                self.header_bar._select_button.set_active(True)
            else:
                return

        if self.selectionMode:
            self.model[widget._iter][6] = not self.model[widget._iter][6]
            return

        self.player.stop()
        self.player.set_playlist('Artist', self.artist, widget.model,
                                 widget._iter, 5, 6)
        self.player.set_playing(True)

    @log
    def set_selection_mode(self, selectionMode):
        if self.selectionMode == selectionMode:
            return
        self.selectionMode = selectionMode
        for songWidget in self.songs:
            songWidget.checkButton.set_visible(selectionMode)
            if not selectionMode:
                songWidget.model[songWidget._iter][6] = False

    @log
    def _check_button_toggled(self, button, songWidget):
        if songWidget.model[songWidget._iter][6] != button.get_active():
            songWidget.model[songWidget._iter][6] = button.get_active()

    @log
    def _model_row_changed(self, model, path, _iter):
        if not self.selectionMode:
            return
        if not model[_iter][5]:
            return
        songWidget = model[_iter][5].song_widget
        selected = model[_iter][6]

        if model[_iter][11] == DiscoveryStatus.FAILED:
            songWidget.now_playing_sign.set_from_icon_name(
                ERROR_ICON_NAME, Gtk.IconSize.SMALL_TOOLBAR)
            songWidget.now_playing_sign.show()
            songWidget.can_be_played = False

        if selected != songWidget.checkButton.get_active():
            songWidget.checkButton.set_active(selected)
Ejemplo n.º 25
0
    def __init__(self, title, header_bar, selection_toolbar, useStack=False):
        Stack.__init__(self, transition_type=StackTransitionType.CROSSFADE)
        self._grid = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL)
        self._iconWidth = -1
        self._iconHeight = 128
        self._offset = 0
        self._adjustmentValueId = 0
        self._adjustmentChangedId = 0
        self._scrollbarVisibleId = 0
        self._model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING,
                                    GObject.TYPE_STRING, GObject.TYPE_STRING,
                                    GdkPixbuf.Pixbuf, GObject.TYPE_OBJECT,
                                    GObject.TYPE_BOOLEAN, GObject.TYPE_INT,
                                    GObject.TYPE_STRING, GObject.TYPE_BOOLEAN,
                                    GObject.TYPE_BOOLEAN)
        self.view = Gd.MainView(shadow_type=Gtk.ShadowType.NONE)
        self.view.set_view_type(Gd.MainViewType.ICON)
        self.view.set_model(self._model)
        self.filter = self._model.filter_new(None)
        self.view.set_model(self.filter)
        self.vadjustment = self.view.get_vadjustment()
        self.selection_toolbar = selection_toolbar
        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        box.pack_start(self.view, True, True, 0)
        if useStack:
            self.stack = Stack(
                transition_type=StackTransitionType.SLIDE_RIGHT, )
            dummy = Gtk.Frame(visible=False)
            self.stack.add_named(dummy, 'dummy')
            self.stack.add_named(box, 'artists')
            self.stack.set_visible_child_name('dummy')
            self._grid.add(self.stack)
        else:
            self._grid.add(box)

        self._cached_count = -1
        self._loadMore = Widgets.LoadMoreButton(self._get_remaining_item_count)
        box.pack_end(self._loadMore.widget, False, False, 0)
        self._loadMore.widget.connect('clicked', self._populate)
        self.view.connect('item-activated', self._on_item_activated)
        self.view.connect('selection-mode-request',
                          self._on_selection_mode_request)
        self._cursor = None
        self.header_bar = header_bar
        self.header_bar._select_button.connect('toggled',
                                               self._on_header_bar_toggled)
        self.header_bar._cancel_button.connect('clicked',
                                               self._on_cancel_button_clicked)

        self.title = title
        self.add(self._grid)

        self.show_all()
        self._items = []
        self._loadMore.widget.hide()
        self._connect_view()
        self.cache = albumArtCache.get_default()
        self._symbolicIcon = self.cache.make_default_icon(
            self._iconHeight, self._iconWidth)

        self._init = False
        grilo.connect('ready', self._on_grilo_ready)
        self.header_bar.header_bar.connect('state-changed',
                                           self._on_state_changed)
        self.view.connect('view-selection-changed',
                          self._on_view_selection_changed)

        self._discovering_urls = {}
Ejemplo n.º 26
0
 def _on_lookup_ready(self, icon, path, _iter):
     if icon:
         self._model.set_value(
             _iter, 4,
             albumArtCache.get_default()._make_icon_frame(icon))
Ejemplo n.º 27
0
from gi.repository import Gtk, Gd, GLib, GObject, Pango
from gi.repository import GdkPixbuf, Gio, Grl
from gi.repository import Tracker
from gettext import gettext as _, ngettext
from gnomemusic.grilo import grilo
from gnomemusic.query import Query
from gnomemusic.albumArtCache import AlbumArtCache
from gnomemusic.playlists import Playlists
from gnomemusic import log
import logging
logger = logging.getLogger(__name__)

playlist = Playlists.get_default()
tracker = Tracker.SparqlConnection.get(None)
ALBUM_ART_CACHE = AlbumArtCache.get_default()
if Gtk.Widget.get_default_direction() is not Gtk.TextDirection.RTL:
    NOW_PLAYING_ICON_NAME = 'media-playback-start-symbolic'
else:
    NOW_PLAYING_ICON_NAME = 'media-playback-start-rtl-symbolic'
ERROR_ICON_NAME = 'dialog-error-symbolic'


@log
def get_count(countQuery):
    count = -1
    if countQuery:
        cursor = tracker.query(countQuery, None)
        if cursor and cursor.next(None):
            count = cursor.get_integer(0)
    return count