[brasero] Integrate BraseroBurnDialog with PackageKit



commit f2c32e0db66d42dafdb0718489e809630b6fd9c6
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Sun Nov 1 16:53:32 2009 +0100

    Integrate BraseroBurnDialog with PackageKit

 libbrasero-burn/brasero-burn-dialog.c |  129 ++++++++++++++++++++++++++++++++-
 1 files changed, 128 insertions(+), 1 deletions(-)
---
diff --git a/libbrasero-burn/brasero-burn-dialog.c b/libbrasero-burn/brasero-burn-dialog.c
index 3f521b7..c0b7824 100644
--- a/libbrasero-burn/brasero-burn-dialog.c
+++ b/libbrasero-burn/brasero-burn-dialog.c
@@ -41,6 +41,7 @@
 #include <glib/gstdio.h>
 
 #include <gdk/gdk.h>
+#include <gdk/gdkx.h>
 
 #include <gtk/gtk.h>
 
@@ -66,7 +67,7 @@
 #include "brasero-drive.h"
 
 #include "brasero-misc.h"
-
+#include "brasero-pk.h"
 
 G_DEFINE_TYPE (BraseroBurnDialog, brasero_burn_dialog, GTK_TYPE_DIALOG);
 
@@ -103,6 +104,8 @@ struct BraseroBurnDialogPrivate {
 	gint64 total_size;
 	GSList *rates;
 
+	GCancellable *cancel_plugin;
+
 	gchar *initial_title;
 	gchar *initial_icon;
 
@@ -2150,6 +2153,121 @@ brasero_burn_dialog_wait_for_ready_state (BraseroBurnDialog *dialog)
 	return (result == BRASERO_BURN_OK);
 }
 
+static BraseroBurnResult
+brasero_burn_dialog_install_missing (BraseroPluginErrorType type,
+                                     const gchar *detail,
+                                     gpointer user_data)
+{
+	BraseroBurnDialogPrivate *priv = BRASERO_BURN_DIALOG_PRIVATE (user_data);
+	GCancellable *cancel;
+	BraseroPK *package;
+	gboolean res;
+	int xid = 0;
+
+	/* Get the xid */
+	xid = gdk_x11_drawable_get_xid (GDK_DRAWABLE (GTK_WIDGET (user_data)->window));
+
+	package = brasero_pk_new ();
+	cancel = g_cancellable_new ();
+	priv->cancel_plugin = cancel;
+	switch (type) {
+		case BRASERO_PLUGIN_ERROR_MISSING_APP:
+			res = brasero_pk_install_missing_app (package, detail, xid, cancel);
+			break;
+
+		case BRASERO_PLUGIN_ERROR_MISSING_LIBRARY:
+			res = brasero_pk_install_missing_library (package, detail, xid, cancel);
+			break;
+
+		case BRASERO_PLUGIN_ERROR_MISSING_GSTREAMER_PLUGIN:
+			res = brasero_pk_install_gstreamer_plugin (package, detail, xid, cancel);
+			break;
+
+		default:
+			res = FALSE;
+			break;
+	}
+
+	if (package) {
+		g_object_unref (package);
+		package = NULL;
+	}
+
+	if (g_cancellable_is_cancelled (cancel)) {
+		g_object_unref (cancel);
+		return BRASERO_BURN_CANCEL;
+	}
+
+	priv->cancel_plugin = NULL;
+	g_object_unref (cancel);
+
+	if (!res)
+		return BRASERO_BURN_ERR;
+
+	return BRASERO_BURN_RETRY;
+}
+
+static BraseroBurnResult
+brasero_burn_dialog_list_missing (BraseroPluginErrorType type,
+                                  const gchar *detail,
+                                  gpointer user_data)
+{
+	GString *string = user_data;
+
+	if (type == BRASERO_PLUGIN_ERROR_MISSING_APP) {
+		g_string_append_c (string, '\n');
+		/* Translators: %s is the name of a missing application */
+		g_string_append_printf (string, _("%s (application)"), detail);
+	}
+	else if (type == BRASERO_PLUGIN_ERROR_MISSING_LIBRARY) {
+		g_string_append_c (string, '\n');
+		/* Translators: %s is the name of a missing library */
+		g_string_append_printf (string, _("%s (library)"), detail);
+	}
+	else if (type == BRASERO_PLUGIN_ERROR_MISSING_GSTREAMER_PLUGIN) {
+		g_string_append_c (string, '\n');
+		/* Translators: %s is the name of a missing Gstreamer plugin */
+		g_string_append_printf (string, _("%s (Gstreamer plugin)"), detail);
+	}
+
+	return BRASERO_BURN_OK;
+}
+
+static gboolean
+brasero_burn_dialog_check_plugin_errors (BraseroBurnDialog *dialog)
+{
+	BraseroBurnDialogPrivate *priv;
+	BraseroBurnResult result;
+	GString *string;
+
+	priv = BRASERO_BURN_DIALOG_PRIVATE (dialog);
+	gtk_widget_set_sensitive (GTK_WIDGET (dialog), FALSE);
+
+	result = brasero_session_foreach_plugin_error (priv->session,
+	                                               brasero_burn_dialog_install_missing,
+	                                               dialog);
+	if (result == BRASERO_BURN_CANCEL)
+		return FALSE;
+
+	gtk_widget_set_sensitive (GTK_WIDGET (dialog), TRUE);
+
+	if (result == BRASERO_BURN_OK)
+		return TRUE;
+
+	string = g_string_new (_("Please install the following manually and try again:"));
+	brasero_session_foreach_plugin_error (priv->session,
+	                                      brasero_burn_dialog_list_missing,
+	                                      string);
+
+	brasero_utils_message_dialog (GTK_WIDGET (dialog),
+	                              _("All required applications and libraries are not installed."),
+	                              string->str,
+	                              GTK_MESSAGE_ERROR);
+	g_string_free (string, TRUE);
+
+	return FALSE;
+}
+
 /**
  * brasero_burn_dialog_run:
  * @dialog: a #BraseroBurnDialog
@@ -2179,6 +2297,10 @@ brasero_burn_dialog_run (BraseroBurnDialog *dialog,
 	if (!brasero_burn_dialog_wait_for_ready_state (dialog))
 		return FALSE;
 
+	/* Make sure all plugins are ready */
+	if (!brasero_burn_dialog_check_plugin_errors (dialog))
+		return FALSE;
+
 	/* disable autoconfiguration */
 	if (BRASERO_IS_SESSION_CFG (priv->session))
 		brasero_session_cfg_disable (BRASERO_SESSION_CFG (priv->session));
@@ -2428,6 +2550,11 @@ brasero_burn_dialog_finalize (GObject * object)
 
 	priv = BRASERO_BURN_DIALOG_PRIVATE (object);
 
+	if (priv->cancel_plugin) {
+		g_cancellable_cancel (priv->cancel_plugin);
+		priv->cancel_plugin = NULL;
+	}
+
 	if (priv->initial_title) {
 		g_free (priv->initial_title);
 		priv->initial_title = NULL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]