GsPlugin Helpers

GsPlugin Helpers — Runtime-loaded modules providing functionality

Stability Level

Unstable, unless otherwise indicated

Functions

Properties

guint64 flags Read / Write

Signals

Types and Values

Object Hierarchy

    GObject
    ╰── GsPlugin

Includes

#include <gnome-software.h>

Description

Plugins are modules that are loaded at runtime to provide information about requests and to service user actions like installing, removing and updating. This allows different distributions to pick and choose how the application installer gathers data.

Plugins also have a priority system where the largest number gets run first. That means if one plugin requires some property or metadata set by another plugin then it **must** depend on the other plugin to be run in the correct order.

As a general rule, try to make plugins as small and self-contained as possible and remember to cache as much data as possible for speed. Memory is cheap, time less so.

Functions

gs_plugin_alloc_data ()

GsPluginData *
gs_plugin_alloc_data (GsPlugin *plugin,
                      gsize sz);

Allocates a private data area for the plugin which can be retrieved using gs_plugin_get_data(). This is normally called in gs_plugin_initialize() and the data should not be manually freed.

Parameters

plugin

a GsPlugin

 

sz

the size of data to allocate, e.g. sizeof(FooPluginPrivate)

 

Returns

the GsPluginData, cleared to NUL butes


gs_plugin_get_data ()

GsPluginData *
gs_plugin_get_data (GsPlugin *plugin);

Gets the private data for the plugin if gs_plugin_alloc_data() has been called.

Parameters

plugin

a GsPlugin

 

Returns

the GsPluginData, or NULL


gs_plugin_get_name ()

const gchar *
gs_plugin_get_name (GsPlugin *plugin);

Gets the plugin name.

Parameters

plugin

a GsPlugin

 

Returns

a string, e.g. "fwupd"


gs_plugin_get_enabled ()

gboolean
gs_plugin_get_enabled (GsPlugin *plugin);

Gets if the plugin is enabled.

Parameters

plugin

a GsPlugin

 

Returns

TRUE if enabled


gs_plugin_set_enabled ()

void
gs_plugin_set_enabled (GsPlugin *plugin,
                       gboolean enabled);

Enables or disables a plugin. This is normally only called from gs_plugin_initialize().

Parameters

plugin

a GsPlugin

 

enabled

the enabled state

 

gs_plugin_has_flags ()

gboolean
gs_plugin_has_flags (GsPlugin *plugin,
                     GsPluginFlags flags);

Finds out if a plugin has a specific flag set.

Parameters

plugin

a GsPlugin

 

flags

a GsPluginFlags, e.g. GS_PLUGIN_FLAGS_RUNNING_SELF

 

Returns

TRUE if the flag is set


gs_plugin_get_scale ()

guint
gs_plugin_get_scale (GsPlugin *plugin);

Gets the window scale factor.

Parameters

plugin

a GsPlugin

 

Returns

the factor, usually 1 for standard screens or 2 for HiDPI


gs_plugin_get_locale ()

const gchar *
gs_plugin_get_locale (GsPlugin *plugin);

Gets the user locale.

Parameters

plugin

a GsPlugin

 

Returns

the locale string, e.g. "en_GB"


gs_plugin_get_profile ()

AsProfile *
gs_plugin_get_profile (GsPlugin *plugin);

Gets the profile object to be used for the plugin. This can be used to make plugin actions appear in the global profile output.

Parameters

plugin

a GsPlugin

 

Returns

the AsProfile


gs_plugin_get_soup_session ()

SoupSession *
gs_plugin_get_soup_session (GsPlugin *plugin);

Gets the soup session that plugins can use when downloading.

Parameters

plugin

a GsPlugin

 

Returns

the SoupSession


gs_plugin_add_rule ()

void
gs_plugin_add_rule (GsPlugin *plugin,
                    GsPluginRule rule,
                    const gchar *name);

If the plugin name is found, the rule will be used to sort the plugin list, for example the plugin specified by name will be ordered after this plugin when GS_PLUGIN_RULE_RUN_AFTER is used.

NOTE: The depsolver is iterative and may not solve overly-complicated rules; If depsolving fails then gnome-software will not start.

Parameters

plugin

a GsPlugin

 

rule

