[totem/wip/kalev/codecs: 2/2] missing plugins: Ask the user before spawning a plugin search
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem/wip/kalev/codecs: 2/2] missing plugins: Ask the user before spawning a plugin search
- Date: Tue, 10 Feb 2015 13:00:24 +0000 (UTC)
commit 173fd6824fff1d0da15c8f9361d7a6307eb5669b
Author: Kalev Lember <kalevlember gmail com>
Date: Mon Feb 2 17:07:42 2015 +0100
missing plugins: Ask the user before spawning a plugin search
Previously, the PackageKit session service implementation would use
Totem's window xid to attatch it's own dialogs. This however no longer
works in Wayland world.
Instead of attaching a dialog to Totem's window, gnome-software by
default now pops up a Shell notification asking for confirmation before
launching the codec search.
To avoid the notification and make the user experience a bit nicer, this
commit implements a confirmation dialog within Totem and passes down
necessary flags to supress the Shell notification in that case.
.../bacon-video-widget-gst-missing-plugins.c | 182 +++++++++++++++-----
1 files changed, 138 insertions(+), 44 deletions(-)
---
diff --git a/src/backend/bacon-video-widget-gst-missing-plugins.c
b/src/backend/bacon-video-widget-gst-missing-plugins.c
index 3d99cd6..19778dc 100644
--- a/src/backend/bacon-video-widget-gst-missing-plugins.c
+++ b/src/backend/bacon-video-widget-gst-missing-plugins.c
@@ -34,6 +34,8 @@
#include <gst/pbutils/pbutils.h>
#include <gst/pbutils/install-plugins.h>
+#include <gio/gdesktopappinfo.h>
+#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#ifdef GDK_WINDOWING_X11
@@ -237,65 +239,29 @@ on_plugin_installation_done (GstInstallPluginsReturn res, gpointer user_data)
}
static gboolean
-bacon_video_widget_gst_on_missing_plugins_event (BaconVideoWidget *bvw, char **details,
- char **descriptions, gboolean playing,
- gpointer user_data)
+bacon_video_widget_start_plugin_installation (TotemCodecInstallContext *ctx, gboolean hide_confirm_search)
{
GstInstallPluginsContext *install_ctx;
- TotemCodecInstallContext *ctx;
GstInstallPluginsReturn status;
- guint i, num;
#ifdef GDK_WINDOWING_X11
GdkDisplay *display;
#endif
- num = g_strv_length (details);
- g_return_val_if_fail (num > 0 && g_strv_length (descriptions) == num, FALSE);
-
- ctx = g_new0 (TotemCodecInstallContext, 1);
- ctx->descriptions = g_strdupv (descriptions);
- ctx->details = g_strdupv (details);
- ctx->playing = playing;
- ctx->bvw = bvw;
-
- for (i = 0; i < num; ++i)
- {
- if (bacon_video_widget_gst_codec_install_plugin_is_blacklisted (ctx->details[i]))
- {
- g_message ("Missing plugin: %s (ignoring)", ctx->details[i]);
- g_free (ctx->details[i]);
- g_free (ctx->descriptions[i]);
- ctx->details[i] = ctx->details[num-1];
- ctx->descriptions[i] = ctx->descriptions[num-1];
- ctx->details[num-1] = NULL;
- ctx->descriptions[num-1] = NULL;
- --num;
- --i;
- } else {
- g_message ("Missing plugin: %s (%s)", ctx->details[i], ctx->descriptions[i]);
- }
- }
-
- if (num == 0)
- {
- g_message ("All missing plugins are blacklisted, doing nothing");
- bacon_video_widget_gst_codec_install_context_free (ctx);
- return FALSE;
- }
-
install_ctx = gst_install_plugins_context_new ();
gst_install_plugins_context_set_desktop_id (install_ctx, "org.gnome.Totem.desktop");
+ gst_install_plugins_context_set_hide_confirm_search (install_ctx, hide_confirm_search);
+ gst_install_plugins_context_set_timestamp (install_ctx, gtk_get_current_event_time ());
#ifdef GDK_WINDOWING_X11
display = gdk_display_get_default ();
if (GDK_IS_X11_DISPLAY (display) &&
- gtk_widget_get_window (GTK_WIDGET (bvw)) != NULL &&
- gtk_widget_get_realized (GTK_WIDGET (bvw)))
+ gtk_widget_get_window (GTK_WIDGET (ctx->bvw)) != NULL &&
+ gtk_widget_get_realized (GTK_WIDGET (ctx->bvw)))
{
gulong xid = 0;
- xid = bacon_video_widget_gst_get_toplevel (GTK_WIDGET (bvw));
+ xid = bacon_video_widget_gst_get_toplevel (GTK_WIDGET (ctx->bvw));
gst_install_plugins_context_set_xid (install_ctx, xid);
}
#endif /* GDK_WINDOWING_X11 */
@@ -325,8 +291,136 @@ bacon_video_widget_gst_on_missing_plugins_event (BaconVideoWidget *bvw, char **d
/* if we managed to start playing, pause playback, since some install
* wizard should now take over in a second anyway and the user might not
* be able to use totem's controls while the wizard is running */
- if (playing)
- bacon_video_widget_pause (bvw);
+ if (ctx->playing)
+ bacon_video_widget_pause (ctx->bvw);
+
+ return TRUE;
+}
+
+static void
+bacon_video_widget_find_in_software_cb (GtkDialog *dialog,
+ GtkResponseType response_type,
+ gpointer user_data)
+{
+ TotemCodecInstallContext *ctx = user_data;
+
+ switch (response_type) {
+ case GTK_RESPONSE_ACCEPT:
+ bacon_video_widget_start_plugin_installation (ctx, TRUE);
+ break;
+ case GTK_RESPONSE_CANCEL:
+ case GTK_RESPONSE_DELETE_EVENT:
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static gboolean
+does_gnome_software_exist (void)
+{
+ GDesktopAppInfo *app_info;
+ gboolean ret = FALSE;
+
+ app_info = g_desktop_app_info_new ("org.gnome.Software.desktop");
+ if (app_info != NULL) {
+ g_object_unref (app_info);
+ ret = TRUE;
+ }
+
+ return ret;
+}
+
+static gboolean
+bacon_video_widget_gst_on_missing_plugins_event (BaconVideoWidget *bvw, char **details,
+ char **descriptions, gboolean playing,
+ gpointer user_data)
+{
+ TotemCodecInstallContext *ctx;
+ guint i, num;
+
+ num = g_strv_length (details);
+ g_return_val_if_fail (num > 0 && g_strv_length (descriptions) == num, FALSE);
+
+ ctx = g_new0 (TotemCodecInstallContext, 1);
+ ctx->descriptions = g_strdupv (descriptions);
+ ctx->details = g_strdupv (details);
+ ctx->playing = playing;
+ ctx->bvw = bvw;
+
+ for (i = 0; i < num; ++i)
+ {
+ if (bacon_video_widget_gst_codec_install_plugin_is_blacklisted (ctx->details[i]))
+ {
+ g_message ("Missing plugin: %s (ignoring)", ctx->details[i]);
+ g_free (ctx->details[i]);
+ g_free (ctx->descriptions[i]);
+ ctx->details[i] = ctx->details[num-1];
+ ctx->descriptions[i] = ctx->descriptions[num-1];
+ ctx->details[num-1] = NULL;
+ ctx->descriptions[num-1] = NULL;
+ --num;
+ --i;
+ } else {
+ g_message ("Missing plugin: %s (%s)", ctx->details[i], ctx->descriptions[i]);
+ }
+ }
+
+ if (num == 0)
+ {
+ g_message ("All missing plugins are blacklisted, doing nothing");
+ bacon_video_widget_gst_codec_install_context_free (ctx);
+ return FALSE;
+ }
+
+ if (does_gnome_software_exist ())
+ {
+ GtkWidget *button;
+ GtkWidget *dialog;
+ GtkWidget *toplevel;
+ gchar *descriptions_text;
+ gchar *message_text;
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (bvw));
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
+ GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CANCEL,
+ _("Unable to play the file"));
+
+ if (num == 2) {
+ /* TRANSLATORS: separator for a list of codecs */
+ descriptions_text = g_strjoinv (_(" and "), ctx->descriptions);
+ } else {
+ /* TRANSLATORS: separator for a list of codecs */
+ descriptions_text = g_strjoinv (_(", "), ctx->descriptions);
+ }
+ message_text = g_strdup_printf (ngettext ("%s is required to play the file, but is not
installed.",
+ "%s are required to play the file, but are not
installed.",
+ num),
+ descriptions_text);
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", message_text);
+ button = gtk_dialog_add_button (GTK_DIALOG (dialog),
+ /* TRANSLATORS: this is a button to launch gnome-software */
+ _("_Find in Software"),
+ GTK_RESPONSE_ACCEPT);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "suggested-action");
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (bacon_video_widget_find_in_software_cb),
+ ctx);
+
+ gtk_window_present (GTK_WINDOW (dialog));
+
+ g_free (descriptions_text);
+ g_free (message_text);
+ } else {
+ return bacon_video_widget_start_plugin_installation (ctx, FALSE);
+ }
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]