[gnome-software] trivial: Use an in-app notification rather than a mondal dialog for file-to-app



commit 479d2d90c94db75477a2b9156b379fa292978d27
Author: Richard Hughes <richard hughsie com>
Date:   Sun Sep 25 09:25:05 2016 +0100

    trivial: Use an in-app notification rather than a mondal dialog for file-to-app

 src/gs-shell-details.c |   40 +++-------------------------------------
 src/gs-shell.c         |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 37 deletions(-)
---
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 8ae27be..d9fc3ed 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -1419,18 +1419,6 @@ gs_shell_details_app_refine_cb (GObject *source,
 }
 
 static void
-gs_shell_details_failed_response_cb (GtkDialog *dialog,
-                                    gint response,
-                                    GsShellDetails *self)
-{
-       /* unmap the dialog */
-       gtk_widget_destroy (GTK_WIDGET (dialog));
-
-       /* switch away from the details view that failed to load */
-       gs_shell_set_mode (self->shell, GS_SHELL_MODE_OVERVIEW);
-}
-
-static void
 gs_shell_details_file_to_app_cb (GObject *source,
                                 GAsyncResult *res,
                                 gpointer user_data)
@@ -1445,38 +1433,16 @@ gs_shell_details_file_to_app_cb (GObject *source,
                g_signal_handlers_disconnect_by_func (self->app, gs_shell_details_notify_state_changed_cb, 
self);
                g_signal_handlers_disconnect_by_func (self->app, gs_shell_details_progress_changed_cb, self);
        }
+
        /* save app */
        g_set_object (&self->app,
                      gs_plugin_loader_file_to_app_finish (plugin_loader,
                                                           res,
                                                           &error));
        if (self->app == NULL) {
-               GtkWidget *dialog;
-               const gchar *msg;
-
-               if (g_error_matches (error,
-                                    GS_PLUGIN_ERROR,
-                                    GS_PLUGIN_ERROR_NOT_SUPPORTED)) {
-                       /* TRANSLATORS: the file format was not recognised by
-                        * any plugin, e.g. if you try installing a .tar.gz */
-                       msg = _("The file is not supported.");
-               } else {
-                       msg = error->message;
-               }
-
-               dialog = gtk_message_dialog_new (gs_shell_get_window (self->shell),
-                                                GTK_DIALOG_MODAL |
-                                                GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                GTK_MESSAGE_ERROR,
-                                                GTK_BUTTONS_CLOSE,
-                                                _("Sorry, this did not work"));
-               gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                         "%s", msg);
-               g_signal_connect (dialog, "response",
-                                 G_CALLBACK (gs_shell_details_failed_response_cb), self);
-               gs_shell_modal_dialog_present (self->shell, GTK_DIALOG (dialog));
-
                g_warning ("failed to convert to GsApp: %s", error->message);
+               /* switch away from the details view that failed to load */
+               gs_shell_set_mode (self->shell, GS_SHELL_MODE_OVERVIEW);
                return;
        }
 
diff --git a/src/gs-shell.c b/src/gs-shell.c
index ad83869..8cf2927 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -1232,6 +1232,37 @@ gs_shell_show_event_launch (GsShell *shell, GsPluginEvent *event)
 }
 
 static gboolean
+gs_shell_show_event_file_to_app (GsShell *shell, GsPluginEvent *event)
+{
+       GsShellEventButtons buttons = GS_SHELL_EVENT_BUTTON_NONE;
+       GsShellPrivate *priv = gs_shell_get_instance_private (shell);
+       const GError *error = gs_plugin_event_get_error (event);
+       g_autoptr(GString) str = g_string_new (NULL);
+
+       switch (error->code) {
+       case GS_PLUGIN_ERROR_NO_SECURITY:
+               /* TRANSLATORS: failure text for the in-app notification */
+               g_string_append (str, _("Failed to install file: "
+                                       "authentication failed"));
+               break;
+       case GS_PLUGIN_ERROR_NO_SPACE:
+               /* TRANSLATORS: failure text for the in-app notification */
+               g_string_append (str, _("Not enough disk space — free up some space "
+                                       "and try again"));
+               buttons |= GS_SHELL_EVENT_BUTTON_NO_SPACE;
+               break;
+       default:
+               break;
+       }
+       if (str->len == 0)
+               return FALSE;
+
+       /* show in-app notification */
+       gs_shell_show_event_app_notify (shell, str->str, buttons);
+       return TRUE;
+}
+
+static gboolean
 gs_shell_show_event_fallback (GsShell *shell, GsPluginEvent *event)
 {
        GsApp *origin = gs_plugin_event_get_origin (event);
@@ -1303,6 +1334,8 @@ gs_shell_show_event (GsShell *shell, GsPluginEvent *event)
                return gs_shell_show_event_remove (shell, event);
        case GS_PLUGIN_ACTION_LAUNCH:
                return gs_shell_show_event_launch (shell, event);
+       case GS_PLUGIN_ACTION_FILE_TO_APP:
+               return gs_shell_show_event_file_to_app (shell, event);
        default:
                break;
        }


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