a GsPluginRule, e.g. GS_PLUGIN_RULE_CONFLICTS

 

name

a plugin name, e.g. "appstream"

 

gs_plugin_download_data ()

GBytes *
gs_plugin_download_data (GsPlugin *plugin,
                         GsApp *app,
                         const gchar *uri,
                         GCancellable *cancellable,
                         GError **error);

Downloads data.

Parameters

plugin

a GsPlugin

 

app

a GsApp, or NULL

 

uri

a remote URI

 

cancellable

a GCancellable, or NULL

 

error

a GError, or NULL

 

Returns

the downloaded data, or NULL


gs_plugin_download_file ()

gboolean
gs_plugin_download_file (GsPlugin *plugin,
                         GsApp *app,
                         const gchar *uri,
                         const gchar *filename,
                         GCancellable *cancellable,
                         GError **error);

Downloads data and saves it to a file.

Parameters

plugin

a GsPlugin

 

app

a GsApp, or NULL

 

uri

a remote URI

 

filename

a local filename

 

cancellable

a GCancellable, or NULL

 

error

a GError, or NULL

 

Returns

TRUE for success


gs_plugin_check_distro_id ()

gboolean
gs_plugin_check_distro_id (GsPlugin *plugin,
                           const gchar *distro_id);

Checks if the distro is compatible.

Parameters

plugin

a GsPlugin

 

distro_id

a distro ID, e.g. "fedora"

 

Returns

TRUE if compatible


gs_plugin_cache_lookup ()

GsApp *
gs_plugin_cache_lookup (GsPlugin *plugin,
                        const gchar *key);

Looks up an application object from the per-plugin cache

Parameters

plugin

a GsPlugin

 

key

a string

 

Returns

the GsApp, or NULL.

[transfer full][nullable]


gs_plugin_cache_add ()

void
gs_plugin_cache_add (GsPlugin *plugin,
                     const gchar *key,
                     GsApp *app);

Adds an application to the per-plugin cache. This is optional, and the plugin can use the cache however it likes.

Parameters

plugin

a GsPlugin

 

key

a string

 

app

a GsApp

 

gs_plugin_cache_invalidate ()

void
gs_plugin_cache_invalidate (GsPlugin *plugin);

Invalidate the per-plugin cache by marking all entries as invalid. This is optional, and the plugin can evict the cache whenever it likes.

Parameters

plugin

a GsPlugin

 

gs_plugin_status_update ()

void
gs_plugin_status_update (GsPlugin *plugin,
                         GsApp *app,
                         GsPluginStatus status);

Update the state of the plugin so any UI can be updated.

Parameters

plugin

a GsPlugin

 

app

a GsApp, or NULL

 

status

a GsPluginStatus, e.g. GS_PLUGIN_STATUS_DOWNLOADING

 

gs_plugin_app_launch ()

gboolean
gs_plugin_app_launch (GsPlugin *plugin,
                      GsApp *app,
                      GError **error);

Launches the application using GAppInfo.

Parameters

plugin

a GsPlugin

 

app

a GsApp

 

error

a GError, or NULL

 

Returns

TRUE for success


gs_plugin_updates_changed ()

void
gs_plugin_updates_changed (GsPlugin *plugin);

Emit a signal that tells the plugin loader that the list of updates may have changed.

Parameters

plugin

a GsPlugin

 

gs_plugin_status_to_string ()

const gchar *
gs_plugin_status_to_string (GsPluginStatus status);

Converts the GsPluginStatus enum to a string.

Parameters

Returns

the string representation, or "unknown"

Types and Values

GS_TYPE_PLUGIN

#define GS_TYPE_PLUGIN (gs_plugin_get_type ())

struct GsPluginClass

struct GsPluginClass {
	GObjectClass		 parent_class;
	void			(*updates_changed) (GsPlugin *plugin);
	void			(*status_changed) (GsPlugin *plugin,
							 GsApp		*app,
							 guint		 status);
	gpointer		 padding[29];
};

GsPluginData

typedef struct GsPluginData GsPluginData;

enum GsPluginStatus

The ststus of the plugin.

Members

GS_PLUGIN_STATUS_UNKNOWN

Unknown status

 

GS_PLUGIN_STATUS_WAITING

