[PATCH 1/5] core: Add "content-changed" signal



This signal is emitted by media sources (if they handle it) to notify a change
has happened in the source content.

Depending on the source, it can provide more specific information like where
the change happened, or the kind of change (content added or content removed).

Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>
---
 configure.ac                     |    5 ++++
 src/Makefile.am                  |   23 +++++++++++++++++++-
 src/grl-marshal.list             |    1 +
 src/grl-media-source.c           |   42 ++++++++++++++++++++++++++++++++++++++
 src/grl-media-source.h           |   20 ++++++++++++++++++
 src/grl-type-builtins.c.template |   35 +++++++++++++++++++++++++++++++
 src/grl-type-builtins.h.template |   24 +++++++++++++++++++++
 7 files changed, 149 insertions(+), 1 deletions(-)
 create mode 100644 src/grl-marshal.list
 create mode 100644 src/grl-type-builtins.c.template
 create mode 100644 src/grl-type-builtins.h.template

diff --git a/configure.ac b/configure.ac
index 58270c4..c91e6e8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,6 +95,11 @@ PKG_CHECK_MODULES(DEPS, glib-2.0 \
 			gio-2.0 \
 			libxml-2.0)
 
+GLIB_GENMARSHAL=`pkg-config --variable=glib_genmarshal glib-2.0`
+GLIB_MKENUMS=`pkg-config --variable=glib_mkenums glib-2.0`
+AC_SUBST(GLIB_GENMARSHAL)
+AC_SUBST(GLIB_MKENUMS)
+
 # Tools
 
 PKG_CHECK_MODULES(GTU, gtk+-2.0 \
diff --git a/src/Makefile.am b/src/Makefile.am
index 18bd8f6..7e08256 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,23 @@
 
 INCLUDES = -DGRL_PLUGINS_CONF_DIR=\""$(GRL_PLUGINS_CONF_DIR)"\"
 
+# autogenerated files
+grl-marshal.h: grl-marshal.list
+	$(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix grl_marshal	\
+	--header grl-marshal.list > $@
+
+grl-marshal.c: grl-marshal.h grl-marshal.list
+	$(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix grl_marshal	\
+	--body grl-marshal.list > $@
+
+grl-type-builtins.h: grl-media-source.h grl-type-builtins.h.template
+	$(AM_V_GEN) $(GLIB_MKENUMS) --template grl-type-builtins.h.template	\
+	grl-media-source.h > $@
+
+grl-type-builtins.c: grl-type-builtins.h grl-media-source.h grl-type-builtins.c.template
+	$(AM_V_GEN) $(GLIB_MKENUMS) --template grl-type-builtins.c.template	\
+	grl-media-source.h > $@
+
 lib_LTLIBRARIES = lib@GRL_NAME@.la
 
 lib@GRL_NAME@_la_CFLAGS =	\
@@ -24,6 +41,8 @@ lib@GRL_NAME@_la_SOURCES =					\
 	grl-plugin-registry.c					\
 	grl-metadata-key.c grl-metadata-key-priv.h		\
 	grl-metadata-source.c grl-metadata-source-priv.h	\
+	grl-type-builtins.c grl-type-builtins.h			\
+	grl-marshal.c grl-marshal.h				\
 	grl-media-source.c grl-util.c				\
 	grl-multiple.c						\
 	grl-log.c grl-log-priv.h				\
@@ -72,7 +91,9 @@ noinst_HEADERS =			\
 	grl-media-plugin-priv.h		\
 	grl-metadata-source-priv.h	\
 	grl-metadata-key-priv.h		\
-	grl-sync-priv.h
+	grl-sync-priv.h			\
+	grl-type-builtins.h		\
+	grl-marshal.h
 
 MAINTAINERCLEANFILES =	\
 	*.in		\
diff --git a/src/grl-marshal.list b/src/grl-marshal.list
new file mode 100644
index 0000000..b524c7a
--- /dev/null
+++ b/src/grl-marshal.list
@@ -0,0 +1 @@
+VOID:OBJECT,ENUM,BOOLEAN
diff --git a/src/grl-media-source.c b/src/grl-media-source.c
index e5312d8..fd2e804 100644
--- a/src/grl-media-source.c
+++ b/src/grl-media-source.c
@@ -47,6 +47,9 @@
 #include "grl-error.h"
 #include "grl-log.h"
 
+#include "grl-marshal.h"
+#include "grl-type-builtins.h"
+
 #include <string.h>
 
 #define GRL_LOG_DOMAIN_DEFAULT  media_source_log_domain
@@ -175,6 +178,12 @@ static guint grl_media_source_gen_operation_id (GrlMediaSource *source);
 
 /* ================ GrlMediaSource GObject ================ */
 
+enum {
+  SIG_CONTENT_CHANGED,
+  SIG_LAST,
+};
+static gint registry_signals[SIG_LAST];
+
 G_DEFINE_ABSTRACT_TYPE (GrlMediaSource,
                         grl_media_source,
                         GRL_TYPE_METADATA_SOURCE);
@@ -214,6 +223,39 @@ grl_media_source_class_init (GrlMediaSourceClass *media_source_class)
 						      0, G_MAXUINT, 0,
 						      G_PARAM_READWRITE |
 						      G_PARAM_STATIC_STRINGS));
+  /**
+   * GrlMediaSource::content-changed:
+   * @source: source that has changed
+   * @media: the media that has changed, or contains the children that have
+   * changed
+   * @change_type: what has happened
+   * @location_unknown: @TRUE if the change can be in the @media or in any
+   * descendant of it. @FALSE means that either the @media has changed, or a
+   * direct child has changed
+   *
+   * Signals that the content in the source has changed. Usually @media is a
+   * #GrlBox, meaning that the content of that box has changed. if
+   * @location_unknown is @TRUE it means the source can establish where the
+   * change happened: could be either in the box, in any child, or in any
+   * undirect descendant.
+   *
+   * For the cases where the source only can signal that a change happened, but
+   * not where, it would use the root box (@NULL id) and location_unknown as
+   * #TRUE.
+   */
+  registry_signals[SIG_CONTENT_CHANGED] =
+    g_signal_new("content-changed",
+                 G_TYPE_FROM_CLASS (gobject_class),
+                 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+                 G_STRUCT_OFFSET(GrlMediaSourceClass, content_changed),
+                 NULL,
+                 NULL,
+                 grl_marshal_VOID__OBJECT_ENUM_BOOLEAN,
+                 G_TYPE_NONE,
+                 3,
+                 GRL_TYPE_MEDIA,
+                 GRL_TYPE_MEDIA_SOURCE_CHANGE_TYPE,
+                 G_TYPE_BOOLEAN);
 }
 
 static void
