| Top |
These functions provide useful functionality that makes it easy to add new plugin functions.
gchar * gs_utils_get_content_type (GFile *file,GCancellable *cancellable,GError **error);
Gets the standard content type for a file.
void gs_utils_get_content_type_async (GFile *file,GCancellable *cancellable,GAsyncReadyCallback callback,gpointer user_data);
Asynchronously get the standard content type for the file
.
Finish the operation with gs_utils_get_content_type_finish
.
file |
a GFile |
|
cancellable |
a GCancellable, or |
|
callback |
callback for when the asynchronous operation is complete |
|
user_data |
data to pass to |
Since: 47
gchar * gs_utils_get_content_type_finish (GFile *file,GAsyncResult *result,GError **error);
Finish an asynchronous operation started with gs_utils_get_content_type_async().
file |
a GFile |
|
result |
result of the asynchronous operation |
|
error |
return location for a GError, or |
Since: 47
gboolean gs_utils_symlink (const gchar *target,const gchar *linkpath,GError **error);
Creates a symlink that can cross filesystem boundaries. Any parent directories needed for target to exist are also created.
gboolean gs_utils_unlink (const gchar *filename,GError **error);
Deletes a file from disk.
gboolean gs_mkdir_parent (const gchar *path,GError **error);
Creates any required directories, including any parent directories.
gchar * gs_utils_get_cache_filename (const gchar *kind,const gchar *resource,GsUtilsCacheFlags flags,GError **error);
Returns a filename that points into the cache.
This may be per-system or per-user, the latter being more likely
when GS_UTILS_CACHE_FLAG_WRITEABLE is specified in flags
.
If GS_UTILS_CACHE_FLAG_USE_HASH is set in flags
then the returned filename
will contain the hashed version of resource
.
If there is more than one match, the file that has been modified last is returned.
If a plugin requests a file to be saved in the cache it is the plugins
responsibility to remove the file when it is no longer valid or is too old
-- gnome-software will not ever clean the cache for the plugin.
For this reason it is a good idea to use the plugin name as kind
.
This function can only fail if GS_UTILS_CACHE_FLAG_ENSURE_EMPTY or
GS_UTILS_CACHE_FLAG_CREATE_DIRECTORY are passed in flags
.
kind |
A cache kind, e.g. "fwupd" or "screenshots/123x456" |
|
resource |
A resource, e.g. "system.bin" or "http://foo.bar/baz.bin" |
|
flags |
Some GsUtilsCacheFlags, e.g. |
|
error |
A GError, or |
gchar *
gs_utils_get_user_hash (GError **error);
This SHA1 hash is composed of the contents of machine-id and your username and is also salted with a hardcoded value.
This provides an identifier that can be used to identify a specific user on a machine, allowing them to cast only one vote or perform one review on each app.
There is no known way to calculate the machine ID or username from the machine hash and there should be no privacy issue.
GPermission * gs_utils_get_permission (const gchar *id,GCancellable *cancellable,GError **error);
Gets a permission object for an ID.
void gs_utils_get_permission_async (const gchar *id,GCancellable *cancellable,GAsyncReadyCallback callback,gpointer user_data);
Asynchronously gets a GPermission object representing the given polkit
action id
.
id |
a polkit action ID, for example |
|
cancellable |
a GCancellable, or |
[nullable] |
callback |
callback for when the asynchronous operation is complete |
|
user_data |
data to pass to |
Since: 42
GPermission * gs_utils_get_permission_finish (GAsyncResult *result,GError **error);
Finish an asynchronous operation started with gs_utils_get_permission_async().
Since: 42
gboolean gs_utils_strv_fnmatch (gchar **strv,const gchar *str);
Matches a string against a list of globs.
gchar *
gs_utils_sort_key (const gchar *str);
Useful to sort strings in a locale-sensitive, presentational way. Case is ignored and utf8 collation is used (e.g. accents are ignored).
gint gs_utils_sort_strcmp (const gchar *str1,const gchar *str2);
Compares two strings in a locale-sensitive, presentational way.
Case is ignored and utf8 collation is used (e.g. accents are ignored). NULL
is sorted before all non-NULL strings, and NULLs compare equal.
GDesktopAppInfo *
gs_utils_get_desktop_app_info (const gchar *id);
Gets a a GDesktopAppInfo taking into account the kde4- prefix.
If the given id
doesn not have a ".desktop" suffix, it will add one to it
for convenience.
gboolean gs_utils_rmtree (const gchar *directory,GError **error);
Deletes a directory from disk and all its contents.
unsigned int gs_utils_estimate_average_rating_score (const uint64_t *score_values,size_t n_scores,const uint64_t *votes,gboolean *out_should_show_score);
Estimates an average rating score for an app, using the given votes
and the
star scale of score_values
.
This behaves similarly to the simple mean of the votes, but it does some
statistics to calculate a confidence interval on the result. This means that
the average rating can be hidden if there have not been enough votes to give
a confident mean rating. See out_should_show_score
.
The properties that we want for the user interface are:
Users can rate apps on a 1-5 star scale.
We show an ‘average’ rating for an app, on the same scale, by combining the votes weighted by their star score value.
The ‘average’ rating for an app must be recognisable to users as being an average of the votes histogram.
Small numbers of votes (a small sample size) must not allow apps to be disproportionately ranked. For example, an app with 1 vote of 5/5 must not be ranked more highly than an app with 200 votes of 4/5 and 200 votes of 5/5.
The ‘average’ rating shown for an app must be equal to the rating used for ranking purposes, or apps may appear to be sorted out of order to users.
All these properties can be achieved by this approach proposed by Evan Miller which we implement.
At a high level:
Submitted user votes are treated as samples of a larger population of all users’ opinions of an app.
Statistics are used to estimate the mean and variance of the population average.
The variance is used to give a credible interval on the population average, and the lower bound of this credible interval is used as the ‘average’ rating.
If the credible interval is too wide, the ‘average’ rating should not be shown, because there have not been enough votes to make it meaningful.
The acceptable credible interval is currently set at 0.5 (i.e. half a star),
as users will not notice/care about that difference between the ‘average’
given in the UI and the mean of the votes histogram. The ‘average’ rating is
currently shown to a 0.1 star granularity (e.g. ‘4.1 out of 5’), so if we
wanted to guarantee the ‘average’ matching the votes histogram we should set
acceptable_credible_interval = 0.1. However, this would require at least
176 votes for each app (using 90% confidence), assuming all voters voted in
consensus. It would need 4344 votes if voting was polarised. Given that most
apps receive 10-50 votes (and only a handful of apps receive more), requiring
this level of credibility is not practical.
Similarly for the confidence interval, we’ve chosen 90% confidence as anything higher would require too many votes.
According to https://www.evanmiller.org/ranking-items-with-star-ratings.htmltable for w = 0.5 and 90% confidence, a credible interval can be achieved with 81 uniformly distributed votes, 31 consensus votes, or 168 polarised votes.
score_values |
array of possible rating scores and
their values; for a 1-5 star scale, this would be |
[array length=n_scores] |
n_scores |
length of |
|
votes |
array of number of votes for each score,
indexed the same as |
[array length=n_scores] |
out_should_show_score |
return location for a boolean indicating if there have been enough votes to be able to reliably show an average score. |
[out][optional] |
void gs_utils_error_add_app_id (GError **error,GsApp *app);
Adds app unique ID prefix to the error.
Since: 3.30
void gs_utils_error_add_origin_id (GError **error,GsApp *origin);
Adds origin unique ID prefix to the error.
Since: 3.30
gchar *
gs_utils_error_strip_app_id (GError *error);
Removes a possible app ID prefix from the error, and returns the removed app ID.
Since: 3.30
gchar *
gs_utils_error_strip_origin_id (GError *error);
Removes a possible origin ID prefix from the error, and returns the removed origin ID.
Since: 3.30
gboolean
gs_utils_error_convert_gio (GError **perror);
Converts the GIOError to an error with a GsPluginError domain.
gboolean
gs_utils_error_convert_gresolver (GError **perror);
Converts the GResolverError to an error with a GsPluginError domain.
gboolean
gs_utils_error_convert_gdbus (GError **perror);
Converts the GDBusError to an error with a GsPluginError domain.
gboolean
gs_utils_error_convert_gdk_pixbuf (GError **perror);
Converts the GdkPixbufError to an error with a GsPluginError domain.
gboolean
gs_utils_error_convert_appstream (GError **perror);
Converts the various AppStream error types to an error with a GsPluginError domain.
gchar *
gs_utils_get_url_scheme (const gchar *url);
Gets the scheme from the URL string.
gchar *
gs_utils_get_url_path (const gchar *url);
Gets the path from the URL string, removing any leading slashes.
const gchar *
gs_user_agent (void);
Gets the user agent to use for remote requests.
void gs_utils_append_key_value (GString *str,gsize align_len,const gchar *key,const gchar *value);
Adds a line to an existing string, padding the key to a set number of spaces.
str |
A GString |
|
align_len |
The alignment of the |
|
key |
The text to use as a title |
|
value |
The text to use as a value |
Since: 3.26
gboolean gs_utils_parse_evr (const gchar *evr,gchar **out_epoch,gchar **out_version,gchar **out_release);
gchar *
gs_utils_unique_id_compat_convert (const gchar *data_id);
Converts the unique ID string from its legacy 6-part form into a new-style 5-part AppStream data-id. Does nothing if the string is already valid.
See !583 for the history of this conversion.
A newly allocated string with the new-style data-id, or NULL if input was no valid ID.
[nullable]
Since: 40
gchar * gs_utils_build_unique_id (AsComponentScope scope,AsBundleKind bundle_kind,const gchar *origin,const gchar *cid,const gchar *branch);
Builds an identifier string unique to the individual dataset using the supplied information.
It's similar to as_utils_build_data_id(), except it respects the origin
for the packages.
scope |
Scope of the metadata as AsComponentScope e.g. |
|
bundle_kind |
Bundling system providing this data, e.g. 'package' or 'flatpak' |
|
origin |
Origin string, e.g. 'os' or 'gnome-apps-nightly' |
|
cid |
AppStream component ID, e.g. 'org.freedesktop.appstream.cli' |
|
branch |
Branch, e.g. '3-20' or 'master' |
Since: 41
void gs_utils_pixbuf_blur (GdkPixbuf *src,guint radius,guint iterations);
Blurs an image. Warning, this method is s..l..o..w... for large images.
gboolean (*GsFileSizeIncludeFunc) (const gchar *filename,GFileTest file_kind,gpointer user_data);
Check whether include the filename
in the size calculation.
The filename
is a relative path to the file name passed to
the GsFileSizeIncludeFunc.
filename |
file name to check |
|
file_kind |
the file kind, one of GFileTest enums |
|
user_data |
a user data passed to the |
Since: 41
guint64 gs_utils_get_file_size (const gchar *filename,GsFileSizeIncludeFunc include_func,gpointer user_data,GCancellable *cancellable);
Gets the size of the file or a directory identified by filename
.
When the include_func
is not NULL, it can limit which files are included
in the resulting size. When it's NULL, all files and subdirectories are included.
filename |
a file name to get the size of; it can be a file or a directory |
|
include_func |
optional callback to limit what files to count. |
[nullable][scope call] |
user_data |
user data passed to the |
|
cancellable |
an optional GCancellable or |
[nullable] |
Since: 41
gchar * gs_utils_get_file_etag (GFile *file,GDateTime **last_modified_date_out,GCancellable *cancellable);
Gets the ETag for the file
, previously stored by
gs_utils_set_file_etag().
file |
a file to get the ETag for |
|
last_modified_date_out |
return location for the last modified date of the file ( |
[out callee-allocates][transfer full][optional][nullable] |
cancellable |
an optional GCancellable or |
[nullable] |
The ETag stored for the file
,
or NULL, when the file does not exist, no ETag is stored for it
or other error occurs.
Since: 43
gboolean gs_utils_set_file_etag (GFile *file,const gchar *etag,GCancellable *cancellable);
Sets the ETag for the file
. When the etag
is NULL or an empty
string, then unsets the ETag for the file
. The ETag can be read
back with gs_utils_get_file_etag().
The file
should exist, otherwise the function fails.
Since: 42
gchar *
gs_utils_get_upgrade_background (const gchar *version);
Get the path to a background image to display as the background for a banner
advertising an upgrade to the given version
.
If a path is returned, it’s guaranteed to exist on the file system.
Vendors can drop their customised backgrounds in this directory for them to
be used by gnome-software. See doc/vendor-customisation.md.
version |
version string of the upgrade (which must be non-empty
if provided), or |
[nullable] |
path to an upgrade
background image to use, or NULL if a suitable one didn’t exist.
[transfer full][type filename][nullable]
Since: 42
gint gs_utils_app_sort_name (GsApp *app1,GsApp *app2,gpointer user_data);
Comparison function to sort apps in increasing alphabetical order of name.
This is suitable for passing to gs_app_list_sort().
Since: 43
gint gs_utils_app_sort_match_value (GsApp *app1,GsApp *app2,gpointer user_data);
Comparison function to sort apps in decreasing order of match value (“match-value”).
This is suitable for passing to gs_app_list_sort().
Since: 43
gint gs_utils_app_sort_priority (GsApp *app1,GsApp *app2,gpointer user_data);
Comparison function to sort apps in increasing order of their priority (“priority”).
This is suitable for passing to gs_app_list_sort().
Since: 43
void gs_utils_gstring_replace (GString *str,const gchar *find,const gchar *replace);
Replaces all find
occurrences in str
with replace
.
str |
a GString to replace the text in |
|
find |
a text to find |
|
replace |
a text to replace the found text with |
Since: 45
gint gs_utils_app_sort_kind (GsApp *app1,GsApp *app2);
Comparison function to sort apps by Appstream kind, then by increasing alphabetical order of name.
This is useful for sorting apps with multiple kinds (E.g Updates / Updated pages), as opposed to category pages where all apps are of the same kind.
Since: 47
gint gs_utils_compare_versions (const gchar *ver1,const gchar *ver2);
Compares ver1
and ver2
, return value as , that is, a number
below zero, when the strcmp()ver1
is before ver2
zero, when ver1
is the same
as ver2
, and a number above zero, when ver1
is lower than ver2
.
Since: 48