diff options
author | Richard Hughes <richard@hughsie.com> | 2014-04-21 12:28:50 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-04-21 12:33:18 +0100 |
commit | a6ed8b78e5a1355b0e9b318c0224d141528e6574 (patch) | |
tree | fdda8208cd120d00c781afd404214411c8003560 | |
parent | 10fded3aab7aaffe3ab30fea413a22cfc2cb6c94 (diff) | |
download | appstream-glib-a6ed8b78e5a1355b0e9b318c0224d141528e6574.tar.gz |
Add AsProblem to report non-critical problems with data
-rw-r--r-- | docs/api/appstream-glib-docs.sgml | 1 | ||||
-rw-r--r-- | libappstream-glib/Makefile.am | 5 | ||||
-rw-r--r-- | libappstream-glib/appstream-glib.h | 1 | ||||
-rw-r--r-- | libappstream-glib/as-problem.c | 243 | ||||
-rw-r--r-- | libappstream-glib/as-problem.h | 123 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 1 |
6 files changed, 374 insertions, 0 deletions
diff --git a/docs/api/appstream-glib-docs.sgml b/docs/api/appstream-glib-docs.sgml index fa9ca0c..4b44016 100644 --- a/docs/api/appstream-glib-docs.sgml +++ b/docs/api/appstream-glib-docs.sgml @@ -38,6 +38,7 @@ <xi:include href="xml/as-release.xml"/> <xi:include href="xml/as-screenshot.xml"/> <xi:include href="xml/as-store.xml"/> + <xi:include href="xml/as-problem.xml"/> <xi:include href="xml/as-enums.xml"/> <xi:include href="xml/as-node.xml"/> <xi:include href="xml/as-tag.xml"/> diff --git a/libappstream-glib/Makefile.am b/libappstream-glib/Makefile.am index dd4d96d..d554eb0 100644 --- a/libappstream-glib/Makefile.am +++ b/libappstream-glib/Makefile.am @@ -57,6 +57,7 @@ libappstream_glib_include_HEADERS = \ as-enums.h \ as-image.h \ as-node.h \ + as-problem.h \ as-release.h \ as-screenshot.h \ as-store.h \ @@ -72,6 +73,8 @@ libappstream_glib_la_SOURCES = \ as-image-private.h \ as-node.c \ as-node-private.h \ + as-problem.c \ + as-problem.h \ as-release.c \ as-release-private.h \ as-resources.c \ @@ -124,6 +127,8 @@ introspection_sources = \ as-image.h \ as-node.c \ as-node.h \ + as-problem.c \ + as-problem.h \ as-release.c \ as-release.h \ as-screenshot.c \ diff --git a/libappstream-glib/appstream-glib.h b/libappstream-glib/appstream-glib.h index 1fd72cf..795f4c0 100644 --- a/libappstream-glib/appstream-glib.h +++ b/libappstream-glib/appstream-glib.h @@ -28,6 +28,7 @@ #include <as-enums.h> #include <as-image.h> #include <as-node.h> +#include <as-problem.h> #include <as-release.h> #include <as-screenshot.h> #include <as-store.h> diff --git a/libappstream-glib/as-problem.c b/libappstream-glib/as-problem.c new file mode 100644 index 0000000..f4447b6 --- /dev/null +++ b/libappstream-glib/as-problem.c @@ -0,0 +1,243 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2014 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * SECTION:as-problem + * @short_description: Object representing a problem with an application + * @include: appstream-glib.h + * @stability: Stable + * + * Problems have a unlocalized message and also contain a line number and kind. + * + * See also: #AsApp + */ + +#include "config.h" + +#include "as-problem.h" + +typedef struct _AsProblemPrivate AsProblemPrivate; +struct _AsProblemPrivate +{ + AsProblemKind kind; + gchar *message; + guint line_number; +}; + +G_DEFINE_TYPE_WITH_PRIVATE (AsProblem, as_problem, G_TYPE_OBJECT) + +#define GET_PRIVATE(o) (as_problem_get_instance_private (o)) + +/** + * as_problem_finalize: + **/ +static void +as_problem_finalize (GObject *object) +{ + AsProblem *problem = AS_PROBLEM (object); + AsProblemPrivate *priv = GET_PRIVATE (problem); + + g_free (priv->message); + + G_OBJECT_CLASS (as_problem_parent_class)->finalize (object); +} + +/** + * as_problem_init: + **/ +static void +as_problem_init (AsProblem *problem) +{ + AsProblemPrivate *priv = GET_PRIVATE (problem); + priv->kind = AS_PROBLEM_KIND_UNKNOWN; + priv->line_number = 0; +} + +/** + * as_problem_class_init: + **/ +static void +as_problem_class_init (AsProblemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = as_problem_finalize; +} + +/** + * as_problem_kind_to_string: + * @kind: the #AsProblemKind. + * + * Converts the enumerated value to an text representation. + * + * Returns: string version of @kind + * + * Since: 0.1.4 + **/ +const gchar * +as_problem_kind_to_string (AsProblemKind kind) +{ + if (kind == AS_PROBLEM_KIND_TAG_DUPLICATED) + return "tag-duplicated"; + if (kind == AS_PROBLEM_KIND_TAG_MISSING) + return "tag-missing"; + if (kind == AS_PROBLEM_KIND_TAG_INVALID) + return "tag-invalid"; + if (kind == AS_PROBLEM_KIND_ATTRIBUTE_MISSING) + return "attribute-missing"; + if (kind == AS_PROBLEM_KIND_ATTRIBUTE_INVALID) + return "attribute-invalid"; + if (kind == AS_PROBLEM_KIND_MARKUP_INVALID) + return "markup-invalid"; + if (kind == AS_PROBLEM_KIND_STYLE_INCORRECT) + return "style-invalid"; + if (kind == AS_PROBLEM_KIND_TRANSLATIONS_REQUIRED) + return "translations-required"; + if (kind == AS_PROBLEM_KIND_DUPLICATE_DATA) + return "duplicate-data"; + if (kind == AS_PROBLEM_KIND_VALUE_MISSING) + return "value-missing"; + if (kind == AS_PROBLEM_KIND_FILE_INVALID) + return "file-invalid"; + if (kind == AS_PROBLEM_KIND_ASPECT_RATIO_INCORRECT) + return "aspect-ratio-invalid"; + if (kind == AS_PROBLEM_KIND_RESOLUTION_INCORRECT) + return "resolution-invalid"; + if (kind == AS_PROBLEM_KIND_URL_NOT_FOUND) + return "url-not-found"; + return NULL; +} + +/** + * as_problem_get_kind: + * @problem: a #AsProblem instance. + * + * Gets the problem kind. + * + * Returns: a #AsProblemKind, e.g. %AS_PROBLEM_KIND_TAG_MISSING + * + * Since: 0.1.4 + **/ +AsProblemKind +as_problem_get_kind (AsProblem *problem) +{ + AsProblemPrivate *priv = GET_PRIVATE (problem); + return priv->kind; +} + +/** + * as_problem_get_line_number: + * @problem: a #AsProblem instance. + * + * Gets the line number of the problem if known. + * + * Returns: a line number, where 0 is unknown + * + * Since: 0.1.4 + **/ +guint +as_problem_get_line_number (AsProblem *problem) +{ + AsProblemPrivate *priv = GET_PRIVATE (problem); + return priv->line_number; +} + +/** + * as_problem_get_message: + * @problem: a #AsProblem instance. + * + * Gets the specific message for the problem. + * + * Returns: the message + * + * Since: 0.1.4 + **/ +const gchar * +as_problem_get_message (AsProblem *problem) +{ + AsProblemPrivate *priv = GET_PRIVATE (problem); + return priv->message; +} + +/** + * as_problem_set_kind: + * @problem: a #AsProblem instance. + * @kind: the #AsProblemKind. + * + * Sets the problem kind. + * + * Since: 0.1.4 + **/ +void +as_problem_set_kind (AsProblem *problem, AsProblemKind kind) +{ + AsProblemPrivate *priv = GET_PRIVATE (problem); + priv->kind = kind; +} + +/** + * as_problem_set_line_number: + * @problem: a #AsProblem instance. + * @line_number: a #guint instance. + * + * Adds an line_number to the problem. + * + * Since: 0.1.4 + **/ +void +as_problem_set_line_number (AsProblem *problem, guint line_number) +{ + AsProblemPrivate *priv = GET_PRIVATE (problem); + priv->line_number = line_number; +} + +/** + * as_problem_set_message: + * @problem: a #AsProblem instance. + * @message: the message text. + * + * Sets a message on the problem. + * + * Since: 0.1.4 + **/ +void +as_problem_set_message (AsProblem *problem, const gchar *message) +{ + AsProblemPrivate *priv = GET_PRIVATE (problem); + g_free (priv->message); + priv->message = g_strdup (message); +} + +/** + * as_problem_new: + * + * Creates a new #AsProblem. + * + * Returns: (transfer full): a #AsProblem + * + * Since: 0.1.4 + **/ +AsProblem * +as_problem_new (void) +{ + AsProblem *problem; + problem = g_object_new (AS_TYPE_PROBLEM, NULL); + return AS_PROBLEM (problem); +} diff --git a/libappstream-glib/as-problem.h b/libappstream-glib/as-problem.h new file mode 100644 index 0000000..9f59352 --- /dev/null +++ b/libappstream-glib/as-problem.h @@ -0,0 +1,123 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2014 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#if !defined (__APPSTREAM_GLIB_H) && !defined (AS_COMPILATION) +#error "Only <appstream-glib.h> can be included directly." +#endif + +#ifndef __AS_PROBLEM_H +#define __AS_PROBLEM_H + +#include <glib-object.h> + +#define AS_TYPE_PROBLEM (as_problem_get_type()) +#define AS_PROBLEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), AS_TYPE_PROBLEM, AsProblem)) +#define AS_PROBLEM_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls), AS_TYPE_PROBLEM, AsProblemClass)) +#define AS_IS_PROBLEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), AS_TYPE_PROBLEM)) +#define AS_IS_PROBLEM_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls), AS_TYPE_PROBLEM)) +#define AS_PROBLEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), AS_TYPE_PROBLEM, AsProblemClass)) + +G_BEGIN_DECLS + +typedef struct _AsProblem AsProblem; +typedef struct _AsProblemClass AsProblemClass; + +struct _AsProblem +{ + GObject parent; +}; + +struct _AsProblemClass +{ + GObjectClass parent_class; + /*< private >*/ + void (*_as_reserved1) (void); + void (*_as_reserved2) (void); + void (*_as_reserved3) (void); + void (*_as_reserved4) (void); + void (*_as_reserved5) (void); + void (*_as_reserved6) (void); + void (*_as_reserved7) (void); + void (*_as_reserved8) (void); +}; + +/** + * AsProblemKind: + * @AS_PROBLEM_KIND_UNKNOWN: Type invalid or not known + * @AS_PROBLEM_KIND_TAG_DUPLICATED: A tag is duplicated + * @AS_PROBLEM_KIND_TAG_MISSING: A required tag is missing + * @AS_PROBLEM_KIND_TAG_INVALID: A tag value is invalid + * @AS_PROBLEM_KIND_ATTRIBUTE_MISSING: A required attribute is missing + * @AS_PROBLEM_KIND_ATTRIBUTE_INVALID: An attribute is invalid + * @AS_PROBLEM_KIND_MARKUP_INVALID: The XML markup is invalid + * @AS_PROBLEM_KIND_STYLE_INCORRECT: Style guidelines are incorrect + * @AS_PROBLEM_KIND_TRANSLATIONS_REQUIRED: Translations are required + * @AS_PROBLEM_KIND_DUPLICATE_DATA: Some data is duplicated + * @AS_PROBLEM_KIND_VALUE_MISSING: A value is required + * @AS_PROBLEM_KIND_URL_NOT_FOUND: The URL is not found + * @AS_PROBLEM_KIND_FILE_INVALID: The file is invalid + * @AS_PROBLEM_KIND_ASPECT_RATIO_INCORRECT: The image aspect ratio is wrong + * @AS_PROBLEM_KIND_RESOLUTION_INCORRECT: The image resolution is wrong + * + * The problem type. + **/ +typedef enum { + AS_PROBLEM_KIND_UNKNOWN, + AS_PROBLEM_KIND_TAG_DUPLICATED, + AS_PROBLEM_KIND_TAG_MISSING, + AS_PROBLEM_KIND_TAG_INVALID, + AS_PROBLEM_KIND_ATTRIBUTE_MISSING, + AS_PROBLEM_KIND_ATTRIBUTE_INVALID, + AS_PROBLEM_KIND_MARKUP_INVALID, + AS_PROBLEM_KIND_STYLE_INCORRECT, + AS_PROBLEM_KIND_TRANSLATIONS_REQUIRED, + AS_PROBLEM_KIND_DUPLICATE_DATA, + AS_PROBLEM_KIND_VALUE_MISSING, + AS_PROBLEM_KIND_URL_NOT_FOUND, + AS_PROBLEM_KIND_FILE_INVALID, + AS_PROBLEM_KIND_ASPECT_RATIO_INCORRECT, + AS_PROBLEM_KIND_RESOLUTION_INCORRECT, + /*< private >*/ + AS_PROBLEM_KIND_LAST +} AsProblemKind; + +GType as_problem_get_type (void); +AsProblem *as_problem_new (void); + +/* helpers */ +const gchar *as_problem_kind_to_string (AsProblemKind kind); + +/* getters */ +AsProblemKind as_problem_get_kind (AsProblem *problem); +guint as_problem_get_line_number (AsProblem *problem); +const gchar *as_problem_get_message (AsProblem *problem); + +/* setters */ +void as_problem_set_kind (AsProblem *problem, + AsProblemKind kind); +void as_problem_set_line_number (AsProblem *problem, + guint line_number); +void as_problem_set_message (AsProblem *problem, + const gchar *message); + +G_END_DECLS + +#endif /* __AS_PROBLEM_H */ diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index 5bab150..bca144f 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -28,6 +28,7 @@ #include "as-enums.h" #include "as-image-private.h" #include "as-node-private.h" +#include "as-problem.h" #include "as-release-private.h" #include "as-screenshot-private.h" #include "as-store.h" |