[gnome-software] Always return search results back to the shell



commit 03dfb3868e4ed469569928df2391be671eb5c8a5
Author: Richard Hughes <richard hughsie com>
Date:   Mon Oct 21 14:39:08 2013 +0100

    Always return search results back to the shell
    
    You need the previous set of patches to avoid starting up PackageKit on each
    application refine.

 src/gs-plugin-loader-sync.c    |   22 ++++++++++++++++++++++
 src/gs-plugin-loader-sync.h    |    5 +++++
 src/gs-shell-search-provider.c |   23 ++++++++++++++++-------
 3 files changed, 43 insertions(+), 7 deletions(-)
---
diff --git a/src/gs-plugin-loader-sync.c b/src/gs-plugin-loader-sync.c
index 6b14645..cff110a 100644
--- a/src/gs-plugin-loader-sync.c
+++ b/src/gs-plugin-loader-sync.c
@@ -23,6 +23,28 @@
 
 #include "gs-plugin-loader-sync.h"
 
+/**
+ * gs_plugin_loader_get_app_by_id:
+ */
+GsApp *
+gs_plugin_loader_get_app_by_id (GsPluginLoader *plugin_loader,
+                               const gchar *id,
+                               GsPluginRefineFlags flags,
+                               GCancellable *cancellable,
+                               GError **error)
+{
+       GsApp *app;
+       gboolean ret;
+
+       app = gs_app_new (id);
+       app = gs_plugin_loader_dedupe (plugin_loader, app);
+       ret = gs_plugin_loader_app_refine (plugin_loader, app, flags,
+                                          cancellable, error);
+       if (!ret)
+               g_clear_object (&app);
+       return app;
+}
+
 /* tiny helper to help us do the async operation */
 typedef struct {
        GError          **error;
diff --git a/src/gs-plugin-loader-sync.h b/src/gs-plugin-loader-sync.h
index 1d6472a..6f47489 100644
--- a/src/gs-plugin-loader-sync.h
+++ b/src/gs-plugin-loader-sync.h
@@ -64,6 +64,11 @@ gboolean      gs_plugin_loader_app_action            (GsPluginLoader *plugin_loader,
                                                         GsPluginLoaderAction action,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
+GsApp          *gs_plugin_loader_get_app_by_id         (GsPluginLoader *plugin_loader,
+                                                        const gchar    *id,
+                                                        GsPluginRefineFlags flags,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
 
 G_END_DECLS
 
diff --git a/src/gs-shell-search-provider.c b/src/gs-shell-search-provider.c
index 63a4b9c..5ccfee5 100644
--- a/src/gs-shell-search-provider.c
+++ b/src/gs-shell-search-provider.c
@@ -27,6 +27,8 @@
 #include <string.h>
 #include <glib/gi18n.h>
 
+#include "gs-plugin-loader-sync.h"
+
 #include "gs-shell-search-provider-generated.h"
 #include "gs-shell-search-provider.h"
 
@@ -195,23 +197,29 @@ handle_get_result_metas (GsShellSearchProvider2        *skeleton,
        GdkPixbuf *pixbuf;
        gint i;
        GVariantBuilder builder;
+       GError *error = NULL;
 
        g_debug ("****** GetResultMetas");
 
        for (i = 0; results[i]; i++) {
-               GsApp *app, *new_app;
+               GsApp *app;
 
                if (g_hash_table_lookup (self->metas_cache, results[i]))
                        continue;
 
-               app = gs_app_new (results[i]);
-               new_app = gs_plugin_loader_dedupe (self->plugin_loader, app);
-               if (new_app == app) {
-                       g_warning ("didn't find app %s in loader list", results[i]);
-                       g_object_unref (app);
+               /* find the application with this ID */
+               app = gs_plugin_loader_get_app_by_id (self->plugin_loader,
+                                                     results[i],
+                                                     GS_PLUGIN_REFINE_FLAGS_DEFAULT |
+                                                     GS_PLUGIN_REFINE_FLAGS_REQUIRE_DESCRIPTION,
+                                                     NULL,
+                                                     &error);
+               if (app == NULL) {
+                       g_warning ("failed to refine %s: %s",
+                                  results[i], error->message);
+                       g_clear_error (&error);
                        continue;
                }
-               app = new_app;
 
                g_variant_builder_init (&meta, G_VARIANT_TYPE ("a{sv}"));
                g_variant_builder_add (&meta, "{sv}", "id", g_variant_new_string (gs_app_get_id (app)));
@@ -221,6 +229,7 @@ handle_get_result_metas (GsShellSearchProvider2        *skeleton,
                g_variant_builder_add (&meta, "{sv}", "description", g_variant_new_string (gs_app_get_summary 
(app)));
                meta_variant = g_variant_builder_end (&meta);
                g_hash_table_insert (self->metas_cache, g_strdup (gs_app_get_id (app)), g_variant_ref_sink 
(meta_variant));
+               g_object_unref (app);
 
        }
 


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