[gnome-software/wip/ubuntu-3-26: 13/14] details: Show an in-app notification when passed an invalid file or URL



commit 59ac8634e98bdad70ebea3f4137d4f5da5bfb73b
Author: Iain Lane <iain orangesquash org uk>
Date:   Tue Apr 4 13:25:33 2017 +0100

    details: Show an in-app notification when passed an invalid file or URL
    
    Previously there was no feedback when gnome-software was fed a bad URL
    on the commandline - show a message.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788424

 src/gs-details-page.c |   46 +++++++++++++++++++++++++++++++++++++++++-----
 src/gs-shell.c        |   12 +-----------
 src/gs-shell.h        |   13 +++++++++++++
 3 files changed, 55 insertions(+), 16 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 7124fc2..eee5e19 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1588,23 +1588,47 @@ set_app (GsDetailsPage *self, GsApp *app)
        gs_details_page_app_refine2 (self);
 }
 
+typedef struct {
+       GsDetailsPage *page;
+       gchar *url;
+} GsDetailsFileHelper;
+
+static void
+gs_details_page_file_helper_free (GsDetailsFileHelper *helper)
+{
+       g_object_unref (helper->page);
+       g_free (helper->url);
+       g_free (helper);
+}
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GsDetailsFileHelper, gs_details_page_file_helper_free);
+
 static void
 gs_details_page_file_to_app_cb (GObject *source,
                                 GAsyncResult *res,
                                 gpointer user_data)
 {
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
-       GsDetailsPage *self = GS_DETAILS_PAGE (user_data);
+       g_autoptr(GsDetailsFileHelper) helper = user_data;
+       GsDetailsPage *self = helper->page;
        g_autoptr(GsAppList) list = NULL;
        g_autoptr(GError) error = NULL;
+       g_autofree gchar *msg = NULL;
 
        list = gs_plugin_loader_job_process_finish (plugin_loader,
                                                    res,
                                                    &error);
        if (list == NULL) {
+               /* TRANSLATORS: This message is shown when opening
+                * gnome-software with a path to an unhandled app, e.g.
+                * /no/such/file */
+               msg = g_strdup_printf (_("Don't know how to handle ā€˜%sā€™"), helper->url);
                g_warning ("failed to convert file to GsApp: %s", error->message);
                /* go back to the overview */
                gs_shell_change_mode (self->shell, GS_SHELL_MODE_OVERVIEW, NULL, FALSE);
+               gs_shell_show_event_app_notify (self->shell,
+                                               msg,
+                                               GS_SHELL_EVENT_BUTTON_NONE);
        } else {
                GsApp *app = gs_app_list_index (list, 0);
                set_app (self, app);
@@ -1617,17 +1641,23 @@ gs_details_page_url_to_app_cb (GObject *source,
                                gpointer user_data)
 {
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
-       GsDetailsPage *self = GS_DETAILS_PAGE (user_data);
+       g_autoptr(GsDetailsFileHelper) helper = user_data;
+       GsDetailsPage *self = helper->page;
        g_autoptr(GsAppList) list = NULL;
        g_autoptr(GError) error = NULL;
+       g_autofree gchar *msg = NULL;
 
        list = gs_plugin_loader_job_process_finish (plugin_loader,
                                                    res,
                                                    &error);
        if (list == NULL) {
+               msg = g_strdup_printf (_("Don't know how to handle ā€˜%sā€™"), helper->url);
                g_warning ("failed to convert URL to GsApp: %s", error->message);
                /* go back to the overview */
                gs_shell_change_mode (self->shell, GS_SHELL_MODE_OVERVIEW, NULL, FALSE);
+               gs_shell_show_event_app_notify (self->shell,
+                                               msg,
+                                               GS_SHELL_EVENT_BUTTON_NONE);
        } else {
                GsApp *app = gs_app_list_index (list, 0);
                set_app (self, app);
@@ -1638,6 +1668,9 @@ void
 gs_details_page_set_local_file (GsDetailsPage *self, GFile *file)
 {
        g_autoptr(GsPluginJob) plugin_job = NULL;
+       GsDetailsFileHelper *helper = g_new0 (GsDetailsFileHelper, 1);
+       helper->page = g_object_ref (self);
+       helper->url = g_file_get_uri (file);
        gs_details_page_set_state (self, GS_DETAILS_PAGE_STATE_LOADING);
        plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_FILE_TO_APP,
                                         "file", file,
@@ -1660,13 +1693,16 @@ gs_details_page_set_local_file (GsDetailsPage *self, GFile *file)
        gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,
                                            self->cancellable,
                                            gs_details_page_file_to_app_cb,
-                                           self);
+                                           helper);
 }
 
 void
 gs_details_page_set_url (GsDetailsPage *self, const gchar *url)
 {
        g_autoptr(GsPluginJob) plugin_job = NULL;
+       GsDetailsFileHelper *helper = g_new0 (GsDetailsFileHelper, 1);
+       helper->page = g_object_ref (self);
+       helper->url = g_strdup (url);
        gs_details_page_set_state (self, GS_DETAILS_PAGE_STATE_LOADING);
        plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_URL_TO_APP,
                                         "search", url,
@@ -1685,11 +1721,11 @@ gs_details_page_set_url (GsDetailsPage *self, const gchar *url)
                                                         GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME |
                                                         GS_PLUGIN_REFINE_FLAGS_REQUIRE_PERMISSIONS |
                                                         GS_PLUGIN_REFINE_FLAGS_REQUIRE_SCREENSHOTS,
-                                        NULL);
+                                        helper);
        gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,
                                            self->cancellable,
                                            gs_details_page_url_to_app_cb,
-                                           self);
+                                           helper);
 }
 
 static void
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 7a68492..22544ac 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -743,17 +743,7 @@ gs_shell_allow_updates_notify_cb (GsPluginLoader *plugin_loader,
                                        priv->mode == GS_SHELL_MODE_UPDATES);
 }
 
