1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
From: Kentaro Hayashi <kenhys@gmail.com>
Date: Mon, 13 Apr 2020 15:21:23 +0900
Subject: [PATCH] Use GDBus instead of dbus-glib
dbus-glib is deprecated since Debian stretch (Debian 9) and
Ubuntu 18.04 (bionic)
This patch also change condition to notify when title, artist or album is changed
It is incompatible change but better for user experience.
BEFORE:
Notify if title and artist and album is changed
AFTER:
Notify if either title or artist or album is changed
Signed-off-by: Kentaro Hayashi <kenhys@gmail.com>
---
configure.ac | 1 -
subscribe/rhythmbox/Makefile.am | 4 +-
subscribe/rhythmbox/rhythmbox.c | 201 +++++++++++++++++++++-------------------
3 files changed, 108 insertions(+), 98 deletions(-)
diff --git a/configure.ac b/configure.ac
index 383de96..31c11ba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,7 +30,6 @@ PKG_CHECK_MODULES(LIBCURL, libcurl)
PKG_CHECK_MODULES(LIBXML2, libxml-2.0)
PKG_CHECK_MODULES(OPENSSL, openssl)
PKG_CHECK_MODULES(SQLITE3, sqlite3)
-PKG_CHECK_MODULES(DBUSGLIB1, dbus-glib-1)
PKG_CHECK_MODULES(NOTIFY, libnotify,
[ENABLE_LIBNOTIFY="display/libnotify"
AC_SUBST([ENABLE_LIBNOTIFY])
diff --git a/subscribe/rhythmbox/Makefile.am b/subscribe/rhythmbox/Makefile.am
index 79d2479..9ec99df 100644
--- a/subscribe/rhythmbox/Makefile.am
+++ b/subscribe/rhythmbox/Makefile.am
@@ -2,7 +2,7 @@ subscribedir = $(pkglibdir)/subscribe
subscribe_LTLIBRARIES = librhythmbox.la
librhythmbox_la_SOURCES = rhythmbox.c
librhythmbox_la_LDFLAGS = -rpath $(subscribedir) -module -L../../plugins
-librhythmbox_la_CFLAGS = $(GLIB2_CFLAGS) $(LIBCURL_CFLAGS) $(LIBXML2_CFLAGS) $(DBUSGLIB1_CFLAGS) -I$(srcdir)/../..
-librhythmbox_la_LIBADD = $(GLIB2_LIBS) $(LIBCURL_LIBS) $(LIBXML2_LIBS) $(DBUSGLIB1_LIBS) -lgolplug
+librhythmbox_la_CFLAGS = $(GLIB2_CFLAGS) $(LIBCURL_CFLAGS) $(LIBXML2_CFLAGS) -I$(srcdir)/../..
+librhythmbox_la_LIBADD = $(GLIB2_LIBS) $(LIBCURL_LIBS) $(LIBXML2_LIBS) -lgolplug
EXTRA_DIST =
diff --git a/subscribe/rhythmbox/rhythmbox.c b/subscribe/rhythmbox/rhythmbox.c
index ed28df0..faae54f 100644
--- a/subscribe/rhythmbox/rhythmbox.c
+++ b/subscribe/rhythmbox/rhythmbox.c
@@ -27,8 +27,7 @@
#include <stdio.h>
#include <gmodule.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
@@ -40,8 +39,8 @@
#define REQUEST_TIMEOUT (5)
static SUBSCRIPTOR_CONTEXT* sc;
-static DBusGConnection *conn;
-static DBusGProxy* proxy;
+static GDBusConnection *conn;
+static GDBusProxy* proxy;
static gboolean enable = FALSE;
static gchar* last_title;
@@ -152,131 +151,143 @@ static gboolean
get_rhythmbox_info(gpointer GOL_UNUSED_ARG(data)) {
if (!enable) return FALSE;
- DBusGProxy *player = NULL;
- DBusGProxy *shell = NULL;
+ GDBusProxy *player = NULL;
GError *error = NULL;
if (!conn) {
- conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
if (error) g_error_free(error);
if (!conn) return FALSE;
}
if (!proxy) {
- proxy = dbus_g_proxy_new_for_name(
+ proxy = g_dbus_proxy_new_sync(
conn,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
- "org.freedesktop.DBus");
+ "org.freedesktop.DBus",
+ NULL,
+ &error);
if (error) g_error_free(error);
if (!proxy) return FALSE;
}
gboolean exists = FALSE;
- if (dbus_g_proxy_call_with_timeout(
- proxy,
- "NameHasOwner",
- 5000,
- &error,
- G_TYPE_STRING,
- "org.gnome.Rhythmbox",
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN,
- &exists,
- G_TYPE_INVALID)) {
+ GVariant *parameters = g_variant_new("(s)", "org.gnome.Rhythmbox3");
+ g_variant_ref(parameters);
+ GVariant *variants = g_dbus_proxy_call_sync(
+ proxy,
+ "NameHasOwner",
+ parameters,
+ G_DBUS_CALL_FLAGS_NONE,
+ 5000,
+ NULL,
+ &error);
+ if (!variants) {
if (error) g_error_free(error);
- if (!exists) return TRUE;
- }
-
- if (!shell) {
- shell = dbus_g_proxy_new_for_name(
- conn,
- "org.gnome.Rhythmbox",
- "/org/gnome/Rhythmbox/Shell",
- "org.gnome.Rhythmbox.Shell");
+ g_variant_unref(parameters);
+ return TRUE;
+ } else {
+ g_variant_unref(parameters);
+ g_variant_get(variants, "(b)", &exists);
+ if (!exists) {
+ g_variant_unref(variants);
+ return TRUE;
+ }
+ g_variant_unref(variants);
}
-
+
if (!player) {
- player = dbus_g_proxy_new_for_name(
+ player = g_dbus_proxy_new_sync(
conn,
- "org.gnome.Rhythmbox",
- "/org/gnome/Rhythmbox/Player",
- "org.gnome.Rhythmbox.Player");
- }
-
- gboolean playing;
- if (!dbus_g_proxy_call_with_timeout(
- player,
- "getPlaying",
- 5000,
- &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN,
- &playing,
- G_TYPE_INVALID)) {
- if (error) g_error_free(error);
- if (!playing) return TRUE;
- }
-
- char *uri;
- if (!dbus_g_proxy_call_with_timeout(
- player,
- "getPlayingUri",
- 5000,
- &error,
- G_TYPE_INVALID,
- G_TYPE_STRING,
- &uri,
- G_TYPE_INVALID)) {
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.gnome.Rhythmbox3",
+ "/org/mpris/MediaPlayer2",
+ "org.mpris.MediaPlayer2.Player",
+ NULL,
+ &error);
if (error) g_error_free(error);
- return TRUE;
+ if (!player) return FALSE;
}
- GHashTable *table;
- if (!dbus_g_proxy_call_with_timeout(
- shell,
- "getSongProperties",
- 5000,
- &error,
- G_TYPE_STRING,
- uri,
- G_TYPE_INVALID,
- dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
- &table,
- G_TYPE_INVALID)) {
- if (error) g_error_free(error);
- return TRUE;
+ gboolean playing = FALSE;
+ variants = g_dbus_proxy_get_cached_property(
+ player,
+ "PlaybackStatus"
+ );
+ if (!variants) {
+ g_object_unref(player);
+ return FALSE;
+ } else {
+ gsize length = 0;
+ const gchar *playing = g_variant_get_string(variants, &length);
+ if (!playing || (playing && g_strcmp0(playing, "Playing"))) {
+ g_object_unref(player);
+ return TRUE;
+ }
}
- g_free(uri);
gchar* title = NULL;
gchar* artist = NULL;
gchar* album = NULL;
- GValue* value = (GValue*) g_hash_table_lookup(table, "rb:stream-song-title");
- if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
- title = g_strdup(g_value_get_string(value));
+ variants = g_dbus_proxy_get_cached_property(
+ player,
+ "Metadata"
+ );
+ if (!variants) {
+ g_object_unref(player);
+ return FALSE;
} else {
- value = (GValue*) g_hash_table_lookup(table, "title");
- if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
- title = g_strdup(g_value_get_string(value));
+ gsize length = 0;
+ GVariant *variant = g_variant_lookup_value(variants,
+ "xesam:title",
+ G_VARIANT_TYPE_STRING);
+ if (!variant) {
+ g_object_unref(player);
+ return FALSE;
+ } else {
+ title = g_strdup(g_variant_get_string(variant, &length));
+ g_variant_unref(variant);
}
+
+ variant = g_variant_lookup_value(variants,
+ "xesam:artist",
+ G_VARIANT_TYPE_STRING_ARRAY);
+ if (!variant) {
+ g_object_unref(player);
+ return FALSE;
+ } else {
+ const gchar **array = g_variant_get_strv(variant,
+ &length);
+ if (length > 0) {
+ artist = g_strjoinv(",", (gchar **)array);
+ } else {
+ artist = g_strdup("Unknown");
+ }
+ g_variant_unref(variant);
+ }
+
+ variant = g_variant_lookup_value(variants,
+ "xesam:album",
+ G_VARIANT_TYPE_STRING);
+ if (!variant) {
+ g_object_unref(player);
+ return FALSE;
+ } else {
+ album = g_strdup(g_variant_get_string(variant, &length));
+ g_variant_unref(variant);
+ }
+ g_variant_unref(variants);
}
- value = (GValue*) g_hash_table_lookup(table, "artist");
- if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
- artist = g_strdup(g_value_get_string(value));
- }
- value = (GValue*) g_hash_table_lookup(table, "album");
- if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
- album = g_strdup(g_value_get_string(value));
- }
-
- g_hash_table_destroy(table);
if (title && artist && album &&
- (!last_title || strcmp(last_title, title)) &&
- (!last_artist || strcmp(last_artist, artist)) &&
- (!last_album || strcmp(last_album, album))) {
+ ((!last_title || strcmp(last_title, title)) ||
+ (!last_artist || strcmp(last_artist, artist)) ||
+ (!last_album || strcmp(last_album, album)))) {
NOTIFICATION_INFO* ni = g_new0(NOTIFICATION_INFO, 1);
ni->title = g_strdup(title);
ni->text = g_strdup_printf("%s\n%s", album, artist);
|