diff --git a/src/grl-media-source.h b/src/grl-media-source.h
index 6975004..83a5360 100644
--- a/src/grl-media-source.h
+++ b/src/grl-media-source.h
@@ -63,6 +63,19 @@
   (G_TYPE_INSTANCE_GET_CLASS ((obj),                            \
                               GRL_TYPE_MEDIA_SOURCE,            \
                               GrlMediaSourceClass))
+/**
+ * GrlMediaSourceChangeType:
+ * @GRL_CONTENT_CHANGED: content has changed.
+ * @GRL_CONTENT_ADDED: new content has been added.
+ * @GRL_CONTENT_REMOVED: content has been removed
+ *
+ * Specifies which kind of change has happened in the plugin
+ */
+typedef enum {
+  GRL_CONTENT_CHANGED,
+  GRL_CONTENT_ADDED,
+  GRL_CONTENT_REMOVED,
+} GrlMediaSourceChangeType;
 
 /* GrlMediaSource object */
 
@@ -382,6 +395,12 @@ struct _GrlMediaSourceClass {
 
   /*< private >*/
   gpointer _grl_reserved[GRL_PADDING];
+
+  /* signals */
+  void (*content_changed) (GrlMediaSource *source,
+                           GrlMedia *media,
+                           GrlMediaSourceChangeType change_type,
+                           gboolean location_unknown);
 };
 
 G_BEGIN_DECLS
@@ -502,6 +521,7 @@ GrlMedia *grl_media_source_get_media_from_uri_sync (GrlMediaSource *source,
                                                     const GList *keys,
                                                     GrlMetadataResolutionFlags flags,
                                                     GError **error);
+
 G_END_DECLS
 
 #endif /* _GRL_MEDIA_SOURCE_H_ */
diff --git a/src/grl-type-builtins.c.template b/src/grl-type-builtins.c.template
new file mode 100644
index 0000000..734d23a
--- /dev/null
+++ b/src/grl-type-builtins.c.template
@@ -0,0 +1,35 @@
+/*** BEGIN file-header ***/
+#include "grl-type-builtins.h"
+#include "@filename@"
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+@enum_name@_get_type (void)
+{
+    static GType etype = 0;
+    if (G_UNLIKELY(etype == 0)) {
+        static const G@Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+            { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+            { 0, NULL, NULL }
+        };
+        etype = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+    }
+    return etype;
+}
+
+/*** END value-tail ***/
+
+/*** BEGIN file-tail ***/
+
+/*** END file-tail ***/
diff --git a/src/grl-type-builtins.h.template b/src/grl-type-builtins.h.template
new file mode 100644
index 0000000..6714f84
--- /dev/null
+++ b/src/grl-type-builtins.h.template
@@ -0,0 +1,24 @@
+/*** BEGIN file-header ***/
+#ifndef _GRL_TYPE_BUILTINS_H_
+#define _GRL_TYPE_BUILTINS_H_
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType @enum_name@_get_type (void) G_GNUC_CONST;
+#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
+/*** END value-header ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* _GRL_TYPE_BUILTINS_H_ */
+/*** END file-tail ***/
-- 
1.7.3.5



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