Waiting

 

GS_PLUGIN_STATUS_FINISHED

Finished

 

GS_PLUGIN_STATUS_SETUP

Setup in progress

 

GS_PLUGIN_STATUS_DOWNLOADING

Downloading in progress

 

GS_PLUGIN_STATUS_QUERYING

Querying in progress

 

GS_PLUGIN_STATUS_INSTALLING

Installing in progress

 

GS_PLUGIN_STATUS_REMOVING

Removing in progress

 

enum GsPluginFlags

The flags for the plugin at this point in time.

Members

GS_PLUGIN_FLAGS_NONE

No flags set

 

GS_PLUGIN_FLAGS_RUNNING_SELF

The plugin is running

 

GS_PLUGIN_FLAGS_RUNNING_OTHER

Another plugin is running

 

GS_PLUGIN_FLAGS_EXCLUSIVE

An exclusive action is running

 

GS_PLUGIN_FLAGS_RECENT

This plugin recently ran

 

enum GsPluginError

The failure error types.

Members

GS_PLUGIN_ERROR_FAILED

Generic failure

 

GS_PLUGIN_ERROR_NOT_SUPPORTED

Action not supported

 

GS_PLUGIN_ERROR_CANCELLED

Action was cancelled

 

GS_PLUGIN_ERROR_NO_NETWORK

No network connection available

 

GS_PLUGIN_ERROR_NO_SECURITY

Security policy forbid action

 

GS_PLUGIN_ERROR_NO_SPACE

No disk space to allow action

 

enum GsPluginRefineFlags

The refine flags.

Members

GS_PLUGIN_REFINE_FLAGS_DEFAULT

No explicit flags set

 

GS_PLUGIN_REFINE_FLAGS_USE_HISTORY

Get the historical view

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE

Require the license

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_URL

Require the URL

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_DESCRIPTION

Require the long description

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE

Require the installed and download sizes

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING

Require the rating

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION

Require the version

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_HISTORY

Require the history

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION

Require enough to install or remove the package

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS

Require update details

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN

Require the origin

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_RELATED

Require related packages

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH

Require the menu path

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_ADDONS

Require available addons

 

GS_PLUGIN_REFINE_FLAGS_ALLOW_PACKAGES

Allow packages to be returned

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_SEVERITY

Require update severity

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPGRADE_REMOVED

Require distro upgrades

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE

Require the provenance

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS

Require user-reviews

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS

Require user-ratings

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_KEY_COLORS

Require the key colors

 

GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON

Require the icon to be loaded

 

enum GsPluginRefreshFlags

The flags used for refresh. Regeneration and downloading is only done if the cache is older than the cache_age.

The GS_PLUGIN_REFRESH_FLAGS_METADATA can be used to make sure there's enough metadata to start the application. The GS_PLUGIN_REFRESH_FLAGS_PAYLOAD flag should only be used when the session is idle and bandwidth is unmetered as the amount of data and IO may be large.

Members

GS_PLUGIN_REFRESH_FLAGS_NONE

Generate new metadata if possible

 

GS_PLUGIN_REFRESH_FLAGS_METADATA

Download new metadata

 

GS_PLUGIN_REFRESH_FLAGS_PAYLOAD

Download any pending payload

 

enum GsPluginRule

The rules used for ordering plugins. Plugins are expected to add rules in gs_plugin_initialize().

Members

GS_PLUGIN_RULE_CONFLICTS

The plugin conflicts with another

 

GS_PLUGIN_RULE_RUN_AFTER

Order the plugin after another

 

GS_PLUGIN_RULE_RUN_BEFORE

Order the plugin before another

 

GS_PLUGIN_ERROR

#define GS_PLUGIN_ERROR					1

GsPlugin

typedef struct _GsPlugin GsPlugin;

Property Details

The “flags” property

  “flags”                    guint64

Flags: Read / Write

Default value: 0

Signal Details

The “status-changed” signal

void
user_function (GsPlugin *gsplugin,
               GsApp    *arg1,
               guint     arg2,
               gpointer  user_data)

Flags: Run Last


The “updates-changed” signal

void
user_function (GsPlugin *gsplugin,
               gpointer  user_data)

Flags: Run Last