[gnome-software] Only filter incompatible project groups when searching



commit c41bb6c7e27c8b6f8ffa00f7e5f26a7b794b8a48
Author: Richard Hughes <richard hughsie com>
Date:   Fri Sep 27 10:26:36 2013 +0100

    Only filter incompatible project groups when searching
    
    We still want to show the extended descriptions on other desktops, for instance
    showing the full description for gedit if using XFCE. If we filter the list only
    when searching then gnome-software does the right thing in more cases.

 src/gs-plugin-loader.c        |   64 +++++++++++++++++++++++++++++++++++++++++
 src/plugins/appstream-cache.c |   41 +-------------------------
 2 files changed, 65 insertions(+), 40 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 1eba4b7..53472cd 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -41,6 +41,7 @@ struct GsPluginLoaderPrivate
 
        GMutex                   app_cache_mutex;
        GHashTable              *app_cache;
+       gchar                   **compatible_projects;
 };
 
 G_DEFINE_TYPE (GsPluginLoader, gs_plugin_loader, G_TYPE_OBJECT)
@@ -432,6 +433,54 @@ gs_plugin_loader_remove_system (GList *list)
        return list;
 }
 
+
+/**
+ * gs_plugin_loader_get_app_is_compatible:
+ */
+static gboolean
+gs_plugin_loader_get_app_is_compatible (GsPluginLoader *plugin_loader, GsApp *app)
+{
+       GsPluginLoaderPrivate *priv = plugin_loader->priv;
+       const gchar *tmp;
+       guint i;
+
+       /* search for any compatible projects */
+       tmp = gs_app_get_project_group (app);
+       if (tmp == NULL)
+               return TRUE;
+       for (i = 0; priv->compatible_projects[i] != NULL; i++) {
+               if (g_strcmp0 (tmp,  priv->compatible_projects[i]) == 0)
+                       return TRUE;
+       }
+       return FALSE;
+}
+
+/**
+ * gs_plugin_loader_remove_incompat:
+ **/
+static GList *
+gs_plugin_loader_remove_incompat (GsPluginLoader *plugin_loader, GList *list)
+{
+       GList *l;
+       GList *new = NULL;
+       GsApp *app;
+       gboolean compat;
+
+       for (l = list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               compat = gs_plugin_loader_get_app_is_compatible (plugin_loader, app);
+               if (compat) {
+                       gs_plugin_add_app (&new, app);
+               } else {
+                       g_debug ("removing incompatible %s from project group %s",
+                                gs_app_get_id (app),
+                                gs_app_get_project_group (app));
+               }
+       }
+       gs_plugin_list_free (list);
+       return new;
+}
+
 /******************************************************************************/
 
 /* async state */
