[gnome-software/27-codec-install-oddities-in-unable-to-find-message] gs-extras-page: Include application name in codec "not found" string



commit 823c6020943c787596be77b753e82db1cbb05d4d
Author: Milan Crha <mcrha redhat com>
Date:   Tue Sep 8 16:56:29 2020 +0200

    gs-extras-page: Include application name in codec "not found" string
    
    Change the 'Unable to find...' coded string to include the application
    name, which requested it. Also reword the string.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/27
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/merge_requests/504

 src/gs-application.c |  7 ++++---
 src/gs-dbus-helper.c |  4 ++--
 src/gs-extras-page.c | 47 ++++++++++++++++++++++++++++++++++++++++++-----
 src/gs-extras-page.h |  3 ++-
 src/gs-shell.c       |  4 ++--
 src/gs-shell.h       |  3 ++-
 6 files changed, 54 insertions(+), 14 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 9c2676ef..06f811a0 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -798,9 +798,10 @@ install_resources_activated (GSimpleAction *action,
        GdkDisplay *display;
        const gchar *mode;
        const gchar *startup_id;
+       const gchar *desktop_id;
        g_autofree gchar **resources = NULL;
 
-       g_variant_get (parameter, "(&s^a&s&s)", &mode, &resources, &startup_id);
+       g_variant_get (parameter, "(&s^a&s&s&s)", &mode, &resources, &startup_id, &desktop_id);
 
        display = gdk_display_get_default ();
 #ifdef GDK_WINDOWING_X11
@@ -821,7 +822,7 @@ install_resources_activated (GSimpleAction *action,
        gs_application_present_window (app, startup_id);
 
        gs_shell_reset_state (app->shell);
-       gs_shell_show_extras_search (app->shell, mode, resources);
+       gs_shell_show_extras_search (app->shell, mode, resources, desktop_id);
 }
 
 static GActionEntry actions[] = {
@@ -846,7 +847,7 @@ static GActionEntry actions_after_loading[] = {
        { "details-url", details_url_activated, "(s)", NULL, NULL },
        { "install", install_activated, "(su)", NULL, NULL },
        { "filename", filename_activated, "(s)", NULL, NULL },
-       { "install-resources", install_resources_activated, "(sass)", NULL, NULL },
+       { "install-resources", install_resources_activated, "(sasss)", NULL, NULL },
        { "nop", NULL, NULL, NULL }
 };
 
diff --git a/src/gs-dbus-helper.c b/src/gs-dbus-helper.c
index b90ff980..85325a49 100644
--- a/src/gs-dbus-helper.c
+++ b/src/gs-dbus-helper.c
@@ -321,7 +321,7 @@ notify_search_resources (GsExtrasPageMode   mode,
        g_notification_set_body (n, body);
        /* TRANSLATORS: this is a button that launches gnome-software */
        g_notification_add_button_with_target (n, _("Find in Software"), "app.install-resources", "(s^ass)", 
mode_string, resources, "");
-       g_notification_set_default_action_and_target (n, "app.install-resources", "(s^ass)", mode_string, 
resources, "");
+       g_notification_set_default_action_and_target (n, "app.install-resources", "(s^asss)", mode_string, 
resources, "", desktop_id);
        g_application_send_notification (g_application_get_default (), "install-resources", n);
 }
 
@@ -349,7 +349,7 @@ install_resources (GsExtrasPageMode   mode,
        app = g_application_get_default ();
        mode_string = gs_extras_page_mode_to_string (mode);
        g_action_group_activate_action (G_ACTION_GROUP (app), "install-resources",
-                                       g_variant_new ("(s^ass)", mode_string, resources, startup_id));
+                                       g_variant_new ("(s^asss)", mode_string, resources, startup_id, 
desktop_id));
 }
 
 static gboolean
diff --git a/src/gs-extras-page.c b/src/gs-extras-page.c
index 9b9aeece..21a50421 100644
--- a/src/gs-extras-page.c
+++ b/src/gs-extras-page.c
@@ -54,6 +54,7 @@ struct _GsExtrasPage
        GsLanguage               *language;
        GsVendor                 *vendor;
        guint                     pending_search_cnt;
+       gchar                    *caller_app_name;
 
        GtkWidget                *label_failed;
        GtkWidget                *label_no_results;
@@ -452,12 +453,23 @@ build_no_results_label (GsExtrasPage *self)
        url = g_strdup_printf ("<a href=\"%s\">%s</a>",
                               gs_app_get_url (app, AS_URL_KIND_MISSING),
                                /* TRANSLATORS: hyperlink title */
-                               _("this website"));
+                               _("the documentation"));
 
        codec_titles = build_comma_separated_list ((gchar **) array->pdata);
