diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c index 2be6d525..63ad4ec3 100644 --- a/lib/xdg-app-installation.c +++ b/lib/xdg-app-installation.c @@ -557,6 +557,42 @@ xdg_app_installation_list_remotes (XdgAppInstallation *self, return g_steal_pointer (&remotes); } +/** + * xdg_app_installation_get_remote_by_name: + * @self: a #XdgAppInstallation + * @name: a remote name + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Looks up a remote by name. + * + * Returns: (transfer full): a #XdgAppRemote instances, or %NULL error + */ +XdgAppRemote * +xdg_app_installation_get_remote_by_name (XdgAppInstallation *self, + const gchar *name, + GCancellable *cancellable, + GError **error) +{ + XdgAppInstallationPrivate *priv = xdg_app_installation_get_instance_private (self); + g_auto(GStrv) remote_names = NULL; + int i; + + remote_names = xdg_app_dir_list_remotes (priv->dir, cancellable, error); + if (remote_names == NULL) + return NULL; + + for (i = 0; remote_names[i] != NULL; i++) + { + if (strcmp (remote_names[i], name) == 0) + return xdg_app_remote_new (priv->dir, remote_names[i]); + } + + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + "No remote named '%s'", name); + return NULL; +} + char * xdg_app_installation_load_app_overrides (XdgAppInstallation *self, const char *app_id, diff --git a/lib/xdg-app-installation.h b/lib/xdg-app-installation.h index c381384e..16a44e44 100644 --- a/lib/xdg-app-installation.h +++ b/lib/xdg-app-installation.h @@ -114,6 +114,10 @@ XDG_APP_EXTERN XdgAppInstalledRef * xdg_app_installation_get_current_installed_a XDG_APP_EXTERN GPtrArray *xdg_app_installation_list_remotes (XdgAppInstallation *self, GCancellable *cancellable, GError **error); +XDG_APP_EXTERN XdgAppRemote *xdg_app_installation_get_remote_by_name (XdgAppInstallation *self, + const gchar *name, + GCancellable *cancellable, + GError **error); XDG_APP_EXTERN char * xdg_app_installation_load_app_overrides (XdgAppInstallation *self, const char *app_id, GCancellable *cancellable,