[PATCH 1/1] core: Add "supported-media" property



From: "Juan A. Suarez Romero" <jasuarez igalia com>

This property flag for GrlSource specifies the type of media the source can
deal with.

Thus, if our application is designed to show video content only, we could
discard all sources not providing this kind of media.

The default value for this property, if not specified, is GRL_MEDIA_TYPE_ALL.
---
 doc/grilo/grilo-sections.txt |    1 +
 src/Makefile.am              |    2 +-
 src/data/grl-media.h         |   17 +++++++++++++++++
 src/grl-source.c             |   43 +++++++++++++++++++++++++++++++++++++++++-
 src/grl-source.h             |    2 ++
 5 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/doc/grilo/grilo-sections.txt b/doc/grilo/grilo-sections.txt
index 7a42604..ed76aca 100644
--- a/doc/grilo/grilo-sections.txt
+++ b/doc/grilo/grilo-sections.txt
@@ -82,6 +82,7 @@ grl_source_get_media_from_uri_sync
 grl_source_get_name
 grl_source_get_plugin
 grl_source_get_rank
+grl_source_get_supported_media
 grl_source_may_resolve
 grl_source_notify_change
 grl_source_notify_change_list
diff --git a/src/Makefile.am b/src/Makefile.am
index c0aea2c..e4aeb63 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,7 +15,7 @@ grl-marshal.c: grl-marshal.h grl-marshal.list
 	$(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix grl_marshal	\
 	--body grl-marshal.list >> $@
 
-enum_headers = grl-source.h grl-caps.h grl-operation-options.h
+enum_headers = grl-source.h grl-caps.h grl-operation-options.h data/grl-media.h
 
 grl-type-builtins.h: $(enum_headers) grl-type-builtins.h.template
 	$(AM_V_GEN) $(GLIB_MKENUMS) --template grl-type-builtins.h.template	\
diff --git a/src/data/grl-media.h b/src/data/grl-media.h
index 10b049a..9ed666d 100644
--- a/src/data/grl-media.h
+++ b/src/data/grl-media.h
@@ -74,6 +74,23 @@ typedef enum {
   GRL_MEDIA_SERIALIZE_FULL
 } 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;
 
diff --git a/src/grl-source.c b/src/grl-source.c
index be40274..3c76df0 100644
--- a/src/grl-source.c
+++ b/src/grl-source.c
@@ -61,7 +61,8 @@ enum {
   PROP_DESC,
   PROP_PLUGIN,
   PROP_RANK,
-  PROP_AUTO_SPLIT_THRESHOLD
+  PROP_AUTO_SPLIT_THRESHOLD,
+  PROP_SUPPORTED_MEDIA
 };
 
 enum {
@@ -80,6 +81,7 @@ struct _GrlSourcePrivate {
   gchar *name;
   gchar *desc;
   gint rank;
+  GrlMediaType supported_media;
   guint auto_split_threshold;
   GrlPlugin *plugin;
 };
@@ -363,6 +365,23 @@ grl_source_class_init (GrlSourceClass *source_class)
                                                       0, G_MAXUINT, 0,
                                                       G_PARAM_READWRITE |
                                                       G_PARAM_STATIC_STRINGS));
+  /**
+   * GrlSource:supported-media:
+   *
+   * List of supported media types by this source.
+   *
+   * Since: 0.2.3
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_SUPPORTED_MEDIA,
+                                   g_param_spec_flags ("supported-media",
+                                                       "Supported media",
+                                                       "List of supported media types",
+                                                       GRL_TYPE_MEDIA_TYPE,
+                                                       GRL_MEDIA_TYPE_ALL,
+                                                       G_PARAM_READWRITE |
+                                                       G_PARAM_CONSTRUCT |
+                                                       G_PARAM_STATIC_STRINGS));
 
   /**
    * GrlSource::content-changed:
@@ -478,6 +497,9 @@ grl_source_set_property (GObject *object,
   case PROP_AUTO_SPLIT_THRESHOLD:
     source->priv->auto_split_threshold = g_value_get_uint (value);
     break;
+  case PROP_SUPPORTED_MEDIA:
+    source->priv->supported_media = g_value_get_flags (value);
+    break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (source, prop_id, pspec);
     break;
@@ -513,6 +535,9 @@ grl_source_get_property (GObject *object,
   case PROP_AUTO_SPLIT_THRESHOLD:
     g_value_set_uint (value, source->priv->auto_split_threshold);
     break;
+  case PROP_SUPPORTED_MEDIA:
+    g_value_set_flags (value, source->priv->supported_media);
+    break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (source, prop_id, pspec);
     break;
@@ -2881,6 +2906,22 @@ grl_source_get_rank (GrlSource *source)
 }
 
 /**
+ * grl_source_get_supported_media:
+ * @source: a source
+ *
+ * Gets the supported type of medias @source can deal with.
+ *
+ * Returns: a #GrlMediaType value
+ **/
+GrlMediaType
+grl_source_get_supported_media (GrlSource *source)
+{
+  g_return_val_if_fail (GRL_IS_SOURCE (source), 0);
+
+  return source->priv->supported_media;
+}
+
+/**
  * grl_source_supported_operations:
  * @source: a source
  *
diff --git a/src/grl-source.h b/src/grl-source.h
index 4ff6315..8347d0a 100644
--- a/src/grl-source.h
+++ b/src/grl-source.h
@@ -628,6 +628,8 @@ GrlPlugin *grl_source_get_plugin (GrlSource *source);
 
 gint grl_source_get_rank (GrlSource *source);
 
+GrlMediaType grl_source_get_supported_media (GrlSource *source);
+
 G_END_DECLS
 
 #endif /* _GRL_SOURCE_H_ */
-- 
1.7.10.4



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