[gnome-software: 6/29] gs-plugin-os-release: Port to the new GsPlugin lifecycle
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 6/29] gs-plugin-os-release: Port to the new GsPlugin lifecycle
- Date: Wed, 13 Oct 2021 12:39:53 +0000 (UTC)
commit 652981afa31df7d1b965f10a23f0df5920410c8a
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu May 20 20:33:32 2021 +0100
gs-plugin-os-release: Port to the new GsPlugin lifecycle
Signed-off-by: Philip Withnall <pwithnall endlessos org>
plugins/core/gs-plugin-os-release.c | 65 +++++++++++++++++++++++++------------
plugins/core/gs-plugin-os-release.h | 22 +++++++++++++
2 files changed, 66 insertions(+), 21 deletions(-)
---
diff --git a/plugins/core/gs-plugin-os-release.c b/plugins/core/gs-plugin-os-release.c
index db94ff045..4b57378f7 100644
--- a/plugins/core/gs-plugin-os-release.c
+++ b/plugins/core/gs-plugin-os-release.c
@@ -10,30 +10,39 @@
#include <gnome-software.h>
-struct GsPluginData {
+#include "gs-plugin-os-release.h"
+
+struct _GsPluginOsRelease
+{
+ GsPlugin parent;
+
GsApp *app_system;
};
-void
-gs_plugin_initialize (GsPlugin *plugin)
+G_DEFINE_TYPE (GsPluginOsRelease, gs_plugin_os_release, GS_TYPE_PLUGIN)
+
+static void
+gs_plugin_os_release_dispose (GObject *object)
{
- GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
- priv->app_system = gs_app_new ("system");
- gs_app_set_kind (priv->app_system, AS_COMPONENT_KIND_OPERATING_SYSTEM);
- gs_app_set_state (priv->app_system, GS_APP_STATE_INSTALLED);
+ GsPluginOsRelease *self = GS_PLUGIN_OS_RELEASE (object);
+
+ g_clear_object (&self->app_system);
+
+ G_OBJECT_CLASS (gs_plugin_os_release_parent_class)->dispose (object);
}
-void
-gs_plugin_destroy (GsPlugin *plugin)
+static void
+gs_plugin_os_release_init (GsPluginOsRelease *self)
{
- GsPluginData *priv = gs_plugin_get_data (plugin);
- g_object_unref (priv->app_system);
+ self->app_system = gs_app_new ("system");
+ gs_app_set_kind (self->app_system, AS_COMPONENT_KIND_OPERATING_SYSTEM);
+ gs_app_set_state (self->app_system, GS_APP_STATE_INSTALLED);
}
gboolean
gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
- GsPluginData *priv = gs_plugin_get_data (plugin);
+ GsPluginOsRelease *self = GS_PLUGIN_OS_RELEASE (plugin);
const gchar *cpe_name;
const gchar *home_url;
const gchar *name;
@@ -47,13 +56,13 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
return FALSE;
cpe_name = gs_os_release_get_cpe_name (os_release);
if (cpe_name != NULL)
- gs_app_set_metadata (priv->app_system, "GnomeSoftware::CpeName", cpe_name);
+ gs_app_set_metadata (self->app_system, "GnomeSoftware::CpeName", cpe_name);
name = gs_os_release_get_name (os_release);
if (name != NULL)
- gs_app_set_name (priv->app_system, GS_APP_QUALITY_LOWEST, name);
+ gs_app_set_name (self->app_system, GS_APP_QUALITY_LOWEST, name);
version = gs_os_release_get_version_id (os_release);
if (version != NULL)
- gs_app_set_version (priv->app_system, version);
+ gs_app_set_version (self->app_system, version);
os_id = gs_os_release_get_id (os_release);
@@ -63,7 +72,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
g_autoptr(SoupURI) uri = NULL;
/* homepage */
- gs_app_set_url (priv->app_system, AS_URL_KIND_HOMEPAGE, home_url);
+ gs_app_set_url (self->app_system, AS_URL_KIND_HOMEPAGE, home_url);
/* Build ID from the reverse-DNS URL and the ID and version. */
uri = soup_uri_new (home_url);
@@ -78,7 +87,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
split[0],
(os_id != NULL) ? os_id : "unnamed",
(version != NULL) ? version : "unversioned");
- gs_app_set_id (priv->app_system, id);
+ gs_app_set_id (self->app_system, id);
}
}
}
@@ -95,21 +104,35 @@ gs_plugin_refine_wildcard (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- GsPluginData *priv = gs_plugin_get_data (plugin);
+ GsPluginOsRelease *self = GS_PLUGIN_OS_RELEASE (plugin);
/* match meta-id */
if (g_strcmp0 (gs_app_get_id (app), "system") == 0) {
/* copy over interesting metadata */
if (gs_app_get_install_date (app) != 0 &&
- gs_app_get_install_date (priv->app_system) == 0) {
- gs_app_set_install_date (priv->app_system,
+ gs_app_get_install_date (self->app_system) == 0) {
+ gs_app_set_install_date (self->app_system,
gs_app_get_install_date (app));
}
- gs_app_list_add (list, priv->app_system);
+ gs_app_list_add (list, self->app_system);
return TRUE;
}
/* success */
return TRUE;
}
+
+static void
+gs_plugin_os_release_class_init (GsPluginOsReleaseClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = gs_plugin_os_release_dispose;
+}
+
+GType
+gs_plugin_query_type (void)
+{
+ return GS_TYPE_PLUGIN_OS_RELEASE;
+}
diff --git a/plugins/core/gs-plugin-os-release.h b/plugins/core/gs-plugin-os-release.h
new file mode 100644
index 000000000..9ab9d0d63
--- /dev/null
+++ b/plugins/core/gs-plugin-os-release.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_OS_RELEASE (gs_plugin_os_release_get_type ())
+
+G_DECLARE_FINAL_TYPE (GsPluginOsRelease, gs_plugin_os_release, GS, PLUGIN_OS_RELEASE, GsPlugin)
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]