[gnome-software] Only get the application origin when specified



commit c722308ee6b5064f7a3df114a339cd7149921320
Author: Richard Hughes <richard hughsie com>
Date:   Sat Feb 8 22:19:20 2014 +0100

    Only get the application origin when specified
    
    Additionally, use the repo description in the UI, rather than the ID

 src/gs-cmd.c                              |    4 +-
 src/gs-plugin.h                           |    1 +
 src/gs-shell-details.c                    |    1 +
 src/plugins/gs-plugin-packagekit-refine.c |   95 ++++++++++++++++++++++++++---
 4 files changed, 92 insertions(+), 9 deletions(-)
---
diff --git a/src/gs-cmd.c b/src/gs-cmd.c
index bc14ced..d4c7aa8 100644
--- a/src/gs-cmd.c
+++ b/src/gs-cmd.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2013-2014 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -133,6 +133,8 @@ gs_cmd_refine_flag_from_string (const gchar *flag, GError **error)
                return GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION;
        if (g_strcmp0 (flag, "update-details") == 0)
                return GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS;
+       if (g_strcmp0 (flag, "origin") == 0)
+               return GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN;
        g_set_error (error,
                     GS_PLUGIN_ERROR,
                     GS_PLUGIN_ERROR_NOT_SUPPORTED,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 1b41e48..0da5d00 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -92,6 +92,7 @@ typedef enum {
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_HISTORY          = 1 << 7,
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION     = 1 << 8,
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS   = 1 << 9,
+       GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN           = 1 << 10,
        GS_PLUGIN_REFINE_FLAGS_LAST
 } GsPluginRefineFlags;
 
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 66a530b..9e47b6c 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -888,6 +888,7 @@ gs_shell_details_set_app (GsShellDetails *shell_details, GsApp *app)
                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION |
                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_HISTORY |
                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION |
+                                          GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN |
                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_URL,
                                           priv->cancellable,
                                           gs_shell_details_app_refine_cb,
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 87ac417..3bb6899 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2013-2014 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -32,6 +32,7 @@
 
 struct GsPluginPrivate {
        PkClient                *client;
+       GHashTable              *sources;
 };
 
 /**
@@ -49,12 +50,15 @@ gs_plugin_get_name (void)
 void
 gs_plugin_initialize (GsPlugin *plugin)
 {
-       /* create private area */
        plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
        plugin->priv->client = pk_client_new ();
        pk_client_set_background (plugin->priv->client, FALSE);
        pk_client_set_interactive (plugin->priv->client, FALSE);
        pk_client_set_cache_age (plugin->priv->client, G_MAXUINT);
+       plugin->priv->sources = g_hash_table_new_full (g_str_hash,
+                                                      g_str_equal,
+                                                      g_free,
+                                                      g_free);
 }
 
 /**
@@ -76,6 +80,7 @@ gs_plugin_get_deps (GsPlugin *plugin)
 void
 gs_plugin_destroy (GsPlugin *plugin)
 {
+       g_hash_table_unref (plugin->priv->sources);
        g_object_unref (plugin->priv->client);
 }
 
@@ -112,10 +117,27 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
 }
 
 /**
+ * gs_plugin_packagekit_set_origin:
+ **/
+static void
+gs_plugin_packagekit_set_origin (GsPlugin *plugin,
+                                GsApp *app,
+                                const gchar *id)
+{
+       const gchar *name;
+       name = g_hash_table_lookup (plugin->priv->sources, id);
+       if (name != NULL)
+               gs_app_set_origin (app, name);
+       else
+               gs_app_set_origin (app, id);
+}
+
+/**
  * gs_plugin_packagekit_resolve_packages_app:
  **/
 static void
