[gnome-software: 22/29] gs-plugin-packagekit-refresh: Port to the new GsPlugin lifecycle
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 22/29] gs-plugin-packagekit-refresh: Port to the new GsPlugin lifecycle
- Date: Wed, 13 Oct 2021 12:39:54 +0000 (UTC)
commit 56dc1d28721a02eab9fad35308fe209db8d0b05a
Author: Philip Withnall <pwithnall endlessos org>
Date: Mon Oct 11 12:26:06 2021 +0100
gs-plugin-packagekit-refresh: Port to the new GsPlugin lifecycle
Signed-off-by: Philip Withnall <pwithnall endlessos org>
plugins/packagekit/gs-plugin-packagekit-refresh.c | 106 +++++++++++++++-------
plugins/packagekit/gs-plugin-packagekit-refresh.h | 22 +++++
2 files changed, 93 insertions(+), 35 deletions(-)
---
diff --git a/plugins/packagekit/gs-plugin-packagekit-refresh.c
b/plugins/packagekit/gs-plugin-packagekit-refresh.c
index ef06bcd23..c76450625 100644
--- a/plugins/packagekit/gs-plugin-packagekit-refresh.c
+++ b/plugins/packagekit/gs-plugin-packagekit-refresh.c
@@ -16,45 +16,65 @@
#include "gs-packagekit-helper.h"
#include "packagekit-common.h"
+#include "gs-plugin-packagekit-refresh.h"
+
/*
* SECTION:
* Do a PackageKit UpdatePackages(ONLY_DOWNLOAD) method on refresh and
* also convert any package files to applications the best we can.
*/
-struct GsPluginData {
+struct _GsPluginPackagekitRefresh {
+ GsPlugin parent;
+
PkTask *task;
GMutex task_mutex;
};
-void
-gs_plugin_initialize (GsPlugin *plugin)
+G_DEFINE_TYPE (GsPluginPackagekitRefresh, gs_plugin_packagekit_refresh, GS_TYPE_PLUGIN)
+
+static void
+gs_plugin_packagekit_refresh_init (GsPluginPackagekitRefresh *self)
{
- GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+ GsPlugin *plugin = GS_PLUGIN (self);
- g_mutex_init (&priv->task_mutex);
- priv->task = pk_task_new ();
- pk_task_set_only_download (priv->task, TRUE);
- pk_client_set_background (PK_CLIENT (priv->task), TRUE);
- pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ g_mutex_init (&self->task_mutex);
+ self->task = pk_task_new ();
+ pk_task_set_only_download (self->task, TRUE);
+ pk_client_set_background (PK_CLIENT (self->task), TRUE);
+ pk_client_set_interactive (PK_CLIENT (self->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
/* we can return better results than dpkg directly */
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "dpkg");
}
-void
-gs_plugin_destroy (GsPlugin *plugin)
+static void
+gs_plugin_packagekit_refresh_dispose (GObject *object)
{
- GsPluginData *priv = gs_plugin_get_data (plugin);
- g_mutex_clear (&priv->task_mutex);
- g_object_unref (priv->task);
+ GsPluginPackagekitRefresh *self = GS_PLUGIN_PACKAGEKIT_REFRESH (object);
+
+ g_clear_object (&self->task);
+
+ G_OBJECT_CLASS (gs_plugin_packagekit_refresh_parent_class)->dispose (object);
+}
+
+static void
+gs_plugin_packagekit_refresh_finalize (GObject *object)
+{
+ GsPluginPackagekitRefresh *self = GS_PLUGIN_PACKAGEKIT_REFRESH (object);
+
+ g_mutex_clear (&self->task_mutex);
+
+ G_OBJECT_CLASS (gs_plugin_packagekit_refresh_parent_class)->finalize (object);
}
static gboolean
-_download_only (GsPlugin *plugin, GsAppList *list,
- GCancellable *cancellable, GError **error)
+_download_only (GsPluginPackagekitRefresh *self,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
{
- GsPluginData *priv = gs_plugin_get_data (plugin);
+ GsPlugin *plugin = GS_PLUGIN (self);
g_auto(GStrv) package_ids = NULL;
g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
g_autoptr(PkPackageSack) sack = NULL;
@@ -64,18 +84,18 @@ _download_only (GsPlugin *plugin, GsAppList *list,
/* get the list of packages to update */
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
- g_mutex_lock (&priv->task_mutex);
+ g_mutex_lock (&self->task_mutex);
/* never refresh the metadata here as this can surprise the frontend if
* we end up downloading a different set of packages than what was
* shown to the user */
- pk_client_set_cache_age (PK_CLIENT (priv->task), G_MAXUINT);
- pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
- results = pk_client_get_updates (PK_CLIENT (priv->task),
+ pk_client_set_cache_age (PK_CLIENT (self->task), G_MAXUINT);
+ pk_client_set_interactive (PK_CLIENT (self->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ results = pk_client_get_updates (PK_CLIENT (self->task),
pk_bitfield_value (PK_FILTER_ENUM_NONE),
cancellable,
gs_packagekit_helper_cb, helper,
error);
- g_mutex_unlock (&priv->task_mutex);
+ g_mutex_unlock (&self->task_mutex);
if (!gs_plugin_packagekit_results_valid (results, error)) {
return FALSE;
}
@@ -89,18 +109,18 @@ _download_only (GsPlugin *plugin, GsAppList *list,
GsApp *app = gs_app_list_index (list, i);
gs_packagekit_helper_add_app (helper, app);
}
- g_mutex_lock (&priv->task_mutex);
+ g_mutex_lock (&self->task_mutex);
/* never refresh the metadata here as this can surprise the frontend if
* we end up downloading a different set of packages than what was
* shown to the user */
- pk_client_set_cache_age (PK_CLIENT (priv->task), G_MAXUINT);
- pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
- results2 = pk_task_update_packages_sync (priv->task,
+ pk_client_set_cache_age (PK_CLIENT (self->task), G_MAXUINT);
+ pk_client_set_interactive (PK_CLIENT (self->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ results2 = pk_task_update_packages_sync (self->task,
package_ids,
cancellable,
gs_packagekit_helper_cb, helper,
error);
- g_mutex_unlock (&priv->task_mutex);
+ g_mutex_unlock (&self->task_mutex);
if (results2 == NULL) {
gs_plugin_packagekit_error_convert (error);
return FALSE;
@@ -119,6 +139,7 @@ gs_plugin_download (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ GsPluginPackagekitRefresh *self = GS_PLUGIN_PACKAGEKIT_REFRESH (plugin);
g_autoptr(GsAppList) list_tmp = gs_app_list_new ();
g_autoptr(GError) error_local = NULL;
gboolean retval;
@@ -155,7 +176,7 @@ gs_plugin_download (GsPlugin *plugin,
}
}
- retval = _download_only (plugin, list_tmp, cancellable, error);
+ retval = _download_only (self, list_tmp, cancellable, error);
if (!gs_metered_remove_from_download_scheduler (schedule_entry_handle, NULL, &error_local))
g_warning ("Failed to remove schedule entry: %s", error_local->message);
@@ -169,7 +190,7 @@ gs_plugin_refresh (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- GsPluginData *priv = gs_plugin_get_data (plugin);
+ GsPluginPackagekitRefresh *self = GS_PLUGIN_PACKAGEKIT_REFRESH (plugin);
g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
g_autoptr(GsApp) app_dl = gs_app_new (gs_plugin_get_name (plugin));
g_autoptr(PkResults) results = NULL;
@@ -177,21 +198,36 @@ gs_plugin_refresh (GsPlugin *plugin,
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
gs_packagekit_helper_set_progress_app (helper, app_dl);
- g_mutex_lock (&priv->task_mutex);
+ g_mutex_lock (&self->task_mutex);
/* cache age of 1 is user-initiated */
- pk_client_set_background (PK_CLIENT (priv->task), cache_age > 1);
- pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
- pk_client_set_cache_age (PK_CLIENT (priv->task), cache_age);
+ pk_client_set_background (PK_CLIENT (self->task), cache_age > 1);
+ pk_client_set_interactive (PK_CLIENT (self->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ pk_client_set_cache_age (PK_CLIENT (self->task), cache_age);
/* refresh the metadata */
- results = pk_client_refresh_cache (PK_CLIENT (priv->task),
+ results = pk_client_refresh_cache (PK_CLIENT (self->task),
FALSE /* force */,
cancellable,
gs_packagekit_helper_cb, helper,
error);
- g_mutex_unlock (&priv->task_mutex);
+ g_mutex_unlock (&self->task_mutex);
if (!gs_plugin_packagekit_results_valid (results, error)) {
return FALSE;
}
return TRUE;
}
+
+static void
+gs_plugin_packagekit_refresh_class_init (GsPluginPackagekitRefreshClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = gs_plugin_packagekit_refresh_dispose;
+ object_class->finalize = gs_plugin_packagekit_refresh_finalize;
+}
+
+GType
+gs_plugin_query_type (void)
+{
+ return GS_TYPE_PLUGIN_PACKAGEKIT_REFRESH;
+}
diff --git a/plugins/packagekit/gs-plugin-packagekit-refresh.h
b/plugins/packagekit/gs-plugin-packagekit-refresh.h
new file mode 100644
index 000000000..551b1a4be
--- /dev/null
+++ b/plugins/packagekit/gs-plugin-packagekit-refresh.h
@@ -0,0 +1,22 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2021 Endless OS Foundation LLC
+ *
+ * Author: Philip Withnall <pwithnall endlessos org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#pragma once
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_PLUGIN_PACKAGEKIT_REFRESH (gs_plugin_packagekit_refresh_get_type ())
+
+G_DECLARE_FINAL_TYPE (GsPluginPackagekitRefresh, gs_plugin_packagekit_refresh, GS,
PLUGIN_PACKAGEKIT_REFRESH, GsPlugin)
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]