-       /* TRANSLATORS: no codecs were found. First %s will be replaced by actual codec name(s), second %s is 
a link titled "this website" */
-       return g_strdup_printf (ngettext ("Unfortunately, the %s you were searching for could not be found. 
Please see %s for more information.",
-                                         "Unfortunately, the %s you were searching for could not be found. 
Please see %s for more information.",
+       if (self->caller_app_name) {
+               /* TRANSLATORS: no codecs were found. The first %s will be replaced by actual codec name(s),
+                  the second %s is the application name, which requested the codecs, the third %s is a link 
titled "the documentation" */
+               return g_strdup_printf (ngettext ("Unable to find the %s requested by %s. Please see %s for 
more information.",
+                                                 "Unable to find the %s requested by %s. Please see %s for 
more information.",
+                                                 num),
+                                       codec_titles,
+                                       self->caller_app_name,
+                                       url);
+       }
+
+       /* TRANSLATORS: no codecs were found. First %s will be replaced by actual codec name(s), second %s is 
a link titled "the documentation" */
+       return g_strdup_printf (ngettext ("Unable to find the %s you were searching for. Please see %s for 
more information.",
+                                         "Unable to find the %s you were searching for. Please see %s for 
more information.",
                                          num),
                                codec_titles,
                                url);
@@ -974,12 +986,36 @@ gs_extras_page_search_printer_drivers (GsExtrasPage *self, gchar **device_ids)
        gs_extras_page_load (self, array_search_data);
 }
 
+static gchar *
+gs_extras_page_get_app_name (const gchar *desktop_id)
+{
+       GDesktopAppInfo *app_info;
+       gchar *app_name;
+
+       if (!desktop_id || !*desktop_id)
+               return NULL;
+
+       app_info = g_desktop_app_info_new (desktop_id);
+       if (!app_info)
+               return NULL;
+
+       app_name = g_strdup (g_app_info_get_display_name (G_APP_INFO (app_info)));
+
+       g_object_unref (app_info);
+
+       return app_name;
+}
+
 void
 gs_extras_page_search (GsExtrasPage  *self,
                        const gchar   *mode_str,
-                       gchar        **resources)
+                       gchar        **resources,
+                      const gchar   *desktop_id)
 {
        self->mode = gs_extras_page_mode_from_string (mode_str);
+       g_clear_pointer (&self->caller_app_name, g_free);
+       self->caller_app_name = gs_extras_page_get_app_name (desktop_id);
+
        switch (self->mode) {
        case GS_EXTRAS_PAGE_MODE_INSTALL_PACKAGE_FILES:
                gs_extras_page_search_package_files (self, resources);
@@ -1164,6 +1200,7 @@ gs_extras_page_dispose (GObject *object)
        g_clear_object (&self->plugin_loader);
 
        g_clear_pointer (&self->array_search_data, g_ptr_array_unref);
+       g_clear_pointer (&self->caller_app_name, g_free);
 
        G_OBJECT_CLASS (gs_extras_page_parent_class)->dispose (object);
 }
diff --git a/src/gs-extras-page.h b/src/gs-extras-page.h
index e4dc0010..ad248b50 100644
--- a/src/gs-extras-page.h
+++ b/src/gs-extras-page.h
@@ -34,6 +34,7 @@ const gchar           *gs_extras_page_mode_to_string          (GsExtrasPageMode         
mode);
 GsExtrasPage           *gs_extras_page_new                     (void);
 void                    gs_extras_page_search                  (GsExtrasPage            *self,
                                                                 const gchar             *mode,
-                                                                gchar                  **resources);
+                                                                gchar                  **resources,
+                                                                const gchar             *desktop_id);
 
 G_END_DECLS
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 8f0dc6f1..4c39a909 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -2401,7 +2401,7 @@ gs_shell_show_category (GsShell *shell, GsCategory *category)
        gs_shell_change_mode (shell, GS_SHELL_MODE_CATEGORY, category, TRUE);
 }
 
-void gs_shell_show_extras_search (GsShell *shell, const gchar *mode, gchar **resources)
+void gs_shell_show_extras_search (GsShell *shell, const gchar *mode, gchar **resources, const gchar 
*desktop_id)
 {
        GsShellPrivate *priv = gs_shell_get_instance_private (shell);
        GsPage *page;
@@ -2409,7 +2409,7 @@ void gs_shell_show_extras_search (GsShell *shell, const gchar *mode, gchar **res
        page = GS_PAGE (gtk_builder_get_object (priv->builder, "extras_page"));
 
        save_back_entry (shell);
-       gs_extras_page_search (GS_EXTRAS_PAGE (page), mode, resources);
+       gs_extras_page_search (GS_EXTRAS_PAGE (page), mode, resources, desktop_id);
        gs_shell_change_mode (shell, GS_SHELL_MODE_EXTRAS, NULL, TRUE);
        gs_shell_activate (shell);
 }
diff --git a/src/gs-shell.h b/src/gs-shell.h
index a02d24d7..7259b722 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -81,7 +81,8 @@ void           gs_shell_show_search_result    (GsShell        *shell,
                                                 const gchar    *search);
 void            gs_shell_show_extras_search    (GsShell        *shell,
                                                 const gchar    *mode,
-                                                gchar          **resources);
+                                                gchar          **resources,
+                                                const gchar    *desktop_id);
 void            gs_shell_show_uri              (GsShell        *shell,
                                                 const gchar    *url);
 void            gs_shell_setup                 (GsShell        *shell,


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