[gnome-music/wip/jfelder/lastfm-ui-part-2: 20/24] scrobbler: Add a configure account operation
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/lastfm-ui-part-2: 20/24] scrobbler: Add a configure account operation
- Date: Sat, 15 Feb 2020 11:16:35 +0000 (UTC)
commit 352b03bd159918041433a5b62557711eaea909e3
Author: Jean Felder <jfelder src gnome org>
Date: Tue Jan 14 21:38:25 2020 +0100
scrobbler: Add a configure account operation
If no account has been configured yet, GNOME settings is launched with
a dialog to add a Last.fm account.
If an account has already been configured, GNOME settings is launched with
a dialog to edit this account.
gnomemusic/scrobbler.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-
org.gnome.Music.json | 1 +
2 files changed, 53 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/scrobbler.py b/gnomemusic/scrobbler.py
index a9b5fd9e..cbf52039 100644
--- a/gnomemusic/scrobbler.py
+++ b/gnomemusic/scrobbler.py
@@ -28,7 +28,7 @@ from hashlib import md5
import gi
gi.require_version('Goa', '1.0')
gi.require_version('Soup', '2.4')
-from gi.repository import GLib, Goa, GObject, Soup
+from gi.repository import Gio, GLib, Goa, GObject, Soup
from gnomemusic.musiclogger import MusicLogger
import gnomemusic.utils as utils
@@ -167,6 +167,54 @@ class GoaLastFM(GObject.GObject):
e.message))
return None
+ def configure(self):
+ if self.props.state == GoaLastFM.State.NOT_AVAILABLE:
+ self._log.warning("Error, cannot configure a Last.fm account.")
+ return
+
+ Gio.bus_get(Gio.BusType.SESSION, None, self._get_connection_db, None)
+
+ def _get_connection_db(self, source, res, user_data=None):
+ try:
+ connection = Gio.bus_get_finish(res)
+ except GLib.Error as e:
+ self._log.warning(
+ "Error: Unable to get the DBus connection: {}".format(
+ e.message))
+ return
+
+ Gio.DBusProxy.new(
+ connection, Gio.DBusProxyFlags.NONE, None,
+ "org.gnome.ControlCenter", "/org/gnome/ControlCenter",
+ "org.gtk.Actions", None, self._get_control_center_proxy_cb, None)
+
+ def _get_control_center_proxy_cb(self, source, res, user_data=None):
+ try:
+ settings_proxy = Gio.DBusProxy.new_finish(res)
+ except GLib.Error as e:
+ self._log.warning(
+ "Error: Unable to get a proxy: {}".format(e.message))
+ return
+
+ if self._state == GoaLastFM.State.NOT_CONFIGURED:
+ params = [GLib.Variant("s", "add"), GLib.Variant("s", "lastfm")]
+ else:
+ params = [GLib.Variant("s", self._account.props.id)]
+
+ args = GLib.Variant("(sav)", ("online-accounts", params))
+ variant = GLib.Variant("(sava{sv})", ("launch-panel", [args], {}))
+ settings_proxy.call(
+ "Activate", variant, Gio.DBusCallFlags.NONE, -1, None,
+ self._on_control_center_activated)
+
+ def _on_control_center_activated(self, proxy, res, user_data=None):
+ try:
+ proxy.call_finish(res)
+ except GLib.Error as e:
+ self._log.warning(
+ "Error: Failed to activate control-center: {}".format(
+ e.message))
+
class LastFmScrobbler(GObject.GObject):
"""Scrobble songs to Last.fm"""
@@ -192,6 +240,9 @@ class LastFmScrobbler(GObject.GObject):
self._soup_session = Soup.Session.new()
self._scrobble_cache = []
+ def configure(self):
+ self._goa_lastfm.configure()
+
@GObject.Property(type=int, default=GoaLastFM.State.NOT_AVAILABLE)
def account_state(self):
"""Get the Last.fm account state
diff --git a/org.gnome.Music.json b/org.gnome.Music.json
index 30a2ccab..f965ba0c 100644
--- a/org.gnome.Music.json
+++ b/org.gnome.Music.json
@@ -16,6 +16,7 @@
"--filesystem=xdg-run/dconf", "--filesystem=~/.config/dconf:ro",
"--talk-name=ca.desrt.dconf", "--env=DCONF_USER_CONFIG_DIR=.config/dconf",
"--own-name=org.mpris.MediaPlayer2.GnomeMusic",
+ "--talk-name=org.gnome.ControlCenter",
"--talk-name=org.gnome.SettingsDaemon.MediaKeys",
"--talk-name=com.intel.dleyna-server",
"--talk-name=org.gtk.vfs",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]