From 906512bd9be3986e428512db00ba68166428bfa1 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 13 Dec 2021 15:25:03 +0000 Subject: [PATCH 1/2] contrib: Delete example plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s out of date and not tested, so mostly worthless. Signed-off-by: Philip Withnall --- contrib/gs-plugin-example.c | 58 ------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 contrib/gs-plugin-example.c diff --git a/contrib/gs-plugin-example.c b/contrib/gs-plugin-example.c deleted file mode 100644 index 7a366f04b..000000000 --- a/contrib/gs-plugin-example.c +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * vi:set noexpandtab tabstop=8 shiftwidth=8: - * - * Copyright (C) 2016 Richard Hughes - * - * 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 -#include - -/* - * Compile and install with: - * - * |[ - * gcc -shared -o libgs_plugin_example.so gs-plugin-example.c -fPIC \ - * $(pkg-config --libs --cflags gnome-software) \ - * -DI_KNOW_THE_GNOME_SOFTWARE_API_IS_SUBJECT_TO_CHANGE && \ - * cp libgs_plugin_example.so $(pkg-config gnome-software --variable=plugindir) - * ]| - */ - -void -gs_plugin_initialize (GsPlugin *plugin) -{ - gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "appstream"); -} - -gboolean -gs_plugin_add_search (GsPlugin *plugin, - gchar **values, - GsAppList *list, - GCancellable *cancellable, - GError **error) -{ - for (gsize i = 0; values[i] != NULL; i++) { - if (g_strcmp0 (values[i], "fotoshop") == 0) { - g_autoptr(GsApp) app = gs_app_new ("gimp.desktop"); - gs_app_add_quirk (app, GS_APP_QUIRK_IS_WILDCARD); - gs_app_list_add (list, app); - } - } - return TRUE; -} -- GitLab From 42a999f87d7ac0e63cd4f0ff3f16c6bb8add572f Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 13 Dec 2021 15:25:26 +0000 Subject: [PATCH 2/2] docs: Update plugin initialisation documentation In line with the changes from !1114. Signed-off-by: Philip Withnall Helps: #1472 --- doc/api/gnome-software-docs.xml | 48 +++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/doc/api/gnome-software-docs.xml b/doc/api/gnome-software-docs.xml index fbff82664..6f5b77b75 100644 --- a/doc/api/gnome-software-docs.xml +++ b/doc/api/gnome-software-docs.xml @@ -65,9 +65,12 @@ - The plugin only needs to define the vfuncs that are required, and the + The plugin needs to create a class derived from GsPlugin, + and define the vfuncs that it needs. The plugin name is taken automatically from the suffix of the - .so file. + .so file. The type of the plugin is exposed to + gnome-software using gs_plugin_query_type(), which + must be exported from the module. A sample plugin @@ -79,9 +82,19 @@ #include <glib.h> #include <gnome-software.h> -void -gs_plugin_initialize (GsPlugin *plugin) +struct _GsPluginSample { + GsPlugin parent; + + /* private data here */ +}; + +G_DEFINE_TYPE (GsPluginSample, gs_plugin_sample, GS_TYPE_PLUGIN) + +static void +gs_plugin_sample_init (GsPluginSample *self) { + GsPlugin *plugin = GS_PLUGIN (self); + gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "appstream"); } @@ -101,6 +114,17 @@ gs_plugin_add_search (GsPlugin *plugin, } return TRUE; } + +static void +gs_plugin_sample_class_init (GsPluginSampleClass *klass) +{ +} + +GType +gs_plugin_query_type (void) +{ + return GS_TYPE_PLUGIN_SAMPLE; +} @@ -149,14 +173,16 @@ cp libgs_plugin_example.so $(pkg-config gnome-software --variable=plugindir) Self disabling on other distributions -void -gs_plugin_initialize (GsPlugin *plugin) +static void +gs_plugin_sample_init (GsPluginSample *self) { + GsPlugin *plugin = GS_PLUGIN (self); + if (!gs_plugin_check_distro_id (plugin, "ubuntu")) { gs_plugin_set_enabled (plugin, FALSE); return; } - /* allocate private data etc. */ + /* set up private data etc. */ } @@ -177,11 +203,11 @@ gs_plugin_initialize (GsPlugin *plugin) Example showing a custom installed application -#include <gnome-software.h> - -void -gs_plugin_initialize (GsPlugin *plugin) +static void +gs_plugin_sample_init (GsPluginSample *self) { + GsPlugin *plugin = GS_PLUGIN (self); + gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "icons"); } -- GitLab