lib: Add xdg_app_installed_ref_launch()

tingping/wmclass
Alexander Larsson 2015-12-07 13:36:39 +01:00
parent 000c59f60e
commit 5b1931dc8d
6 changed files with 78 additions and 25 deletions

View File

@ -54,15 +54,18 @@ main (int argc, char *argv[])
"org.gnome.gedit",
NULL, "master", NULL, NULL);
if (app1)
g_print ("gedit master: %d %s %s %s %s %s %s %d\n",
xdg_app_ref_get_kind (XDG_APP_REF(app1)),
xdg_app_ref_get_name (XDG_APP_REF(app1)),
xdg_app_ref_get_arch (XDG_APP_REF(app1)),
xdg_app_ref_get_version (XDG_APP_REF(app1)),
xdg_app_ref_get_commit (XDG_APP_REF(app1)),
xdg_app_installed_ref_get_origin (app1),
xdg_app_installed_ref_get_deploy_dir (app1),
xdg_app_installed_ref_get_current (app1));
{
g_print ("gedit master: %d %s %s %s %s %s %s %d\n",
xdg_app_ref_get_kind (XDG_APP_REF(app1)),
xdg_app_ref_get_name (XDG_APP_REF(app1)),
xdg_app_ref_get_arch (XDG_APP_REF(app1)),
xdg_app_ref_get_version (XDG_APP_REF(app1)),
xdg_app_ref_get_commit (XDG_APP_REF(app1)),
xdg_app_installed_ref_get_origin (app1),
xdg_app_installed_ref_get_deploy_dir (app1),
xdg_app_installed_ref_get_current (app1));
xdg_app_installed_ref_launch (app1, NULL, NULL);
}
app2 = xdg_app_installation_get_current_installed_app (installation,
"org.gnome.gedit",

View File

@ -142,7 +142,6 @@ get_ref (XdgAppInstallation *self,
g_auto(GStrv) parts = NULL;
g_autofree char *origin = NULL;
g_autofree char *commit = NULL;
g_autoptr(XdgAppDir) dir = NULL;
g_autoptr(GFile) deploy_dir = NULL;
g_autoptr(GFile) deploy_subdir = NULL;
g_autofree char *deploy_path = NULL;
@ -171,6 +170,7 @@ get_ref (XdgAppInstallation *self,
commit,
origin,
deploy_path,
priv->dir,
is_current);
}

View File

@ -26,11 +26,13 @@
#define __XDG_APP_INSTALLED_REF_PRIVATE_H__
#include <xdg-app-installed-ref.h>
#include <xdg-app-dir.h>
XdgAppInstalledRef *xdg_app_installed_ref_new (const char *full_ref,
const char *commit,
const char *origin,
const char *deploy_dir,
XdgAppDir *dir,
gboolean current);
#endif /* __XDG_APP_INSTALLED_REF_PRIVATE_H__ */

View File

@ -25,6 +25,9 @@
#include "xdg-app-installed-ref.h"
#include "xdg-app-enum-types.h"
#include "xdg-app-error.h"
#include "xdg-app-utils.h"
#include "xdg-app-run.h"
#include "xdg-app-dir.h"
typedef struct _XdgAppInstalledRefPrivate XdgAppInstalledRefPrivate;
@ -34,6 +37,7 @@ struct _XdgAppInstalledRefPrivate
char *origin;
char *deploy_dir;
XdgAppDir *dir;
char *metadata;
};
@ -56,6 +60,7 @@ xdg_app_installed_ref_finalize (GObject *object)
g_free (priv->origin);
g_free (priv->deploy_dir);
g_free (priv->metadata);
g_object_unref (priv->dir);
G_OBJECT_CLASS (xdg_app_installed_ref_parent_class)->finalize (object);
}
@ -206,14 +211,50 @@ xdg_app_installed_ref_load_metadata (XdgAppInstalledRef *self,
return priv->metadata;
}
gboolean
xdg_app_installed_ref_launch (XdgAppInstalledRef *self,
GCancellable *cancellable,
GError **error)
{
XdgAppInstalledRefPrivate *priv = xdg_app_installed_ref_get_instance_private (self);
g_autofree char *app_ref = NULL;
g_autoptr(XdgAppDeploy) app_deploy = NULL;
app_ref =
xdg_app_build_app_ref (xdg_app_ref_get_name (XDG_APP_REF (self)),
xdg_app_ref_get_version (XDG_APP_REF (self)),
xdg_app_ref_get_arch (XDG_APP_REF (self)));
app_deploy =
xdg_app_dir_load_deployed (priv->dir, app_ref,
xdg_app_ref_get_commit (XDG_APP_REF (self)),
cancellable, error);
if (app_deploy == NULL)
return FALSE;
return xdg_app_run_app (app_ref,
app_deploy,
NULL,
NULL,
XDG_APP_RUN_FLAG_BACKGROUND,
NULL,
NULL, 0,
cancellable, error);
}
XdgAppInstalledRef *
xdg_app_installed_ref_new (const char *full_ref,
const char *commit,
const char *origin,
const char *deploy_dir,
XdgAppDir *dir,
gboolean current)
{
XdgAppRefKind kind = XDG_APP_REF_KIND_APP;
XdgAppInstalledRefPrivate *priv;
XdgAppInstalledRef *ref;
g_auto(GStrv) parts = NULL;
parts = g_strsplit (full_ref, "/", -1);
@ -221,14 +262,19 @@ xdg_app_installed_ref_new (const char *full_ref,
if (strcmp (parts[0], "app") != 0)
kind = XDG_APP_REF_KIND_RUNTIME;
return g_object_new (XDG_APP_TYPE_INSTALLED_REF,
"kind", kind,
"name", parts[1],
"arch", parts[2],
"version", parts[3],
"commit", commit,
"origin", origin,
"current", current,
"deploy-dir", deploy_dir,
NULL);
ref = g_object_new (XDG_APP_TYPE_INSTALLED_REF,
"kind", kind,
"name", parts[1],
"arch", parts[2],
"version", parts[3],
"commit", commit,
"origin", origin,
"current", current,
"deploy-dir", deploy_dir,
NULL);
priv = xdg_app_installed_ref_get_instance_private (ref);
priv->dir = g_object_ref (dir);
return ref;
}

View File

@ -54,5 +54,8 @@ XDG_APP_EXTERN gboolean xdg_app_installed_ref_get_current (XdgAppInstalle
XDG_APP_EXTERN const char * xdg_app_installed_ref_load_metadata (XdgAppInstalledRef *self,
GCancellable *cancellable,
GError **error);
XDG_APP_EXTERN gboolean xdg_app_installed_ref_launch (XdgAppInstalledRef *self,
GCancellable *cancellable,
GError **error);
#endif /* __XDG_APP_INSTALLED_REF_H__ */

View File

@ -56,7 +56,7 @@ xdg_app_ref_finalize (GObject *object)
g_free (priv->arch);
g_free (priv->version);
g_free (priv->commit);
G_OBJECT_CLASS (xdg_app_ref_parent_class)->finalize (object);
}
@ -208,7 +208,7 @@ xdg_app_ref_get_arch (XdgAppRef *self)
return priv->arch;
}
const char *
xdg_app_ref_get_version (XdgAppRef *self)
{
@ -216,7 +216,7 @@ xdg_app_ref_get_version (XdgAppRef *self)
return priv->version;
}
const char *
xdg_app_ref_get_commit (XdgAppRef *self)
{
@ -224,7 +224,7 @@ xdg_app_ref_get_commit (XdgAppRef *self)
return priv->commit;
}
XdgAppRefKind
xdg_app_ref_get_kind (XdgAppRef *self)
{
@ -232,4 +232,3 @@ xdg_app_ref_get_kind (XdgAppRef *self)
return priv->kind;
}