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

Re: [virt-tools-list] [libosinfo] API to query required user avatar format



On Thu, Nov 15, 2012 at 12:44:47AM +0200, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>
> 
> Add a new API for apps to be able to query in which format do the user
> avatar file need to be in.
> 
> Based on a patch from Fabiano FidĂȘncio <fabiano fidencio org>.
> ---
>  data/install-scripts/windows-cmd.xml |   6 +
>  data/schemas/libosinfo.rng           |  30 +++++
>  osinfo/Makefile.am                   |   2 +
>  osinfo/libosinfo.syms                |   8 +-
>  osinfo/osinfo.h                      |   1 +
>  osinfo/osinfo_avatar_format.c        | 250 +++++++++++++++++++++++++++++++++++
>  osinfo/osinfo_avatar_format.h        |  95 +++++++++++++
>  osinfo/osinfo_install_script.c       |  53 ++++++++
>  osinfo/osinfo_install_script.h       |   6 +
>  osinfo/osinfo_loader.c               |  44 ++++++
>  po/POTFILES.in                       |   1 +
>  11 files changed, 495 insertions(+), 1 deletion(-)
>  create mode 100644 osinfo/osinfo_avatar_format.c
>  create mode 100644 osinfo/osinfo_avatar_format.h
> 
> diff --git a/data/install-scripts/windows-cmd.xml b/data/install-scripts/windows-cmd.xml
> index 020a493..3c6ba23 100644
> --- a/data/install-scripts/windows-cmd.xml
> +++ b/data/install-scripts/windows-cmd.xml
> @@ -12,6 +12,12 @@
>        <param name="target-disk" policy="optional"/>
>        <param name="script-disk" policy="optional"/>
>      </config>
> +    <avatar-format>
> +        <mime-type>image/bmp</mime-type>
> +        <depth>24</depth>
> +        <width>48</width>
> +        <height>48</height>
> +    </avatar-format>
>      <template>
>        <xsl:stylesheet
>          xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng
> index 3c57c36..c27c680 100644
> --- a/data/schemas/libosinfo.rng
> +++ b/data/schemas/libosinfo.rng
> @@ -478,6 +478,9 @@
>            </element>
>          </optional>
>          <optional>
> +          <ref name='avatar-format'/>
> +        </optional>
> +        <optional>
>            <element name='config'>
>              <oneOrMore>
>                <element name='param'>
> @@ -509,6 +512,33 @@
>      </element>
>    </define>
>  
> +  <define name='avatar-format'>
> +    <element name='avatar-format'>
> +      <interleave>
> +        <optional>
> +          <element name="mime-type">
> +            <text/>
> +          </element>
> +        </optional>
> +        <optional>
> +          <element name="width">
> +            <ref name='num'/>
> +          </element>
> +        </optional>
> +        <optional>
> +          <element name="height">
> +            <ref name='num'/>
> +          </element>
> +        </optional>
> +        <optional>
> +          <element name="depth">
> +            <ref name='num'/>
> +          </element>
> +        </optional>
> +      </interleave>
> +    </element>
> +  </define>
> +
>    <define name="customElement">
>      <element>
>        <anyName/>
> diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
> index abaa78c..e85adb7 100644
> --- a/osinfo/Makefile.am
> +++ b/osinfo/Makefile.am
> @@ -55,6 +55,7 @@ libosinfo_1_0_includedir = $(includedir)/libosinfo-1.0/osinfo
>  
>  libosinfo_1_0_include_HEADERS = \
>    osinfo.h			\
> +  osinfo_avatar_format.h 	\
>    osinfo_db.h			\
>    osinfo_loader.h		\
>    osinfo_device.h		\
> @@ -88,6 +89,7 @@ libosinfo_1_0_include_HEADERS = \
>    $(NULL)
>  
>  libosinfo_1_0_la_SOURCES =	\
> +  osinfo_avatar_format.c 	\
>    osinfo_entity.c		\
>    osinfo_enum_types.c		\
>    osinfo_filter.c		\
> diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
> index de33a70..271e3d7 100644
> --- a/osinfo/libosinfo.syms
> +++ b/osinfo/libosinfo.syms
> @@ -317,6 +317,12 @@ LIBOSINFO_0.2.1 {
>  
>  LIBOSINFO_0.2.2 {
>      global:
> +	osinfo_avatar_format_get_type;
> +	osinfo_avatar_format_get_mime_type;
> +	osinfo_avatar_format_get_width;
> +	osinfo_avatar_format_get_height;
> +	osinfo_avatar_format_get_depth;
> +
>  	osinfo_install_config_param_policy_get_type;
>  	osinfo_media_error_get_type;
>  	osinfo_product_relationship_get_type;
> @@ -336,10 +342,10 @@ LIBOSINFO_0.2.2 {
>  	osinfo_install_config_get_script_disk;
>  	osinfo_install_config_set_script_disk;
>  
> +	osinfo_install_script_get_avatar_format;
>  	osinfo_install_script_get_path_format;
>  } LIBOSINFO_0.2.1;
>  
> -
>  /* Symbols in next release...
>  
>    LIBOSINFO_0.0.2 {
> diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
> index 81ed1cc..559eaa8 100644
> --- a/osinfo/osinfo.h
> +++ b/osinfo/osinfo.h
> @@ -39,6 +39,7 @@
>  #include <osinfo/osinfo_install_config.h>
>  #include <osinfo/osinfo_install_config_param.h>
>  #include <osinfo/osinfo_install_script.h>
> +#include <osinfo/osinfo_avatar_format.h>
>  #include <osinfo/osinfo_install_scriptlist.h>
>  #include <osinfo/osinfo_productlist.h>
>  #include <osinfo/osinfo_product.h>
> diff --git a/osinfo/osinfo_avatar_format.c b/osinfo/osinfo_avatar_format.c
> new file mode 100644
> index 0000000..5f6a4e3
> --- /dev/null
> +++ b/osinfo/osinfo_avatar_format.c
> @@ -0,0 +1,250 @@
> +/*
> + * 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 fidencio org>
> + *   Zeeshan Ali (Khattak) <zeeshanak gnome org>
> + */
> +
> +#include <config.h>
> +
> +#include <osinfo/osinfo.h>
> +#include <glib/gi18n-lib.h>
> +
> +G_DEFINE_TYPE (OsinfoAvatarFormat, osinfo_avatar_format, OSINFO_TYPE_ENTITY);
> +
> +#define OSINFO_AVATAR_FORMAT_GET_PRIVATE(obj)  \
> +        (G_TYPE_INSTANCE_GET_PRIVATE ((obj),                \
> +         OSINFO_TYPE_AVATAR_FORMAT,            \
> +         OsinfoAvatarFormatPrivate))
> +
> +#define DEFAULT_MIME_TYPE "image/png"
> +
> +/**
> + * SECTION: osinfo_avatar_format
> + * @short_description: The required format of avatar for an install script
> + * @see_also: #OsinfoInstallScript
> + */
> +
> +enum {
> +    PROP_0,
> +
> +    PROP_MIME_TYPE,
> +    PROP_WIDTH,
> +    PROP_HEIGHT,
> +    PROP_DEPTH,
> +};
> +
> +static void
> +osinfo_avatar_format_get_property(GObject *object,
> +				  guint property_id,
> +                                  GValue *value,
> +                                  GParamSpec *pspec)
> +{
> +    OsinfoAvatarFormat *avatar = OSINFO_AVATAR_FORMAT (object);
> +
> +    switch (property_id)
> +        {
> +        case PROP_MIME_TYPE:
> +        {
> +            const gchar *mime_type;
> +
> +            mime_type = osinfo_avatar_format_get_mime_type(avatar);
> +            g_value_set_string(value, mime_type);
> +            break;
> +        }
> +        case PROP_WIDTH:
> +            g_value_set_int(value,
> +                            osinfo_avatar_format_get_width(avatar));
> +            break;
> +        case PROP_HEIGHT:
> +            g_value_set_int(value,
> +                            osinfo_avatar_format_get_height(avatar));
> +            break;
> +        case PROP_DEPTH:
> +            g_value_set_int(value,
> +                            osinfo_avatar_format_get_depth(avatar));
> +            break;
> +        default:
> +            /* We don't have any other property... */
> +            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
> +            break;
> +        }
> +}
> +
> +/* Init functions */
> +static void
> +osinfo_avatar_format_class_init (OsinfoAvatarFormatClass *klass)
> +{
> +    GObjectClass *g_klass = G_OBJECT_CLASS (klass);
> +    GParamSpec *pspec;
> +
> +    g_klass->get_property = osinfo_avatar_format_get_property;
> +
> +    /**
> +     * OsinfoAvatarFormat:mime-type:
> +     *
> +     * The required mime-type of the avatar.


What if several formats are supported?

> +     **/
> +    pspec = g_param_spec_string("mime-type",
> +                                "MIME Type",
> +                                _("The required mime-type of the avatar"),
> +                                DEFAULT_MIME_TYPE,
> +                                G_PARAM_READABLE |
> +                                G_PARAM_STATIC_STRINGS);
> +    g_object_class_install_property(g_klass,
> +                                    PROP_MIME_TYPE,
> +                                    pspec);
> +
> +    /**
> +     * OsinfoAvatarFormat:width:
> +     *
> +     * The required width (in pixels) of the avatar.

What does 'required' means here? That no other width will work?
Installer are not able to scale the avatar?

> +     **/
> +    pspec = g_param_spec_int("width",
> +                             "Width",
> +                             _("The required width (in pixels) of the avatar"),
> +                             -1,
> +                             G_MAXINT,
> +                             -1,
> +                             G_PARAM_READABLE |
> +                             G_PARAM_STATIC_STRINGS);
> +    g_object_class_install_property(g_klass,
> +                                    PROP_WIDTH,
> +                                    pspec);
> +
> +    /**
> +     * OsinfoAvatarFormat:height:
> +     *
> +     * The required height (in pixels) of the avatar.
> +     **/
> +    pspec = g_param_spec_int("height",
> +                             "Height",
> +                             _("The required height (in pixels) of the avatar."),
> +                             -1,
> +                             G_MAXINT,
> +                             -1,
> +                             G_PARAM_READABLE |
> +                             G_PARAM_STATIC_STRINGS);
> +    g_object_class_install_property(g_klass,
> +                                    PROP_HEIGHT,
> +                                    pspec);
> +
> +    /**
> +     * OsinfoAvatarFormat:depth:
> +     *
> +     * The required depth (in bits) of the avatar.

Is that really required? I don't think such a property is really useful as
the number of bits per pixel (I guess this is what this means?) is not
expressive enough, you need to know the bits used by each component (R, G,
B) as well as their bit position. I'd rather not have this property at all
for now, and add it when it's really needed.


> +     **/
> +    pspec = g_param_spec_int("depth",
> +                             "Depth",
> +                             _("The required depth (in bits) of the avatar."),
> +                             -1,
> +                             G_MAXINT,
> +                             -1,
> +                             G_PARAM_READABLE |
> +                             G_PARAM_STATIC_STRINGS);
> +    g_object_class_install_property(g_klass,
> +                                    PROP_DEPTH,
> +                                    pspec);
> +}
> +
> +static void
> +osinfo_avatar_format_init (OsinfoAvatarFormat *avatar)
> +{
> +}
> +
> +/**
> + * osinfo_avatar_format_new:
> + *
> + * Construct a new user avatar file to a #OsinfoInstallScript.
> + *
> + * Returns: (transfer full): the necessary information to create an avatar for
> + *                           an user
> + */
> +OsinfoAvatarFormat *
> +osinfo_avatar_format_new(void)
> +{
> +    return g_object_new(OSINFO_TYPE_AVATAR_FORMAT, NULL);
> +}
> +
> +/**
> + * osinfo_avatar_format_get_mime_type:
> + * @avatar: the avatar info
> + *
> + * Returns: (transfer none): the required mime-type of the avatar.
> + */
> +const gchar *
> +osinfo_avatar_format_get_mime_type(OsinfoAvatarFormat *avatar)
> +{
> +    const gchar *mime_type;
> +
> +    mime_type = osinfo_entity_get_param_value(OSINFO_ENTITY(avatar),
> +                                               OSINFO_AVATAR_FORMAT_PROP_MIME_TYPE);
> +    if (mime_type == NULL)
> +        return DEFAULT_MIME_TYPE;
> +
> +    return mime_type;
> +}
> +
> +/**
> + * osinfo_avatar_format_get_width:
> + * @avatar: the avatar info
> + *
> + * Returns: (transfer none): the required width (in pixels) of the avatar, or -1.
> + */
> +gint
> +osinfo_avatar_format_get_width(OsinfoAvatarFormat *avatar)
> +{
> +    return osinfo_entity_get_param_value_int64(OSINFO_ENTITY(avatar),
> +                                               OSINFO_AVATAR_FORMAT_PROP_WIDTH);
> +}
> +
> +/**
> + * osinfo_avatar_format_get_height:
> + * @avatar: the avatar info
> + *
> + * Returns: (transfer none): the required height (in pixels) of the avatar, or -1.
> + */
> +gint
> +osinfo_avatar_format_get_height(OsinfoAvatarFormat *avatar)
> +{
> +    return osinfo_entity_get_param_value_int64(OSINFO_ENTITY(avatar),
> +                                               OSINFO_AVATAR_FORMAT_PROP_HEIGHT);
> +}
> +
> +/**
> + * osinfo_avatar_format_get_depth:
> + * @avatar: the avatar info
> + *
> + * Returns: (transfer none): the required depth (in bits) of the avatar, or -1.
> + */
> +gint
> +osinfo_avatar_format_get_depth(OsinfoAvatarFormat *avatar)
> +{
> +    return osinfo_entity_get_param_value_int64(OSINFO_ENTITY(avatar),
> +                                               OSINFO_AVATAR_FORMAT_PROP_DEPTH);
> +}
> +
> +/*
> + * Local variables:
> + *  indent-tabs-mode: nil
> + *  c-indent-level: 4
> + *  c-basic-offset: 4
> + * End:
> + */
> diff --git a/osinfo/osinfo_avatar_format.h b/osinfo/osinfo_avatar_format.h
> new file mode 100644
> index 0000000..48efc75
> --- /dev/null
> +++ b/osinfo/osinfo_avatar_format.h
> @@ -0,0 +1,95 @@
> +/*
> + * libosinfo: OS installation avatar information
> + *
> + * 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 fidencio org>
> + *   Zeeshan Ali (Khattak) <zeeshanak gnome org>
> + */
> +
> +#include <glib-object.h>
> +
> +#ifndef __OSINFO_AVATAR_FORMAT_H__
> +#define __OSINFO_AVATAR_FORMAT_H__
> +
> +/*
> + * Type macros.
> + */
> +#define OSINFO_TYPE_AVATAR_FORMAT              \
> +        (osinfo_avatar_format_get_type ())
> +
> +#define OSINFO_AVATAR_FORMAT(obj)              \
> +        (G_TYPE_CHECK_INSTANCE_CAST ((obj),    \
> +         OSINFO_TYPE_AVATAR_FORMAT,            \
> +         OsinfoAvatarFormat))
> +
> +#define OSINFO_IS_AVATAR_FORMAT(obj)           \
> +        (G_TYPE_CHECK_INSTANCE_TYPE ((obj),    \
> +         OSINFO_TYPE_AVATAR_FORMAT))
> +
> +#define OSINFO_AVATAR_FORMAT_CLASS(klass)      \
> +        (G_TYPE_CHECK_CLASS_CAST ((klass),     \
> +         OSINFO_TYPE_AVATAR_FORMAT,            \
> +         OsinfoAvatarFormatClass))
> +
> +#define OSINFO_IS_AVATAR_FORMAT_CLASS(klass)   \
> +        (G_TYPE_CHECK_CLASS_TYPE ((klass),     \
> +         OSINFO_TYPE_AVATAR_FORMAT))
> +
> +#define OSINFO_AVATAR_FORMAT_GET_CLASS(obj)    \
> +        (G_TYPE_INSTANCE_GET_CLASS ((obj),     \
> +         OSINFO_TYPE_AVATAR_FORMAT,            \
> +         OsinfoAvatarFormatClass))
> +
> +typedef struct _OsinfoAvatarFormat OsinfoAvatarFormat;
> +typedef struct _OsinfoAvatarFormatClass OsinfoAvatarFormatClass;
> +
> +#define OSINFO_AVATAR_FORMAT_PROP_MIME_TYPE "mime-type"
> +#define OSINFO_AVATAR_FORMAT_PROP_WIDTH     "width"
> +#define OSINFO_AVATAR_FORMAT_PROP_HEIGHT    "height"
> +#define OSINFO_AVATAR_FORMAT_PROP_DEPTH     "depth"
> +
> +/* object */
> +struct _OsinfoAvatarFormat
> +{
> +    OsinfoEntity parent_instance;
> +};
> +
> +/* class */
> +struct _OsinfoAvatarFormatClass
> +{
> +    OsinfoEntityClass parent_class;
> +};
> +
> +GType osinfo_avatar_format_get_type(void);
> +
> +OsinfoAvatarFormat *osinfo_avatar_format_new(void);
> +
> +const gchar *osinfo_avatar_format_get_mime_type(OsinfoAvatarFormat *avatar);
> +gint osinfo_avatar_format_get_width(OsinfoAvatarFormat *avatar);
> +gint osinfo_avatar_format_get_height(OsinfoAvatarFormat *avatar);
> +gint osinfo_avatar_format_get_depth(OsinfoAvatarFormat *avatar);
> +
> +#endif /* __OSINFO_AVATAR_FORMAT_H__ */
> +/*
> + * Local variables:
> + *  indent-tabs-mode: nil
> + *  c-indent-level: 4
> + *  c-basic-offset: 4
> + * End:
> + */
> diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
> index 54dae64..75d8f4a 100644
> --- a/osinfo/osinfo_install_script.c
> +++ b/osinfo/osinfo_install_script.c
> @@ -50,6 +50,7 @@ struct _OsinfoInstallScriptPrivate
>      gchar *output_prefix;
>      gchar *output_filename;
>      GList *config_param_list;
> +    OsinfoAvatarFormat *avatar;
>  };
>  
>  enum {
> @@ -60,6 +61,7 @@ enum {
>      PROP_PROFILE,
>      PROP_PRODUCT_KEY_FORMAT,
>      PROP_PATH_FORMAT,
> +    PROP_AVATAR_FORMAT,
>  };
>  
>  typedef struct _OsinfoInstallScriptGenerateData OsinfoInstallScriptGenerateData;
> @@ -142,6 +144,11 @@ osinfo_os_get_property(GObject    *object,
>                           osinfo_install_script_get_path_format(script));
>          break;
>  
> +    case PROP_AVATAR_FORMAT:
> +        g_value_take_object(value,
> +                            osinfo_install_script_get_avatar_format(script));
> +        break;
> +
>      default:
>          /* We don't have any other property... */
>          G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
> @@ -157,6 +164,8 @@ osinfo_install_script_finalize (GObject *object)
>      g_free(script->priv->output_prefix);
>      g_free(script->priv->output_filename);
>      g_list_free_full(script->priv->config_param_list, g_object_unref);
> +    if (script->priv->avatar != NULL)
> +        g_object_unref(script->priv->avatar);
>  
>      /* Chain up to the parent class */
>      G_OBJECT_CLASS (osinfo_install_script_parent_class)->finalize (object);
> @@ -240,6 +249,18 @@ osinfo_install_script_class_init (OsinfoInstallScriptClass *klass)
>                                      PROP_PATH_FORMAT,
>                                      pspec);
>  
> +    pspec = g_param_spec_object("avatar-format",
> +                                "Avatar Format",
> +                                _("Expected avatar format"),
> +                                OSINFO_TYPE_AVATAR_FORMAT,
> +                                G_PARAM_READABLE |
> +                                G_PARAM_STATIC_NAME |
> +                                G_PARAM_STATIC_NICK |
> +                                G_PARAM_STATIC_BLURB);

G_PARAM_STATIC_STRINGS would be better here.

Christophe

Attachment: pgpwCiy1DEHAt.pgp
Description: PGP signature


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