From 07376458f5c490f2e6bfa682692fbe1b2dc07784 Mon Sep 17 00:00:00 2001
From: Kalev Lember <kalevlember@gmail.com>
Date: Mon, 2 Feb 2015 13:57:17 +0100
Subject: [PATCH 1/4] gstreamer plugin: Add support for v2 of the PK session
service interface
This adds support for the Modify2 interface, but keeps the older
interface supported as a fallback.
---
contrib/gstreamer-plugin/pk-gstreamer-install.c | 115 +++++++++++++++++-------
1 file changed, 85 insertions(+), 30 deletions(-)
diff --git a/contrib/gstreamer-plugin/pk-gstreamer-install.c b/contrib/gstreamer-plugin/pk-gstreamer-install.c
index ad6cf98..c2a5cfe 100644
--- a/contrib/gstreamer-plugin/pk-gstreamer-install.c
+++ b/contrib/gstreamer-plugin/pk-gstreamer-install.c
@@ -259,6 +259,76 @@ out:
return suffix;
}
+static gboolean
+pk_gst_dbus_install_resources (gchar **resources, const gchar *desktop_id, guint timestamp, GError **error)
+{
+ _cleanup_object_unref_ GDBusProxy *proxy = NULL;
+ _cleanup_variant_unref_ GVariant *value = NULL;
+
+ /* get proxy */
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.PackageKit",
+ "/org/freedesktop/PackageKit",
+ "org.freedesktop.PackageKit.Modify2",
+ NULL,
+ error);
+ if (proxy != NULL) {
+ /* invoke the method */
+ value = g_dbus_proxy_call_sync (proxy,
+ "InstallGStreamerResources",
+ g_variant_new ("(^a&sssu)",
+ resources,
+ "hide-finished",
+ desktop_id,
+ timestamp),
+ G_DBUS_CALL_FLAGS_NONE,
+ 60 * 60 * 1000, /* 1 hour */
+ NULL,
+ error);
+ if (value != NULL)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+pk_gst_dbus_install_resources_compat (gchar **resources, gint xid, GError **error)
+{
+ _cleanup_object_unref_ GDBusProxy *proxy = NULL;
+ _cleanup_variant_unref_ GVariant *value = NULL;
+
+ /* get proxy */
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.PackageKit",
+ "/org/freedesktop/PackageKit",
+ "org.freedesktop.PackageKit.Modify",
+ NULL,
+ error);
+ if (proxy != NULL) {
+ /* invoke the method */
+ value = g_dbus_proxy_call_sync (proxy,
+ "InstallGStreamerResources",
+ g_variant_new ("(u^a&ss)",
+ xid,
+ resources,
+ "hide-finished"),
+ G_DBUS_CALL_FLAGS_NONE,
+ 60 * 60 * 1000, /* 1 hour */
+ NULL,
+ error);
+ if (value != NULL)
+ return TRUE;
+ }
+
+ return FALSE;
+}
/**
* main:
@@ -269,18 +339,21 @@ main (int argc, gchar **argv)
GOptionContext *context;
guint i;
guint len;
+ gboolean ret;
gchar **codecs = NULL;
gint xid = 0;
+ guint timestamp = 0;
const gchar *suffix;
gchar *resource;
_cleanup_error_free_ GError *error = NULL;
- _cleanup_object_unref_ GDBusProxy *proxy = NULL;
+ _cleanup_free_ gchar *desktop_id = NULL;
_cleanup_ptrarray_unref_ GPtrArray *array = NULL;
_cleanup_strv_free_ gchar **resources = NULL;
- _cleanup_variant_unref_ GVariant *value = NULL;
const GOptionEntry options[] = {
{ "transient-for", '\0', 0, G_OPTION_ARG_INT, &xid, "The XID of the parent window", NULL },
+ { "desktop-id", '\0', 0, G_OPTION_ARG_STRING, &desktop_id, "The desktop ID of the calling application", NULL },
+ { "timestamp", '\0', 0, G_OPTION_ARG_INT, ×tamp, "The timestamp of the user interaction that triggered this call", NULL },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &codecs, "GStreamer install infos", NULL },
{ NULL }
};
@@ -307,22 +380,7 @@ main (int argc, gchar **argv)
/* this is our parent window */
g_message ("PackageKit: xid = %i", xid);
-
- /* get proxy */
- proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
- G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- NULL,
- "org.freedesktop.PackageKit",
- "/org/freedesktop/PackageKit",
- "org.freedesktop.PackageKit.Modify",
- NULL,
- &error);
- if (proxy == NULL) {
- g_warning ("Cannot connect to PackageKit session service: %s",
- error->message);
- return GST_INSTALL_PLUGINS_ERROR;
- }
+ g_message ("PackageKit: desktop_id = %s", desktop_id);
/* use a ()(64bit) suffix for 64 bit */
suffix = pk_gst_get_arch_suffix ();
@@ -384,18 +442,15 @@ main (int argc, gchar **argv)
/* convert to a GStrv */
resources = pk_ptr_array_to_strv (array);
- /* invoke the method */
- value = g_dbus_proxy_call_sync (proxy,
- "InstallGStreamerResources",
- g_variant_new ("(u^a&ss)",
- xid,
- resources,
- "hide-finished"),
- G_DBUS_CALL_FLAGS_NONE,
- 60 * 60 * 1000, /* 1 hour */
- NULL,
- &error);
- if (value == NULL) {
+ /* first try the new interface */
+ ret = pk_gst_dbus_install_resources (resources, desktop_id, timestamp, &error);
+ if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
+ /* ... and if that fails, fall back to the compat interface */
+ g_clear_error (&error);
+ g_message ("PackageKit: falling back to compat dbus interface");
+ ret = pk_gst_dbus_install_resources_compat (resources, xid, &error);
+ }
+ if (!ret) {
/* use the error string to return a good GStreamer exit code */
g_message ("PackageKit: Did not install codec: %s", error->message);
if (g_strrstr (error->message, "did not agree to search") != NULL)
--
2.3.0
From aa8b11490e1ef3c687c85dbef126d23320c8deca Mon Sep 17 00:00:00 2001
From: Kalev Lember <kalevlember@gmail.com>
Date: Tue, 10 Feb 2015 13:33:06 +0100
Subject: [PATCH 2/4] gstreamer plugin: Add a new --interaction command line
option
This allows passing in e.g --interaction=hide-confirm-search which would
tell the PK session service implementation that it shouldn't ask for
confirmation again, since the app has already done that.
---
contrib/gstreamer-plugin/pk-gstreamer-install.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/contrib/gstreamer-plugin/pk-gstreamer-install.c b/contrib/gstreamer-plugin/pk-gstreamer-install.c
index c2a5cfe..a89d8a4 100644
--- a/contrib/gstreamer-plugin/pk-gstreamer-install.c
+++ b/contrib/gstreamer-plugin/pk-gstreamer-install.c
@@ -260,7 +260,7 @@ out:
}
static gboolean
-pk_gst_dbus_install_resources (gchar **resources, const gchar *desktop_id, guint timestamp, GError **error)
+pk_gst_dbus_install_resources (gchar **resources, const gchar *desktop_id, guint timestamp, const gchar *interaction, GError **error)
{
_cleanup_object_unref_ GDBusProxy *proxy = NULL;
_cleanup_variant_unref_ GVariant *value = NULL;
@@ -281,7 +281,7 @@ pk_gst_dbus_install_resources (gchar **resources, const gchar *desktop_id, guint
"InstallGStreamerResources",
g_variant_new ("(^a&sssu)",
resources,
- "hide-finished",
+ interaction,
desktop_id,
timestamp),
G_DBUS_CALL_FLAGS_NONE,
@@ -347,6 +347,7 @@ main (int argc, gchar **argv)
gchar *resource;
_cleanup_error_free_ GError *error = NULL;
_cleanup_free_ gchar *desktop_id = NULL;
+ _cleanup_free_ gchar *interaction = NULL;
_cleanup_ptrarray_unref_ GPtrArray *array = NULL;
_cleanup_strv_free_ gchar **resources = NULL;
@@ -354,6 +355,7 @@ main (int argc, gchar **argv)
{ "transient-for", '\0', 0, G_OPTION_ARG_INT, &xid, "The XID of the parent window", NULL },
{ "desktop-id", '\0', 0, G_OPTION_ARG_STRING, &desktop_id, "The desktop ID of the calling application", NULL },
{ "timestamp", '\0', 0, G_OPTION_ARG_INT, ×tamp, "The timestamp of the user interaction that triggered this call", NULL },
+ { "interaction", '\0', 0, G_OPTION_ARG_STRING, &interaction, "Interaction mode specifying which UI elements should be shown", NULL },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &codecs, "GStreamer install infos", NULL },
{ NULL }
};
@@ -443,7 +445,7 @@ main (int argc, gchar **argv)
resources = pk_ptr_array_to_strv (array);
/* first try the new interface */
- ret = pk_gst_dbus_install_resources (resources, desktop_id, timestamp, &error);
+ ret = pk_gst_dbus_install_resources (resources, desktop_id, timestamp, interaction, &error);
if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
/* ... and if that fails, fall back to the compat interface */
g_clear_error (&error);
--
2.3.0
From 3bbea278b8f1b8208a937be779905978a6326e77 Mon Sep 17 00:00:00 2001
From: Kalev Lember <kalevlember@gmail.com>
Date: Fri, 13 Feb 2015 14:00:31 +0100
Subject: [PATCH 3/4] gstreamer plugin: Adapt to gstreamer missing plugin
changes
The final version that went into upstream gst-plugins-base passes
--startup-notification-id instead of --timestamp.
---
contrib/gstreamer-plugin/pk-gstreamer-install.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/contrib/gstreamer-plugin/pk-gstreamer-install.c b/contrib/gstreamer-plugin/pk-gstreamer-install.c
index a89d8a4..99b85f3 100644
--- a/contrib/gstreamer-plugin/pk-gstreamer-install.c
+++ b/contrib/gstreamer-plugin/pk-gstreamer-install.c
@@ -260,7 +260,7 @@ out:
}
static gboolean
-pk_gst_dbus_install_resources (gchar **resources, const gchar *desktop_id, guint timestamp, const gchar *interaction, GError **error)
+pk_gst_dbus_install_resources (gchar **resources, const gchar *desktop_id, const gchar *startup_id, const gchar *interaction, GError **error)
{
_cleanup_object_unref_ GDBusProxy *proxy = NULL;
_cleanup_variant_unref_ GVariant *value = NULL;
@@ -279,11 +279,11 @@ pk_gst_dbus_install_resources (gchar **resources, const gchar *desktop_id, guint
/* invoke the method */
value = g_dbus_proxy_call_sync (proxy,
"InstallGStreamerResources",
- g_variant_new ("(^a&sssu)",
+ g_variant_new ("(^a&ssss)",
resources,
interaction,
desktop_id,
- timestamp),
+ startup_id),
G_DBUS_CALL_FLAGS_NONE,
60 * 60 * 1000, /* 1 hour */
NULL,
@@ -342,20 +342,20 @@ main (int argc, gchar **argv)
gboolean ret;
gchar **codecs = NULL;
gint xid = 0;
- guint timestamp = 0;
const gchar *suffix;
gchar *resource;
_cleanup_error_free_ GError *error = NULL;
_cleanup_free_ gchar *desktop_id = NULL;
_cleanup_free_ gchar *interaction = NULL;
+ _cleanup_free_ gchar *startup_id = NULL;
_cleanup_ptrarray_unref_ GPtrArray *array = NULL;
_cleanup_strv_free_ gchar **resources = NULL;
const GOptionEntry options[] = {
{ "transient-for", '\0', 0, G_OPTION_ARG_INT, &xid, "The XID of the parent window", NULL },
{ "desktop-id", '\0', 0, G_OPTION_ARG_STRING, &desktop_id, "The desktop ID of the calling application", NULL },
- { "timestamp", '\0', 0, G_OPTION_ARG_INT, ×tamp, "The timestamp of the user interaction that triggered this call", NULL },
{ "interaction", '\0', 0, G_OPTION_ARG_STRING, &interaction, "Interaction mode specifying which UI elements should be shown", NULL },
+ { "startup-notification-id", '\0', 0, G_OPTION_ARG_STRING, &startup_id, "The startup notification ID for focus stealing prevention", NULL },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &codecs, "GStreamer install infos", NULL },
{ NULL }
};
@@ -445,7 +445,7 @@ main (int argc, gchar **argv)
resources = pk_ptr_array_to_strv (array);
/* first try the new interface */
- ret = pk_gst_dbus_install_resources (resources, desktop_id, timestamp, interaction, &error);
+ ret = pk_gst_dbus_install_resources (resources, desktop_id, startup_id, interaction, &error);
if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
/* ... and if that fails, fall back to the compat interface */
g_clear_error (&error);
--
2.3.0
From 0b2f0c75df4896ff96f07e5cf63356596f5106b4 Mon Sep 17 00:00:00 2001
From: Kalev Lember <kalevlember@gmail.com>
Date: Mon, 16 Feb 2015 17:57:08 +0100
Subject: [PATCH 4/4] gstreamer plugin: Adapt to gnome-software session service
changes
---
contrib/gstreamer-plugin/pk-gstreamer-install.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/contrib/gstreamer-plugin/pk-gstreamer-install.c b/contrib/gstreamer-plugin/pk-gstreamer-install.c
index 99b85f3..4cae3ba 100644
--- a/contrib/gstreamer-plugin/pk-gstreamer-install.c
+++ b/contrib/gstreamer-plugin/pk-gstreamer-install.c
@@ -259,6 +259,21 @@ out:
return suffix;
}
+static GVariant *
+make_platform_data (const gchar *startup_id)
+{
+ GVariantBuilder builder;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+ if (startup_id && g_utf8_validate (startup_id, -1, NULL)) {
+ g_variant_builder_add (&builder, "{sv}",
+ "desktop-startup-id", g_variant_new_string (startup_id));
+ }
+
+ return g_variant_builder_end (&builder);
+}
+
static gboolean
pk_gst_dbus_install_resources (gchar **resources, const gchar *desktop_id, const gchar *startup_id, const gchar *interaction, GError **error)
{
@@ -279,11 +294,11 @@ pk_gst_dbus_install_resources (gchar **resources, const gchar *desktop_id, const
/* invoke the method */
value = g_dbus_proxy_call_sync (proxy,
"InstallGStreamerResources",
- g_variant_new ("(^a&ssss)",
+ g_variant_new ("(^a&sss@a{sv})",
resources,
interaction,
desktop_id,
- startup_id),
+ make_platform_data (startup_id)),
G_DBUS_CALL_FLAGS_NONE,
60 * 60 * 1000, /* 1 hour */
NULL,
--
2.3.0