/**
 * gs_plugin_xdg_app_is_xref:
 */
static gboolean
gs_plugin_xdg_app_is_xref (GsApp *app, XdgAppRef *xref)
{
	g_autofree gchar *id = NULL;

	/* check ID */
	id = gs_plugin_xdg_app_build_id (xref);
	if (g_strcmp0 (id, gs_app_get_id (app)) == 0)
		return TRUE;

	/* check source ID */
//	if (g_strcmp0 (id, gs_app_get_id (app)) == 0)
//		return TRUE;

	/* do all the metadata items match? */
	if (g_strcmp0 (gs_app_get_xdgapp_name (app),
		       xdg_app_ref_get_name (xref)) == 0 &&
	    g_strcmp0 (gs_app_get_xdgapp_arch (app),
		       xdg_app_ref_get_arch (xref)) == 0 &&
	    g_strcmp0 (gs_app_get_xdgapp_branch (app),
		       xdg_app_ref_get_branch (xref)) == 0)
		return TRUE;

	/* sad panda */
	return FALSE;
}
/**
 * gs_plugin_xdg_app_set_metadata:
 */
static void
gs_plugin_xdg_app_set_metadata (GsApp *app, XdgAppRef *xref)
{
	gs_app_set_management_plugin (app, "xdg-app");
	gs_app_set_xdgapp_kind (app, xdg_app_ref_get_kind (xref));
	gs_app_set_xdgapp_name (app, xdg_app_ref_get_name (xref));
	gs_app_set_xdgapp_arch (app, xdg_app_ref_get_arch (xref));
	gs_app_set_xdgapp_branch (app, xdg_app_ref_get_branch (xref));
	gs_app_set_xdgapp_commit (app, xdg_app_ref_get_commit (xref));
}
/**
 * gs_plugin_refresh:
 */
gboolean
gs_plugin_refresh (GsPlugin *plugin,
		   guint cache_age,
		   GsPluginRefreshFlags flags,
		   GCancellable *cancellable,
		   GError **error)
{
	GsPluginData *priv = gs_plugin_get_data (plugin);
	guint i;
	g_autoptr(GPtrArray) xrefs = NULL;

	/* update AppStream metadata */
	if (flags & GS_PLUGIN_REFRESH_FLAGS_METADATA) {
		if (!gs_plugin_refresh_appstream (plugin, cache_age,
						  cancellable, error))
			return FALSE;
	}

	/* no longer interesting */
	if ((flags & GS_PLUGIN_REFRESH_FLAGS_PAYLOAD) == 0)
		return TRUE;

	/* get all the updates available from all remotes */
	xrefs = xdg_app_installation_list_installed_refs_for_update (priv->installation,
								     cancellable,
								     error);
	if (xrefs == NULL)
		return FALSE;
	for (i = 0; i < xrefs->len; i++) {
		XdgAppInstalledRef *xref = g_ptr_array_index (xrefs, i);
		g_autoptr(GsApp) app = NULL;
		g_autoptr(XdgAppInstalledRef) xref2 = NULL;

		/* try to create a GsApp so we can do progress reporting */
		app = gs_plugin_xdg_app_create_installed (plugin, xref, NULL);

		/* fetch but do not deploy */
		g_debug ("pulling update for %s",
			 xdg_app_ref_get_name (XDG_APP_REF (xref)));
		xref2 = xdg_app_installation_update (priv->installation,
						     XDG_APP_UPDATE_FLAGS_NO_DEPLOY,
						     xdg_app_ref_get_kind (XDG_APP_REF (xref)),
						     xdg_app_ref_get_name (XDG_APP_REF (xref)),
						     xdg_app_ref_get_arch (XDG_APP_REF (xref)),
						     xdg_app_ref_get_branch (XDG_APP_REF (xref)),
						     gs_plugin_xdg_app_progress_cb, app,
						     cancellable, error);
		if (xref2 == NULL)
			return FALSE;
	}

	return TRUE;
}
Ejemplo n.º 4
0
XdgApplication::XdgApplication(XdgAppInstalledRef *app_ref, SoftwareBackend *backend)
        : Application(backend)
{
    m_state = Application::Installed;
    m_id = xdg_app_ref_get_name(XDG_APP_REF(app_ref));
    m_branch = xdg_app_ref_get_branch(XDG_APP_REF(app_ref));
    m_origin = xdg_app_installed_ref_get_origin(app_ref);
    m_name = m_id;
    m_arch = xdg_app_ref_get_arch(XDG_APP_REF(app_ref));

    m_currentCommit = xdg_app_ref_get_commit(XDG_APP_REF(app_ref));
    m_latestCommit = xdg_app_installed_ref_get_latest_commit(app_ref);

    if (m_branch.isEmpty())
        m_branch = "master";

    QString desktopId;

    switch (xdg_app_ref_get_kind(XDG_APP_REF(app_ref))) {
    case XDG_APP_REF_KIND_APP:
        m_type = Application::App;

        desktopId = m_name + ".desktop";
        break;
    case XDG_APP_REF_KIND_RUNTIME:
        m_type = Application::Runtime;
        m_icon = QIcon::fromTheme("package-x-generic");
        m_summary = "Framework for applications";

        desktopId = m_name + ".runtime";
        break;
    default:
        // TODO: Handle errors here!
        break;
    }

    QString deployDir = xdg_app_installed_ref_get_deploy_dir(app_ref);
    QString desktopPath = deployDir + "/files/share/applications";
    QString appdataPath = deployDir + "/files/share/appdata";

    Appstream::Store store;
    store.load(desktopPath);
    store.load(appdataPath);

    Appstream::Component component = store.componentById(desktopId);
    if (!component.isNull())
        refineFromAppstream(component);
}