lib: Change how listing installed refs work

Now we return a GPtrArray, and the main call returns both apps
and runtimes, and a new _by_kind version lets you get only a specific one.
tingping/wmclass
Alexander Larsson 2015-12-17 19:50:40 +01:00
parent dd7693b99e
commit b9c582bc75
3 changed files with 119 additions and 41 deletions

View File

@ -18,11 +18,9 @@ int
main (int argc, char *argv[])
{
XdgAppInstallation *installation;
XdgAppInstalledRef **apps;
XdgAppRemoteRef **refs;
XdgAppInstalledRef *app1;
XdgAppInstalledRef *app2;
XdgAppInstalledRef **runtimes;
XdgAppRemoteRef *remote_ref;
XdgAppRemote **remotes;
GError *error = NULL;
@ -65,42 +63,75 @@ main (int argc, char *argv[])
return 0;
}
g_print ("**** Listing all installed apps\n");
apps = xdg_app_installation_list_installed_refs (installation,
XDG_APP_REF_KIND_APP,
NULL, NULL);
g_print ("\n**** Listing all installed refs\n");
{
g_autoptr(GPtrArray) refs = NULL;
for (i = 0; apps[i] != NULL; i++)
{
g_print ("%d %s %s %s %s %s %s %d\n",
xdg_app_ref_get_kind (XDG_APP_REF(apps[i])),
xdg_app_ref_get_name (XDG_APP_REF(apps[i])),
xdg_app_ref_get_arch (XDG_APP_REF(apps[i])),
xdg_app_ref_get_version (XDG_APP_REF(apps[i])),
xdg_app_ref_get_commit (XDG_APP_REF(apps[i])),
xdg_app_installed_ref_get_origin (apps[i]),
xdg_app_installed_ref_get_deploy_dir (apps[i]),
xdg_app_installed_ref_get_current (apps[i]));
g_print ("metadata:\n%s\n", xdg_app_installed_ref_load_metadata (apps[i], NULL, NULL));
}
refs = xdg_app_installation_list_installed_refs (installation,
NULL, NULL);
for (i = 0; i < refs->len; i++)
{
XdgAppInstalledRef *ref = g_ptr_array_index(refs,i);
g_print ("%d %s %s %s %s %s %s %d\n",
xdg_app_ref_get_kind (XDG_APP_REF(ref)),
xdg_app_ref_get_name (XDG_APP_REF(ref)),
xdg_app_ref_get_arch (XDG_APP_REF(ref)),
xdg_app_ref_get_version (XDG_APP_REF(ref)),
xdg_app_ref_get_commit (XDG_APP_REF(ref)),
xdg_app_installed_ref_get_origin (ref),
xdg_app_installed_ref_get_deploy_dir (ref),
xdg_app_installed_ref_get_current (ref));
}
}
g_print ("**** Listing all installed apps\n");
{
g_autoptr(GPtrArray) apps = NULL;
apps = xdg_app_installation_list_installed_refs_by_kind (installation,
XDG_APP_REF_KIND_APP,
NULL, NULL);
for (i = 0; i < apps->len; i++)
{
XdgAppInstalledRef *app = g_ptr_array_index(apps,i);
g_print ("%d %s %s %s %s %s %s %d\n",
xdg_app_ref_get_kind (XDG_APP_REF(app)),
xdg_app_ref_get_name (XDG_APP_REF(app)),
xdg_app_ref_get_arch (XDG_APP_REF(app)),
xdg_app_ref_get_version (XDG_APP_REF(app)),
xdg_app_ref_get_commit (XDG_APP_REF(app)),
xdg_app_installed_ref_get_origin (app),
xdg_app_installed_ref_get_deploy_dir (app),
xdg_app_installed_ref_get_current (app));
g_print ("metadata:\n%s\n", xdg_app_installed_ref_load_metadata (app, NULL, NULL));
}
}
g_print ("\n**** Listing all installed runtimes\n");
runtimes = xdg_app_installation_list_installed_refs (installation,
XDG_APP_REF_KIND_RUNTIME,
NULL, NULL);
{
g_autoptr(GPtrArray) runtimes = NULL;
for (i = 0; runtimes[i] != NULL; i++)
{
g_print ("%d %s %s %s %s %s %s %d\n",
xdg_app_ref_get_kind (XDG_APP_REF(runtimes[i])),
xdg_app_ref_get_name (XDG_APP_REF(runtimes[i])),
xdg_app_ref_get_arch (XDG_APP_REF(runtimes[i])),
xdg_app_ref_get_version (XDG_APP_REF(runtimes[i])),
xdg_app_ref_get_commit (XDG_APP_REF(runtimes[i])),
xdg_app_installed_ref_get_origin (runtimes[i]),
xdg_app_installed_ref_get_deploy_dir (runtimes[i]),
xdg_app_installed_ref_get_current (runtimes[i]));
}
runtimes = xdg_app_installation_list_installed_refs_by_kind (installation,
XDG_APP_REF_KIND_RUNTIME,
NULL, NULL);
for (i = 0; i < runtimes->len; i++)
{
XdgAppInstalledRef *runtime = g_ptr_array_index(runtimes,i);
g_print ("%d %s %s %s %s %s %s %d\n",
xdg_app_ref_get_kind (XDG_APP_REF(runtime)),
xdg_app_ref_get_name (XDG_APP_REF(runtime)),
xdg_app_ref_get_arch (XDG_APP_REF(runtime)),
xdg_app_ref_get_version (XDG_APP_REF(runtime)),
xdg_app_ref_get_commit (XDG_APP_REF(runtime)),
xdg_app_installed_ref_get_origin (runtime),
xdg_app_installed_ref_get_deploy_dir (runtime),
xdg_app_installed_ref_get_current (runtime));
}
}
g_print ("\n**** Getting installed gedit master\n");
app1 = xdg_app_installation_get_installed_ref (installation,

View File

@ -263,20 +263,65 @@ xdg_app_installation_get_current_installed_app (XdgAppInstallation *self,
/**
* xdg_app_installation_list_installed_refs:
* @self: a #XdgAppInstallation
* @kind: the kind of installation
* @cancellable: (nullable): a #GCancellable
* @error: return location for a #GError
*
* Lists the installed references.
*
* Returns: (transfer full) (array zero-terminated=1): an array of
* Returns: (transfer container) (element-type XdgAppInstalledRef): an GPtrArray of
* #XdgAppInstalledRef instances
*/
XdgAppInstalledRef **
GPtrArray *
xdg_app_installation_list_installed_refs (XdgAppInstallation *self,
XdgAppRefKind kind,
GCancellable *cancellable,
GError **error)
{
XdgAppInstallationPrivate *priv = xdg_app_installation_get_instance_private (self);
g_auto(GStrv) raw_refs_app = NULL;
g_auto(GStrv) raw_refs_runtime = NULL;
g_autoptr(GPtrArray) refs = g_ptr_array_new_with_free_func (g_object_unref);
int i;
if (!xdg_app_dir_list_refs (priv->dir,
"app",
&raw_refs_app,
cancellable, error))
return NULL;
for (i = 0; raw_refs_app[i] != NULL; i++)
g_ptr_array_add (refs,
get_ref (self, raw_refs_app[i], cancellable));
if (!xdg_app_dir_list_refs (priv->dir,
"runtime",
&raw_refs_runtime,
cancellable, error))
return NULL;
for (i = 0; raw_refs_runtime[i] != NULL; i++)
g_ptr_array_add (refs,
get_ref (self, raw_refs_runtime[i], cancellable));
return g_steal_pointer (&refs);
}
/**
* xdg_app_installation_list_installed_refs_by_kind:
* @self: a #XdgAppInstallation
* @kind: the kind of installation
* @cancellable: (nullable): a #GCancellable
* @error: return location for a #GError
*
* Lists the installed references of a specific kind.
*
* Returns: (transfer container) (element-type XdgAppInstalledRef): an GPtrArray of
* #XdgAppInstalledRef instances
*/
GPtrArray *
xdg_app_installation_list_installed_refs_by_kind (XdgAppInstallation *self,
XdgAppRefKind kind,
GCancellable *cancellable,
GError **error)
{
XdgAppInstallationPrivate *priv = xdg_app_installation_get_instance_private (self);
g_auto(GStrv) raw_refs = NULL;
@ -293,8 +338,7 @@ xdg_app_installation_list_installed_refs (XdgAppInstallation *self,
g_ptr_array_add (refs,
get_ref (self, raw_refs[i], cancellable));
g_ptr_array_add (refs, NULL);
return (XdgAppInstalledRef **)g_ptr_array_free (g_steal_pointer (&refs), FALSE);
return g_steal_pointer (&refs);
}
/**

View File

@ -61,7 +61,10 @@ typedef void (*XdgAppProgressCallback)(const char *status,
gpointer user_data);
XDG_APP_EXTERN gboolean xdg_app_installation_get_is_user (XdgAppInstallation *self);
XDG_APP_EXTERN XdgAppInstalledRef **xdg_app_installation_list_installed_refs (XdgAppInstallation *self,
XDG_APP_EXTERN GPtrArray *xdg_app_installation_list_installed_refs (XdgAppInstallation *self,
GCancellable *cancellable,
GError **error);
XDG_APP_EXTERN GPtrArray *xdg_app_installation_list_installed_refs_by_kind (XdgAppInstallation *self,
XdgAppRefKind kind,
GCancellable *cancellable,
GError **error);