[virt-tools-list] [PATCH 3/4] install script: add install_script_avatar entity

Fabiano Fidêncio fabiano at fidencio.org
Sun Aug 26 08:50:16 UTC 2012


Add a new entity called OsinfoInstallScriptAvatar to help the creation
of an Avatar file for an install script. If avatar entity needs to be
set, just add, in the .xml's script file:
<avatar>
    <image-type>...</image-type>
    <extension>...</extension>
    <alpha>...</alpha>
    <width>...</width>
    <height>...</height>
</avatar>
---
 data/install-scripts/fedora.xml       |   7 +
 data/install-scripts/windows-sif.xml  |   7 +
 data/schemas/libosinfo.rng            |  25 ++-
 docs/reference/Libosinfo.types        |   1 +
 osinfo/Makefile.am                    |   2 +
 osinfo/libosinfo.syms                 |   7 +
 osinfo/osinfo.h                       |   1 +
 osinfo/osinfo_install_script.c        |  13 ++
 osinfo/osinfo_install_script.h        |   5 +
 osinfo/osinfo_install_script_avatar.c | 352 ++++++++++++++++++++++++++++++++++
 osinfo/osinfo_install_script_avatar.h |  84 ++++++++
 osinfo/osinfo_loader.c                |  61 ++++++
 12 files changed, 564 insertions(+), 1 deletion(-)
 create mode 100644 osinfo/osinfo_install_script_avatar.c
 create mode 100644 osinfo/osinfo_install_script_avatar.h

diff --git a/data/install-scripts/fedora.xml b/data/install-scripts/fedora.xml
index eef4f4a..f7ee68c 100644
--- a/data/install-scripts/fedora.xml
+++ b/data/install-scripts/fedora.xml
@@ -113,6 +113,13 @@ reboot
         <param name="user-password" policy="required"/>
         <param name="admin-password" policy="required"/>
     </config>
+    <avatar>
+        <image-type>png</image-type>
+        <extension>.png</extension>
+        <alpha>true</alpha>
+        <width>-1</width>
+        <height>-1</height>
+    </avatar>
     <template filename="fedora.ks">
       <xsl:stylesheet
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
diff --git a/data/install-scripts/windows-sif.xml b/data/install-scripts/windows-sif.xml
index 76f9baf..7c0acfe 100644
--- a/data/install-scripts/windows-sif.xml
+++ b/data/install-scripts/windows-sif.xml
@@ -70,6 +70,13 @@
       <param name="user-realname" policy="required"/>
       <param name="hostname" policy="required"/>
     </config>
+    <avatar>
+        <image-type>bmp</image-type>
+        <extension>.bmp</extension>
+        <alpha>false</alpha>
+        <width>48</width>
+        <height>48</height>
+    </avatar>
     <template filename="winnt.sif">
       <xsl:stylesheet
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng
index 1392f74..4d1906d 100644
--- a/data/schemas/libosinfo.rng
+++ b/data/schemas/libosinfo.rng
@@ -410,7 +410,7 @@
       <element name='profile'>
         <text/>
       </element>
-      <element name='config'>
+       <element name='config'>
         <attribute name="name"/>
         <attribute name="policy">
           <ref name='policies'/>
@@ -419,6 +419,9 @@
       <element name='product-key-format'>
         <text/>
       </element>
+      <optional>
+        <ref name='avatar'/>
+      </optional>
       <element name='template'>
         <attribute name="filename"/>
         <choice>
@@ -441,6 +444,26 @@
     </element>
   </define>
 
+  <define name='avatar'>
+    <interleaves>
+      <element name="image-type"/>
+        </text>
+      </element>
+      <element name="extension"/>
+        </text>
+      </element>
+      <element name="alpha"/>
+        </text>
+      </element>
+      <element name="width"/>
+        </text>
+      </element>
+      <element name="height"/>
+        </text>
+      </element>
+    </interleaves>
+  </define>
+
   <define name="customElement">
     <element>
       <anyName/>
diff --git a/docs/reference/Libosinfo.types b/docs/reference/Libosinfo.types
index 8744ee6..91b29c6 100644
--- a/docs/reference/Libosinfo.types
+++ b/docs/reference/Libosinfo.types
@@ -11,6 +11,7 @@ osinfo_filter_get_type
 osinfo_install_config_get_type
 osinfo_install_config_param_get_type
 osinfo_install_script_get_type
