[gnome-software/1612-revisit-error-display] gs-shell: Extract setting of GsShell::events_info_uri into a function



commit 6454e46d951684f499c851cd27d585353efa1d79
Author: Milan Crha <mcrha redhat com>
Date:   Tue Aug 23 13:29:50 2022 +0200

    gs-shell: Extract setting of GsShell::events_info_uri into a function
    
    It avoids code duplication around that variable and will be used
    in the following change to set also detailed error text.

 src/gs-shell.c | 97 ++++++++++++++++++++--------------------------------------
 1 file changed, 34 insertions(+), 63 deletions(-)
---
diff --git a/src/gs-shell.c b/src/gs-shell.c
index e4dcceccb..cd74178fb 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -1250,6 +1250,26 @@ gs_shell_append_detailed_error (GsShell *shell, GString *str, const GError *erro
        }
 }
 
+static gboolean
+gs_shell_handle_events_more_info (GsShell *self,
+                                 GsApp *origin)
+{
+       const gchar *uri;
+
+       g_clear_pointer (&self->events_info_uri, g_free);
+
+       if (origin == NULL)
+               return FALSE;
+
+       uri = gs_app_get_url (origin, AS_URL_KIND_HELP);
+       if (uri != NULL) {
+               self->events_info_uri = g_strdup (uri);
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
 static gboolean
 gs_shell_show_event_refresh (GsShell *shell, GsPluginEvent *event)
 {
@@ -1334,15 +1354,8 @@ gs_shell_show_event_refresh (GsShell *shell, GsPluginEvent *event)
        if (str->len == 0)
                return FALSE;
 
-       /* add more-info button */
-       if (origin != NULL) {
-               const gchar *uri = gs_app_get_url (origin, AS_URL_KIND_HELP);
-               if (uri != NULL) {
-                       g_free (shell->events_info_uri);
-                       shell->events_info_uri = g_strdup (uri);
-                       buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
-               }
-       }
+       if (gs_shell_handle_events_more_info (shell, origin))
+               buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
 
        /* show in-app notification */
        gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1454,15 +1467,8 @@ gs_shell_show_event_install (GsShell *shell, GsPluginEvent *event)
        if (str->len == 0)
                return FALSE;
 
-       /* add more-info button */
-       if (origin != NULL) {
-               const gchar *uri = gs_app_get_url (origin, AS_URL_KIND_HELP);
-               if (uri != NULL) {
-                       g_free (shell->events_info_uri);
-                       shell->events_info_uri = g_strdup (uri);
-                       buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
-               }
-       }
+       if (gs_shell_handle_events_more_info (shell, origin))
+               buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
 
        /* show in-app notification */
        gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1621,15 +1627,8 @@ gs_shell_show_event_update (GsShell *shell, GsPluginEvent *event)
        if (str->len == 0)
                return FALSE;
 
-       /* add more-info button */
-       if (origin != NULL) {
-               const gchar *uri = gs_app_get_url (origin, AS_URL_KIND_HELP);
-               if (uri != NULL) {
-                       g_free (shell->events_info_uri);
-                       shell->events_info_uri = g_strdup (uri);
-                       buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
-               }
-       }
+       if (gs_shell_handle_events_more_info (shell, origin))
+               buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
 
        /* show in-app notification */
        gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1723,15 +1722,8 @@ gs_shell_show_event_upgrade (GsShell *shell, GsPluginEvent *event)
        if (str->len == 0)
                return FALSE;
 
-       /* add more-info button */
-       if (origin != NULL) {
-               const gchar *uri = gs_app_get_url (origin, AS_URL_KIND_HELP);
-               if (uri != NULL) {
-                       g_free (shell->events_info_uri);
-                       shell->events_info_uri = g_strdup (uri);
-                       buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
-               }
-       }
+       if (gs_shell_handle_events_more_info (shell, origin))
+               buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
 
        /* show in-app notification */
        gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1794,15 +1786,8 @@ gs_shell_show_event_remove (GsShell *shell, GsPluginEvent *event)
        if (str->len == 0)
                return FALSE;
 
-       /* add more-info button */
-       if (origin != NULL) {
-               const gchar *uri = gs_app_get_url (origin, AS_URL_KIND_HELP);
-               if (uri != NULL) {
-                       g_free (shell->events_info_uri);
-                       shell->events_info_uri = g_strdup (uri);
-                       buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
-               }
-       }
+       if (gs_shell_handle_events_more_info (shell, origin))
+               buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
 
        /* show in-app notification */
        gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1852,15 +1837,8 @@ gs_shell_show_event_launch (GsShell *shell, GsPluginEvent *event)
        if (str->len == 0)
                return FALSE;
 
-       /* add more-info button */
-       if (origin != NULL) {
-               const gchar *uri = gs_app_get_url (origin, AS_URL_KIND_HELP);
-               if (uri != NULL) {
-                       g_free (shell->events_info_uri);
-                       shell->events_info_uri = g_strdup (uri);
-                       buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
-               }
-       }
+       if (gs_shell_handle_events_more_info (shell, origin))
+               buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
 
        /* show in-app notification */
        gs_shell_show_event_app_notify (shell, str->str, buttons);
@@ -1991,15 +1969,8 @@ gs_shell_show_event_fallback (GsShell *shell, GsPluginEvent *event)
        if (str->len == 0)
                return FALSE;
 
-       /* add more-info button */
-       if (origin != NULL) {
-               const gchar *uri = gs_app_get_url (origin, AS_URL_KIND_HELP);
-               if (uri != NULL) {
-                       g_free (shell->events_info_uri);
-                       shell->events_info_uri = g_strdup (uri);
-                       buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
-               }
-       }
+       if (gs_shell_handle_events_more_info (shell, origin))
+               buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
 
        /* show in-app notification */
        gs_shell_show_event_app_notify (shell, str->str, buttons);


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