[gnome-music/wip/jfelder/lastfm-ui-part-2: 5/9] scrobbler: Add a configure account operation
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/lastfm-ui-part-2: 5/9] scrobbler: Add a configure account operation
- Date: Sat, 1 Feb 2020 10:15:10 +0000 (UTC)
commit 8f776b9e2c1af75087635f42e956bae450a65420
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 | 52 ++++++++++++++++++++++++++++++++++++++++++++++++-
org.gnome.Music.json | 1 +
2 files changed, 52 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/scrobbler.py b/gnomemusic/scrobbler.py
index f3cc5ac3..1a58f52f 100644
--- a/gnomemusic/scrobbler.py
+++ b/gnomemusic/scrobbler.py
@@ -28,7 +28,7 @@ import logging
import gi
gi.require_versions({"Goa": "1.0", "GoaBackend": "1.0", "Soup": "2.4"})
-from gi.repository import GLib, Goa, GoaBackend, GObject, Soup
+from gi.repository import Gio, GLib, Goa, GoaBackend, GObject, Soup
from gnomemusic import log
import gnomemusic.utils as utils
@@ -171,6 +171,53 @@ class GoaLastFM(GObject.GObject):
"Error: Unable to retrieve last.fm session key", e.message)
return None
+ def configure(self):
+ if self.props.state == GoaLastFM.State.NOT_AVAILABLE:
+ logger.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:
+ logger.warning(
+ "Error: Unable to get the DBus connection:", 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:
+ logger.warning(
+ "Error: Unable to get a proxy:", 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:
+ logger.warning(
+ "Error: Failed to activate control-center: {}".format(
+ e.message))
+
class LastFmScrobbler(GObject.GObject):
"""Scrobble songs to Last.fm"""
@@ -199,6 +246,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 c1e440c5..1457394f 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]