diff options
author | Richard Hughes <richard@hughsie.com> | 2014-03-12 20:02:46 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-03-12 21:12:39 +0000 |
commit | f4ae41b80d0c386c1afc869f68d62139f8709da9 (patch) | |
tree | 8a9e310f7f5d502bcbbd6d6f4ad4e7b25dd14325 | |
parent | 30e0038b9b05a01396e7062f13ceadc410be3efb (diff) | |
download | appstream-glib-f4ae41b80d0c386c1afc869f68d62139f8709da9.tar.gz |
Add AsScreenshot
-rw-r--r-- | libappstream-glib/Makefile.am | 2 | ||||
-rw-r--r-- | libappstream-glib/appstream-glib.h | 1 | ||||
-rw-r--r-- | libappstream-glib/as-screenshot.c | 179 | ||||
-rw-r--r-- | libappstream-glib/as-screenshot.h | 84 |
4 files changed, 266 insertions, 0 deletions
diff --git a/libappstream-glib/Makefile.am b/libappstream-glib/Makefile.am index c127a8b..84e7e2f 100644 --- a/libappstream-glib/Makefile.am +++ b/libappstream-glib/Makefile.am @@ -26,6 +26,7 @@ libappstream_glib_include_HEADERS = \ as-app.h \ as-image.h \ as-release.h \ + as-screenshot.h \ as-tag.h \ as-version.h @@ -33,6 +34,7 @@ libappstream_glib_la_SOURCES = \ as-app.c \ as-image.c \ as-release.c \ + as-screenshot.c \ as-tag.c \ as-version.h diff --git a/libappstream-glib/appstream-glib.h b/libappstream-glib/appstream-glib.h index b5c831b..31ef797 100644 --- a/libappstream-glib/appstream-glib.h +++ b/libappstream-glib/appstream-glib.h @@ -27,6 +27,7 @@ #include <as-app.h> #include <as-image.h> #include <as-release.h> +#include <as-screenshot.h> #include <as-tag.h> #include <as-version.h> diff --git a/libappstream-glib/as-screenshot.c b/libappstream-glib/as-screenshot.c new file mode 100644 index 0000000..1e0ff4b --- /dev/null +++ b/libappstream-glib/as-screenshot.c @@ -0,0 +1,179 @@ +/* -*- 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 + */ + +#include "config.h" + +#include "as-screenshot.h" + +typedef struct _AsScreenshotPrivate AsScreenshotPrivate; +struct _AsScreenshotPrivate +{ + AsScreenshotKind kind; + GHashTable *captions; + GPtrArray *images; +}; + +G_DEFINE_TYPE_WITH_PRIVATE (AsScreenshot, as_screenshot, G_TYPE_OBJECT) + +#define GET_PRIVATE(o) (as_screenshot_get_instance_private (o)) + +/** + * as_screenshot_finalize: + **/ +static void +as_screenshot_finalize (GObject *object) +{ + AsScreenshot *screenshot = AS_SCREENSHOT (object); + AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); + + g_ptr_array_unref (priv->images); + g_hash_table_unref (priv->captions); + + G_OBJECT_CLASS (as_screenshot_parent_class)->finalize (object); +} + +/** + * as_screenshot_init: + **/ +static void +as_screenshot_init (AsScreenshot *screenshot) +{ + AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); + priv->kind = AS_SCREENSHOT_KIND_NORMAL; + priv->images = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); + priv->captions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); +} + +/** + * as_screenshot_class_init: + **/ +static void +as_screenshot_class_init (AsScreenshotClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = as_screenshot_finalize; +} + +/** + * as_screenshot_kind_from_string: + */ +AsScreenshotKind +as_screenshot_kind_from_string (const gchar *kind) +{ + if (g_strcmp0 (kind, "normal") == 0) + return AS_SCREENSHOT_KIND_NORMAL; + if (g_strcmp0 (kind, "default") == 0) + return AS_SCREENSHOT_KIND_DEFAULT; + return AS_SCREENSHOT_KIND_UNKNOWN; +} + +/** + * as_screenshot_kind_to_string: + */ +const gchar * +as_screenshot_kind_to_string (AsScreenshotKind kind) +{ + if (kind == AS_SCREENSHOT_KIND_NORMAL) + return "normal"; + if (kind == AS_SCREENSHOT_KIND_DEFAULT) + return "default"; + return NULL; +} + +/** + * as_screenshot_get_kind: + */ +AsScreenshotKind +as_screenshot_get_kind (AsScreenshot *screenshot) +{ + AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); + return priv->kind; +} + +/** + * as_screenshot_get_images: + */ +GPtrArray * +as_screenshot_get_images (AsScreenshot *screenshot) +{ + AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); + return priv->images; +} + +/** + * as_screenshot_get_caption: + */ +const gchar * +as_screenshot_get_caption (AsScreenshot *screenshot, const gchar *locale) +{ + AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); + if (locale == NULL) + locale = "C"; + return g_hash_table_lookup (priv->captions, locale); +} + +/** + * as_screenshot_set_kind: + */ +void +as_screenshot_set_kind (AsScreenshot *screenshot, AsScreenshotKind kind) +{ + AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); + priv->kind = kind; +} + +/** + * as_screenshot_add_image: + */ +void +as_screenshot_add_image (AsScreenshot *screenshot, AsImage *image) +{ + AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); + g_ptr_array_add (priv->images, g_object_ref (image)); +} + +/** + * as_screenshot_set_caption: + */ +void +as_screenshot_set_caption (AsScreenshot *screenshot, + const gchar *locale, + const gchar *caption, + gsize caption_length) +{ + AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); + if (locale == NULL) + locale = "C"; + g_hash_table_insert (priv->captions, + g_strdup (locale), + g_strndup (caption, caption_length)); +} + +/** + * as_screenshot_new: + **/ +AsScreenshot * +as_screenshot_new (void) +{ + AsScreenshot *screenshot; + screenshot = g_object_new (AS_TYPE_SCREENSHOT, NULL); + return AS_SCREENSHOT (screenshot); +} diff --git a/libappstream-glib/as-screenshot.h b/libappstream-glib/as-screenshot.h new file mode 100644 index 0000000..ba603dc --- /dev/null +++ b/libappstream-glib/as-screenshot.h @@ -0,0 +1,84 @@ +/* -*- 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_SCREENSHOT_H +#define AS_SCREENSHOT_H + +#include <glib-object.h> + +#include "as-image.h" + +#define AS_TYPE_SCREENSHOT (as_screenshot_get_type()) +#define AS_SCREENSHOT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), AS_TYPE_SCREENSHOT, AsScreenshot)) +#define AS_SCREENSHOT_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls), AS_TYPE_SCREENSHOT, AsScreenshotClass)) +#define AS_IS_SCREENSHOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), AS_TYPE_SCREENSHOT)) +#define AS_IS_SCREENSHOT_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls), AS_TYPE_SCREENSHOT)) +#define AS_SCREENSHOT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), AS_TYPE_SCREENSHOT, AsScreenshotClass)) + +G_BEGIN_DECLS + +typedef struct _AsScreenshot AsScreenshot; +typedef struct _AsScreenshotClass AsScreenshotClass; + +struct _AsScreenshot +{ + GObject parent; +}; + +struct _AsScreenshotClass +{ + GObjectClass parent_class; +}; + +typedef enum { + AS_SCREENSHOT_KIND_NORMAL, + AS_SCREENSHOT_KIND_DEFAULT, + AS_SCREENSHOT_KIND_UNKNOWN, + AS_SCREENSHOT_KIND_LAST +} AsScreenshotKind; + +GType as_screenshot_get_type (void); +AsScreenshot *as_screenshot_new (void); + +AsScreenshotKind as_screenshot_kind_from_string (const gchar *kind); +const gchar *as_screenshot_kind_to_string (AsScreenshotKind kind); + +AsScreenshotKind as_screenshot_get_kind (AsScreenshot *screenshot); +const gchar *as_screenshot_get_caption (AsScreenshot *app, + const gchar *locale); +GPtrArray *as_screenshot_get_images (AsScreenshot *screenshot); + +void as_screenshot_set_kind (AsScreenshot *screenshot, + AsScreenshotKind kind); +void as_screenshot_set_caption (AsScreenshot *app, + const gchar *locale, + const gchar *caption, + gsize caption_length); +void as_screenshot_add_image (AsScreenshot *screenshot, + AsImage *image); + +G_END_DECLS + +#endif /* AS_SCREENSHOT_H */ |