+osinfo_install_script_avatar_get_type
 osinfo_install_scriptlist_get_type
 osinfo_list_get_type
 osinfo_loader_get_type
diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index 495d2f5..f8df85e 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -61,6 +61,7 @@ libosinfo_1_0_include_HEADERS = \
   osinfo_install_config.h       \
   osinfo_install_config_param.h \
   osinfo_install_script.h       \
+  osinfo_install_script_avatar.h\
   osinfo_install_scriptlist.h   \
   osinfo_product.h		\
   osinfo_productfilter.h	\
@@ -92,6 +93,7 @@ libosinfo_1_0_la_SOURCES =	\
   osinfo_install_config.c       \
   osinfo_install_config_param.c \
   osinfo_install_script.c       \
+  osinfo_install_script_avatar.c\
   osinfo_install_scriptlist.c   \
   osinfo_product.c		\
   osinfo_productfilter.c	\
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index c60f726..de75094 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -285,6 +285,13 @@ LIBOSINFO_0.2.0 {
 	osinfo_install_script_has_config_param;
 	osinfo_install_script_has_config_param_name;
 	osinfo_install_script_get_config_param_list;
+	osinfo_install_script_avatar_get_type;
+	osinfo_install_script_avatar_new;
+	osinfo_install_script_avatar_get_imagetype;
+	osinfo_install_script_avatar_get_extension;
+	osinfo_install_script_avatar_has_alpha;
+	osinfo_install_script_avatar_get_width;
+	osinfo_install_script_avatar_get_height;
 	osinfo_install_scriptlist_new;
 	osinfo_install_scriptlist_new_filtered;
 	osinfo_install_scriptlist_new_union;
diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
index 204569b..8413a2f 100644
--- a/osinfo/osinfo.h
+++ b/osinfo/osinfo.h
@@ -36,6 +36,7 @@
 #include <osinfo/osinfo_install_config.h>
 #include <osinfo/osinfo_install_config_param.h>
 #include <osinfo/osinfo_install_script.h>
+#include <osinfo/osinfo_install_script_avatar.h>
 #include <osinfo/osinfo_install_scriptlist.h>
 #include <osinfo/osinfo_productlist.h>
 #include <osinfo/osinfo_product.h>
diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
index bb4e0f3..529cf05 100644
--- a/osinfo/osinfo_install_script.c
+++ b/osinfo/osinfo_install_script.c
@@ -49,6 +49,7 @@ struct _OsinfoInstallScriptPrivate
     gchar *output_prefix;
     gchar *output_filename;
     GList *config_param_list;
+    OsinfoInstallScriptAvatar *avatar;
 };
 
 enum {
@@ -374,6 +375,18 @@ const gchar *osinfo_install_script_get_output_filename(OsinfoInstallScript *scri
     return osinfo_install_script_get_filename(script);
 }
 
+void osinfo_install_script_set_avatar(OsinfoInstallScript *script, OsinfoInstallScriptAvatar *avatar)
+{
+    if (script->priv->avatar)
+        g_object_unref(script->priv->avatar);
+    script->priv->avatar = avatar;
+}
+
+const OsinfoInstallScriptAvatar *osinfo_install_script_get_avatar(OsinfoInstallScript *script)
+{
+    return script->priv->avatar;
+}
+
 struct _OsinfoInstallScriptGenerateData {
     GSimpleAsyncResult *res;
     OsinfoOs *os;
diff --git a/osinfo/osinfo_install_script.h b/osinfo/osinfo_install_script.h
index a360098..0d28896 100644
--- a/osinfo/osinfo_install_script.h
+++ b/osinfo/osinfo_install_script.h
@@ -24,6 +24,7 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 #include <osinfo/osinfo_install_config_param.h>
+#include <osinfo/osinfo_install_script_avatar.h>
 
 #ifndef __OSINFO_INSTALL_SCRIPT_H__
 #define __OSINFO_INSTALL_SCRIPT_H__
@@ -97,6 +98,10 @@ const gchar *osinfo_install_script_get_output_filename(OsinfoInstallScript *scri
 
 const gchar *osinfo_install_script_get_filename(OsinfoInstallScript *script);
 
+void osinfo_install_script_set_avatar(OsinfoInstallScript *script, OsinfoInstallScriptAvatar *avatar);
+
+const OsinfoInstallScriptAvatar *osinfo_install_script_get_avatar(OsinfoInstallScript *script);
+
 void osinfo_install_script_generate_async(OsinfoInstallScript *script,
                                           OsinfoOs *os,
                                           OsinfoInstallConfig *config,
diff --git a/osinfo/osinfo_install_script_avatar.c b/osinfo/osinfo_install_script_avatar.c
new file mode 100644
index 0000000..c79a632
--- /dev/null
+++ b/osinfo/osinfo_install_script_avatar.c
@@ -0,0 +1,352 @@
+/*
+ * libosinfo:
+ *
+ * Copyright (C) 2009-2012 Red Hat, Inc.
+ *
+ * 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
+ *
+ * Authors:
+ *   Fabiano Fidêncio <fabiano at fidencio.org>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+
+G_DEFINE_TYPE (OsinfoInstallScriptAvatar, osinfo_install_script_avatar, OSINFO_TYPE_ENTITY);
+
+#define OSINFO_INSTALL_SCRIPT_AVATAR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_INSTALL_SCRIPT_AVATAR, OsinfoInstallScriptAvatarPrivate))
+
+/**
+ * SECTION:osinfo_install_script_avatar
+ * @short_description: The necessary information to create an Avatar for an
+ *                     install script
+ * @see_also: #OsinfoInstallScript
+ *
+ *
+ * #OsinfoInstallScriptAvatar is an entity for representing all necessary
+ * information to help the creation of an Avatar file, used in an automated
+ * installation script
+ */
+
+struct _OsinfoInstallScriptAvatarPrivate
+{
+    gchar *imagetype;
+    gchar *extension;
+    gboolean alpha;
+    gint width;
+    gint height;
+};
+
+enum {
+    PROP_0,
+
+    PROP_IMAGETYPE,
+    PROP_EXTENSION,
+    PROP_ALPHA,
+    PROP_WIDTH,
+    PROP_HEIGHT,
+};
+
+static void
+osinfo_install_script_avatar_set_property(GObject *object,
+                                          guint property_id,
+                                          const GValue *value,
+                                          GParamSpec *pspec)
+{
+    OsinfoInstallScriptAvatar *avatar =
+        OSINFO_INSTALL_SCRIPT_AVATAR (object);
+
+    switch (property_id)
+        {
+        case PROP_IMAGETYPE:
+            avatar->priv->imagetype = g_value_dup_string(value);
+            break;
+        case PROP_EXTENSION:
+            avatar->priv->extension = g_value_dup_string(value);
+            break;
+        case PROP_ALPHA:
+            avatar->priv->alpha = g_value_get_boolean(value);
+            break;
+        case PROP_WIDTH:
+            avatar->priv->width = g_value_get_int(value);
+            break;
+        case PROP_HEIGHT:
+            avatar->priv->height = g_value_get_int(value);
+            break;
+        default:
+            /* We don't have any other property... */
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+            break;
+        }
+}
+
+static void
+osinfo_install_script_avatar_get_property(GObject *object,
+                                          guint property_id,
+                                          GValue *value,
+                                          GParamSpec *pspec)
+{
+    OsinfoInstallScriptAvatar *avatar =
+        OSINFO_INSTALL_SCRIPT_AVATAR (object);
+
+    switch (property_id)
+        {
+        case PROP_IMAGETYPE:
+            g_value_set_string(value, avatar->priv->imagetype);
+            break;
+        case PROP_EXTENSION:
+            g_value_set_string(value, avatar->priv->extension);
+            break;
+        case PROP_ALPHA:
+            g_value_set_boolean(value, avatar->priv->alpha);
+            break;
+        case PROP_WIDTH:
+            g_value_set_int(value, avatar->priv->width);
+            break;
+        case PROP_HEIGHT:
+            g_value_set_int(value, avatar->priv->height);
+            break;
+        default:
+            /* We don't have any other property... */
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+            break;
+        }
+}
+
+
+static void
+osinfo_install_script_avatar_finalize(GObject *object)
+{
+    OsinfoInstallScriptAvatar *avatar =
+        OSINFO_INSTALL_SCRIPT_AVATAR(object);
+    g_free(avatar->priv->imagetype);
+    g_free(avatar->priv->extension);
+
+    /* Chain up to the parent class */
+    G_OBJECT_CLASS (osinfo_install_script_avatar_parent_class)->finalize (object);
+}
+
+/* Init functions */
+static void
+osinfo_install_script_avatar_class_init (OsinfoInstallScriptAvatarClass *klass)
+{
+    GObjectClass *g_klass = G_OBJECT_CLASS (klass);
+    GParamSpec *pspec;
+
+    g_klass->set_property = osinfo_install_script_avatar_set_property;
+    g_klass->get_property = osinfo_install_script_avatar_get_property;
+
+    /**
+     * OsinfoInstallScriptAvatar:imagetype:
+     *
+     * The image type of the avatar file.
+     **/
+    pspec = g_param_spec_string("image-type",
+                                "Image-type",
+                                "Avatar image type",
+                                NULL,
+                                G_PARAM_WRITABLE |
+                                G_PARAM_READABLE |
+                                G_PARAM_CONSTRUCT_ONLY |
+                                G_PARAM_STATIC_NAME |
+                                G_PARAM_STATIC_NICK |
+                                G_PARAM_STATIC_BLURB);
+    g_object_class_install_property(g_klass,
+                                    PROP_IMAGETYPE,
+                                    pspec);
+    /**
+     * OsinfoInstallScriptAvatar:extension:
+     *
+     * The extension of the avatar file.
+     **/
+    pspec = g_param_spec_string("extension",
+                                "Extension",
+                                "Parameter extension",
+                                NULL,
+                                G_PARAM_WRITABLE |
+                                G_PARAM_READABLE |
+                                G_PARAM_CONSTRUCT_ONLY |
+                                G_PARAM_STATIC_NAME |
+                                G_PARAM_STATIC_NICK |
+                                G_PARAM_STATIC_BLURB);
+    g_object_class_install_property(g_klass,
+                                    PROP_EXTENSION,
+                                    pspec);
+
+    /**
+     * OsinfoInstallScriptAvatar:alpha:
+     *
+     * The presence of the alpha channel of the avatar file.
+     **/
+    pspec = g_param_spec_boolean("alpha",
+                                 "Alpha",
+                                 "Parameter alpha",
+                                 FALSE,
+                                 G_PARAM_WRITABLE |
+                                 G_PARAM_READABLE |
+                                 G_PARAM_CONSTRUCT_ONLY |
+                                 G_PARAM_STATIC_NAME |
+                                 G_PARAM_STATIC_NICK |
+                                 G_PARAM_STATIC_BLURB);
+    g_object_class_install_property(g_klass,
+                                    PROP_ALPHA,
+                                    pspec);
+
+    /**
+     * OsinfoInstallScriptAvatar:width:
+     *
+     * The width size (in pixels) of the avatar file.
+     **/
+    pspec = g_param_spec_int("width",
+                             "Width",
+                             "Parameter width",
+                             -1,
+                             G_MAXINT,
+                             -1,
+                             G_PARAM_WRITABLE |
+                             G_PARAM_READABLE |
+                             G_PARAM_CONSTRUCT_ONLY |
+                             G_PARAM_STATIC_NAME |
+                             G_PARAM_STATIC_NICK |
+                             G_PARAM_STATIC_BLURB);
+    g_object_class_install_property(g_klass,
+                                    PROP_WIDTH,
+                                    pspec);
+
+    /**
+     * OsinfoInstallScriptAvatar:height:
+     *
+     * The height size (in pixels) of the avatar file.
+     **/
+    pspec = g_param_spec_int("height",
+                             "Height",
+                             "Parameter height",
+                             -1,
+                             G_MAXINT,
+                             -1,
+                             G_PARAM_WRITABLE |
+                             G_PARAM_READABLE |
+                             G_PARAM_CONSTRUCT_ONLY |
+                             G_PARAM_STATIC_NAME |
+                             G_PARAM_STATIC_NICK |
+                             G_PARAM_STATIC_BLURB);
+    g_object_class_install_property(g_klass,
+                                    PROP_HEIGHT,
+                                    pspec);
+
+
+    g_klass->finalize = osinfo_install_script_avatar_finalize;
+
+    g_type_class_add_private (klass, sizeof (OsinfoInstallScriptAvatarPrivate));
+}
+
+static void
+osinfo_install_script_avatar_init (OsinfoInstallScriptAvatar *avatar)
+{
+    OsinfoInstallScriptAvatarPrivate *priv;
+    avatar->priv = priv = OSINFO_INSTALL_SCRIPT_AVATAR_GET_PRIVATE(avatar);
+}
+
+
+/**
+ * osinfo_install_script_avatar_new:
+ * @type: the image type of the avatar file
+ * @extension: the avatar file extension
+ * @alpha: the presence of the alpha channel in the avatar file
+ * @width: the width size (in pixels) of the avatar file
+ * @height: the height size (in pixels) of the avatar file
+ *
+ * Construct a new user avatar file to a #OsinfoInstallScript.
+ *
+ * Returns: (transfer full): the new user avatar
+ */
+OsinfoInstallScriptAvatar *osinfo_install_script_avatar_new(const gchar *mimetype,
+                                                            const gchar *extension,
+                                                            gboolean     alpha,
+                                                            gint         width,
+                                                            gint         height)
+{
+    return g_object_new(OSINFO_TYPE_INSTALL_SCRIPT_AVATAR,
+                        "image type", mimetype,
+                        "extension", extension,
+                        "alpha", alpha,
+                        "width", width,
+                        "height", height,
+                        NULL);
+}
+
+/**
+ * osinfo_install_script_avatar_get_mimetype:
+ * @avatar: the install script avatar
+ *
+ * Returns: (transfer none): the image type of the avatar file
+ */
+const gchar *osinfo_install_script_avatar_get_imagetype(const OsinfoInstallScriptAvatar *avatar)
+{
+    return avatar->priv->imagetype;
+}
+
+/**
+ * osinfo_install_script_avatar_get_extension:
+ * @avatar: the install script avatar
+ *
+ * Returns: (transfer none): the extension of the avatar file
+ */
+const gchar *osinfo_install_script_avatar_get_extension(const OsinfoInstallScriptAvatar *avatar)
+{
+    return avatar->priv->extension;
+}
+
+/**
+ * osinfo_install_script_avatar_has_alpha:
+ * @avatar: the install script avatar
+ *
+ * Returns: (transfer none): the presence of the alpha channel in the avatar file
+ */
+gboolean osinfo_install_script_avatar_has_alpha(const OsinfoInstallScriptAvatar *avatar)
+{
+    return avatar->priv->alpha;
+}
+
+/**
+ * osinfo_install_script_avatar_get_width:
+ * @avatar: the install script avatar
+ *
+ * Returns: (transfer none): the width size (in pixels) of the avatar file
+ */
+gint osinfo_install_script_avatar_get_width(const OsinfoInstallScriptAvatar *avatar)
+{
+    return avatar->priv->width;
+}
+
+/**
+ * osinfo_install_script_avatar_get_height:
+ * @avatar: the install script avatar
+ *
+ * Returns: (transfer none): the heigth size (in pixels) of the avatar file
+ */
+gint osinfo_install_script_avatar_get_heigth(const OsinfoInstallScriptAvatar *avatar)
+{
+    return avatar->priv->height;
+}
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_install_script_avatar.h b/osinfo/osinfo_install_script_avatar.h
new file mode 100644
index 0000000..0d59be8
--- /dev/null
+++ b/osinfo/osinfo_install_script_avatar.h
@@ -0,0 +1,84 @@
+/*
+ * libosinfo: OS installation avatar
+ *
+ * Copyright (C) 2009-2012 Red Hat, Inc.
+ *
+ * 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
+ *
+ * Authors:
+ *   Fabiano Fidêncio <fabiano at fidencio.org>
+ */
+
+#include <glib-object.h>
+
+#ifndef __OSINFO_INSTALL_SCRIPT_AVATAR_H__
+#define __OSINFO_INSTALL_SCRIPT_AVATAR_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_INSTALL_SCRIPT_AVATAR            (osinfo_install_script_avatar_get_type ())
+#define OSINFO_INSTALL_SCRIPT_AVATAR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_INSTALL_SCRIPT_AVATAR, OsinfoInstallScriptAvatar))
+#define OSINFO_IS_INSTALL_SCRIPT_AVATAR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_INSTALL_SCRIPT_AVATAR))
+#define OSINFO_INSTALL_SCRIPT_AVATAR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_INSTALL_SCRIPT_AVATAR, OsinfoInstallScriptAvatarClass))
+#define OSINFO_IS_INSTALL_SCRIPT_AVATAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_INSTALL_SCRIPT_AVATAR))
+#define OSINFO_INSTALL_SCRIPT_AVATAR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_INSTALL_SCRIPT_AVATAR, OsinfoInstallScriptAvatarClass))
+
+typedef struct _OsinfoInstallScriptAvatar        OsinfoInstallScriptAvatar;
+typedef struct _OsinfoInstallScriptAvatarClass   OsinfoInstallScriptAvatarClass;
+typedef struct _OsinfoInstallScriptAvatarPrivate OsinfoInstallScriptAvatarPrivate;
+
+/* object */
+struct _OsinfoInstallScriptAvatar
+{
+    OsinfoEntity parent_instance;
+    /* public */
+
+    /* private */
+    OsinfoInstallScriptAvatarPrivate *priv;
+};
+
+/* class */
+struct _OsinfoInstallScriptAvatarClass
+{
+    OsinfoEntityClass parent_class;
+
+    /* class members */
+};
+
+GType osinfo_install_script_avatar_get_type(void);
+
+OsinfoInstallScriptAvatar *osinfo_install_script_avatar_new(const gchar *mimetype, const gchar *extension, gboolean alpha, gint width, gint height);
+
+const gchar *osinfo_install_script_avatar_get_imagetype(const OsinfoInstallScriptAvatar *avatar);
+
+const gchar *osinfo_install_script_avatar_get_extension(const OsinfoInstallScriptAvatar *avatar);
+
+gboolean osinfo_install_script_avatar_has_alpha(const OsinfoInstallScriptAvatar *avatar);
+
+gint osinfo_install_script_avatar_get_width(const OsinfoInstallScriptAvatar *avatar);
+
+gint osinfo_install_script_avatar_get_heigth(const OsinfoInstallScriptAvatar *avatar);
+
+
+
+#endif /* __OSINFO_INSTALL_CONFIG_PARAM_H__ */
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 404e5b9..04524e0 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -568,7 +568,62 @@ static void osinfo_loader_install_config_param(OsinfoLoader *loader,
     g_free(nodes);
 }
 
+static void osinfo_loader_install_script_avatar(OsinfoLoader *loader,
+                                                OsinfoEntity *entity,
+                                                xmlXPathContextPtr ctxt,
+                                                xmlNodePtr root,
+                                                GError **err)
+{
+    gchar *imagetype, *extension, *ascii_alpha, *ascii_width, *ascii_height;
+    OsinfoInstallScriptAvatar *avatar;
+    gboolean alpha;
+    gint width, height;
+
+    imagetype = osinfo_loader_string("string(./avatar/image-type)", ctxt, err);
+    if (error_is_set(err))
+        return;
+
+    extension = osinfo_loader_string("string(./avatar/extension)", ctxt, err);
+    if (error_is_set(err))
+        return;
+
+    ascii_alpha = osinfo_loader_string("string(./avatar/alpha)", ctxt, err);
+    if (error_is_set(err))
+        return;
 
+    ascii_width = osinfo_loader_string("string(./avatar/width)", ctxt, err);
+    if (error_is_set(err))
+        return;
+
+    ascii_height = osinfo_loader_string("string(./avatar/height)", ctxt, err);
+    if (error_is_set(err))
+        return;
+
+    if (!imagetype      ||
+        !extension      ||
+        !ascii_alpha    ||
+        !ascii_width    ||
+        !ascii_height)
+        return;
+
+    alpha = (g_strcmp0(ascii_alpha, "true") == 0) ? TRUE : FALSE;
+    width = atoi(ascii_width);
+    height = atoi(ascii_height);
+
+    avatar = osinfo_install_script_avatar_new(imagetype,
+                                              extension,
+                                              alpha,
+                                              width,
+                                              height);
+
+    osinfo_install_script_set_avatar(OSINFO_INSTALL_SCRIPT(entity), avatar);
+
+    g_free(imagetype);
+    g_free(extension);
+    g_free(ascii_alpha);
+    g_free(ascii_width);
+    g_free(ascii_height);
+}
 
 static void osinfo_loader_install_script(OsinfoLoader *loader,
                                          xmlXPathContextPtr ctxt,
@@ -630,6 +685,12 @@ static void osinfo_loader_install_script(OsinfoLoader *loader,
                                        root,
                                        err);
 
+    osinfo_loader_install_script_avatar(loader,
+                                        OSINFO_ENTITY(installScript),
+                                        ctxt,
+                                        root,
+                                        err);
+
     osinfo_db_add_install_script(loader->priv->db, installScript);
 
     return;
-- 
1.7.11.4




More information about the virt-tools-list mailing list