summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-02-18 11:40:48 +0100
committerAlexander Larsson <alexl@redhat.com>2016-02-18 11:40:48 +0100
commit3d18255ba35a461e9db4ccfe60389cbcde2550ca (patch)
tree260e404abc71ccbee202a59aeb4f26ac22fcccea /lib
parent5a7e894edd53a8159b478f4190d1cd05950c1a05 (diff)
downloadxdg-app-3d18255ba35a461e9db4ccfe60389cbcde2550ca.tar.gz
Add xdg_app_installation_get_remote_by_name
Diffstat (limited to 'lib')
-rw-r--r--lib/xdg-app-installation.c36
-rw-r--r--lib/xdg-app-installation.h4
2 files changed, 40 insertions, 0 deletions
diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c
index 2be6d52..63ad4ec 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 c381384..16a44e4 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,