[gnome-software] Fix showing the source line in the installed panel



commit 3975607876f8d0797cb15ec68dd78bfb10d67a2d
Author: Richard Hughes <richard hughsie com>
Date:   Fri Sep 9 09:24:30 2016 +0100

    Fix showing the source line in the installed panel
    
    Use the same logic in the installed panel to the search panel and show it for
    both items on duplicate name or bus address.

 src/gs-common.c          |   48 ++++++++++++++++++++++++++++++++++++++++++++++
 src/gs-common.h          |    2 +
 src/gs-shell-installed.c |   11 +++++----
 src/gs-shell-search.c    |   40 ++-----------------------------------
 4 files changed, 59 insertions(+), 42 deletions(-)
---
diff --git a/src/gs-common.c b/src/gs-common.c
index 3fbf8d3..04a57d5 100644
--- a/src/gs-common.c
+++ b/src/gs-common.c
@@ -869,4 +869,52 @@ gs_utils_build_unique_id_kind (AsAppKind kind, const gchar *id)
                                         NULL);
 }
 
+/**
+ * gs_utils_list_has_app_fuzzy:
+ * @list: A #GsAppList
+ * @app: A #GsApp
+ *
+ * Finds out if any application in the list would match a given application,
+ * where the match is valid for a matching D-Bus bus name,
+ * the label in the UI or the same icon.
+ *
+ * This function is normally used to work out if the source should be shown
+ * in a GsAppRow.
+ *
+ * Returns: %TRUE if the app is visually the "same"
+ */
+gboolean
+gs_utils_list_has_app_fuzzy (GsAppList *list, GsApp *app)
+{
+       guint i;
+       GsApp *tmp;
+
+       for (i = 0; i < gs_app_list_length (list); i++) {
+               tmp = gs_app_list_index (list, i);
+
+               /* ignore if the same object */
+               if (app == tmp)
+                       continue;
+
+               /* ignore with the same source */
+               if (g_strcmp0 (gs_app_get_origin_hostname (tmp),
+                              gs_app_get_origin_hostname (app)) == 0) {
+                       continue;
+               }
+
+               /* same D-Bus ID */
+               if (g_strcmp0 (gs_app_get_id (tmp),
+                              gs_app_get_id (app)) == 0) {
+                       return TRUE;
+               }
+
+               /* same name */
+               if (g_strcmp0 (gs_app_get_name (tmp),
+                              gs_app_get_name (app)) == 0) {
+                       return TRUE;
+               }
+       }
+       return FALSE;
+}
+
 /* vim: set noexpandtab: */
diff --git a/src/gs-common.h b/src/gs-common.h
index 5ce0771..e7e464d 100644
--- a/src/gs-common.h
+++ b/src/gs-common.h
@@ -64,6 +64,8 @@ void           gs_utils_show_error_dialog     (GtkWindow      *parent,
                                                 const gchar    *details);
 gchar          *gs_utils_build_unique_id_kind  (AsAppKind       kind,
                                                 const gchar    *id);
+gboolean        gs_utils_list_has_app_fuzzy    (GsAppList      *list,
+                                                GsApp          *app);
 GtkWidget      *gs_search_button_new           (GtkSearchBar   *search_bar);
 
 G_END_DECLS
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index 80d99a6..8847fe5 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -160,7 +160,7 @@ gs_shell_installed_notify_state_changed_cb (GsApp *app,
 static void selection_changed (GsShellInstalled *self);
 
 static void
-gs_shell_installed_add_app (GsShellInstalled *self, GsApp *app)
+gs_shell_installed_add_app (GsShellInstalled *self, GsAppList *list, GsApp *app)
 {
        GtkWidget *app_row;
 
@@ -168,8 +168,9 @@ gs_shell_installed_add_app (GsShellInstalled *self, GsApp *app)
        gs_app_row_set_colorful (GS_APP_ROW (app_row), FALSE);
        gs_app_row_set_show_folders (GS_APP_ROW (app_row), TRUE);
        gs_app_row_set_show_buttons (GS_APP_ROW (app_row), TRUE);
-       gs_app_row_set_show_source (GS_APP_ROW (app_row),
-                                   !gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE));
+       if (!gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE) ||
+           gs_utils_list_has_app_fuzzy (list, app))
+               gs_app_row_set_show_source (GS_APP_ROW (app_row), TRUE);
        g_signal_connect (app_row, "button-clicked",
                          G_CALLBACK (gs_shell_installed_app_remove_cb), self);
        g_signal_connect_object (app, "notify::state",
@@ -216,7 +217,7 @@ gs_shell_installed_get_installed_cb (GObject *source_object,
        }
        for (i = 0; i < gs_app_list_length (list); i++) {
                app = gs_app_list_index (list, i);
-               gs_shell_installed_add_app (self, app);
+               gs_shell_installed_add_app (self, list, app);
        }
 out:
        gs_shell_installed_pending_apps_changed_cb (plugin_loader, self);
@@ -487,7 +488,7 @@ gs_shell_installed_pending_apps_changed_cb (GsPluginLoader *plugin_loader,
 
                /* do not to add pending apps more than once. */
                if (gs_shell_installed_has_app (self, app) == FALSE)
-                       gs_shell_installed_add_app (self, app);
+                       gs_shell_installed_add_app (self, pending, app);
 
                /* incremement the label */
                cnt++;
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index 6fb9bfb..9edd794 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -91,40 +91,6 @@ gs_shell_search_waiting_cancel (GsShellSearch *self)
        self->waiting_id = 0;
 }
 
-static gboolean
-_gs_app_list_is_duplicate (GsAppList *list, GsApp *app)
-{
-       guint i;
-       GsApp *tmp;
-
-       for (i = 0; i < gs_app_list_length (list); i++) {
-               tmp = gs_app_list_index (list, i);
-
-               /* ignore if the same object */
-               if (app == tmp)
-                       continue;
-
-               /* ignore with the same source */
-               if (g_strcmp0 (gs_app_get_origin_hostname (tmp),
-                              gs_app_get_origin_hostname (app)) == 0) {
-                       continue;
-               }
-
-               /* same D-Bus ID */
-               if (g_strcmp0 (gs_app_get_id (tmp),
-                              gs_app_get_id (app)) == 0) {
-                       return TRUE;
-               }
-
-               /* same name */
-               if (g_strcmp0 (gs_app_get_name (tmp),
-                              gs_app_get_name (app)) == 0) {
-                       return TRUE;
-               }
-       }
-       return FALSE;
-}
-
 static void
 gs_shell_search_get_search_cb (GObject *source_object,
                               GAsyncResult *res,
@@ -169,9 +135,9 @@ gs_shell_search_get_search_cb (GObject *source_object,
                app = gs_app_list_index (list, i);
                app_row = gs_app_row_new (app);
                gs_app_row_set_show_sandbox (GS_APP_ROW (app_row), TRUE);
-               gs_app_row_set_show_source (GS_APP_ROW (app_row),
-                                           !gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE) ||
-                                           _gs_app_list_is_duplicate (list, app));
+               if (!gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE) ||
+                   gs_utils_list_has_app_fuzzy (list, app))
+                       gs_app_row_set_show_source (GS_APP_ROW (app_row), TRUE);
                g_signal_connect (app_row, "button-clicked",
                                  G_CALLBACK (gs_shell_search_app_row_clicked_cb),
                                  self);


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