[gnome-music/wip/jfelder/lastfm-ui-part-2: 3/7] 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: 3/7] scrobbler: Add a configure account operation
- Date: Tue, 14 Jan 2020 23:23:01 +0000 (UTC)
commit 1b8f09e41f8303470649576309893744bd30f7ce
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 49cfac3e..b6209b6c 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
@@ -165,6 +165,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_ENABLED:
+ 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"""
@@ -192,6 +239,9 @@ class LastFmScrobbler(GObject.GObject):
self._soup_session = Soup.Session.new()
+ def configure(self):
+ self._goa_lastfm.configure()
+
@GObject.Property(type=int, default=GoaLastFM.State.NOT_ENABLED)
def account_state(self):
"""Get the Last.fm account state
diff --git a/org.gnome.Music.json b/org.gnome.Music.json
index 1a9f06c2..d9f2ae9d 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]