@@ -1095,6 +1144,9 @@ gs_plugin_loader_search_thread_cb (GSimpleAsyncResult *res,
        /* remove duplicates */
        state->list = gs_plugin_loader_list_uniq (plugin_loader, state->list);
 
+       /* remove incompatible projects */
+       state->list = gs_plugin_loader_remove_incompat (plugin_loader, state->list);
+
        /* success */
        state->list = gs_plugin_loader_remove_invalid (state->list);
        if (state->list == NULL) {
@@ -1418,6 +1470,9 @@ gs_plugin_loader_get_category_apps_thread_cb (GSimpleAsyncResult *res,
        /* remove duplicates */
        state->list = gs_plugin_loader_list_uniq (plugin_loader, state->list);
 
+       /* remove incompatible projects */
+       state->list = gs_plugin_loader_remove_incompat (plugin_loader, state->list);
+
        /* success */
        state->list = gs_plugin_loader_remove_system (state->list);
        state->list = gs_plugin_loader_remove_invalid (state->list);
@@ -2084,6 +2139,8 @@ gs_plugin_loader_class_init (GsPluginLoaderClass *klass)
 static void
 gs_plugin_loader_init (GsPluginLoader *plugin_loader)
 {
+       const gchar *tmp;
+
        plugin_loader->priv = GS_PLUGIN_LOADER_GET_PRIVATE (plugin_loader);
        plugin_loader->priv->plugins = g_ptr_array_new_with_free_func ((GDestroyNotify) 
gs_plugin_loader_plugin_free);
        plugin_loader->priv->status_last = GS_PLUGIN_STATUS_LAST;
@@ -2095,6 +2152,12 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
 
        g_mutex_init (&plugin_loader->priv->pending_apps_mutex);
        g_mutex_init (&plugin_loader->priv->app_cache_mutex);
+
+       /* by default we only show project-less apps or compatible projects */
+       tmp = g_getenv ("GNOME_SOFTWARE_COMPATIBLE_PROJECTS");
+       if (tmp == NULL)
+               tmp = "GNOME";
+       plugin_loader->priv->compatible_projects = g_strsplit (tmp, ",", -1);
 }
 
 /**
@@ -2116,6 +2179,7 @@ gs_plugin_loader_finalize (GObject *object)
        /* run the plugins */
        gs_plugin_loader_run (plugin_loader, "gs_plugin_destroy");
 
+       g_strfreev (plugin_loader->priv->compatible_projects);
        g_hash_table_unref (plugin_loader->priv->app_cache);
        g_ptr_array_unref (plugin_loader->priv->pending_apps);
        g_ptr_array_unref (plugin_loader->priv->plugins);
diff --git a/src/plugins/appstream-cache.c b/src/plugins/appstream-cache.c
index 371dbc2..c08301d 100644
--- a/src/plugins/appstream-cache.c
+++ b/src/plugins/appstream-cache.c
@@ -34,7 +34,6 @@ struct AppstreamCachePrivate
        GPtrArray               *icon_path_array;
        GHashTable              *hash_id;       /* of AppstreamApp{id} */
        GHashTable              *hash_pkgname;  /* of AppstreamApp{pkgname} */
-       gchar                   **compatible_projects;
 };
 
 G_DEFINE_TYPE (AppstreamCache, appstream_cache, G_TYPE_OBJECT)
@@ -218,29 +217,6 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
 }
 
 /**
- * appstream_cache_app_is_compatible:
- */
-static gboolean
-appstream_cache_app_is_compatible (AppstreamCache *cache, AppstreamApp *app)
-{
-       AppstreamCachePrivate *priv = cache->priv;
-       const gchar *tmp;
-       guint i;
-
-       /* app has no aligned project */
-       tmp = appstream_app_get_project_group (app);
-       if (tmp == NULL)
-               return TRUE;
-
-       /* search for any compatible projects */
-       for (i = 0; priv->compatible_projects[i] != NULL; i++) {
-               if (g_strcmp0 (tmp,  priv->compatible_projects[i]) == 0)
-                       return TRUE;
-       }
-       return FALSE;
-}
-
-/**
  * appstream_cache_add_item:
  */
 static void
@@ -250,15 +226,8 @@ appstream_cache_add_item (AppstreamCacheHelper *helper)
        AppstreamCachePrivate *priv = helper->cache->priv;
        const gchar *id;
 
-       /* is app compatible with this running desktop */
-       id = appstream_app_get_id (helper->item_temp);
-       if (!appstream_cache_app_is_compatible (helper->cache, helper->item_temp)) {
-               g_debug ("not compatible with the current desktop: %s", id);
-               appstream_app_free (helper->item_temp);
-               return;
-       }
-
        /* have we recorded this before? */
+       id = appstream_app_get_id (helper->item_temp);
        item = g_hash_table_lookup (priv->hash_id, id);
        if (item != NULL) {
                g_warning ("duplicate AppStream entry: %s", id);
@@ -572,7 +541,6 @@ static void
 appstream_cache_init (AppstreamCache *cache)
 {
        AppstreamCachePrivate *priv;
-       const gchar *tmp;
 
        priv = cache->priv = APPSTREAM_CACHE_GET_PRIVATE (cache);
        priv->array = g_ptr_array_new_with_free_func ((GDestroyNotify) appstream_app_free);
@@ -585,12 +553,6 @@ appstream_cache_init (AppstreamCache *cache)
                                                    g_str_equal,
                                                    NULL,
                                                    NULL);
-
-       /* by default we only show project-less apps or compatible projects */
-       tmp = g_getenv ("GNOME_SOFTWARE_COMPATIBLE_PROJECTS");
-       if (tmp == NULL)
-               tmp = "GNOME";
-       priv->compatible_projects = g_strsplit (tmp, ",", -1);
 }
 
 /**
@@ -602,7 +564,6 @@ appstream_cache_finalize (GObject *object)
        AppstreamCache *cache = APPSTREAM_CACHE (object);
        AppstreamCachePrivate *priv = cache->priv;
 
-       g_strfreev (priv->compatible_projects);
        g_ptr_array_unref (priv->array);
        g_ptr_array_unref (priv->icon_path_array);
        g_hash_table_unref (priv->hash_id);


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