[gnome-software] trivial: Add an object for holding an AppStream image



commit 2eb5479d16fb7a9f03cb2f8419244f1380f08fed
Author: Richard Hughes <richard hughsie com>
Date:   Fri Oct 4 09:49:32 2013 +0100

    trivial: Add an object for holding an AppStream image

 src/plugins/Makefile.am       |    2 +
 src/plugins/appstream-image.c |  139 +++++++++++++++++++++++++++++++++++++++++
 src/plugins/appstream-image.h |   59 +++++++++++++++++
 3 files changed, 200 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 12a6145..6f22273 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -62,6 +62,8 @@ libgs_plugin_appstream_la_SOURCES =                   \
        gs-plugin-appstream.c                           \
        appstream-app.c                                 \
        appstream-app.h                                 \
+       appstream-image.c                               \
+       appstream-image.h                               \
        appstream-common.c                              \
        appstream-common.h                              \
        appstream-cache.c                               \
diff --git a/src/plugins/appstream-image.c b/src/plugins/appstream-image.c
new file mode 100644
index 0000000..3ecebaf
--- /dev/null
+++ b/src/plugins/appstream-image.c
@@ -0,0 +1,139 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include "appstream-image.h"
+
+struct AppstreamImage
+{
+       gchar                   *url;
+       guint                    width;
+       guint                    height;
+       AppstreamImageKind       kind;
+};
+
+/**
+ * appstream_image_new:
+ */
+AppstreamImage *
+appstream_image_new (void)
+{
+       return g_slice_new0 (AppstreamImage);
+}
+
+/**
+ * appstream_image_free:
+ */
+void
+appstream_image_free (AppstreamImage *image)
+{
+       g_free (image->url);
+       g_slice_free (AppstreamImage, image);
+}
+
+/**
+ * appstream_image_set_url:
+ */
+void
+appstream_image_set_url (AppstreamImage *image, const gchar *url, gsize url_len)
+{
+       g_free (image->url);
+       image->url = g_strndup (url, url_len);
+}
+
+/**
+ * appstream_image_set_width:
+ */
+void
+appstream_image_set_width (AppstreamImage *image, guint width)
+{
+       image->width = width;
+}
+
+/**
+ * appstream_image_set_height:
+ */
+void
+appstream_image_set_height (AppstreamImage *image, guint height)
+{
+       image->height = height;
+}
+
+/**
+ * appstream_image_set_kind:
+ */
+void
+appstream_image_set_kind (AppstreamImage *image, AppstreamImageKind kind)
+{
+       image->kind = kind;
+}
+
+/**
+ * appstream_image_get_url:
+ */
+const gchar *
+appstream_image_get_url (AppstreamImage *image)
+{
+       return image->url;
+}
+
+/**
+ * appstream_image_get_width:
+ */
+guint
+appstream_image_get_width (AppstreamImage *image)
+{
+       return image->width;
+}
+
+/**
+ * appstream_image_get_height:
+ */
+guint
+appstream_image_get_height (AppstreamImage *image)
+{
+       return image->height;
+}
+
+/**
+ * appstream_image_get_kind:
+ */
+AppstreamImageKind
+appstream_image_get_kind (AppstreamImage *image)
+{
+       return image->kind;
+}
+
+/**
+ * appstream_image_kind_from_string:
+ */
+AppstreamImageKind
+appstream_image_kind_from_string (const gchar *kind)
+{
+       if (g_strcmp0 (kind, "source") == 0)
+               return APPSTREAM_IMAGE_KIND_SOURCE;
+       if (g_strcmp0 (kind, "thumbnail") == 0)
+               return APPSTREAM_IMAGE_KIND_THUMBNAIL;
+       return APPSTREAM_IMAGE_KIND_UNKNOWN;
+}
+
+/* vim: set noexpandtab: */
diff --git a/src/plugins/appstream-image.h b/src/plugins/appstream-image.h
new file mode 100644
index 0000000..af9af55
--- /dev/null
+++ b/src/plugins/appstream-image.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __APPSTREAM_IMAGE_H
+#define __APPSTREAM_IMAGE_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct AppstreamImage  AppstreamImage;
+
+typedef enum {
+       APPSTREAM_IMAGE_KIND_UNKNOWN,
+       APPSTREAM_IMAGE_KIND_SOURCE,
+       APPSTREAM_IMAGE_KIND_THUMBNAIL,
+       APPSTREAM_IMAGE_KIND_LAST
+} AppstreamImageKind;
+
+AppstreamImage *appstream_image_new                    (void);
+void            appstream_image_free                   (AppstreamImage *image);
+
+void            appstream_image_set_url                (AppstreamImage *image,
+                                                        const gchar    *url,
+                                                        gsize           url_len);
+void            appstream_image_set_width              (AppstreamImage *image,
+                                                        guint           width);
+void            appstream_image_set_height             (AppstreamImage *image,
+                                                        guint           height);
+void            appstream_image_set_kind               (AppstreamImage *image,
+                                                        AppstreamImageKind kind);
+
+const gchar    *appstream_image_get_url                (AppstreamImage *image);
+guint           appstream_image_get_width              (AppstreamImage *image);
+guint           appstream_image_get_height             (AppstreamImage *image);
+AppstreamImageKind appstream_image_get_kind            (AppstreamImage *image);
+AppstreamImageKind appstream_image_kind_from_string    (const gchar    *kind);
+
+G_END_DECLS
+
+#endif /* __APPSTREAM_IMAGE_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]