[Xfce4-commits] [panel-plugins/xfce4-pulseaudio-plugin] 01/01: Enable reading DesktopEntry from DBUS, enabling Chromium playback with the plasma-browser-integration plugin (bug #15487)
noreply at xfce.org
noreply at xfce.org
Sun Mar 29 01:38:34 CET 2020
This is an automated email from the git hooks/post-receive script.
b l u e s a b r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository panel-plugins/xfce4-pulseaudio-plugin.
commit c02ece5b1fc415a5379fdd17133249fedc09f1c6
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Sat Mar 28 20:38:24 2020 -0400
Enable reading DesktopEntry from DBUS, enabling Chromium playback with the plasma-browser-integration plugin (bug #15487)
---
panel-plugin/pulseaudio-mpris-player.c | 38 +++++++++++++++-
panel-plugin/pulseaudio-mpris-player.h | 2 +
panel-plugin/pulseaudio-mpris.c | 82 +++++++++++++++++++++++-----------
3 files changed, 96 insertions(+), 26 deletions(-)
diff --git a/panel-plugin/pulseaudio-mpris-player.c b/panel-plugin/pulseaudio-mpris-player.c
index 4a0f87b..9ebae4a 100644
--- a/panel-plugin/pulseaudio-mpris-player.c
+++ b/panel-plugin/pulseaudio-mpris-player.c
@@ -53,12 +53,14 @@ struct _PulseaudioMprisPlayer
gchar *title;
gchar *artist;
+ gchar *full_path;
gboolean can_go_next;
gboolean can_go_previous;
gboolean can_pause;
gboolean can_play;
gboolean can_raise;
+ gboolean can_launch;
PlaybackStatus playback_status;
@@ -425,6 +427,12 @@ pulseaudio_mpris_player_parse_playback_status (PulseaudioMprisPlayer *player,
static void
+pulseaudio_mpris_player_set_details_from_desktop (PulseaudioMprisPlayer *player,
+ const gchar *player_name);
+
+
+
+static void
pulseaudio_mpris_player_parse_player_properties (PulseaudioMprisPlayer *player,
GVariant *properties)
{
@@ -490,6 +498,7 @@ pulseaudio_mpris_player_parse_media_player_properties (PulseaudioMprisPlayer *pl
GVariantIter iter;
GVariant *value;
const gchar *key;
+ const gchar *filename = NULL;
g_variant_iter_init (&iter, properties);
@@ -499,6 +508,11 @@ pulseaudio_mpris_player_parse_media_player_properties (PulseaudioMprisPlayer *pl
{
player->can_raise = g_variant_get_boolean(value);
}
+ else if (0 == g_ascii_strcasecmp (key, "DesktopEntry"))
+ {
+ filename = g_variant_get_string(value, NULL);
+ pulseaudio_mpris_player_set_details_from_desktop (player, filename);
+ }
}
}
@@ -724,8 +738,10 @@ pulseaudio_mpris_player_set_details_from_desktop (PulseaudioMprisPlayer *player,
player->icon_name = g_strdup ("applications-multimedia");
}
- if (full_path != NULL)
+ if (full_path != NULL) {
+ player->full_path = g_strdup (full_path);
g_free (full_path);
+ }
g_key_file_free (key_file);
g_free (file);
@@ -771,6 +787,8 @@ pulseaudio_mpris_player_set_player (PulseaudioMprisPlayer *player,
pulseaudio_mpris_player_set_details_from_desktop (player, player_name);
pulseaudio_mpris_player_dbus_connect (player);
+
+ player->can_launch = player->full_path != NULL;
}
@@ -905,6 +923,14 @@ pulseaudio_mpris_player_get_artist (PulseaudioMprisPlayer *player)
+const gchar *
+pulseaudio_mpris_player_get_full_path (PulseaudioMprisPlayer *player)
+{
+ return player->full_path;
+}
+
+
+
gboolean
pulseaudio_mpris_player_is_connected (PulseaudioMprisPlayer *player)
{
@@ -970,6 +996,14 @@ pulseaudio_mpris_player_can_raise (PulseaudioMprisPlayer *player)
gboolean
+pulseaudio_mpris_player_can_launch (PulseaudioMprisPlayer *player)
+{
+ return player->can_launch;
+}
+
+
+
+gboolean
pulseaudio_mpris_player_is_equal (PulseaudioMprisPlayer *a,
PulseaudioMprisPlayer *b)
{
@@ -990,6 +1024,7 @@ pulseaudio_mpris_player_init (PulseaudioMprisPlayer *player)
player->title = NULL;
player->artist = NULL;
+ player->full_path = NULL;
player->can_go_next = FALSE;
player->can_go_previous = FALSE;
@@ -1020,6 +1055,7 @@ pulseaudio_mpris_player_finalize (GObject *object)
player->title = NULL;
player->artist = NULL;
+ player->full_path = NULL;
player->can_go_next = FALSE;
player->can_go_previous = FALSE;
diff --git a/panel-plugin/pulseaudio-mpris-player.h b/panel-plugin/pulseaudio-mpris-player.h
index 935bb9f..6dc362b 100644
--- a/panel-plugin/pulseaudio-mpris-player.h
+++ b/panel-plugin/pulseaudio-mpris-player.h
@@ -57,6 +57,7 @@ const gchar *pulseaudio_mpris_player_get_player_title (PulseaudioMp
const gchar *pulseaudio_mpris_player_get_icon_name (PulseaudioMprisPlayer *player);
const gchar *pulseaudio_mpris_player_get_title (PulseaudioMprisPlayer *player);
const gchar *pulseaudio_mpris_player_get_artist (PulseaudioMprisPlayer *player);
+const gchar *pulseaudio_mpris_player_get_full_path (PulseaudioMprisPlayer *player);
gboolean pulseaudio_mpris_player_is_connected (PulseaudioMprisPlayer *player);
gboolean pulseaudio_mpris_player_is_playing (PulseaudioMprisPlayer *player);
@@ -67,6 +68,7 @@ gboolean pulseaudio_mpris_player_can_pause (PulseaudioMp
gboolean pulseaudio_mpris_player_can_go_previous (PulseaudioMprisPlayer *player);
gboolean pulseaudio_mpris_player_can_go_next (PulseaudioMprisPlayer *player);
gboolean pulseaudio_mpris_player_can_raise (PulseaudioMprisPlayer *player);
+gboolean pulseaudio_mpris_player_can_launch (PulseaudioMprisPlayer *player);
gboolean pulseaudio_mpris_player_is_equal (PulseaudioMprisPlayer *a,
PulseaudioMprisPlayer *b);
diff --git a/panel-plugin/pulseaudio-mpris.c b/panel-plugin/pulseaudio-mpris.c
index 7413b95..f505454 100644
--- a/panel-plugin/pulseaudio-mpris.c
+++ b/panel-plugin/pulseaudio-mpris.c
@@ -67,6 +67,10 @@ G_DEFINE_TYPE (PulseaudioMpris, pulseaudio_mpris, G_TYPE_OBJECT)
+static PulseaudioMpris *mpris_instance;
+
+
+
static gchar *
find_desktop_entry (const gchar *player_name)
{
@@ -134,6 +138,40 @@ pulseaudio_mpris_class_init (PulseaudioMprisClass *klass)
}
+static gboolean
+player_is_usable (PulseaudioMpris *mpris,
+ const gchar *player) {
+ GVariantIter iter;
+ GVariant *result, *child = NULL;
+ gboolean usable = FALSE;
+
+ result = g_dbus_connection_call_sync (mpris->dbus_connection,
+ player,
+ "/org/mpris/MediaPlayer2",
+ "org.freedesktop.DBus.Properties",
+ "GetAll",
+ g_variant_new ("(s)", "org.mpris.MediaPlayer2"),
+ G_VARIANT_TYPE ("(a{sv})"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
+
+ if (result)
+ {
+ g_variant_iter_init (&iter, result);
+ child = g_variant_iter_next_value (&iter);
+ if (child)
+ {
+ usable = TRUE;
+ g_variant_unref (child);
+ }
+ g_variant_unref (result);
+ }
+
+ return usable;
+}
+
gchar **
pulseaudio_mpris_get_available_players (PulseaudioMpris *mpris)
@@ -169,9 +207,11 @@ pulseaudio_mpris_get_available_players (PulseaudioMpris *mpris)
{
if (g_str_has_prefix(str, "org.mpris.MediaPlayer2."))
{
- res = (gchar**)g_realloc(res, (items + 1) * sizeof(gchar*));
- res[items] = g_strdup(str + 23);
- items++;
+ if (player_is_usable (mpris, str)) {
+ res = (gchar**)g_realloc(res, (items + 1) * sizeof(gchar*));
+ res[items] = g_strdup(str + 23);
+ items++;
+ }
}
}
@@ -314,36 +354,26 @@ pulseaudio_mpris_get_player_snapshot (PulseaudioMpris *mpris,
gboolean
-pulseaudio_mpris_get_player_summary (const gchar *player,
+pulseaudio_mpris_get_player_summary (const gchar *player_id,
gchar **name,
gchar **icon_name,
gchar **full_path)
{
- GKeyFile *key_file;
- gchar *file;
- gchar *filename;
- gchar *path;
+ PulseaudioMprisPlayer *player;
+ player = PULSEAUDIO_MPRIS_PLAYER (g_hash_table_lookup (mpris_instance->players, player_id));
- filename = find_desktop_entry (player);
- if (filename == NULL)
- {
- return FALSE;
- }
+ if (player == NULL)
+ return FALSE;
- file = g_strconcat("applications/", filename, NULL);
- g_free (filename);
+ *name = g_strdup (pulseaudio_mpris_player_get_player_title (player));
+ *icon_name = g_strdup (pulseaudio_mpris_player_get_icon_name (player));
+ *full_path = g_strdup (pulseaudio_mpris_player_get_full_path (player));
- key_file = g_key_file_new();
- if (g_key_file_load_from_data_dirs (key_file, file, &path, G_KEY_FILE_NONE, NULL))
- {
- *name = g_key_file_get_string (key_file, "Desktop Entry", "Name", NULL);
- *icon_name = g_key_file_get_string (key_file, "Desktop Entry", "Icon", NULL);
- *full_path = g_strdup (path);
- g_free (path);
- }
+ if (*full_path == NULL)
+ return FALSE;
- g_key_file_free (key_file);
- g_free (file);
+ if (!pulseaudio_mpris_player_is_connected (player) && !pulseaudio_mpris_player_can_launch (player))
+ return FALSE;
return TRUE;
}
@@ -480,5 +510,7 @@ pulseaudio_mpris_new (PulseaudioConfig *config)
mpris->players = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free);
mpris->player_timer_id = g_timeout_add_seconds (1, pulseaudio_mpris_tick_cb, mpris);
+ mpris_instance = mpris;
+
return mpris;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list