[gnome-music/gnome-3-12] log: extensive logging
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/gnome-3-12] log: extensive logging
- Date: Fri, 4 Apr 2014 13:11:50 +0000 (UTC)
commit 4c3ba4cdc12076ac9cbb492229e6a32efaef9a9e
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date: Fri Apr 4 14:56:12 2014 +0200
log: extensive logging
gnome-music.in | 4 +-
gnomemusic/__init__.py | 23 ++++++++++++
gnomemusic/albumArtCache.py | 27 +++++++++++++-
gnomemusic/application.py | 20 +++++-----
gnomemusic/grilo.py | 45 ++++++++++++-----------
gnomemusic/mpris.py | 14 +++++++
gnomemusic/notification.py | 14 +++++++
gnomemusic/player.py | 55 ++++++++++++++++++++++++++++
gnomemusic/playlists.py | 13 +++++++
gnomemusic/searchbar.py | 10 +++++-
gnomemusic/toolbar.py | 17 +++++++++
gnomemusic/view.py | 85 +++++++++++++++++++++++++++++++++++++++++++
gnomemusic/widgets.py | 48 ++++++++++++++++++++++++
gnomemusic/window.py | 23 ++++++++++++
14 files changed, 363 insertions(+), 35 deletions(-)
---
diff --git a/gnome-music.in b/gnome-music.in
index 3bade7c..25b2223 100644
--- a/gnome-music.in
+++ b/gnome-music.in
@@ -58,7 +58,7 @@ if __name__ == "__main__":
opts, args = parser.parse_args()
if opts.debug:
logging.basicConfig(level=logging.DEBUG,
- format='%(asctime)s %(levelname)s\t%(filename)s:%(lineno)d \t%(message)s',
+ format='%(asctime)s %(levelname)s\t\t%(message)s',
datefmt='%H:%M:%S')
# Gtk hates "-d" switch, so lets drop it
if '-d' in sys.argv:
@@ -67,7 +67,7 @@ if __name__ == "__main__":
sys.argv.remove("--debug")
else:
logging.basicConfig(level=logging.WARN,
- format='%(asctime)s %(levelname)s\t%(filename)s:%(lineno)d \t%(message)s',
+ format='%(asctime)s %(levelname)s\t\t%(message)s',
datefmt='%H:%M:%S')
locale.bindtextdomain('gnome-music', localedir)
diff --git a/gnomemusic/__init__.py b/gnomemusic/__init__.py
index 1bf71a6..db1f4e1 100644
--- a/gnomemusic/__init__.py
+++ b/gnomemusic/__init__.py
@@ -24,3 +24,26 @@
# 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.
+
+import logging
+logger = logging.getLogger(__name__)
+tabbing = 0
+
+
+def log(fn):
+ from itertools import chain
+
+ def wrapped(*v, **k):
+ global tabbing
+ name = fn.__name__
+ module = fn.__module__
+ params = ", ".join(map(repr, chain(v, k.values())))
+
+ logger.debug("%s%s.%s(%s)" % ('|' * tabbing, module, name, params))
+ tabbing += 1
+ retval = fn(*v, **k)
+ tabbing -= 1
+ logger.debug("%sreturned %s" % ('|' * tabbing, retval))
+
+ return retval
+ return wrapped
diff --git a/gnomemusic/albumArtCache.py b/gnomemusic/albumArtCache.py
index df3462a..95bc8b5 100644
--- a/gnomemusic/albumArtCache.py
+++ b/gnomemusic/albumArtCache.py
@@ -32,13 +32,17 @@ from gi.repository import Gtk, GdkPixbuf, Gio, GLib, Grl, Gdk
from gettext import gettext as _
import cairo
from math import pi
-
import threading
import os
import re
+from gnomemusic import log
+import logging
+logger = logging.getLogger(__name__)
class LookupRequest:
+
+ @log
def __init__(self, item, width, height, callback, data=None):
self.item = item
self.width = width or -1
@@ -53,16 +57,19 @@ class LookupRequest:
self.album = item.get_string(Grl.METADATA_KEY_ALBUM)
self.started = False
+ @log
def start(self):
self.started = True
self._try_load()
+ @log
def finish(self, pixbuf):
if pixbuf:
# Cache the path on the original item for faster retrieval
self.item.set_thumbnail(GLib.filename_to_uri(self.path, None))
self.callback(pixbuf, self.path, self.data)
+ @log
def _try_load(self):
if self.key_index >= 2:
if self.icon_format == 'jpeg':
@@ -78,6 +85,7 @@ class LookupRequest:
f.read_async(GLib.PRIORITY_DEFAULT, None, self._on_read_ready, None)
+ @log
def _on_read_ready(self, obj, res, data=None):
try:
stream = obj.read_finish(res)
@@ -92,6 +100,7 @@ class LookupRequest:
self.key_index += 1
self._try_load()
+ @log
def _on_pixbuf_ready(self, source, res, data=None):
try:
pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res)
@@ -117,6 +126,7 @@ class LookupRequest:
self.key_index += 1
self._try_load()
+ @log
def _on_try_load_finished(self, icon, data=None):
if icon:
self.finish(icon)
@@ -138,6 +148,8 @@ class LookupRequest:
class GetUriRequest:
+
+ @log
def __init__(self, uri, artist, album, callback, data=None):
self.uri = uri
self.artist = artist
@@ -151,11 +163,13 @@ class GetUriRequest:
self.stream = None
self.started = False
+ @log
def start(self):
self.started = True
f = Gio.File.new_for_uri(self.uri)
f.read_async(300, None, self._on_read_ready, None)
+ @log
def _on_read_ready(self, outstream, res, user_data=None):
try:
self.stream = outstream.read_finish(res)
@@ -186,12 +200,14 @@ class GetUriRequest:
except Exception as e:
print(e)
+ @log
def _on_replace_ready(self, new_file, res, user_data=None):
outstream = new_file.replace_finish(res)
outstream.splice_async(self.stream,
Gio.IOStreamSpliceFlags.NONE,
300, None, self._on_splice_ready, None)
+ @log
def _on_splice_ready(self, outstream, res, user_data=None):
for values in self.callbacks:
width, height, callback, data = values
@@ -247,6 +263,7 @@ class AlbumArtCache:
return title
+ @log
def __init__(self):
self.logLookupErrors = False
self.requested_uris = {}
@@ -266,6 +283,7 @@ class AlbumArtCache:
except:
pass
+ @log
def make_default_icon(self, width, height):
# get a small pixbuf with the given path
icon = Gtk.IconTheme.get_default().load_icon('folder-music-symbolic', max(width, height) / 4, 0)
@@ -288,6 +306,7 @@ class AlbumArtCache:
GdkPixbuf.InterpType.NEAREST, 0xff)
return self._make_icon_frame(result)
+ @log
def _make_icon_frame(self, pixbuf):
border = 1.5
w = pixbuf.get_width()
@@ -306,6 +325,7 @@ class AlbumArtCache:
return result
+ @log
def _draw_rounded_path(self, x, y, width, height, radius):
key = "%dx%d %dx%d:%d" % (width, height, x, y, radius)
self.frame_lock.acquire()
@@ -332,10 +352,12 @@ class AlbumArtCache:
self.frame_lock.release()
return res
+ @log
def lookup(self, item, width, height, callback, data=None):
request = LookupRequest(item, width, height, callback, data)
request.start()
+ @log
def _normalize_and_hash(self, input_str):
normalized = ' '
@@ -348,6 +370,7 @@ class AlbumArtCache:
return GLib.compute_checksum_for_string(GLib.ChecksumType.MD5,
normalized, -1)
+ @log
def _strip_invalid_entities(self, original):
# Strip blocks
string = self.blocks.sub('', original)
@@ -358,6 +381,7 @@ class AlbumArtCache:
# Remove trailing spaces and convert to lowercase
return string.strip().lower()
+ @log
def get_from_uri(self, uri, artist, album, width, height, callback, data=None):
if not uri:
return
@@ -372,5 +396,6 @@ class AlbumArtCache:
if not request.started:
request.start()
+ @log
def _on_get_uri_request_finish(self, request, data=None):
del self.requested_uris[request.uri]
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index f0f0c4b..a4cafff 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -36,13 +36,14 @@ from gettext import gettext as _
from gnomemusic.window import Window
from gnomemusic.mpris import MediaPlayer2Service
from gnomemusic.notification import NotificationManager
+from gnomemusic import log
import logging
-log = logging.getLogger(__name__)
+logger = logging.getLogger(__name__)
class Application(Gtk.Application):
+ @log
def __init__(self):
- log.debug("Creating app")
Gtk.Application.__init__(self,
application_id='org.gnome.Music',
flags=Gio.ApplicationFlags.FLAGS_NONE)
@@ -58,8 +59,8 @@ class Application(Gtk.Application):
self._window = None
+ @log
def build_app_menu(self):
- log.debug("building app menu")
builder = Gtk.Builder()
builder.add_from_resource('/org/gnome/Music/app-menu.ui')
@@ -83,16 +84,16 @@ class Application(Gtk.Application):
quitAction.connect('activate', self.quit)
self.add_action(quitAction)
+ @log
def new_playlist(self, action, param):
- log.debug("TODO: New playlist action")
pass
+ @log
def help(self, action, param):
- log.debug("Open Help action")
Gtk.show_uri(None, "help:gnome-music", Gdk.CURRENT_TIME)
+ @log
def about(self, action, param):
- log.debug("About action")
builder = Gtk.Builder()
builder.add_from_resource('/org/gnome/Music/AboutDialog.ui')
about = builder.get_object('about_dialog')
@@ -100,24 +101,23 @@ class Application(Gtk.Application):
about.connect("response", self.about_response)
about.show()
+ @log
def about_response(self, dialog, response):
- log.debug("Close about")
dialog.destroy()
+ @log
def do_startup(self):
- log.debug("app is starting up")
Gtk.Application.do_startup(self)
Notify.init(_("Music"))
self.build_app_menu()
+ @log
def quit(self, action=None, param=None):
- logging.debug("Help action")
self._window.destroy()
def do_activate(self):
- log.debug("App is activated")
if not self._window:
self._window = Window(self)
self.service = MediaPlayer2Service(self)
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 66610b5..f45d725 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -25,11 +25,11 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
-import logging
-log = logging.getLogger(__name__)
from gi.repository import Grl, GLib, GObject
-
from gnomemusic.query import Query
+from gnomemusic import log
+import logging
+logger = logging.getLogger(__name__)
class Grilo(GObject.GObject):
@@ -52,8 +52,8 @@ class Grilo(GObject.GObject):
CHANGED_MEDIA_MAX_ITEMS = 500
CHANGED_MEDIA_SIGNAL_TIMEOUT = 2000
+ @log
def __init__(self):
- log.debug("initializing grilo")
GObject.GObject.__init__(self)
self.playlist_path = GLib.build_filenamev([GLib.get_user_data_dir(),
"gnome-music", "playlists"])
@@ -75,12 +75,12 @@ class Grilo(GObject.GObject):
try:
self.registry.load_all_plugins()
except GLib.GError:
- print('Failed to load plugins.')
+ logger.error('Failed to load plugins.')
if self.tracker is not None:
- print("tracker is not none")
+ logger.debug("tracker found")
+ @log
def _on_content_changed(self, mediaSource, changedMedias, changeType, locationUnknown):
- log.debug("content changed")
if changeType == Grl.SourceChangeType.ADDED or changeType == Grl.SourceChangeType.REMOVED:
self.changed_media_ids.append(changedMedias[0].get_id())
if len(self.changed_media_ids) >= self.CHANGED_MEDIA_MAX_ITEMS:
@@ -91,16 +91,17 @@ class Grilo(GObject.GObject):
self.pending_event_id = 0
self.pending_event_id = GLib.timeout_add(self.CHANGED_MEDIA_SIGNAL_TIMEOUT,
self.emit_change_signal)
+ @log
def emit_change_signal(self):
- log.debug("emitting changes-pending signal")
self.changed_media_ids = []
self.pending_event_id = 0
self.emit('changes-pending')
return False
+ @log
def _on_source_added(self, pluginRegistry, mediaSource):
id = mediaSource.get_id()
- log.debug("new grilo source %s was added" % id)
+ logger.debug("new grilo source %s was added" % id)
try:
if id == 'grl-tracker-source':
ops = mediaSource.supported_operations()
@@ -116,29 +117,30 @@ class Grilo(GObject.GObject):
self.tracker.notify_change_start()
self.tracker.connect('content-changed', self._on_content_changed)
except Exception as e:
- log.debug("Source %s: exception %s" % (id, e))
+ logger.debug("Source %s: exception %s" % (id, e))
+ @log
def _on_source_removed(self, pluginRegistry, mediaSource):
- log.debug("source removed")
+ pass
+ @log
def populate_artists(self, offset, callback, count=-1):
- log.debug("populating artists")
self.populate_items(Query.ARTISTS, offset, callback, count)
+ @log
def populate_albums(self, offset, callback, count=50):
- log.debug("populating albums")
self.populate_items(Query.ALBUMS, offset, callback, count)
+ @log
def populate_songs(self, offset, callback, count=-1):
- log.debug("populating songs")
self.populate_items(Query.SONGS, offset, callback, count)
+ @log
def populate_album_songs(self, album_id, callback, count=-1):
- log.debug("populating album songs")
self.populate_items(Query.album_songs(album_id), 0, callback, count)
+ @log
def populate_items(self, query, offset, callback, count=50):
- log.debug("populating items")
options = self.options.copy()
options.set_skip(offset)
if count != -1:
@@ -148,25 +150,26 @@ class Grilo(GObject.GObject):
callback(source, param, item, count)
self.tracker.query(query, self.METADATA_KEYS, options, _callback, None)
+ @log
def _search_callback(self):
- log.debug("populating search callback")
+ pass
+ @log
def search(self, q):
- log.debug("searching for '%s'" % q)
options = self.options.copy()
for source in self.sources:
- print(source.get_name() + ' - ' + q)
+ logger.debug(source.get_name() + ' - ' + q)
source.search(q, [Grl.METADATA_KEY_ID], 0, 10,
options, self._search_callback, source)
+ @log
def get_album_art_for_album_id(self, album_id, _callback):
- log.debug("fetching album art for album with id %s" % album_id)
options = self.options.copy()
query = Query.get_album_for_id(album_id)
self.tracker.query(query, self.METADATA_THUMBNAIL_KEYS, options, _callback, None)
+ @log
def get_media_from_uri(self, uri, callback):
- log.debug("get song for uri '%s'" % uri)
options = self.options.copy()
query = Query.get_song_with_url(uri)
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index e41354b..3f1ed33 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -33,6 +33,9 @@ from gnomemusic.albumArtCache import AlbumArtCache
from gettext import gettext as _
from gi.repository import Grl
+from gnomemusic import log
+import logging
+logger = logging.getLogger(__name__)
class MediaPlayer2Service(dbus.service.Object):
@@ -54,6 +57,7 @@ class MediaPlayer2Service(dbus.service.Object):
self.player.connect('seeked', self._on_seeked)
self.first_song_handler = 0
+ @log
def _get_playback_status(self):
state = self.player.get_playback_status()
if state == PlaybackStatus.PLAYING:
@@ -63,6 +67,7 @@ class MediaPlayer2Service(dbus.service.Object):
else:
return 'Stopped'
+ @log
def _get_loop_status(self):
if self.player.repeat == RepeatType.NONE:
return 'None'
@@ -71,6 +76,7 @@ class MediaPlayer2Service(dbus.service.Object):
else:
return 'Playlist'
+ @log
def _get_metadata(self):
media = self.player.get_current_media()
if not media:
@@ -168,6 +174,7 @@ class MediaPlayer2Service(dbus.service.Object):
return metadata
+ @log
def _on_current_changed(self, player, data=None):
if self.player.repeat == RepeatType.SONG:
self.Seeked(0)
@@ -181,6 +188,7 @@ class MediaPlayer2Service(dbus.service.Object):
},
[])
+ @log
def _on_thumbnail_updated(self, player, path, data=None):
self.PropertiesChanged(self.MEDIA_PLAYER2_PLAYER_IFACE,
{
@@ -189,6 +197,7 @@ class MediaPlayer2Service(dbus.service.Object):
},
[])
+ @log
def _on_playback_status_changed(self, data=None):
self.PropertiesChanged(self.MEDIA_PLAYER2_PLAYER_IFACE,
{
@@ -196,6 +205,7 @@ class MediaPlayer2Service(dbus.service.Object):
},
[])
+ @log
def _on_repeat_mode_changed(self, player, data=None):
self.PropertiesChanged(self.MEDIA_PLAYER2_PLAYER_IFACE,
{
@@ -204,6 +214,7 @@ class MediaPlayer2Service(dbus.service.Object):
},
[])
+ @log
def _on_volume_changed(self, player, data=None):
self.PropertiesChanged(self.MEDIA_PLAYER2_PLAYER_IFACE,
{
@@ -211,6 +222,7 @@ class MediaPlayer2Service(dbus.service.Object):
},
[])
+ @log
def _on_prev_next_invalidated(self, player, data=None):
self.PropertiesChanged(self.MEDIA_PLAYER2_PLAYER_IFACE,
{
@@ -219,6 +231,7 @@ class MediaPlayer2Service(dbus.service.Object):
},
[])
+ @log
def _play_first_song(self, model, path, iter_, data=None):
if self.first_song_handler:
model.disconnect(self.first_song_handler)
@@ -226,6 +239,7 @@ class MediaPlayer2Service(dbus.service.Object):
self.player.set_playlist('Songs', None, model, iter_, 5)
self.player.set_playing(True)
+ @log
def _on_seeked(self, player, position, data=None):
self.Seeked(position)
diff --git a/gnomemusic/notification.py b/gnomemusic/notification.py
index 2e6c5b6..36a02c4 100644
--- a/gnomemusic/notification.py
+++ b/gnomemusic/notification.py
@@ -28,10 +28,15 @@ from gnomemusic.albumArtCache import AlbumArtCache
from gettext import gettext as _
+from gnomemusic import log
+import logging
+logger = logging.getLogger(__name__)
+
IMAGE_SIZE = 125
class NotificationManager:
+ @log
def __init__(self, player):
self._player = player
@@ -50,6 +55,7 @@ class NotificationManager:
self._player.connect('playing-changed', self._on_playing_changed)
self._player.connect('current-changed', self._update_track)
+ @log
def _on_playing_changed(self, player):
# this function might be called from one of the action handlers
# from libnotify, and we can't call _set_actions() from there
@@ -57,6 +63,7 @@ class NotificationManager:
# the stack)
GLib.idle_add(self._update_playing)
+ @log
def _update_playing(self):
isPlaying = self._player.playing
@@ -65,6 +72,7 @@ class NotificationManager:
self._set_actions(isPlaying)
self._update_track(self._player)
+ @log
def _update_track(self, player):
if not self._player.currentTrack:
self._notification.update(_("Not playing"), None, 'gnome-music')
@@ -88,6 +96,7 @@ class NotificationManager:
self._albumArtCache.lookup(item, IMAGE_SIZE, IMAGE_SIZE, self._album_art_loaded)
+ @log
def _album_art_loaded(self, image, path, data):
if path:
self._notification.set_hint('image-path', GLib.Variant('s', path))
@@ -113,6 +122,7 @@ class NotificationManager:
self._notification.show()
+ @log
def _set_actions(self, playing):
self._notification.clear_actions()
@@ -133,14 +143,18 @@ class NotificationManager:
self._notification.add_action('media-skip-forward%s' % postfix, _("Next"),
self._go_next, None)
+ @log
def _go_previous(self, notification, action, data):
self._player.play_previous()
+ @log
def _go_next(self, notification, action, data):
self._player.play_next()
+ @log
def _play(self, notification, action, data):
self._player.play()
+ @log
def _pause(self, notification, action, data):
self._player.pause()
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 0da5d9d..57de796 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -38,6 +38,10 @@ from random import randint
from queue import LifoQueue
from gnomemusic.albumArtCache import AlbumArtCache
+from gnomemusic import log
+import logging
+logger = logging.getLogger(__name__)
+
ART_SIZE = 34
@@ -71,6 +75,7 @@ class Player(GObject.GObject):
'thumbnail-updated': (GObject.SIGNAL_RUN_FIRST, None, (str,)),
}
+ @log
def __init__(self):
GObject.GObject.__init__(self)
self.playlist = None
@@ -105,6 +110,7 @@ class Player(GObject.GObject):
self.playlist_insert_handler = 0
self.playlist_delete_handler = 0
+ @log
def discover_item(self, item, callback, data=None):
url = item.get_url()
if not url:
@@ -119,6 +125,7 @@ class Player(GObject.GObject):
self._discovering_urls[url] = [obj]
self.discoverer.discover_uri_async(url)
+ @log
def _on_discovered(self, discoverer, info, error):
try:
cbs = self._discovering_urls[info.get_uri()]
@@ -133,11 +140,13 @@ class Player(GObject.GObject):
# Not something we're interested in
return
+ @log
def _on_settings_changed(self, settings, value):
self.repeat = settings.get_enum('repeat')
self._sync_prev_next()
self._sync_repeat_image()
+ @log
def _on_bus_state_changed(self, bus, message):
#Note: not all state changes are signaled through here, in particular
#transitions between Gst.State.READY and Gst.State.NULL are never async
@@ -145,6 +154,7 @@ class Player(GObject.GObject):
#In practice, self means only Gst.State.PLAYING and Gst.State.PAUSED are
self._sync_playing()
+ @log
def _onBusError(self, bus, message):
media = self.get_current_media()
if media is not None:
@@ -161,6 +171,7 @@ class Player(GObject.GObject):
self.play_next()
return True
+ @log
def _on_bus_eos(self, bus, message):
self.nextTrack = self._get_next_track()
@@ -186,13 +197,16 @@ class Player(GObject.GObject):
self.progressScale.set_sensitive(False)
self.emit('playback-status-changed')
+ @log
def _on_glib_idle(self):
self.currentTrack = self.nextTrack
self.play()
+ @log
def _on_playlist_size_changed(self, path, _iter=None, data=None):
self._sync_prev_next()
+ @log
def _get_random_iter(self, currentTrack):
currentPath = int(self.playlist.get_path(currentTrack).to_string())
rows = self.playlist.iter_n_children(None)
@@ -203,6 +217,7 @@ class Player(GObject.GObject):
rand = randint(0, rows - 1)
return self.playlist.get_iter_from_string(str(rand))
+ @log
def _get_next_track(self):
if self.currentTrack and self.currentTrack.valid():
currentTrack = self.playlist.get_iter(self.currentTrack.get_path())
@@ -236,6 +251,7 @@ class Player(GObject.GObject):
else:
return None
+ @log
def _get_iter_last(self):
iter = self.playlist.get_iter_first()
last = None
@@ -246,6 +262,7 @@ class Player(GObject.GObject):
return last
+ @log
def _get_previous_track(self):
if self.currentTrack and self.currentTrack.valid():
currentTrack = self.playlist.get_iter(self.currentTrack.get_path())
@@ -279,6 +296,7 @@ class Player(GObject.GObject):
else:
return None
+ @log
def has_next(self):
if not self.playlist or self.playlist.iter_n_children(None) < 1:
return False
@@ -292,6 +310,7 @@ class Player(GObject.GObject):
else:
return True
+ @log
def has_previous(self):
if not self.playlist or self.playlist.iter_n_children(None) < 1:
return False
@@ -305,6 +324,7 @@ class Player(GObject.GObject):
else:
return True
+ @log
def _get_playing(self):
ok, state, pending = self.player.get_state(0)
#log('get playing(), [ok, state, pending] = [%s, %s, %s]'.format(ok, state, pending))
@@ -319,11 +339,13 @@ class Player(GObject.GObject):
def playing(self):
return self._get_playing()
+ @log
def _sync_playing(self):
image = self._pauseImage if self._get_playing() else self._playImage
if self.playBtn.get_image() != image:
self.playBtn.set_image(image)
+ @log
def _sync_prev_next(self):
hasNext = self.has_next()
hasPrevious = self.has_previous()
@@ -333,6 +355,7 @@ class Player(GObject.GObject):
self.emit('prev-next-invalidated')
+ @log
def set_playing(self, value):
self.eventBox.show()
@@ -345,6 +368,7 @@ class Player(GObject.GObject):
self.playBtn.set_image(self._pauseImage)
return media
+ @log
def load(self, media):
self.progressScale.set_value(0)
self._set_duration(media.get_duration())
@@ -374,11 +398,13 @@ class Player(GObject.GObject):
self.emit('playlist-item-changed', self.playlist, currentTrack)
self.emit('current-changed')
+ @log
def _on_cache_lookup(self, pixbuf, path, data=None):
if pixbuf is not None:
self.coverImg.set_from_pixbuf(pixbuf)
self.emit('thumbnail-updated', path)
+ @log
def play(self):
if self.playlist is None:
return
@@ -400,6 +426,7 @@ class Player(GObject.GObject):
self.emit('playback-status-changed')
self.emit('playing-changed')
+ @log
def pause(self):
if self.timeout:
GLib.source_remove(self.timeout)
@@ -409,6 +436,7 @@ class Player(GObject.GObject):
self.emit('playback-status-changed')
self.emit('playing-changed')
+ @log
def stop(self):
if self.timeout:
GLib.source_remove(self.timeout)
@@ -417,6 +445,7 @@ class Player(GObject.GObject):
self.player.set_state(Gst.State.NULL)
self.emit('playing-changed')
+ @log
def play_next(self):
if self.playlist is None:
return True
@@ -430,6 +459,7 @@ class Player(GObject.GObject):
if self.currentTrack:
self.play()
+ @log
def play_previous(self):
if self.playlist is None:
return
@@ -447,12 +477,14 @@ class Player(GObject.GObject):
if self.currentTrack:
self.play()
+ @log
def play_pause(self):
if self.player.get_state(1)[1] == Gst.State.PLAYING:
self.set_playing(False)
else:
self.set_playing(True)
+ @log
def set_playlist(self, type, id, model, iter, field):
self.stop()
@@ -472,12 +504,14 @@ class Player(GObject.GObject):
self.emit('current-changed')
+ @log
def running_playlist(self, type, id):
if type == self.playlistType and id == self.playlistId:
return self.playlist
else:
return None
+ @log
def _setup_view(self):
self._ui = Gtk.Builder()
self._ui.add_from_resource('/org/gnome/Music/PlayerToolbar.ui')
@@ -519,6 +553,7 @@ class Player(GObject.GObject):
self._nextImage.set_property('icon-name', 'media-skip-forward-rtl-symbolic')
self._playImage.set_property('icon-name', 'media-playback-start-rtl-symbolic')
+ @log
def _on_progress_scale_button_released(self, scale, data):
self.on_progress_scale_change_value(self.progressScale)
self._update_position_callback()
@@ -531,6 +566,7 @@ class Player(GObject.GObject):
self.songPlaybackTimeLabel.set_label(self.seconds_to_string(seconds))
return False
+ @log
def _on_progress_scale_event(self, scale, data):
self._lastState = self.player.get_state(1)[1]
self.player.set_state(Gst.State.PAUSED)
@@ -539,6 +575,7 @@ class Player(GObject.GObject):
self.timeout = None
return False
+ @log
def seconds_to_string(self, duration):
seconds = duration
minutes = seconds // 60
@@ -546,28 +583,34 @@ class Player(GObject.GObject):
return '%i:%02i' % (minutes, seconds)
+ @log
def _on_play_btn_clicked(self, btn):
if self._get_playing():
self.pause()
else:
self.play()
+ @log
def _on_next_btn_clicked(self, btn):
self.play_next()
+ @log
def _on_prev_btn_clicked(self, btn):
self.play_previous()
+ @log
def _set_duration(self, duration):
self.duration = duration
self.progressScale.set_range(0.0, duration * 60)
+ @log
def _update_position_callback(self):
position = self.player.query_position(Gst.Format.TIME)[1] / 1000000000
if position > 0:
self.progressScale.set_value(position * 60)
return True
+ @log
def _sync_repeat_image(self):
icon = None
if self.repeat == RepeatType.NONE:
@@ -594,6 +637,7 @@ class Player(GObject.GObject):
self.repeatBtnImage.set_from_icon_name(icon, Gtk.IconSize.MENU)
self.emit('repeat-mode-changed')
+ @log
def on_progress_scale_change_value(self, scroll):
seconds = scroll.get_value() / 60
if seconds != self.duration:
@@ -609,6 +653,7 @@ class Player(GObject.GObject):
#MPRIS
+ @log
def Stop(self):
self.progressScale.set_value(0)
self.progressScale.set_sensitive(False)
@@ -616,6 +661,7 @@ class Player(GObject.GObject):
self.stop()
self.emit('playback-status-changed')
+ @log
def get_playback_status(self):
ok, state, pending = self.player.get_state(0)
if ok == Gst.StateChangeReturn.ASYNC:
@@ -630,16 +676,20 @@ class Player(GObject.GObject):
else:
return PlaybackStatus.STOPPED
+ @log
def get_repeat_mode(self):
return self.repeat
+ @log
def set_repeat_mode(self, mode):
self.repeat = mode
self._sync_repeat_image()
+ @log
def get_position(self):
return self.player.query_position(Gst.Format.TIME)[1] / 1000
+ @log
def set_position(self, offset, start_if_ne=False, next_on_overflow=False):
if offset < 0:
if start_if_ne:
@@ -657,13 +707,16 @@ class Player(GObject.GObject):
elif next_on_overflow:
self.play_next()
+ @log
def get_volume(self):
return self.player.get_volume(GstAudio.StreamVolumeFormat.LINEAR)
+ @log
def set_volume(self, rate):
self.player.set_volume(GstAudio.StreamVolumeFormat.LINEAR, rate)
self.emit('volume-changed')
+ @log
def get_current_media(self):
if not self.currentTrack or not self.currentTrack.valid():
return None
@@ -672,6 +725,8 @@ class Player(GObject.GObject):
class SelectionToolbar():
+
+ @log
def __init__(self):
self._ui = Gtk.Builder()
self._ui.add_from_resource('/org/gnome/Music/SelectionToolbar.ui')
diff --git a/gnomemusic/playlists.py b/gnomemusic/playlists.py
index d5e720d..f6c1bc2 100644
--- a/gnomemusic/playlists.py
+++ b/gnomemusic/playlists.py
@@ -3,6 +3,10 @@ from gnomemusic.grilo import grilo
import os
+from gnomemusic import log
+import logging
+logger = logging.getLogger(__name__)
+
class Playlists(GObject.GObject):
__gsignals__ = {
@@ -21,12 +25,14 @@ class Playlists(GObject.GObject):
self.instance = Playlists()
return self.instance
+ @log
def __init__(self):
GObject.GObject.__init__(self)
self.playlist_dir = os.path.join(GLib.get_user_data_dir(),
'gnome-music',
'playlists')
+ @log
def create_playlist(self, name, iterlist=None):
parser = TotemPlParser.Parser()
playlist = TotemPlParser.Playlist()
@@ -40,6 +46,7 @@ class Playlists(GObject.GObject):
self.emit('playlist-created', name)
return False
+ @log
def get_playlists(self):
playlist_files = [pl_file for pl_file in os.listdir(self.playlist_dir)
if os.path.isfile(os.path.join(self.playlist_dir,
@@ -51,6 +58,7 @@ class Playlists(GObject.GObject):
playlist_names.append(name)
return playlist_names
+ @log
def add_to_playlist(self, playlist_name, uris):
parser = TotemPlParser.Parser()
playlist = TotemPlParser.Playlist()
@@ -78,6 +86,7 @@ class Playlists(GObject.GObject):
False, None, None, None
)
+ @log
def remove_from_playlist(self, playlist_name, uris):
parser = TotemPlParser.Parser()
playlist = TotemPlParser.Playlist()
@@ -103,15 +112,18 @@ class Playlists(GObject.GObject):
False, None, None, None
)
+ @log
def delete_playlist(self, playlist_name):
playlist_file = self.get_path_to_playlist(playlist_name)
if os.path.isfile(playlist_file):
os.remove(playlist_file)
self.emit('playlist-deleted', playlist_name)
+ @log
def get_path_to_playlist(self, playlist_name):
return os.path.join(self.playlist_dir, "%s.pls" % playlist_name)
+ @log
def parse_playlist(self, playlist_name, callback):
parser = TotemPlParser.Parser()
parser.connect('entry-parsed', self._on_entry_parsed, callback)
@@ -120,6 +132,7 @@ class Playlists(GObject.GObject):
False, None, None, None
)
+ @log
def _on_entry_parsed(self, parser, uri, metadata, data=None):
filename = GLib.filename_from_uri(uri)[0]
if filename and not os.path.isfile(filename):
diff --git a/gnomemusic/searchbar.py b/gnomemusic/searchbar.py
index 988ecc6..a511593 100644
--- a/gnomemusic/searchbar.py
+++ b/gnomemusic/searchbar.py
@@ -1,9 +1,12 @@
from gi.repository import Gtk, Gd
-from gettext import gettext as _
+from gnomemusic import log
+import logging
+logger = logging.getLogger(__name__)
class Searchbar(Gd.Revealer):
+ @log
def __init__(self, stack_switcher, search_button):
Gd.Revealer.__init__(self)
self.stack_switcher = stack_switcher
@@ -23,6 +26,7 @@ class Searchbar(Gd.Revealer):
self.connect("notify::child-revealed", self.prepare_search_filter)
self.view = None
+ @log
def set_view_filter(self, model, itr, user_data):
if self._search_entry.get_property("visible"):
search_string = self._search_entry.get_text().lower()
@@ -37,6 +41,7 @@ class Searchbar(Gd.Revealer):
return False
return True
+ @log
def prepare_search_filter(self, widget, data):
self.view = self.stack_switcher.get_stack().get_visible_child()
if self.view.header_bar._state == 0:
@@ -46,11 +51,13 @@ class Searchbar(Gd.Revealer):
self.view.filter.set_visible_func(self.set_view_filter)
self.view.filter.visible_function_set = True
+ @log
def search_entry_changed(self, widget):
self.search_term = self._search_entry.get_text()
if self.view:
self.view.filter.refilter()
+ @log
def show_bar(self, show):
self.set_reveal_child(show)
self._search_button.set_active(show)
@@ -60,5 +67,6 @@ class Searchbar(Gd.Revealer):
else:
self._search_entry.set_text('')
+ @log
def toggle_bar(self):
self.show_bar(not self.get_child_revealed())
diff --git a/gnomemusic/toolbar.py b/gnomemusic/toolbar.py
index 09d9541..ef6f4e4 100644
--- a/gnomemusic/toolbar.py
+++ b/gnomemusic/toolbar.py
@@ -36,6 +36,10 @@ else:
from gi.repository.Gd import StackSwitcher
from gnomemusic.searchbar import Searchbar
+from gnomemusic import log
+import logging
+logger = logging.getLogger(__name__)
+
class ToolbarState:
SINGLE = 0
@@ -54,6 +58,7 @@ class Toolbar(GObject.GObject):
_selectionMode = False
_maximized = False
+ @log
def __init__(self):
GObject.GObject.__init__(self)
self._stack_switcher = StackSwitcher(margin_top=2, margin_bottom=2, can_focus=False)
@@ -92,15 +97,18 @@ class Toolbar(GObject.GObject):
if Gtk.get_minor_version() <= 8:
self._close_button.connect('hierarchy-changed', self._on_hierarchy_changed)
+ @log
def _close_button_clicked(self, btn):
if Gtk.get_minor_version() > 8:
self._close_button.get_toplevel().close()
else:
self._close_button.get_toplevel().destroy()
+ @log
def reset_header_title(self):
self.header_bar.set_custom_title(self._stack_switcher)
+ @log
def _on_hierarchy_changed(self, widget, previous_toplevel):
if previous_toplevel:
previous_toplevel.disconnect(self._window_state_handler)
@@ -108,23 +116,29 @@ class Toolbar(GObject.GObject):
self._window_state_handler = \
self._close_button.get_toplevel().connect('window-state-event', self._on_window_state_event)
+ @log
def _on_window_state_event(self, widget, event):
if event.changed_mask & Gdk.WindowState.MAXIMIZED:
self._maximized = bool(event.new_window_state & Gdk.WindowState.MAXIMIZED)
self._update()
+ @log
def set_stack(self, stack):
self._stack_switcher.set_stack(stack)
+ @log
def get_stack(self):
return self._stack_switcher.get_stack()
+ @log
def hide_stack(self):
self._stack_switcher.hide()
+ @log
def show_stack(self):
self._stack_switcher.show()
+ @log
def set_selection_mode(self, selectionMode):
self._selectionMode = selectionMode
if selectionMode:
@@ -140,16 +154,19 @@ class Toolbar(GObject.GObject):
self.emit('selection-mode-changed')
self._update()
+ @log
def on_back_button_clicked(self, widget):
view = self._stack_switcher.get_stack().get_visible_child()
view._back_button_clicked(view)
self.set_state(ToolbarState.ALBUMS)
+ @log
def set_state(self, state, btn=None):
self._state = state
self._update()
self.emit('state-changed')
+ @log
def _update(self):
if self._state == ToolbarState.SINGLE:
self.header_bar.set_custom_title(None)
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 690cd15..5db712e 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -48,6 +48,10 @@ import gnomemusic.widgets as Widgets
from gnomemusic.playlists import Playlists
from gnomemusic.query import Query
from gnomemusic.albumArtCache import AlbumArtCache as albumArtCache
+from gnomemusic import log
+import logging
+logger = logging.getLogger(__name__)
+
tracker = Tracker.SparqlConnection.get(None)
playlists = Playlists.get_default()
@@ -67,6 +71,7 @@ class ViewContainer(Stack):
countQuery = None
filter = None
+ @log
def __init__(self, title, header_bar, selection_toolbar, view_type, use_sidebar=False, sidebar=None):
Stack.__init__(self,
transition_type=StackTransitionType.CROSSFADE)
@@ -151,14 +156,17 @@ class ViewContainer(Stack):
self._discovering_urls = {}
grilo.connect('changes-pending', self._on_changes_pending)
+ @log
def _on_changes_pending(self, data=None):
pass
+ @log
def _get_remaining_item_count(self):
if self._cached_count < 0:
self._cached_count = Widgets.get_count(self.countQuery)
return self._cached_count - self._offset
+ @log
def _on_header_bar_toggled(self, button):
if button.get_active():
self.view.set_selection_mode(True)
@@ -171,10 +179,12 @@ class ViewContainer(Stack):
self.header_bar.set_selection_mode(False)
self.selection_toolbar.eventbox.set_visible(False)
+ @log
def _on_cancel_button_clicked(self, button):
self.view.set_selection_mode(False)
self.header_bar.set_selection_mode(False)
+ @log
def _on_grilo_ready(self, data=None):
if (self.header_bar.get_stack().get_visible_child() == self
and not self._init):
@@ -182,10 +192,12 @@ class ViewContainer(Stack):
self.header_bar.get_stack().connect('notify::visible-child',
self._on_headerbar_visible)
+ @log
def _on_headerbar_visible(self, widget, param):
if self == widget.get_visible_child() and not self._init:
self._populate()
+ @log
def _on_view_selection_changed(self, widget):
items = self.view.get_selection()
self.selection_toolbar._add_to_playlist_button.\
@@ -198,21 +210,26 @@ class ViewContainer(Stack):
else:
self.header_bar._selection_menu_label.set_text(_("Click on items to select them"))
+ @log
def _populate(self, data=None):
self._init = True
self.populate()
+ @log
def _on_state_changed(self, widget, data=None):
pass
+ @log
def _on_selection_mode_changed(self, widget, data=None):
pass
+ @log
def _connect_view(self):
self._adjustmentValueId = self.vadjustment.connect(
'value-changed',
self._on_scrolled_win_change)
+ @log
def _on_scrolled_win_change(self, data=None):
vScrollbar = self.view.get_vscrollbar()
revealAreaHeight = 32
@@ -236,14 +253,17 @@ class ViewContainer(Stack):
end = False
self._loadMore.set_block(not end)
+ @log
def populate(self):
print('populate')
+ @log
def _on_discovered(self, info, error, _iter):
if error:
print("Info %s: error: %s" % (info, error))
self._model.set(_iter, [8, 10], [self.errorIconName, True])
+ @log
def _add_item(self, source, param, item, remaining):
if not item:
return
@@ -272,6 +292,7 @@ class ViewContainer(Stack):
GLib.idle_add(add_new_item)
+ @log
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():
@@ -282,6 +303,7 @@ class ViewContainer(Stack):
self._iconHeight,
self._on_lookup_ready, itr)
+ @log
def _update_album_art(self, item, itr):
grilo.get_album_art_for_album_id(
item.get_id(),
@@ -289,6 +311,7 @@ class ViewContainer(Stack):
self._insert_album_art(item, cb_item, itr, True)
)
+ @log
def _on_lookup_ready(self, icon, path, _iter):
if icon:
self._model.set_value(
@@ -296,21 +319,26 @@ class ViewContainer(Stack):
albumArtCache.get_default()._make_icon_frame(icon))
self.view.queue_draw()
+ @log
def _add_list_renderers(self):
pass
+ @log
def _on_item_activated(self, widget, id, path):
pass
+ @log
def _on_selection_mode_request(self, *args):
self.header_bar._select_button.clicked()
+ @log
def get_selected_track_uris(self, callback):
callback([])
#Class for the Empty View
class Empty(Stack):
+ @log
def __init__(self, header_bar, player):
Stack.__init__(self,
transition_type=StackTransitionType.CROSSFADE)
@@ -325,6 +353,7 @@ class Empty(Stack):
class Albums(ViewContainer):
+ @log
def __init__(self, header_bar, selection_toolbar, player):
ViewContainer.__init__(self, _("Albums"), header_bar,
selection_toolbar, Gd.MainViewType.ICON)
@@ -336,6 +365,7 @@ class Albums(ViewContainer):
self.items_selected = []
self.items_selected_callback = None
+ @log
def _on_changes_pending(self, data=None):
if (self._init):
self._offset = 0
@@ -343,9 +373,11 @@ class Albums(ViewContainer):
self._model.clear()
self.populate()
+ @log
def _back_button_clicked(self, widget, data=None):
self.set_visible_child(self._grid)
+ @log
def _on_item_activated(self, widget, id, path):
child_path = self.filter.convert_path_to_child_path(path)
_iter = self._model.get_iter(child_path)
@@ -360,10 +392,12 @@ class Albums(ViewContainer):
self.header_bar.header_bar.sub_title = artist
self.set_visible_child(self._albumWidget)
+ @log
def populate(self):
if grilo.tracker:
GLib.idle_add(grilo.populate_albums, self._offset, self._add_item)
+ @log
def get_selected_track_uris(self, callback):
if self.header_bar._state == ToolbarState.SINGLE:
uris = []
@@ -380,12 +414,14 @@ class Albums(ViewContainer):
if len(self.albums_selected):
self._get_selected_album_songs()
+ @log
def _get_selected_album_songs(self):
grilo.populate_album_songs(
self.albums_selected[self.albums_index].get_id(),
self._add_selected_item)
self.albums_index += 1
+ @log
def _add_selected_item(self, source, param, item, remaining):
if item:
self.items_selected.append(item.get_url())
@@ -397,6 +433,7 @@ class Albums(ViewContainer):
class Songs(ViewContainer):
+ @log
def __init__(self, header_bar, selection_toolbar, player):
ViewContainer.__init__(self, _("Songs"), header_bar, selection_toolbar, Gd.MainViewType.LIST)
self.countQuery = Query.SONGS_COUNT
@@ -415,6 +452,7 @@ class Songs(ViewContainer):
self.player = player
self.player.connect('playlist-item-changed', self.update_model)
+ @log
def _on_changes_pending(self, data=None):
if (self._init):
self._model.clear()
@@ -422,6 +460,7 @@ class Songs(ViewContainer):
self._cached_count = -1
self.populate()
+ @log
def _on_item_activated(self, widget, id, path):
_iter = self.filter.get_iter(path)
child_iter = self.filter.convert_iter_to_child_iter(_iter)
@@ -429,6 +468,7 @@ class Songs(ViewContainer):
self.player.set_playlist('Songs', None, self.filter, _iter, 5)
self.player.set_playing(True)
+ @log
def update_model(self, player, playlist, currentIter):
if self.iter_to_clean:
self._model.set_value(self.iter_to_clean, 10, False)
@@ -443,6 +483,7 @@ class Songs(ViewContainer):
self.iter_to_clean = child_iter.copy()
return False
+ @log
def _add_item(self, source, param, item, remaining):
if not item:
return
@@ -468,6 +509,7 @@ class Songs(ViewContainer):
if event == Gio.FileMonitorEvent.DELETED:
self._model.set(_iter, [8, 10], [self.errorIconName, True])
+ @log
def _add_list_renderers(self):
list_widget = self.view.get_generic_view()
cols = list_widget.get_columns()
@@ -528,12 +570,15 @@ class Songs(ViewContainer):
list_widget.add_renderer(type_renderer,
self._on_list_widget_type_render, None)
+ @log
def _on_list_widget_title_render(self, col, cell, model, _iter, data):
pass
+ @log
def _on_list_widget_star_render(self, col, cell, model, _iter, data):
pass
+ @log
def _on_list_widget_duration_render(self, col, cell, model, _iter, data):
item = model.get_value(_iter, 5)
if item:
@@ -542,24 +587,29 @@ class Songs(ViewContainer):
seconds %= 60
cell.set_property('text', '%i:%02i' % (minutes, seconds))
+ @log
def _on_list_widget_artist_render(self, col, cell, model, _iter, data):
pass
+ @log
def _on_list_widget_type_render(self, coll, cell, model, _iter, data):
item = model.get_value(_iter, 5)
if item:
cell.set_property('text', item.get_string(Grl.METADATA_KEY_ALBUM) or _("Unknown Album"))
+ @log
def populate(self):
if grilo.tracker:
GLib.idle_add(grilo.populate_songs, self._offset, self._add_item)
+ @log
def get_selected_track_uris(self, callback):
callback([self.filter.get_value(self.filter.get_iter(path), 5).get_url()
for path in self.view.get_selection()])
class Artists (ViewContainer):
+ @log
def __init__(self, header_bar, selection_toolbar, player):
ViewContainer.__init__(self, _("Artists"), header_bar,
selection_toolbar, Gd.MainViewType.LIST, True)
@@ -594,6 +644,7 @@ class Artists (ViewContainer):
add_class('artist-panel-white')
self.show_all()
+ @log
def _on_changes_pending(self, data=None):
if (self._init):
self._model.clear()
@@ -602,6 +653,7 @@ class Artists (ViewContainer):
self._cached_count = -1
self._populate()
+ @log
def _populate(self, data=None):
selection = self.view.get_generic_view().get_selection()
if not selection.get_selected()[1]:
@@ -615,6 +667,7 @@ class Artists (ViewContainer):
self._init = True
self.populate()
+ @log
def _add_list_renderers(self):
list_widget = self.view.get_generic_view()
@@ -633,6 +686,7 @@ class Artists (ViewContainer):
cols[0].clear_attributes(type_renderer)
cols[0].add_attribute(type_renderer, 'text', 2)
+ @log
def _on_item_activated(self, widget, item_id, path):
# Prepare a new artistAlbumsWidget here
self.new_artistAlbumsWidget = Gtk.Frame(
@@ -664,6 +718,7 @@ class Artists (ViewContainer):
self._artistAlbumsWidget = self.new_artistAlbumsWidget
GLib.idle_add(self.artistAlbumsStack.set_visible_child_name, child_name)
+ @log
def _add_item(self, source, param, item, remaining):
if item is None:
return
@@ -677,10 +732,12 @@ class Artists (ViewContainer):
self._artists[artist.lower()]['albums'].append(item)
+ @log
def populate(self):
if grilo.tracker:
GLib.idle_add(grilo.populate_artists, self._offset, self._add_item)
+ @log
def _on_header_bar_toggled(self, button):
ViewContainer._on_header_bar_toggled(self, button)
@@ -696,6 +753,7 @@ class Artists (ViewContainer):
self.view.get_generic_view().get_selection().select_iter(
self._last_selection)
+ @log
def get_selected_track_uris(self, callback):
self.items_selected = []
self.items_selected_callback = callback
@@ -713,12 +771,14 @@ class Artists (ViewContainer):
if len(self.albums_selected):
self._get_selected_album_songs()
+ @log
def _get_selected_album_songs(self):
grilo.populate_album_songs(
self.albums_selected[self.albums_index].get_id(),
self._add_selected_item)
self.albums_index += 1
+ @log
def _add_selected_item(self, source, param, item, remaining):
if item:
self.items_selected.append(item.get_url())
@@ -732,6 +792,7 @@ class Artists (ViewContainer):
class Playlist(ViewContainer):
playlists_list = playlists.get_playlists()
+ @log
def __init__(self, header_bar, selection_toolbar, player):
self.playlists_sidebar = Gd.MainView(
shadow_type=Gtk.ShadowType.NONE
@@ -802,6 +863,7 @@ class Playlist(ViewContainer):
playlists.connect('song-removed-from-playlist', self._on_song_removed_from_playlist)
self.show_all()
+ @log
def _add_list_renderers(self):
list_widget = self.view.get_generic_view()
cols = list_widget.get_columns()
@@ -862,6 +924,7 @@ class Playlist(ViewContainer):
list_widget.add_renderer(type_renderer,
self._on_list_widget_type_render, None)
+ @log
def _add_sidebar_renderers(self):
list_widget = self.playlists_sidebar.get_generic_view()
@@ -880,12 +943,15 @@ class Playlist(ViewContainer):
cols[0].clear_attributes(type_renderer)
cols[0].add_attribute(type_renderer, "text", 2)
+ @log
def _on_list_widget_title_render(self, col, cell, model, _iter, data):
pass
+ @log
def _on_list_widget_star_render(self, col, cell, model, _iter, data):
pass
+ @log
def _on_list_widget_duration_render(self, col, cell, model, _iter, data):
item = model.get_value(_iter, 5)
if item:
@@ -894,18 +960,22 @@ class Playlist(ViewContainer):
seconds %= 60
cell.set_property('text', '%i:%02i' % (minutes, seconds))
+ @log
def _on_list_widget_artist_render(self, col, cell, model, _iter, data):
pass
+ @log
def _on_list_widget_type_render(self, coll, cell, model, _iter, data):
item = model.get_value(_iter, 5)
if item:
cell.set_property('text', item.get_string(Grl.METADATA_KEY_ALBUM) or _("Unknown Album"))
+ @log
def _populate(self):
self._init = True
self.populate()
+ @log
def update_model(self, player, playlist, currentIter):
if self.iter_to_clean:
self.iter_to_clean_model.set_value(self.iter_to_clean, 10, False)
@@ -919,10 +989,12 @@ class Playlist(ViewContainer):
self.iter_to_clean_model = self._model
return False
+ @log
def _add_playlist_item(self, item):
_iter = self.playlists_model.append()
self.playlists_model.set(_iter, [2], [item])
+ @log
def _on_item_activated(self, widget, id, path):
_iter = self.filter.get_iter(path)
child_iter = self.filter.convert_iter_to_child_iter(_iter)
@@ -930,11 +1002,13 @@ class Playlist(ViewContainer):
self.player.set_playlist('Playlist', self.current_playlist, self.filter, _iter, 5)
self.player.set_playing(True)
+ @log
def _on_item_changed(self, monitor, file1, file2, event, _iter):
if self._model.iter_is_valid(_iter):
if event == Gio.FileMonitorEvent.DELETED:
self._model.set(_iter, [8, 10], [self.errorIconName, True])
+ @log
def _on_playlist_activated(self, widget, item_id, path):
_iter = self.playlists_model.get_iter(path)
playlist = self.playlists_model.get_value(_iter, 2)
@@ -973,9 +1047,11 @@ class Playlist(ViewContainer):
self.songs_count = 0
self._update_songs_count()
+ @log
def _add_item(self, source, param, item):
self._add_item_to_model(item, self._model)
+ @log
def _add_item_to_model(self, item, model):
if not item:
return
@@ -998,15 +1074,18 @@ class Playlist(ViewContainer):
self.songs_count += 1
self._update_songs_count()
+ @log
def _update_songs_count(self):
self.songs_count_label.set_text(
ngettext("%d Song", "%d Songs", self.songs_count)
% self.songs_count)
+ @log
def _on_selection_mode_changed(self, widget, data=None):
self.playlists_sidebar.set_sensitive(not self.header_bar._selectionMode)
self.menubutton.set_sensitive(not self.header_bar._selectionMode)
+ @log
def _on_play_activate(self, menuitem, data=None):
_iter = self._model.get_iter_first()
if not _iter:
@@ -1017,6 +1096,7 @@ class Playlist(ViewContainer):
self.view.emit('item-activated', '0',
self._model.get_path(_iter))
+ @log
def _on_delete_activate(self, menuitem, data=None):
self._model.clear()
_iter = self.playlists_sidebar.get_generic_view().get_selection().get_selected()[1]
@@ -1027,9 +1107,11 @@ class Playlist(ViewContainer):
playlists.delete_playlist(playlist)
self.playlists_model.remove(_iter)
+ @log
def _on_playlist_created(self, playlists, name):
self._add_playlist_item(name)
+ @log
def _on_song_added_to_playlist(self, playlists, name, item):
if name == self.current_playlist:
self._add_item_to_model(item, self._model)
@@ -1038,6 +1120,7 @@ class Playlist(ViewContainer):
if cached_playlist and cached_playlist != self._model:
self._add_item_to_model(item, cached_playlist)
+ @log
def _on_song_removed_from_playlist(self, playlists, name, uri):
if name == self.current_playlist:
model = self._model
@@ -1055,10 +1138,12 @@ class Playlist(ViewContainer):
self._update_songs_count()
return
+ @log
def populate(self):
for item in sorted(self.playlists_list):
self._add_playlist_item(item)
+ @log
def get_selected_track_uris(self, callback):
callback([self.filter.get_value(self.filter.get_iter(path), 5).get_url()
for path in self.view.get_selection()])
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index ff34e57..c61ac4f 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -40,6 +40,9 @@ 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)
@@ -51,6 +54,7 @@ else:
ERROR_ICON_NAME = 'dialog-error-symbolic'
+ log
def get_count(countQuery):
count = -1
if countQuery:
@@ -61,6 +65,7 @@ def get_count(countQuery):
class LoadMoreButton:
+ @log
def __init__(self, counter):
self._block = False
self._counter = counter
@@ -81,11 +86,13 @@ class LoadMoreButton:
self.widget.connect('clicked', self._on_load_more_clicked)
self._on_item_count_changed()
+ @log
def _on_load_more_clicked(self, data=None):
self._label.set_label(_("Loading..."))
self._spinner.show()
self._spinner.start()
+ @log
def _on_item_count_changed(self):
remaining_docs = self._counter()
visible = remaining_docs >= 0 and not self._block
@@ -96,6 +103,7 @@ class LoadMoreButton:
self._spinner.stop()
self._spinner.hide()
+ @log
def set_block(self, block):
if (self._block == block):
return
@@ -111,6 +119,7 @@ class AlbumWidget(Gtk.EventBox):
symbolicIcon = ALBUM_ART_CACHE.make_default_icon(256, 256)
filter = None
+ @log
def __init__(self, player):
super(Gtk.EventBox, self).__init__()
self.player = player
@@ -143,6 +152,7 @@ class AlbumWidget(Gtk.EventBox):
self.get_style_context().add_class('content-view')
self.show_all()
+ @log
def _on_item_activated(self, widget, id, path):
child_path = self.filter.convert_path_to_child_path(path)
_iter = self.model.get_iter(child_path)
@@ -156,6 +166,7 @@ class AlbumWidget(Gtk.EventBox):
self.player.set_playlist('Album', self.album, self.model, _iter, 5)
self.player.set_playing(True)
+ @log
def _add_list_renderers(self):
list_widget = self.view.get_generic_view()
@@ -198,6 +209,7 @@ class AlbumWidget(Gtk.EventBox):
cols[0].clear_attributes(durationRenderer)
cols[0].add_attribute(durationRenderer, 'markup', 1)
+ @log
def _create_model(self):
self.model = Gtk.ListStore(
GObject.TYPE_STRING, # title
@@ -212,6 +224,7 @@ class AlbumWidget(Gtk.EventBox):
GObject.TYPE_BOOLEAN, # icon shown
)
+ @log
def update(self, artist, album, item, header_bar, selection_toolbar):
self.selection_toolbar = selection_toolbar
self.header_bar = header_bar
@@ -252,6 +265,7 @@ class AlbumWidget(Gtk.EventBox):
self.ui.get_object('released_label_info').set_text('----')
self.player.connect('playlist-item-changed', self.update_model)
+ @log
def _on_view_selection_changed(self, widget):
items = self.view.get_selection()
self.selection_toolbar\
@@ -262,11 +276,13 @@ class AlbumWidget(Gtk.EventBox):
else:
self.header_bar._selection_menu_label.set_text(_("Click on items to select them"))
+ @log
def _on_header_cancel_button_clicked(self, button):
self.view.set_selection_mode(False)
self.header_bar.set_selection_mode(False)
self.header_bar.header_bar.title = self.album
+ @log
def _on_header_select_button_toggled(self, button):
if button.get_active():
self.view.set_selection_mode(True)
@@ -283,10 +299,12 @@ class AlbumWidget(Gtk.EventBox):
if(self.player.get_playback_status() != 2):
self.player.eventBox.set_visible(True)
+ @log
def _on_discovered(self, info, error, _iter):
if error:
self.model.set(_iter, [7, 9], [ERROR_ICON_NAME, True])
+ @log
def _on_populate_album_songs(self, source, prefs, track, remaining):
if track:
self.tracks.append(track)
@@ -308,11 +326,13 @@ class AlbumWidget(Gtk.EventBox):
self.ui.get_object('running_length_label_info').set_text(
'%d min' % (int(self.duration / 60) + 1))
+ @log
def _on_item_changed(self, monitor, file1, file2, event_type, _iter):
if self.model.iter_is_valid(_iter):
if event_type == Gio.FileMonitorEvent.DELETED:
self.model.set(_iter, [7, 9], [ERROR_ICON_NAME, True])
+ @log
def _on_look_up(self, pixbuf, path, data=None):
_iter = self.iterToClean
if pixbuf:
@@ -320,6 +340,7 @@ class AlbumWidget(Gtk.EventBox):
if _iter:
self.model.set(_iter, [4], [pixbuf])
+ @log
def update_model(self, player, playlist, currentIter):
#self is not our playlist, return
if (playlist != self.model):
@@ -352,6 +373,8 @@ class AlbumWidget(Gtk.EventBox):
class ArtistAlbums(Gtk.VBox):
+
+ @log
def __init__(self, artist, albums, player):
Gtk.VBox.__init__(self)
self.player = player
@@ -391,11 +414,13 @@ class ArtistAlbums(Gtk.VBox):
self.show_all()
self.player.connect('playlist-item-changed', self.update_model)
+ @log
def add_album(self, album):
widget = ArtistAlbumWidget(album, self.player, self.model)
self._albumBox.pack_start(widget, False, False, 0)
self.widgets.append(widget)
+ @log
def update_model(self, player, playlist, currentIter):
#this is not our playlist, return
if playlist != self.model:
@@ -432,6 +457,7 @@ class ArtistAlbums(Gtk.VBox):
itr = playlist.iter_next(itr)
return False
+ @log
def clean_model(self):
itr = self.model.get_iter_first()
while itr:
@@ -447,6 +473,7 @@ class ArtistAlbums(Gtk.VBox):
class AllArtistsAlbums(ArtistAlbums):
+ @log
def __init__(self, player):
ArtistAlbums.__init__(self, _("All Artists"), [], player)
self._offset = 0
@@ -459,11 +486,13 @@ class AllArtistsAlbums(ArtistAlbums):
self._connect_view()
self._populate()
+ @log
def _get_remaining_item_count(self):
if self._cached_count < 0:
self._cached_count = get_count(self.countQuery)
return self._cached_count - self._offset
+ @log
def _connect_view(self):
self._adjustmentValueId =\
self.vadjustment.connect('value-changed', self._on_scrolled_win_change)
@@ -475,6 +504,7 @@ class AllArtistsAlbums(ArtistAlbums):
self._on_scrolled_win_change)
self._on_scrolled_win_change()
+ @log
def _on_scrolled_win_change(self, scrollbar=None, pspec=None, data=None):
vScrollbar = self._scrolledWindow.get_vscrollbar()
revealAreaHeight = 32
@@ -495,11 +525,13 @@ class AllArtistsAlbums(ArtistAlbums):
end = not (value < (upper - page_size - revealAreaHeight))
self._load_more.set_block(not end)
+ @log
def _populate(self, data=None):
if grilo.tracker:
GLib.idle_add(grilo.populate_albums,
self._offset, self.add_item, 5)
+ @log
def add_item(self, source, param, item, remaining):
if item:
self._offset += 1
@@ -508,6 +540,7 @@ class AllArtistsAlbums(ArtistAlbums):
class ArtistAlbumWidget(Gtk.HBox):
+ @log
def __init__(self, album, player, model):
super(Gtk.HBox, self).__init__()
self.player = player
@@ -536,6 +569,7 @@ class ArtistAlbumWidget(Gtk.HBox):
self.pack_start(self.ui.get_object('ArtistAlbumWidget'), True, True, 0)
self.show_all()
+ @log
def _on_discovered(self, info, error, song_widget):
if error:
self.model.set(song_widget._iter, [4], [ERROR_ICON_NAME])
@@ -545,6 +579,7 @@ class ArtistAlbumWidget(Gtk.HBox):
song_widget.now_playing_sign.show()
song_widget.can_be_played = False
+ @log
def get_songs(self, source, prefs, track, remaining):
if track:
self.tracks.append(track)
@@ -590,18 +625,22 @@ class ArtistAlbumWidget(Gtk.HBox):
self.track_selected)
self.ui.get_object('grid1').show_all()
+ @log
def _on_item_changed(self, monitor, file1, file2, event_type, _iter):
if self.model.iter_is_valid(_iter):
if event_type == Gio.FileMonitorEvent.DELETED:
self.model.set(_iter, [3, 4], [True, ERROR_ICON_NAME])
+ @log
def _update_album_art(self):
ALBUM_ART_CACHE.lookup(self.album, 128, 128, self._get_album_cover)
+ @log
def _get_album_cover(self, pixbuf, path, data=None):
if pixbuf:
self.ui.get_object('cover').set_from_pixbuf(pixbuf)
+ @log
def track_selected(self, widget, _iter):
if not widget.can_be_played:
return
@@ -613,6 +652,7 @@ class ArtistAlbumWidget(Gtk.HBox):
class PlaylistDialog():
+ @log
def __init__(self, parent):
self.ui = Gtk.Builder()
self.ui.add_from_resource('/org/gnome/Music/PlaylistDialog.ui')
@@ -641,6 +681,7 @@ class PlaylistDialog():
self._cancel_button.connect('clicked', self._on_cancel_button_clicked)
self._select_button.connect('clicked', self._on_selection)
+ @log
def get_selected(self):
_iter = self.selection.get_selected()[1]
@@ -649,6 +690,7 @@ class PlaylistDialog():
return self.model[_iter][0]
+ @log
def _add_list_renderers(self):
cols = Gtk.TreeViewColumn()
type_renderer = Gd.StyledTextRenderer(
@@ -664,18 +706,22 @@ class PlaylistDialog():
cols.add_attribute(type_renderer, "editable", 1)
self.view.append_column(cols)
+ @log
def populate(self, items):
for playlist_name in sorted(items):
self.model.append([playlist_name, False])
add_playlist_iter = self.model.append()
self.model.set(add_playlist_iter, [0, 1], [_("New Playlist"), True])
+ @log
def _on_selection(self, select_button):
self.dialog_box.response(Gtk.ResponseType.ACCEPT)
+ @log
def _on_cancel_button_clicked(self, cancel_button):
self.dialog_box.response(Gtk.ResponseType.REJECT)
+ @log
def _on_item_activated(self, view, path, column):
_iter = self.model.get_iter(path)
if self.model.get_value(_iter, 1):
@@ -684,10 +730,12 @@ class PlaylistDialog():
else:
self._select_button.set_sensitive(True)
+ @log
def _on_editing_started(self, renderer, editable, path, data=None):
editable.set_text('')
editable.connect('editing-done', self._on_editing_done, None)
+ @log
def _on_editing_done(self, editable, data=None):
_iter = self.selection.get_selected()[1]
if editable.get_text() != '':
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index ce45190..3200432 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -40,6 +40,9 @@ import gnomemusic.view as Views
import gnomemusic.widgets as Widgets
from gnomemusic.playlists import Playlists
from gnomemusic.grilo import grilo
+from gnomemusic import log
+import logging
+logger = logging.getLogger(__name__)
playlist = Playlists.get_default()
tracker = Tracker.SparqlConnection.get(None)
@@ -52,6 +55,7 @@ else:
class Window(Gtk.ApplicationWindow):
+ @log
def __init__(self, app):
Gtk.ApplicationWindow.__init__(self,
application=app,
@@ -98,6 +102,7 @@ class Window(Gtk.ApplicationWindow):
pass
grilo.connect('changes-pending', self._on_changes_pending)
+ @log
def _on_changes_pending(self, data=None):
count = 1
cursor = tracker.query(Query.SONGS_COUNT, None)
@@ -122,6 +127,7 @@ class Window(Gtk.ApplicationWindow):
self.toolbar._select_button.set_sensitive(True)
self.toolbar.show_stack()
+ @log
def _on_configure_event(self, widget, event):
size = widget.get_size()
self.settings.set_value('window-size', GLib.Variant('ai', [size[0], size[1]]))
@@ -129,9 +135,11 @@ class Window(Gtk.ApplicationWindow):
position = widget.get_position()
self.settings.set_value('window-position', GLib.Variant('ai', [position[0], position[1]]))
+ @log
def _on_window_state_event(self, widget, event):
self.settings.set_boolean('window-maximized', 'GDK_WINDOW_STATE_MAXIMIZED' in
event.new_window_state.value_names)
+ @log
def _grab_media_player_keys(self):
try:
self.proxy.call_sync('GrabMediaPlayerKeys',
@@ -143,9 +151,11 @@ class Window(Gtk.ApplicationWindow):
# We cannot grab media keys if no settings daemon is running
pass
+ @log
def _windows_focus_cb(self, window, event):
self._grab_media_player_keys()
+ @log
def _handle_media_keys(self, proxy, sender, signal, parameters):
if signal != 'MediaPlayerKeyPressed':
print('Received an unexpected signal \'%s\' from media player'.format(signal))
@@ -160,6 +170,7 @@ class Window(Gtk.ApplicationWindow):
elif 'Previous' in response:
self.player.play_previous()
+ @log
def _setup_view(self):
self._box = Gtk.VBox()
self.player = Player()
@@ -204,12 +215,14 @@ class Window(Gtk.ApplicationWindow):
self._box.show()
self.show()
+ @log
def _switch_to_empty_view(self):
self.views.append(Views.Empty(self.toolbar, self.player))
self._stack.add_titled(self.views[0], _("Empty"), _("Empty"))
self.toolbar._search_button.set_sensitive(False)
self.toolbar._select_button.set_sensitive(False)
+ @log
def _switch_to_player_view(self):
self.views.append(Views.Albums(self.toolbar, self.selection_toolbar, self.player))
self.views.append(Views.Artists(self.toolbar, self.selection_toolbar, self.player))
@@ -228,6 +241,7 @@ class Window(Gtk.ApplicationWindow):
self.views[0].populate()
+ @log
def _on_select_all(self, action, param):
if self.toolbar._state != ToolbarState.SINGLE:
model = self._stack.get_visible_child()._model
@@ -248,6 +262,7 @@ class Window(Gtk.ApplicationWindow):
self.toolbar._selection_menu_label.set_text(_("Click on items to select them"))
self._stack.get_visible_child().queue_draw()
+ @log
def _on_select_none(self, action, param):
if self.toolbar._state != ToolbarState.SINGLE:
model = self._stack.get_visible_child()._model
@@ -262,6 +277,7 @@ class Window(Gtk.ApplicationWindow):
self.toolbar._selection_menu_label.set_text(_("Click on items to select them"))
self._stack.get_visible_child().queue_draw()
+ @log
def _on_key_press(self, widget, event):
modifiers = Gtk.accelerator_get_default_mod_mask()
event_and_modifiers = (event.state & modifiers)
@@ -292,9 +308,11 @@ class Window(Gtk.ApplicationWindow):
if event.keyval == Gdk.KEY_space and self.player.eventBox.get_visible():
self.player.play_pause()
+ @log
def _notify_mode_disconnect(self, data=None):
self._stack.disconnect(self._on_notify_model_id)
+ @log
def _on_notify_mode(self, stack, param):
#Slide out artist list on switching to artists view
if stack.get_visible_child() == self.views[1] or \
@@ -303,18 +321,22 @@ class Window(Gtk.ApplicationWindow):
stack.get_visible_child().stack.set_visible_child_name('sidebar')
self.toolbar.searchbar.show_bar(False)
+ @log
def _toggle_view(self, btn, i):
self._stack.set_visible_child(self.views[i])
+ @log
def _on_search_toggled(self, button, data=None):
self.toolbar.searchbar.show_bar(button.get_active())
+ @log
def _on_selection_mode_changed(self, widget, data=None):
if self.toolbar._selectionMode:
in_playlist = self._stack.get_visible_child() == self.views[3]
self.selection_toolbar._add_to_playlist_button.set_visible(not in_playlist)
self.selection_toolbar._remove_from_playlist_button.set_visible(in_playlist)
+ @log
def _on_add_to_playlist_button_clicked(self, widget):
if self._stack.get_visible_child() == self.views[3]:
return
@@ -333,6 +355,7 @@ class Window(Gtk.ApplicationWindow):
self._stack.get_visible_child().get_selected_track_uris(callback)
+ @log
def _on_remove_from_playlist_button_clicked(self, widget):
if self._stack.get_visible_child() != self.views[3]:
return
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]