[gnome-software/wip/hughsie/xdg-app: 38/39] Split the PackageKit origin_ui functionality out to a new plugin
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/xdg-app: 38/39] Split the PackageKit origin_ui functionality out to a new plugin
- Date: Mon, 18 Jan 2016 15:04:51 +0000 (UTC)
commit af64f54a826b8ebbd3ab5a843a00c224b27a44fa
Author: Richard Hughes <richard hughsie com>
Date: Mon Jan 18 13:59:00 2016 +0000
Split the PackageKit origin_ui functionality out to a new plugin
We need this is we have to use PackageKit for other apps from new plugins.
src/plugins/Makefile.am | 6 +
src/plugins/gs-plugin-packagekit-origin.c | 198 +++++++++++++++++++++++++++++
src/plugins/gs-plugin-packagekit-refine.c | 76 +-----------
3 files changed, 208 insertions(+), 72 deletions(-)
---
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index d215463..66e926b 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -44,6 +44,7 @@ plugin_LTLIBRARIES = \
libgs_plugin_packagekit-refine.la \
libgs_plugin_packagekit-refresh.la \
libgs_plugin_packagekit-offline.la \
+ libgs_plugin_packagekit-origin.la \
libgs_plugin_packagekit-history.la \
libgs_plugin_packagekit.la
@@ -190,6 +191,11 @@ libgs_plugin_packagekit_offline_la_LIBADD = $(GS_PLUGIN_LIBS)
libgs_plugin_packagekit_offline_la_LDFLAGS = -module -avoid-version
libgs_plugin_packagekit_offline_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+libgs_plugin_packagekit_origin_la_SOURCES = gs-plugin-packagekit-origin.c
+libgs_plugin_packagekit_origin_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_packagekit_origin_la_LDFLAGS = -module -avoid-version
+libgs_plugin_packagekit_origin_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+
check_PROGRAMS = \
gs-self-test
diff --git a/src/plugins/gs-plugin-packagekit-origin.c b/src/plugins/gs-plugin-packagekit-origin.c
new file mode 100644
index 0000000..72c73cd
--- /dev/null
+++ b/src/plugins/gs-plugin-packagekit-origin.c
@@ -0,0 +1,198 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013-2014 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
+#include <packagekit-glib2/packagekit.h>
+
+#include <gs-plugin.h>
+#include <gs-utils.h>
+
+#include "packagekit-common.h"
+
+/*
+ * SECTION:
+ * Uses the system PackageKit instance to return convert short origins like
+ * 'fedora-updates' into longer summaries for the UI.
+ *
+ * Requires: | [origin]
+ * Refines: | [origin-ui]
+ */
+
+struct GsPluginPrivate {
+ PkClient *client;
+ GHashTable *sources;
+};
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+ return "packagekit-origin";
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ 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);
+}
+
+/**
+ * gs_plugin_get_deps:
+ */
+const gchar **
+gs_plugin_get_deps (GsPlugin *plugin)
+{
+ static const gchar *deps[] = {
+ "packagekit-refine", /* need origin */
+ NULL };
+ return deps;
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+ g_hash_table_unref (plugin->priv->sources);
+ g_object_unref (plugin->priv->client);
+}
+
+/**
+ * gs_plugin_packagekit_origin_ensure_sources:
+ **/
+static gboolean
+gs_plugin_packagekit_origin_ensure_sources (GsPlugin *plugin,
+ GCancellable *cancellable,
+ GError **error)
+{
+ PkRepoDetail *rd;
+ guint i;
+ g_autoptr(PkResults) results = NULL;
+ g_autoptr(GPtrArray) array = NULL;
+
+ /* already done */
+ if (g_hash_table_size (plugin->priv->sources) > 0)
+ return TRUE;
+
+ /* 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,
+ NULL, plugin,
+ error);
+ if (results == NULL)
+ return FALSE;
+ array = pk_results_get_repo_detail_array (results);
+ for (i = 0; i < array->len; i++) {
+ rd = g_ptr_array_index (array, i);
+ g_hash_table_insert (plugin->priv->sources,
+ g_strdup (pk_repo_detail_get_id (rd)),
+ g_strdup (pk_repo_detail_get_description (rd)));
+ }
+ return TRUE;
+}
+
+/**
+ * gs_plugin_packagekit_origin_refine_app:
+ **/
+static gboolean
+gs_plugin_packagekit_origin_refine_app (GsPlugin *plugin,
+ GsApp *app,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const gchar *origin_id;
+ const gchar *origin_ui;
+
+ if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") != 0)
+ return TRUE;
+ if (gs_app_get_origin (app) == NULL)
+ return TRUE;
+ if (gs_app_get_origin_ui (app) != NULL)
+ return TRUE;
+
+ /* this is for libsolv */
+ origin_id = gs_app_get_origin (app);
+ if (g_strcmp0 (origin_id, "@commandline") == 0) {
+ gs_app_set_origin_ui (app, "User");
+ return TRUE;
+ }
+
+ /* this is fedora specific */
+ if (g_str_has_prefix (origin_id, "koji-override-")) {
+ gs_app_set_origin_ui (app, "Koji");
+ return TRUE;
+ }
+
+ /* ensure set up */
+ if (!gs_plugin_packagekit_origin_ensure_sources (plugin, cancellable, error))
+ return FALSE;
+
+ /* set new value */
+ origin_ui = g_hash_table_lookup (plugin->priv->sources, origin_id);
+ if (origin_ui != NULL)
+ gs_app_set_origin_ui (app, origin_ui);
+ return TRUE;
+}
+
+/**
+ * gs_plugin_refine:
+ */
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GList **list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GList *l;
+ GsApp *app;
+
+ /* only run when required */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) == 0)
+ return TRUE;
+
+ /* for each app */
+ for (l = *list; l != NULL; l = l->next) {
+ app = GS_APP (l->data);
+ if (!gs_plugin_packagekit_origin_refine_app (plugin, app,
+ cancellable,
+ error))
+ return FALSE;
+ }
+ return TRUE;
+}
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index f7a2c1b..142a296 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -80,10 +80,6 @@ gs_plugin_initialize (GsPlugin *plugin)
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);
}
/**
@@ -105,7 +101,6 @@ 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);
g_object_unref (plugin->priv->control);
}
@@ -153,21 +148,6 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
gs_plugin_status_update (plugin, NULL, plugin_status);
}
-/**
- * gs_plugin_packagekit_set_origin:
- **/
-static void
-gs_plugin_packagekit_set_origin (GsPlugin *plugin,
- GsApp *app,
- const gchar *id)
-{
- const gchar *name;
- gs_app_set_origin (app, id);
- name = g_hash_table_lookup (plugin->priv->sources, id);
- if (name != NULL)
- gs_app_set_origin_ui (app, name);
-}
-
static void
gs_plugin_packagekit_set_metadata_from_package (GsPlugin *plugin,
GsApp *app,
@@ -181,15 +161,13 @@ gs_plugin_packagekit_set_metadata_from_package (GsPlugin *plugin,
switch (pk_package_get_info (package)) {
case PK_INFO_ENUM_INSTALLED:
data = pk_package_get_data (package);
- if (g_str_has_prefix (data, "installed:")) {
- gs_plugin_packagekit_set_origin (plugin,
- app,
- data + 10);
- }
+ if (g_str_has_prefix (data, "installed:"))
+ gs_app_set_origin (app, data + 10);
break;
case PK_INFO_ENUM_UNAVAILABLE:
data = pk_package_get_data (package);
- gs_plugin_packagekit_set_origin (plugin, app, data);
+ if (data != NULL)
+ gs_app_set_origin (app, data);
gs_app_set_state (app, AS_APP_STATE_UNAVAILABLE);
gs_app_set_size (app, GS_APP_SIZE_MISSING);
break;
@@ -726,42 +704,6 @@ gs_plugin_refine_require_details (GsPlugin *plugin,
}
/**
- * gs_plugin_packagekit_get_source_list:
- **/
-static gboolean
-gs_plugin_packagekit_get_source_list (GsPlugin *plugin,
- GCancellable *cancellable,
- GError **error)
-{
- PkRepoDetail *rd;
- ProgressData data;
- guint i;
- g_autoptr(PkResults) results = NULL;
- g_autoptr(GPtrArray) array = NULL;
-
- data.plugin = plugin;
- data.ptask = NULL;
- data.profile_id = NULL;
-
- /* 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, &data,
- error);
- if (results == NULL)
- return FALSE;
- array = pk_results_get_repo_detail_array (results);
- for (i = 0; i < array->len; i++) {
- rd = g_ptr_array_index (array, i);
- g_hash_table_insert (plugin->priv->sources,
- g_strdup (pk_repo_detail_get_id (rd)),
- g_strdup (pk_repo_detail_get_description (rd)));
- }
- return TRUE;
-}
-
-/**
* gs_plugin_refine_requires_version:
*/
static gboolean
@@ -945,16 +887,6 @@ gs_plugin_refine (GsPlugin *plugin,
}
}
- /* 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? */
ptask = as_profile_start_literal (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]