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



commit e66665af8ae28f7eceac7b89cc5452fe02efbdda
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 |   44 ++++++++++++++++++++++++++++++++++++++++----
 src/gs-shell.c        |   12 +-----------
 src/gs-shell.h        |   13 +++++++++++++
 3 files changed, 54 insertions(+), 15 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 1c9cfdb..3208883 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1587,23 +1587,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);
@@ -1616,17 +1640,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);
@@ -1637,6 +1667,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,
@@ -1659,13 +1692,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,7 +1721,7 @@ gs_details_page_set_url (GsDetailsPage *self, const gchar *url)
                                                         GS_PLUGIN_REFINE_FLAGS_REQUIRE_PERMISSIONS |
                                                         GS_PLUGIN_REFINE_FLAGS_REQUIRE_SCREENSHOTS |
                                                         GS_PLUGIN_REFINE_FLAGS_ALLOW_PACKAGES,
-                                        NULL);
+                                        helper);
        gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,
                                            self->cancellable,
                                            gs_details_page_url_to_app_cb,
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 4b59f0d..233d025 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -770,17 +770,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]