[gnome-software/wip/ubuntu-master: 232/232] details: Show an in-app notification when passed an invalid file or URL



commit 81d6d69bc720a4879c95f21e7e2e6bf51a7b1e3e
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.

 src/gs-details-page.c |   50 +++++++++++++++++++++++++++++++++++++++++++-----
 src/gs-shell.c        |   12 +----------
 src/gs-shell.h        |   13 ++++++++++++
 3 files changed, 58 insertions(+), 17 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index e5c98b7..a81227e 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1500,21 +1500,46 @@ 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(GsApp) app = NULL;
        g_autoptr(GError) error = NULL;
+       g_autofree gchar *msg = NULL;
 
        app = gs_plugin_loader_file_to_app_finish (plugin_loader,
                                                   res,
                                                   &error);
-       if (app == NULL)
+       if (app == 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);
+               gs_shell_show_event_app_notify (self->shell,
+                                               msg,
+                                               GS_SHELL_EVENT_BUTTON_NONE);
+       }
        set_app (self, app);
 }
 
@@ -1524,21 +1549,31 @@ 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(GsApp) app = NULL;
        g_autoptr(GError) error = NULL;
+       g_autofree gchar *msg = NULL;
 
        app = gs_plugin_loader_url_to_app_finish (plugin_loader,
                                                  res,
                                                  &error);
-       if (app == NULL)
+       if (app == 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);
+               gs_shell_show_event_app_notify (self->shell,
+                                               msg,
+                                               GS_SHELL_EVENT_BUTTON_NONE);
+       }
        set_app (self, app);
 }
 
 void
 gs_details_page_set_local_file (GsDetailsPage *self, GFile *file)
 {
+       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);
        gs_plugin_loader_file_to_app_async (self->plugin_loader,
                                            file,
@@ -1558,12 +1593,15 @@ gs_details_page_set_local_file (GsDetailsPage *self, GFile *file)
                                            GS_PLUGIN_FAILURE_FLAGS_USE_EVENTS,
                                            self->cancellable,
                                            gs_details_page_file_to_app_cb,
-                                           self);
+                                           helper);
 }
 
 void
 gs_details_page_set_url (GsDetailsPage *self, const gchar *url)
 {
+       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);
        gs_plugin_loader_url_to_app_async (self->plugin_loader,
                                           url,
@@ -1583,7 +1621,7 @@ gs_details_page_set_url (GsDetailsPage *self, const gchar *url)
                                           GS_PLUGIN_FAILURE_FLAGS_USE_EVENTS,
                                           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 a45e5a8..5e85f54 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]