[grilo] core: add GrlMedia media-type property



commit 900a3ab4ad7c93aecc5b10ba7722b026bb65d88a
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Tue Dec 15 17:35:00 2015 +0100

    core: add GrlMedia media-type property
    
    This property will store the type of media (audio, video, image or container).
    
    The type for supported media in source has been renamed to GrlSupportedMedia.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755551

 bindings/vala/grilo-0.3.vapi |   20 ++++++++---
 src/Makefile.am              |    2 +-
 src/data/grl-media.c         |   74 ++++++++++++++++++++++++++++++++++++++++++
 src/data/grl-media.h         |   22 ++----------
 src/grl-metadata-key.h       |   16 +++++++++
 src/grl-source.c             |   10 +++---
 src/grl-source.h             |   18 +++++++++-
 tools/grilo-test-ui/main.c   |   16 ++++----
 8 files changed, 140 insertions(+), 38 deletions(-)
---
diff --git a/bindings/vala/grilo-0.3.vapi b/bindings/vala/grilo-0.3.vapi
index 57f5485..6c9f012 100644
--- a/bindings/vala/grilo-0.3.vapi
+++ b/bindings/vala/grilo-0.3.vapi
@@ -179,6 +179,8 @@ namespace Grl {
                public void set_url (string url);
                public void set_url_data (string url, string mime);
                public static Grl.Media unserialize (string serial);
+               [NoAccessorMethod]
+               public Grl.MediaType media_type { get; set construct; }
        }
        [CCode (cheader_filename = "grilo.h", type_id = "grl_media_audio_get_type ()")]
        public class MediaAudio : Grl.Media {
@@ -439,7 +441,7 @@ namespace Grl {
                public unowned string get_name ();
                public unowned Grl.Plugin get_plugin ();
                public int get_rank ();
-               public Grl.MediaType get_supported_media ();
+               public Grl.SupportedMedia get_supported_media ();
                [CCode (cname = "grl_source_supported_operations")]
                public uint get_supported_operations ();
                [CCode (array_length = false, array_null_terminated = true)]
@@ -493,7 +495,7 @@ namespace Grl {
                [NoAccessorMethod]
                public string[] source_tags { owned get; set construct; }
                [NoAccessorMethod]
-               public Grl.MediaType supported_media { get; set construct; }
+               public Grl.SupportedMedia supported_media { get; set construct; }
                public signal void content_changed (GLib.GenericArray<Grl.Media> changed_medias, 
Grl.SourceChangeType change_type, bool location_unknown);
        }
        [CCode (cheader_filename = "grilo.h")]
@@ -741,13 +743,12 @@ namespace Grl {
                FULL
        }
        [CCode (cheader_filename = "grilo.h", cprefix = "GRL_MEDIA_TYPE_", type_id = "grl_media_type_get_type 
()")]
-       [Flags]
        public enum MediaType {
-               NONE,
+               UNKNOWN,
                AUDIO,
                VIDEO,
                IMAGE,
-               ALL
+               CONTAINER
        }
        [CCode (cheader_filename = "grilo.h", cprefix = "GRL_RANK_", has_type_id = false)]
        public enum Rank {
@@ -771,6 +772,15 @@ namespace Grl {
                ADDED,
                REMOVED
        }
+       [CCode (cheader_filename = "grilo.h", cprefix = "GRL_SUPPORTED_MEDIA_", type_id = 
"grl_supported_media_get_type ()")]
+       [Flags]
+       public enum SupportedMedia {
+               NONE,
+               AUDIO,
+               VIDEO,
+               IMAGE,
+               ALL
+       }
        [CCode (cheader_filename = "grilo.h", cprefix = "GRL_OP_", type_id = "grl_supported_ops_get_type ()")]
        [Flags]
        public enum SupportedOps {
diff --git a/src/Makefile.am b/src/Makefile.am
index a6e2ccb..c9d5e72 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,7 +24,7 @@ grl-marshal.c: grl-marshal.list grl-marshal.h
        $(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix grl_marshal     \
        --body $< >> $  tmp && mv $  tmp $@
 
-enum_headers = grl-source.h grl-caps.h grl-operation-options.h data/grl-media.h
+enum_headers = grl-source.h grl-caps.h grl-operation-options.h grl-metadata-key.h data/grl-media.h
 
 grl-type-builtins.h: $(enum_headers) grl-type-builtins.h.template
        $(AM_V_GEN) $(GLIB_MKENUMS) --template $(srcdir)/grl-type-builtins.h.template   \
diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index 5043a6d..ed37ea7 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -33,6 +33,7 @@
  */
 
 #include "grl-media.h"
+#include "grl-type-builtins.h"
 #include <grilo.h>
 #include <stdlib.h>
 #include <string.h>
@@ -40,24 +41,96 @@
 #define GRL_LOG_DOMAIN_DEFAULT  media_log_domain
 GRL_LOG_DOMAIN(media_log_domain);
 
+#define GRL_MEDIA_GET_PRIVATE(object)             \
+  (G_TYPE_INSTANCE_GET_PRIVATE((object),          \
+                               GRL_TYPE_MEDIA,    \
+                               GrlMediaPrivate))
+
 #define RATING_MAX  5.00
 #define SERIAL_STRING_ALLOC 100
 
+enum {
+  PROP_0,
+  PROP_MEDIA_TYPE
+};
+
+struct _GrlMediaPrivate {
+  GrlMediaType media_type;
+};
+
 static void grl_media_finalize (GObject *object);
 
 G_DEFINE_TYPE (GrlMedia, grl_media, GRL_TYPE_DATA);
 
 static void
+grl_media_set_property (GObject *object,
+                        guint prop_id,
+                        const GValue *value,
+                        GParamSpec *pspec)
+{
+  GrlMedia *media = GRL_MEDIA (object);
+
+  switch (prop_id) {
+  case PROP_MEDIA_TYPE:
+    media->priv->media_type = g_value_get_enum (value);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (media, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+grl_media_get_property (GObject *object,
+                        guint prop_id,
+                        GValue *value,
+                        GParamSpec *pspec)
+{
+  GrlMedia *media = GRL_MEDIA (object);
+
+  switch (prop_id) {
+  case PROP_MEDIA_TYPE:
+    g_value_set_enum (value, media->priv->media_type);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (media, prop_id, pspec);
+    break;
+  }
+}
+
+static void
 grl_media_class_init (GrlMediaClass *klass)
 {
   GObjectClass *gobject_class = (GObjectClass *)klass;
 
   gobject_class->finalize = grl_media_finalize;
+  gobject_class->set_property = grl_media_set_property;
+  gobject_class->get_property = grl_media_get_property;
+
+  /**
+   * GrlMedia::media-type
+   *
+   * The type of the media.
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_MEDIA_TYPE,
+                                   g_param_spec_enum ("media-type",
+                                                      "Media type",
+                                                      "Type of media",
+                                                      GRL_TYPE_MEDIA_TYPE,
+                                                      GRL_MEDIA_TYPE_UNKNOWN,
+                                                      G_PARAM_READWRITE |
+                                                      G_PARAM_CONSTRUCT |
+                                                      G_PARAM_STATIC_STRINGS));
+
+  g_type_class_add_private (klass,
+                            sizeof (GrlMediaPrivate));
 }
 
 static void
 grl_media_init (GrlMedia *self)
 {
+  self->priv = GRL_MEDIA_GET_PRIVATE (self);
 }
 
 static void
@@ -83,6 +156,7 @@ GrlMedia *
 grl_media_new (void)
 {
   return g_object_new (GRL_TYPE_MEDIA,
+                       "media-type", GRL_MEDIA_TYPE_UNKNOWN,
                       NULL);
 }
 
diff --git a/src/data/grl-media.h b/src/data/grl-media.h
index fb8c2c1..7cc4efd 100644
--- a/src/data/grl-media.h
+++ b/src/data/grl-media.h
@@ -77,30 +77,16 @@ typedef enum {
 } GrlMediaSerializeType;
 
 
-/**
- * GrlMediaType:
- * @GRL_MEDIA_TYPE_NONE: no media
- * @GRL_MEDIA_TYPE_AUDIO: audio media
- * @GRL_MEDIA_TYPE_VIDEO: video media
- * @GRL_MEDIA_TYPE_IMAGE: image media
- * @GRL_MEDIA_TYPE_ALL: any media
- */
-typedef enum {
-  GRL_MEDIA_TYPE_NONE  = 0,
-  GRL_MEDIA_TYPE_AUDIO = (1 << 0),
-  GRL_MEDIA_TYPE_VIDEO = (1 << 1),
-  GRL_MEDIA_TYPE_IMAGE = (1 << 2),
-  GRL_MEDIA_TYPE_ALL   = (GRL_MEDIA_TYPE_AUDIO | GRL_MEDIA_TYPE_VIDEO | GRL_MEDIA_TYPE_IMAGE)
-} GrlMediaType;
-
-typedef struct _GrlMedia      GrlMedia;
-typedef struct _GrlMediaClass GrlMediaClass;
+typedef struct _GrlMedia        GrlMedia;
+typedef struct _GrlMediaPrivate GrlMediaPrivate;
+typedef struct _GrlMediaClass   GrlMediaClass;
 
 struct _GrlMedia
 {
   GrlData parent;
 
   /*< private >*/
+  GrlMediaPrivate *priv;
   gpointer _grl_reserved[GRL_PADDING_SMALL];
 };
 
diff --git a/src/grl-metadata-key.h b/src/grl-metadata-key.h
index a5706fd..681aa97 100644
--- a/src/grl-metadata-key.h
+++ b/src/grl-metadata-key.h
@@ -42,6 +42,22 @@
 
 typedef guint32 GrlKeyID;
 
+/**
+ * GrlMediaType:
+ * @GRL_MEDIA_TYPE_UNKNOWN: unknown media
+ * @GRL_MEDIA_TYPE_AUDIO: audio media
+ * @GRL_MEDIA_TYPE_VIDEO: video media
+ * @GRL_MEDIA_TYPE_IMAGE: image media
+ * @GRL_MEDIA_TYPE_CONTAINER: contaddiner media
+ */
+typedef enum {
+  GRL_MEDIA_TYPE_UNKNOWN,
+  GRL_MEDIA_TYPE_AUDIO,
+  GRL_MEDIA_TYPE_VIDEO,
+  GRL_MEDIA_TYPE_IMAGE,
+  GRL_MEDIA_TYPE_CONTAINER
+} GrlMediaType;
+
 #define g_value_get_grl_key_id(value) ((GrlKeyID) g_value_get_uint(value))
 #define g_value_set_grl_key_id(value,key) g_value_set_uint(value,(guint)key)
 
diff --git a/src/grl-source.c b/src/grl-source.c
index 171975d..ea120d2 100644
--- a/src/grl-source.c
+++ b/src/grl-source.c
@@ -88,7 +88,7 @@ struct _GrlSourcePrivate {
   gchar *name;
   gchar *desc;
   gint rank;
-  GrlMediaType supported_media;
+  GrlSupportedMedia supported_media;
   guint auto_split_threshold;
   GrlPlugin *plugin;
   GIcon *icon;
@@ -402,8 +402,8 @@ grl_source_class_init (GrlSourceClass *source_class)
                                    g_param_spec_flags ("supported-media",
                                                        "Supported media",
                                                        "List of supported media types",
-                                                       GRL_TYPE_MEDIA_TYPE,
-                                                       GRL_MEDIA_TYPE_ALL,
+                                                       GRL_TYPE_SUPPORTED_MEDIA,
+                                                       GRL_SUPPORTED_MEDIA_ALL,
                                                        G_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT |
                                                        G_PARAM_STATIC_STRINGS));
@@ -3093,11 +3093,11 @@ grl_source_get_rank (GrlSource *source)
  *
  * Gets the supported type of medias @source can deal with.
  *
- * Returns: a #GrlMediaType value
+ * Returns: a #GrlSupportedMedia value
  *
  * Since: 0.2.3
  **/
-GrlMediaType
+GrlSupportedMedia
 grl_source_get_supported_media (GrlSource *source)
 {
   g_return_val_if_fail (GRL_IS_SOURCE (source), 0);
diff --git a/src/grl-source.h b/src/grl-source.h
index 24163fd..a9b0523 100644
--- a/src/grl-source.h
+++ b/src/grl-source.h
@@ -111,6 +111,22 @@ typedef enum {
   GRL_OP_NOTIFY_CHANGE   = 1 << 9
 } GrlSupportedOps;
 
+ /**
+ * GrlSupportedMedia:
+ * @GRL_SUPPORTED_MEDIA_NONE: no media
+ * @GRL_SUPPORTED_MEDIA_AUDIO: audio media
+ * @GRL_SUPPORTED_MEDIA_VIDEO: video media
+ * @GRL_SUPPORTED_MEDIA_IMAGE: image media
+ * @GRL_SUPPORTED_MEDIA_ALL: any media
+ */
+typedef enum {
+  GRL_SUPPORTED_MEDIA_NONE  = 0,
+  GRL_SUPPORTED_MEDIA_AUDIO = (1 << 0),
+  GRL_SUPPORTED_MEDIA_VIDEO = (1 << 1),
+  GRL_SUPPORTED_MEDIA_IMAGE = (1 << 2),
+  GRL_SUPPORTED_MEDIA_ALL   = (GRL_SUPPORTED_MEDIA_AUDIO | GRL_SUPPORTED_MEDIA_VIDEO | 
GRL_SUPPORTED_MEDIA_IMAGE)
+} GrlSupportedMedia;
+
 /**
  * GrlSourceChangeType:
  * @GRL_CONTENT_CHANGED: content has changed. It is used when any property of
@@ -636,7 +652,7 @@ GrlPlugin *grl_source_get_plugin (GrlSource *source);
 
 gint grl_source_get_rank (GrlSource *source);
 
-GrlMediaType grl_source_get_supported_media (GrlSource *source);
+GrlSupportedMedia grl_source_get_supported_media (GrlSource *source);
 
 const char ** grl_source_get_tags (GrlSource *source);
 
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index 1f5287f..951a70a 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -892,21 +892,21 @@ add_source_metadata (GtkTreeModel *model,
 }
 
 static char *
-media_type_to_str (GrlMediaType type)
+supported_media_to_str (GrlMediaType type)
 {
   GString *s;
 
-  if (type == GRL_MEDIA_TYPE_NONE)
+  if (type == GRL_SUPPORTED_MEDIA_NONE)
     return g_strdup ("None");
-  if (type == GRL_MEDIA_TYPE_ALL)
+  if (type == GRL_SUPPORTED_MEDIA_ALL)
     return g_strdup ("All");
 
   s = g_string_new (NULL);
-  if (GRL_MEDIA_TYPE_AUDIO & type)
+  if (GRL_SUPPORTED_MEDIA_AUDIO & type)
     g_string_append (s, "audio, ");
-  if (GRL_MEDIA_TYPE_VIDEO & type)
+  if (GRL_SUPPORTED_MEDIA_VIDEO & type)
     g_string_append (s, "video, ");
-  if (GRL_MEDIA_TYPE_IMAGE & type)
+  if (GRL_SUPPORTED_MEDIA_IMAGE & type)
     g_string_append (s, "image, ");
 
   g_string_truncate (s, s->len - 2);
@@ -955,7 +955,7 @@ populate_source_metadata (GrlSource *source)
     char *str;
     guint auto_split_threshold;
     int rank;
-    GrlMediaType supported_media;
+    GrlSupportedMedia supported_media;
     GIcon *icon;
     char **tags;
 
@@ -981,7 +981,7 @@ populate_source_metadata (GrlSource *source)
     add_source_metadata (view->metadata_model, "rank", str);
     g_free (str);
 
-    str = media_type_to_str (supported_media);
+    str = supported_media_to_str (supported_media);
     add_source_metadata (view->metadata_model, "supported-media", str);
     g_free (str);
 


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