diff --git a/contrib/gs-plugin-example.c b/contrib/gs-plugin-example.c deleted file mode 100644 index 7a366f04ba514cf56744ac53246aa006742b9eea..0000000000000000000000000000000000000000 --- 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; -} diff --git a/doc/api/gnome-software-docs.xml b/doc/api/gnome-software-docs.xml index fbff82664d73131e89623f46f400430c11f3f6f2..6f5b77b75f4c59bdc68bb849a4a159d03f8fcba5 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"); }