[gnome-music/wip/jfelder/lastfm-ui-v1: 3/6] 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: 3/6] scrobbler: Add a state property
- Date: Sun, 5 Jan 2020 20:31:53 +0000 (UTC)
commit 68008d8ae5b2206fabedaaa531e03f0fb32a9a01
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 | 46 ++++++++++++++++++++++++++--------------------
1 file changed, 26 insertions(+), 20 deletions(-)
---
diff --git a/gnomemusic/scrobbler.py b/gnomemusic/scrobbler.py
index d2105dfa..207a3499 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,27 @@ 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
-
- :returns: The disabled status
+ 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
+ self.notify("state")
+
+ @GObject.Property(type=int, default=0, flags=GObject.ParamFlags.READABLE)
+ def state(self):
+ """Retrieve the state for the Last.fm account
+
+ :returns: The account state
:rtype: bool
"""
- return self._disabled
-
- @disabled.setter
- def disabled(self, value):
- """Set the disabled status for the Last.fm account
-
- :param bool value: status
- """
- self._disabled = value
+ return self._state
@GObject.Property
def secret(self):
@@ -169,7 +174,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]