[gnome-software/1364-implement-other-apps-by-author-section-in-app-details-page: 13/15] gs-details-page: Consider app IDs with and without ".desktop" the same




commit 29b8b4648edfa9bec1e2c25d6f6ad1dd90d69c71
Author: Milan Crha <mcrha redhat com>
Date:   Tue Mar 15 18:22:36 2022 +0100

    gs-details-page: Consider app IDs with and without ".desktop" the same
    
    Let the app IDs with and without the ".desktop" suffix being considered
    the same apps and remove them from the list of other apps of the developer.

 src/gs-details-page.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index f9b7d4657..97a827b50 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -966,6 +966,33 @@ gs_details_page_app_tile_clicked (GsAppTile *tile,
        gs_details_page_set_app (self, app);
 }
 
+/* Consider app IDs with and without the ".desktop" suffix being the same app */
+static gboolean
+gs_details_page_app_id_equal (GsApp *app1,
+                             GsApp *app2)
+{
+       const gchar *id1, *id2;
+
+       id1 = gs_app_get_id (app1);
+       id2 = gs_app_get_id (app2);
+       if (g_strcmp0 (id1, id2) == 0)
+               return TRUE;
+
+       if (id1 == NULL || id2 == NULL)
+               return FALSE;
+
+       if (g_str_has_suffix (id1, ".desktop")) {
+               return !g_str_has_suffix (id2, ".desktop") &&
+                       strlen (id1) == strlen (id2) + 8 /* strlen (".desktop") */ &&
+                       g_str_has_prefix (id1, id2);
+       }
+
+       return g_str_has_suffix (id2, ".desktop") &&
+               !g_str_has_suffix (id1, ".desktop") &&
+               strlen (id2) == strlen (id1) + 8 /* strlen (".desktop") */ &&
+               g_str_has_prefix (id2, id1);
+}
+
 static void
 gs_details_page_search_other_apps_cb (GObject *source_object,
                                      GAsyncResult *result,
@@ -992,7 +1019,7 @@ gs_details_page_search_other_apps_cb (GObject *source_object,
 
        for (guint i = 0; i < gs_app_list_length (list); i++) {
                GsApp *app = gs_app_list_index (list, i);
-               if (g_strcmp0 (gs_app_get_id (app), gs_app_get_id (self->app)) != 0) {
+               if (!gs_details_page_app_id_equal (app, self->app)) {
                        GtkWidget *tile = gs_summary_tile_new (app);
                        g_signal_connect (tile, "clicked", G_CALLBACK (gs_details_page_app_tile_clicked), 
self);
                        gtk_flow_box_insert (GTK_FLOW_BOX (self->box_other_apps), tile, -1);


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