-typedef enum {
-       GS_SHELL_EVENT_BUTTON_NONE              = 0,
-       GS_SHELL_EVENT_BUTTON_SOURCES           = 1 << 0,
-       GS_SHELL_EVENT_BUTTON_NO_SPACE          = 1 << 1,
-       GS_SHELL_EVENT_BUTTON_NETWORK_SETTINGS  = 1 << 2,
-       GS_SHELL_EVENT_BUTTON_MORE_INFO         = 1 << 3,
-       GS_SHELL_EVENT_BUTTON_RESTART_REQUIRED  = 1 << 4,
-       GS_SHELL_EVENT_BUTTON_LAST
-} GsShellEventButtons;
-
-static void
+void
 gs_shell_show_event_app_notify (GsShell *shell,
                                const gchar *title,
                                GsShellEventButtons buttons)
diff --git a/src/gs-shell.h b/src/gs-shell.h
index b3ba20e..267e530 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -40,6 +40,16 @@ struct _GsShellClass
 };
 
 typedef enum {
+       GS_SHELL_EVENT_BUTTON_NONE              = 0,
+       GS_SHELL_EVENT_BUTTON_SOURCES           = 1 << 0,
+       GS_SHELL_EVENT_BUTTON_NO_SPACE          = 1 << 1,
+       GS_SHELL_EVENT_BUTTON_NETWORK_SETTINGS  = 1 << 2,
+       GS_SHELL_EVENT_BUTTON_MORE_INFO         = 1 << 3,
+       GS_SHELL_EVENT_BUTTON_RESTART_REQUIRED  = 1 << 4,
+       GS_SHELL_EVENT_BUTTON_LAST
+} GsShellEventButtons;
+
+typedef enum {
        GS_SHELL_MODE_UNKNOWN,
        GS_SHELL_MODE_OVERVIEW,
        GS_SHELL_MODE_INSTALLED,
@@ -98,6 +108,9 @@ void          gs_shell_show_extras_search    (GsShell        *shell,
                                                 gchar          **resources);
 void            gs_shell_show_uri              (GsShell        *shell,
                                                 const gchar    *url);
+void           gs_shell_show_event_app_notify  (GsShell                *shell,
+                                                const gchar            *title,
+                                                GsShellEventButtons    buttons);
 void            gs_shell_setup                 (GsShell        *shell,
                                                 GsPluginLoader *plugin_loader,
                                                 GCancellable   *cancellable);


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