Commit 76003d19 authored by Matthias Klumpp's avatar Matthias Klumpp
Browse files

Move metadata format/style/version enums to AsContext

parent 65385d32
......@@ -57,6 +57,107 @@ G_DEFINE_TYPE_WITH_PRIVATE (AsContext, as_context, G_TYPE_OBJECT)
#define GET_PRIVATE(o) (as_context_get_instance_private (o))
/**
* as_format_kind_to_string:
* @kind: the #AsFormatKind.
*
* Converts the enumerated value to an text representation.
*
* Returns: string version of @kind
*
* Since: 0.10
**/
const gchar*
as_format_kind_to_string (AsFormatKind kind)
{
if (kind == AS_FORMAT_KIND_XML)
return "xml";
if (kind == AS_FORMAT_KIND_YAML)
return "yaml";
return "unknown";
}
/**
* as_format_kind_from_string:
* @kind_str: the string.
*
* Converts the text representation to an enumerated value.
*
* Returns: a #AsFormatKind or %AS_FORMAT_KIND_UNKNOWN for unknown
*
* Since: 0.10
**/
AsFormatKind
as_format_kind_from_string (const gchar *kind_str)
{
if (g_strcmp0 (kind_str, "xml") == 0)
return AS_FORMAT_KIND_XML;
if (g_strcmp0 (kind_str, "yaml") == 0)
return AS_FORMAT_KIND_YAML;
return AS_FORMAT_KIND_UNKNOWN;
}
/**
* as_format_version_to_string:
* @version: the #AsFormatKind.
*
* Converts the enumerated value to an text representation.
*
* Returns: string version of @version
*
* Since: 0.10
**/
const gchar*
as_format_version_to_string (AsFormatVersion version)
{
if (version == AS_FORMAT_VERSION_V0_6)
return "0.6";
if (version == AS_FORMAT_VERSION_V0_7)
return "0.7";
if (version == AS_FORMAT_VERSION_V0_8)
return "0.8";
if (version == AS_FORMAT_VERSION_V0_9)
return "0.9";
if (version == AS_FORMAT_VERSION_V0_10)
return "0.10";
if (version == AS_FORMAT_VERSION_V0_11)
return "0.11";
if (version == AS_FORMAT_VERSION_V0_12)
return "0.12";
return "?.??";
}
/**
* as_format_version_from_string:
* @version_str: the string.
*
* Converts the text representation to an enumerated value.
*
* Returns: a #AsFormatVersion. For unknown, the highest version
* number is assumed.
*
* Since: 0.10
**/
AsFormatVersion
as_format_version_from_string (const gchar *version_str)
{
if (g_strcmp0 (version_str, "0.12") == 0)
return AS_FORMAT_VERSION_V0_12;
if (g_strcmp0 (version_str, "0.11") == 0)
return AS_FORMAT_VERSION_V0_11;
if (g_strcmp0 (version_str, "0.10") == 0)
return AS_FORMAT_VERSION_V0_10;
if (g_strcmp0 (version_str, "0.9") == 0)
return AS_FORMAT_VERSION_V0_9;
if (g_strcmp0 (version_str, "0.8") == 0)
return AS_FORMAT_VERSION_V0_8;
if (g_strcmp0 (version_str, "0.7") == 0)
return AS_FORMAT_VERSION_V0_7;
if (g_strcmp0 (version_str, "0.6") == 0)
return AS_FORMAT_VERSION_V0_6;
return AS_FORMAT_VERSION_V0_10;
}
static void
as_context_finalize (GObject *object)
{
......
......@@ -26,7 +26,6 @@
#define __AS_CONTEXT_H
#include <glib-object.h>
#include "as-metadata.h"
G_BEGIN_DECLS
......@@ -45,6 +44,74 @@ struct _AsContextClass
void (*_as_reserved6) (void);
};
/**
* AsFormatStyle:
* @AS_FORMAT_STYLE_METAINFO: Parse AppStream upstream metadata (metainfo files)
* @AS_FORMAT_STYLE_COLLECTION: Parse AppStream metadata collections (shipped by software distributors)
*
* There are a few differences between AppStream's metainfo files (shipped by upstream projects)
* and the collection metadata (shipped by distributors).
* The data source kind indicates which style we should process.
* Usually you do not want to set this explicitly.
**/
typedef enum {
AS_FORMAT_STYLE_UNKNOWN,
AS_FORMAT_STYLE_METAINFO,
AS_FORMAT_STYLE_COLLECTION,
/*< private >*/
AS_FORMAT_STYLE_LAST
} AsFormatStyle;
/**
* AsFormatKind:
* @AS_FORMAT_KIND_UNKNOWN: Unknown metadata format.
* @AS_FORMAT_KIND_XML: AppStream XML metadata.
* @AS_FORMAT_KIND_YAML: AppStream YAML (DEP-11) metadata.
* @AS_FORMAT_KIND_DESKTOP_ENTRY: XDG Desktop Entry data.
*
* Format of the AppStream metadata.
**/
typedef enum {
AS_FORMAT_KIND_UNKNOWN,
AS_FORMAT_KIND_XML,
AS_FORMAT_KIND_YAML,
AS_FORMAT_KIND_DESKTOP_ENTRY,
/*< private >*/
AS_FORMAT_KIND_LAST
} AsFormatKind;
const gchar *as_format_kind_to_string (AsFormatKind kind);
AsFormatKind as_format_kind_from_string (const gchar *kind_str);
/**
* AsFormatVersion:
* @AS_FORMAT_VERSION_V0_6: 0.6
* @AS_FORMAT_VERSION_V0_7: 0.7
* @AS_FORMAT_VERSION_V0_8: 0.8
* @AS_FORMAT_VERSION_V0_9: 0.9
* @AS_FORMAT_VERSION_V0_10: 0.10
* @AS_FORMAT_VERSION_V0_11: 0.11
* @AS_FORMAT_VERSION_V0_12: 0.12
*
* Format version / API level of the AppStream metadata.
**/
typedef enum {
AS_FORMAT_VERSION_V0_6,
AS_FORMAT_VERSION_V0_7,
AS_FORMAT_VERSION_V0_8,
AS_FORMAT_VERSION_V0_9,
AS_FORMAT_VERSION_V0_10,
AS_FORMAT_VERSION_V0_11,
AS_FORMAT_VERSION_V0_12,
/*< private >*/
AS_FORMAT_VERSION_LAST
} AsFormatVersion;
const gchar *as_format_version_to_string (AsFormatVersion version);
AsFormatVersion as_format_version_from_string (const gchar *version_str);
#define AS_CURRENT_FORMAT_VERSION AS_FORMAT_VERSION_V0_12
AsContext *as_context_new (void);
AsFormatVersion as_context_get_format_version (AsContext *ctx);
......
......@@ -67,107 +67,6 @@ typedef struct
G_DEFINE_TYPE_WITH_PRIVATE (AsMetadata, as_metadata, G_TYPE_OBJECT)
#define GET_PRIVATE(o) (as_metadata_get_instance_private (o))
/**
* as_format_kind_to_string:
* @kind: the #AsFormatKind.
*
* Converts the enumerated value to an text representation.
*
* Returns: string version of @kind
*
* Since: 0.10
**/
const gchar*
as_format_kind_to_string (AsFormatKind kind)
{
if (kind == AS_FORMAT_KIND_XML)
return "xml";
if (kind == AS_FORMAT_KIND_YAML)
return "yaml";
return "unknown";
}
/**
* as_format_kind_from_string:
* @kind_str: the string.
*
* Converts the text representation to an enumerated value.
*
* Returns: a #AsFormatKind or %AS_FORMAT_KIND_UNKNOWN for unknown
*
* Since: 0.10
**/
AsFormatKind
as_format_kind_from_string (const gchar *kind_str)
{
if (g_strcmp0 (kind_str, "xml") == 0)
return AS_FORMAT_KIND_XML;
if (g_strcmp0 (kind_str, "yaml") == 0)
return AS_FORMAT_KIND_YAML;
return AS_FORMAT_KIND_UNKNOWN;
}
/**
* as_format_version_to_string:
* @version: the #AsFormatKind.
*
* Converts the enumerated value to an text representation.
*
* Returns: string version of @version
*
* Since: 0.10
**/
const gchar*
as_format_version_to_string (AsFormatVersion version)
{
if (version == AS_FORMAT_VERSION_V0_6)
return "0.6";
if (version == AS_FORMAT_VERSION_V0_7)
return "0.7";
if (version == AS_FORMAT_VERSION_V0_8)
return "0.8";
if (version == AS_FORMAT_VERSION_V0_9)
return "0.9";
if (version == AS_FORMAT_VERSION_V0_10)
return "0.10";
if (version == AS_FORMAT_VERSION_V0_11)
return "0.11";
if (version == AS_FORMAT_VERSION_V0_12)
return "0.12";
return "?.??";
}
/**
* as_format_version_from_string:
* @version_str: the string.
*
* Converts the text representation to an enumerated value.
*
* Returns: a #AsFormatVersion. For unknown, the highest version
* number is assumed.
*
* Since: 0.10
**/
AsFormatVersion
as_format_version_from_string (const gchar *version_str)
{
if (g_strcmp0 (version_str, "0.12") == 0)
return AS_FORMAT_VERSION_V0_12;
if (g_strcmp0 (version_str, "0.11") == 0)
return AS_FORMAT_VERSION_V0_11;
if (g_strcmp0 (version_str, "0.10") == 0)
return AS_FORMAT_VERSION_V0_10;
if (g_strcmp0 (version_str, "0.9") == 0)
return AS_FORMAT_VERSION_V0_9;
if (g_strcmp0 (version_str, "0.8") == 0)
return AS_FORMAT_VERSION_V0_8;
if (g_strcmp0 (version_str, "0.7") == 0)
return AS_FORMAT_VERSION_V0_7;
if (g_strcmp0 (version_str, "0.6") == 0)
return AS_FORMAT_VERSION_V0_6;
return AS_FORMAT_VERSION_V0_10;
}
/**
* as_metadata_init:
**/
......
......@@ -30,6 +30,7 @@
#include <gio/gio.h>
#include "as-component.h"
#include "as-context.h"
G_BEGIN_DECLS
......@@ -48,74 +49,6 @@ struct _AsMetadataClass
void (*_as_reserved6) (void);
};
/**
* AsFormatStyle:
* @AS_FORMAT_STYLE_METAINFO: Parse AppStream upstream metadata (metainfo files)
* @AS_FORMAT_STYLE_COLLECTION: Parse AppStream metadata collections (shipped by software distributors)
*
* There are a few differences between AppStream's metainfo files (shipped by upstream projects)
* and the collection metadata (shipped by distributors).
* The data source kind indicates which style we should process.
* Usually you do not want to set this explicitly.
**/
typedef enum {
AS_FORMAT_STYLE_UNKNOWN,
AS_FORMAT_STYLE_METAINFO,
AS_FORMAT_STYLE_COLLECTION,
/*< private >*/
AS_FORMAT_STYLE_LAST
} AsFormatStyle;
/**
* AsFormatKind:
* @AS_FORMAT_KIND_UNKNOWN: Unknown metadata format.
* @AS_FORMAT_KIND_XML: AppStream XML metadata.
* @AS_FORMAT_KIND_YAML: AppStream YAML (DEP-11) metadata.
* @AS_FORMAT_KIND_DESKTOP_ENTRY: XDG Desktop Entry data.
*
* Format of the AppStream metadata.
**/
typedef enum {
AS_FORMAT_KIND_UNKNOWN,
AS_FORMAT_KIND_XML,
AS_FORMAT_KIND_YAML,
AS_FORMAT_KIND_DESKTOP_ENTRY,
/*< private >*/
AS_FORMAT_KIND_LAST
} AsFormatKind;
const gchar *as_format_kind_to_string (AsFormatKind kind);
AsFormatKind as_format_kind_from_string (const gchar *kind_str);
/**
* AsFormatVersion:
* @AS_FORMAT_VERSION_V0_6: 0.6
* @AS_FORMAT_VERSION_V0_7: 0.7
* @AS_FORMAT_VERSION_V0_8: 0.8
* @AS_FORMAT_VERSION_V0_9: 0.9
* @AS_FORMAT_VERSION_V0_10: 0.10
* @AS_FORMAT_VERSION_V0_11: 0.11
* @AS_FORMAT_VERSION_V0_12: 0.12
*
* Format version / API level of the AppStream metadata.
**/
typedef enum {
AS_FORMAT_VERSION_V0_6,
AS_FORMAT_VERSION_V0_7,
AS_FORMAT_VERSION_V0_8,
AS_FORMAT_VERSION_V0_9,
AS_FORMAT_VERSION_V0_10,
AS_FORMAT_VERSION_V0_11,
AS_FORMAT_VERSION_V0_12,
/*< private >*/
AS_FORMAT_VERSION_LAST
} AsFormatVersion;
const gchar *as_format_version_to_string (AsFormatVersion version);
AsFormatVersion as_format_version_from_string (const gchar *version_str);
#define AS_CURRENT_FORMAT_VERSION AS_FORMAT_VERSION_V0_12
/**
* AsParseFlags:
* @AS_PARSE_FLAG_NONE: No flags.
......
......@@ -793,8 +793,11 @@ as_xml_parse_document (const gchar *data, gssize len, GError **error)
/**
* as_xml_node_to_str:
* @root: The document root node.
*
* Converts an XML node into its textural representation.
* This takes ownership of the root node and frees it in
* the process.
*
* Returns: XML metadata.
*/
......
......@@ -29,6 +29,7 @@
#include <libxml/parser.h>
#include <libxml/xmlsave.h>
#include "as-context.h"
#include "as-metadata.h"
#include "as-tag.h"
G_BEGIN_DECLS
......
......@@ -27,6 +27,7 @@
#include <yaml.h>
#include "as-context.h"
#include "as-metadata.h"
#include "as-tag.h"
G_BEGIN_DECLS
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment