[gnome-music/wip/jfelder/lastfm-ui-v1: 32/35] scrobbler: Add a state property
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/lastfm-ui-v1: 32/35] scrobbler: Add a state property
- Date: Tue, 14 Jan 2020 16:17:42 +0000 (UTC)
commit 7e833ff453686676d6d9fa23735185270c17b376
Author: Jean Felder <jfelder src gnome org>
Date: Sat Jan 4 16:16:06 2020 +0100
scrobbler: Add a state property
GoaLastFM does not make a distinction between a configured account
with music support disbled and no configured account.
This distinction is necessary in order to enable Last.fm music report
from the application. Indeed, It is pointless to enable it if there
is no configured account.
This bottleneck is solved by introducing a state property. It can have
3 different values:
- NOT_CONFIGURED: no account found
- DISABLED: an account has been found but music support is disabled
- ENABLED : an account has been found and music support is enabled
gnomemusic/scrobbler.py | 43 +++++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 18 deletions(-)
---
diff --git a/gnomemusic/scrobbler.py b/gnomemusic/scrobbler.py
index c4a044c0..1d14cd16 100644
--- a/gnomemusic/scrobbler.py
+++ b/gnomemusic/scrobbler.py
@@ -22,6 +22,7 @@
# 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 enum import IntEnum
from hashlib import md5
import logging
@@ -41,6 +42,13 @@ class GoaLastFM(GObject.GObject):
"""Last.fm account handling through GOA
"""
+ class State(IntEnum):
+ """GoaLastFM account State"""
+
+ NOT_CONFIGURED = 0
+ DISABLED = 1
+ ENABLED = 2
+
def __repr__(self):
return '<GoaLastFM>'
@@ -55,8 +63,9 @@ class GoaLastFM(GObject.GObject):
self._client = None
self._account = None
self._authentication = None
- self._disabled = True
+ self._state = GoaLastFM.State.NOT_CONFIGURED
self._music_disabled_id = None
+ self.notify("state")
@log
def _new_client_callback(self, source, result):
@@ -89,31 +98,28 @@ class GoaLastFM(GObject.GObject):
if account.props.provider_type == "lastfm":
self._authentication = obj.get_oauth2_based()
self._account = account
- self.disabled = self._account.props.music_disabled
self._music_disabled_id = self._account.connect(
'notify::music-disabled', self._goa_music_disabled)
+ self._goa_music_disabled(self._account)
break
@log
- def _goa_music_disabled(self, klass, args):
- self.disabled = klass.props.music_disabled
-
- @GObject.Property(type=bool, default=True)
- def disabled(self):
- """Retrieve the disabled status for the Last.fm account
+ def _goa_music_disabled(self, klass, args=None):
+ if self._account.props.music_disabled is True:
+ self._state = GoaLastFM.State.DISABLED
+ else:
+ self._state = GoaLastFM.State.ENABLED
- :returns: The disabled status
- :rtype: bool
- """
- return self._disabled
+ self.notify("state")
- @disabled.setter
- def disabled(self, value):
- """Set the disabled status for the Last.fm account
+ @GObject.Property(type=int, default=0, flags=GObject.ParamFlags.READABLE)
+ def state(self):
+ """Retrieve the state for the Last.fm account
- :param bool value: status
+ :returns: The account state
+ :rtype: GoaLastFM.State
"""
- self._disabled = value
+ return self._state
@GObject.Property
def secret(self):
@@ -169,7 +175,8 @@ class LastFmScrobbler(GObject.GObject):
:returns: True is music is reported to Last.fm
:rtype: bool
"""
- return not self._goa_lastfm.props.disabled and self._report is True
+ return (self._goa_lastfm.props.state == GoaLastFM.State.ENABLED
+ and self._report is True)
@GObject.Property(type=bool, default=False)
def scrobbled(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]