-gs_plugin_packagekit_resolve_packages_app (GPtrArray *packages,
+gs_plugin_packagekit_resolve_packages_app (GsPlugin *plugin,
+                                          GPtrArray *packages,
                                           GsApp *app)
 {
        GPtrArray *sources;
@@ -142,8 +164,11 @@ gs_plugin_packagekit_resolve_packages_app (GPtrArray *packages,
                                case GS_APP_STATE_INSTALLED:
                                        number_installed++;
                                        data = pk_package_get_data (package);
-                                       if (g_str_has_prefix (data, "installed:"))
-                                               gs_app_set_origin (app, data + 10);
+                                       if (g_str_has_prefix (data, "installed:")) {
+                                               gs_plugin_packagekit_set_origin (plugin,
+                                                                                app,
+                                                                                data + 10);
+                                       }
                                        break;
                                case GS_APP_STATE_AVAILABLE:
                                        number_available++;
@@ -200,7 +225,7 @@ gs_plugin_packagekit_resolve_packages (GsPlugin *plugin,
 {
        GList *l;
        GPtrArray *array = NULL;
-       GPtrArray *package_ids;
+       GPtrArray *package_ids = NULL;
        GPtrArray *packages = NULL;
        GPtrArray *sources;
        GsApp *app;
@@ -250,10 +275,11 @@ gs_plugin_packagekit_resolve_packages (GsPlugin *plugin,
        packages = pk_results_get_package_array (results);
        for (l = list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
-               gs_plugin_packagekit_resolve_packages_app (packages, app);
+               gs_plugin_packagekit_resolve_packages_app (plugin, packages, app);
        }
 out:
-       g_ptr_array_unref (package_ids);
+       if (package_ids != NULL)
+               g_ptr_array_unref (package_ids);
        if (packages != NULL)
                g_ptr_array_unref (packages);
        if (error_code != NULL)
@@ -579,6 +605,47 @@ out:
 }
 
 /**
+ * gs_plugin_packagekit_get_source_list:
+ **/
+static gboolean
+gs_plugin_packagekit_get_source_list (GsPlugin *plugin,
+                                     GCancellable *cancellable,
+                                     GError **error)
+{
+       GPtrArray *array = NULL;
+       PkRepoDetail *rd;
+       PkResults *results;
+       gboolean ret = TRUE;
+       guint i;
+
+       /* ask PK for the repo details */
+       results = pk_client_get_repo_list (plugin->priv->client,
+                                          pk_bitfield_from_enums (PK_FILTER_ENUM_NONE, -1),
+                                          cancellable,
+                                          gs_plugin_packagekit_progress_cb, plugin,
+                                          error);
+       if (results == NULL) {
+               ret = FALSE;
+               goto out;
+       }
+       array = pk_results_get_repo_detail_array (results);
+       for (i = 0; i < array->len; i++) {
+               rd = g_ptr_array_index (array, i);
+#if PK_CHECK_VERSION(0,9,1)
+               g_hash_table_insert (plugin->priv->sources,
+                                    g_strdup (pk_repo_detail_get_id (rd)),
+                                    g_strdup (pk_repo_detail_get_description (rd)));
+#endif
+       }
+out:
+       if (array != NULL)
+               g_ptr_array_unref (array);
+       if (results != NULL)
+               g_object_unref (results);
+       return ret;
+}
+
+/**
  * gs_plugin_refine_requires_version:
  */
 static gboolean
@@ -628,6 +695,8 @@ gs_plugin_refine_requires_package_id (GsApp *app, GsPluginRefineFlags flags)
                return TRUE;
        if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS) > 0)
                return TRUE;
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) > 0)
+               return TRUE;
        return FALSE;
 }
 
@@ -649,6 +718,16 @@ gs_plugin_refine (GsPlugin *plugin,
        const gchar *tmp;
        gboolean ret = TRUE;
 
+       /* get the repo_id -> repo_name mapping set up */
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) > 0 &&
+            g_hash_table_size (plugin->priv->sources) == 0) {
+               ret = gs_plugin_packagekit_get_source_list (plugin,
+                                                           cancellable,
+                                                           error);
+               if (!ret)
+                       goto out;
+       }
+
        /* can we resolve in one go? */
        gs_profile_start (plugin->profile, "packagekit-refine[name->id]");
        for (l = *list; l != NULL; l = l->next) {


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