[gnome-software] Show a modal error message if install or remove actions failed
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Show a modal error message if install or remove actions failed
- Date: Thu, 17 Oct 2013 12:23:13 +0000 (UTC)
commit d3e9c9ff48b1b1f2189e7805b50ed4a8c8dddd21
Author: Richard Hughes <richard hughsie com>
Date: Thu Oct 17 13:22:53 2013 +0100
Show a modal error message if install or remove actions failed
Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=709738
src/gs-shell-details.c | 10 ++++++++
src/gs-shell-installed.c | 4 +++
src/gs-shell-search.c | 18 ++++++++++++++-
src/gs-utils.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++
src/gs-utils.h | 5 ++++
5 files changed, 89 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index b76d2a0..e856c9b 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -600,9 +600,14 @@ gs_shell_details_app_installed_cb (GObject *source,
g_warning ("failed to install %s: %s",
gs_app_get_id (helper->app),
error->message);
+ gs_app_notify_failed_modal (helper->shell_details->priv->builder,
+ helper->app,
+ GS_PLUGIN_LOADER_ACTION_INSTALL,
+ error);
g_error_free (error);
return;
}
+
gs_app_notify_installed (helper->app);
g_object_unref (helper->shell_details);
g_object_unref (helper->app);
@@ -629,9 +634,14 @@ gs_shell_details_app_removed_cb (GObject *source,
g_warning ("failed to remove %s: %s",
gs_app_get_id (helper->app),
error->message);
+ gs_app_notify_failed_modal (helper->shell_details->priv->builder,
+ helper->app,
+ GS_PLUGIN_LOADER_ACTION_REMOVE,
+ error);
g_error_free (error);
return;
}
+
gs_shell_details_refresh (helper->shell_details);
g_object_unref (helper->shell_details);
g_object_unref (helper->app);
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index aced745..fe2f784 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -130,6 +130,10 @@ gs_shell_installed_app_removed_cb (GObject *source,
g_warning ("failed to remove %s: %s",
gs_app_get_id (app),
error->message);
+ gs_app_notify_failed_modal (priv->builder,
+ app,
+ GS_PLUGIN_LOADER_ACTION_REMOVE,
+ error);
g_error_free (error);
} else {
/* remove from the list */
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index 2405959..f37a9f2 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -84,6 +84,10 @@ gs_shell_search_app_installed_cb (GObject *source,
g_warning ("failed to install %s: %s",
gs_app_get_id (helper->app),
error->message);
+ gs_app_notify_failed_modal (helper->shell_search->priv->builder,
+ helper->app,
+ GS_PLUGIN_LOADER_ACTION_INSTALL,
+ error);
g_error_free (error);
} else {
gs_app_notify_installed (helper->app);
@@ -103,6 +107,7 @@ gs_shell_search_app_removed_cb (GObject *source,
{
GError *error = NULL;
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
+ GsShellSearchHelper *helper = (GsShellSearchHelper *) user_data;
gboolean ret;
ret = gs_plugin_loader_app_action_finish (plugin_loader,
@@ -111,8 +116,15 @@ gs_shell_search_app_removed_cb (GObject *source,
if (!ret) {
g_warning ("failed to remove: %s",
error->message);
+ gs_app_notify_failed_modal (helper->shell_search->priv->builder,
+ helper->app,
+ GS_PLUGIN_LOADER_ACTION_REMOVE,
+ error);
g_error_free (error);
}
+ g_object_unref (helper->app);
+ g_object_unref (helper->shell_search);
+ g_free (helper);
}
/**
@@ -150,13 +162,17 @@ gs_shell_search_app_remove (GsShellSearch *shell_search, GsApp *app)
gtk_dialog_add_button (GTK_DIALOG (dialog), _("Remove"), GTK_RESPONSE_OK);
response = gtk_dialog_run (GTK_DIALOG (dialog));
if (response == GTK_RESPONSE_OK) {
+ GsShellSearchHelper *helper;
g_debug ("remove %s", gs_app_get_id (app));
+ helper = g_new0 (GsShellSearchHelper, 1);
+ helper->app = g_object_ref (app);
+ helper->shell_search = g_object_ref (shell_search);
gs_plugin_loader_app_action_async (priv->plugin_loader,
app,
GS_PLUGIN_LOADER_ACTION_REMOVE,
priv->cancellable,
gs_shell_search_app_removed_cb,
- shell_search);
+ helper);
}
g_string_free (markup, TRUE);
gtk_widget_destroy (dialog);
diff --git a/src/gs-utils.c b/src/gs-utils.c
index d5626ab..194b039 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -176,6 +176,59 @@ gs_app_notify_installed (GsApp *app)
g_free (summary);
}
+/**
+ * gs_app_notify_failed_modal_response_cb:
+ **/
+static void
+gs_app_notify_failed_modal_response_cb (GtkDialog *dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+/**
+ * gs_app_notify_failed_modal:
+ **/
+void
+gs_app_notify_failed_modal (GtkBuilder *builder,
+ GsApp *app,
+ GsPluginLoaderAction action,
+ const GError *error)
+{
+ GtkWidget *dialog;
+ GtkWindow *window;
+ gchar *msg;
+
+ switch (action) {
+ case GS_PLUGIN_LOADER_ACTION_INSTALL:
+ /* TRANSLATORS: this is when the install fails */
+ msg = g_strdup_printf (_("%s failed to be installed"),
+ gs_app_get_name (app));
+ break;
+ case GS_PLUGIN_LOADER_ACTION_REMOVE:
+ /* TRANSLATORS: this is when the remove fails */
+ msg = g_strdup_printf (_("%s failed to be removed"),
+ gs_app_get_name (app));
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ window = GTK_WINDOW (gtk_builder_get_object (builder, "window_software"));
+ dialog = gtk_message_dialog_new (window,
+ GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s", msg);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", error->message);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gs_app_notify_failed_modal_response_cb), NULL);
+ gtk_window_present (GTK_WINDOW (dialog));
+}
+
guint
gs_string_replace (GString *string, const gchar *search, const gchar *replace)
{
diff --git a/src/gs-utils.h b/src/gs-utils.h
index ea78d59..39e68ff 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include "gs-app.h"
+#include "gs-plugin-loader.h"
G_BEGIN_DECLS
@@ -34,6 +35,10 @@ void gs_container_remove_all (GtkContainer *container);
void gs_grab_focus_when_mapped (GtkWidget *widget);
void gs_app_notify_installed (GsApp *app);
+void gs_app_notify_failed_modal (GtkBuilder *builder,
+ GsApp *app,
+ GsPluginLoaderAction action,
+ const GError *error);
guint gs_string_replace (GString *string,
const gchar *search,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]