Commit fd9afa72 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

changed the gth_metadata_provider_can_read/can_write functions

added a mime type argument to the can_read/can_write functions
to make them more usefull.
parent 422d05cd
......@@ -21,23 +21,41 @@
*/
#include <config.h>
#include <string.h>
#include <glib/gi18n.h>
#include <glib.h>
#include <gthumb.h>
#include "gth-comment.h"
#include "gth-metadata-provider-comment.h"
#define GTH_METADATA_PROVIDER_COMMENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTH_TYPE_METADATA_PROVIDER_COMMENT, GthMetadataProviderCommentPrivate))
static gpointer parent_class = NULL;
struct _GthMetadataProviderCommentPrivate {
int dummy;
};
static gboolean
gth_metadata_provider_comment_can_read (GthMetadataProvider *self,
const char *mime_type,
char **attribute_v)
{
return _g_file_attributes_matches_any_v ("comment::*,"
"general::datetime,"
"general::description,"
"general::location,"
"general::tags",
attribute_v);
}
static gpointer parent_class = NULL;
static gboolean
gth_metadata_provider_comment_can_write (GthMetadataProvider *self,
const char *mime_type,
char **attribute_v)
{
return _g_file_attributes_matches_any_v ("comment::*,"
"general::datetime,"
"general::description,"
"general::location,"
"general::tags",
attribute_v);
}
static void
......@@ -192,57 +210,18 @@ gth_metadata_provider_comment_write (GthMetadataProvider *self,
}
static void
gth_metadata_provider_comment_finalize (GObject *object)
{
/*GthMetadataProviderComment *comment = GTH_METADATA_PROVIDER_COMMENT (object);*/
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static GObject *
gth_metadata_provider_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
GthMetadataProviderClass *klass;
GObjectClass *parent_class;
GObject *obj;
GthMetadataProvider *self;
klass = GTH_METADATA_PROVIDER_CLASS (g_type_class_peek (GTH_TYPE_METADATA_PROVIDER));
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
obj = parent_class->constructor (type, n_construct_properties, construct_properties);
self = GTH_METADATA_PROVIDER (obj);
g_object_set (self, "readable-attributes", "comment::*,general::datetime,general::description,general::location,general::tags", NULL);
g_object_set (self, "writable-attributes", "comment::*,general::datetime,general::description,general::location,general::tags", NULL);
return obj;
}
static void
gth_metadata_provider_comment_class_init (GthMetadataProviderCommentClass *klass)
{
parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (GthMetadataProviderCommentPrivate));
G_OBJECT_CLASS (klass)->finalize = gth_metadata_provider_comment_finalize;
G_OBJECT_CLASS (klass)->constructor = gth_metadata_provider_constructor;
GTH_METADATA_PROVIDER_CLASS (klass)->can_read = gth_metadata_provider_comment_can_read;
GTH_METADATA_PROVIDER_CLASS (klass)->can_write = gth_metadata_provider_comment_can_write;
GTH_METADATA_PROVIDER_CLASS (klass)->read = gth_metadata_provider_comment_read;
GTH_METADATA_PROVIDER_CLASS (klass)->write = gth_metadata_provider_comment_write;
}
static void
gth_metadata_provider_comment_init (GthMetadataProviderComment *catalogs)
{
}
GType
gth_metadata_provider_comment_get_type (void)
{
......@@ -258,7 +237,7 @@ gth_metadata_provider_comment_get_type (void)
NULL,
sizeof (GthMetadataProviderComment),
0,
(GInstanceInitFunc) gth_metadata_provider_comment_init
(GInstanceInitFunc) NULL
};
type = g_type_register_static (GTH_TYPE_METADATA_PROVIDER,
......
......@@ -35,13 +35,11 @@
#define GTH_METADATA_PROVIDER_COMMENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GTH_TYPE_METADATA_PROVIDER_COMMENT, GthMetadataProviderCommentClass))
typedef struct _GthMetadataProviderComment GthMetadataProviderComment;
typedef struct _GthMetadataProviderCommentPrivate GthMetadataProviderCommentPrivate;
typedef struct _GthMetadataProviderCommentClass GthMetadataProviderCommentClass;
struct _GthMetadataProviderComment
{
GthMetadataProvider __parent;
GthMetadataProviderCommentPrivate *priv;
};
struct _GthMetadataProviderCommentClass
......
......@@ -29,15 +29,49 @@
#include "gth-metadata-provider-exiv2.h"
#define GTH_METADATA_PROVIDER_EXIV2_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTH_TYPE_METADATA_PROVIDER_EXIV2, GthMetadataProviderExiv2Private))
static GthMetadataProviderClass *parent_class = NULL;
struct _GthMetadataProviderExiv2Private {
int dummy;
};
static gboolean
gth_metadata_provider_exiv2_can_read (GthMetadataProvider *self,
const char *mime_type,
char **attribute_v)
{
if (! _g_content_type_is_a (mime_type, "image/*"))
return FALSE;
return _g_file_attributes_matches_any_v ("Exif::*,"
"Xmp::*,"
"Iptc::*,"
"Embedded::Image::*,"
"Embedded::Photo::*,"
"general::datetime,"
"general::description,"
"general::location,"
"general::tags",
attribute_v);
}
static GthMetadataProviderClass *parent_class = NULL;
static gboolean
gth_metadata_provider_exiv2_can_write (GthMetadataProvider *self,
const char *mime_type,
char **attribute_v)
{
if (! exiv2_supports_writes (mime_type))
return FALSE;
return _g_file_attributes_matches_any_v ("Exif::*,"
"Xmp::*,"
"Iptc::*,"
"Embedded::Image::*,"
"Embedded::Photo::*,"
"general::datetime,"
"general::description,"
"general::location,"
"general::tags",
attribute_v);
}
static void
......@@ -164,57 +198,18 @@ gth_metadata_provider_exiv2_write (GthMetadataProvider *self,
}
static void
gth_metadata_provider_exiv2_finalize (GObject *object)
{
/*GthMetadataProviderExiv2 *comment = GTH_METADATA_PROVIDER_EXIV2 (object);*/
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static GObject *
gth_metadata_provider_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
GthMetadataProviderClass *klass;
GObjectClass *parent_class;
GObject *obj;
GthMetadataProvider *self;
klass = GTH_METADATA_PROVIDER_CLASS (g_type_class_peek (GTH_TYPE_METADATA_PROVIDER));
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
obj = parent_class->constructor (type, n_construct_properties, construct_properties);
self = GTH_METADATA_PROVIDER (obj);
g_object_set (self, "readable-attributes", "Exif::*,Xmp::*,Iptc::*,Embedded::Image::*,Embedded::Photo::*,general::datetime,general::description,general::location,general::tags", NULL);
g_object_set (self, "writable-attributes", "Exif::*,Xmp::*,Iptc::*,Embedded::Image::*,Embedded::Photo::*,general::datetime,general::description,general::location,general::tags", NULL);
return obj;
}
static void
gth_metadata_provider_exiv2_class_init (GthMetadataProviderExiv2Class *klass)
{
parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (GthMetadataProviderExiv2Private));
G_OBJECT_CLASS (klass)->finalize = gth_metadata_provider_exiv2_finalize;
G_OBJECT_CLASS (klass)->constructor = gth_metadata_provider_constructor;
GTH_METADATA_PROVIDER_CLASS (klass)->can_read = gth_metadata_provider_exiv2_can_read;
GTH_METADATA_PROVIDER_CLASS (klass)->can_write = gth_metadata_provider_exiv2_can_write;
GTH_METADATA_PROVIDER_CLASS (klass)->read = gth_metadata_provider_exiv2_read;
GTH_METADATA_PROVIDER_CLASS (klass)->write = gth_metadata_provider_exiv2_write;
}
static void
gth_metadata_provider_exiv2_init (GthMetadataProviderExiv2 *catalogs)
{
}
GType
gth_metadata_provider_exiv2_get_type (void)
{
......@@ -230,7 +225,7 @@ gth_metadata_provider_exiv2_get_type (void)
NULL,
sizeof (GthMetadataProviderExiv2),
0,
(GInstanceInitFunc) gth_metadata_provider_exiv2_init
(GInstanceInitFunc) NULL
};
type = g_type_register_static (GTH_TYPE_METADATA_PROVIDER,
......
......@@ -35,13 +35,11 @@
#define GTH_METADATA_PROVIDER_EXIV2_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GTH_TYPE_METADATA_PROVIDER_EXIV2, GthMetadataProviderExiv2Class))
typedef struct _GthMetadataProviderExiv2 GthMetadataProviderExiv2;
typedef struct _GthMetadataProviderExiv2Private GthMetadataProviderExiv2Private;
typedef struct _GthMetadataProviderExiv2Class GthMetadataProviderExiv2Class;
struct _GthMetadataProviderExiv2
{
GthMetadataProvider __parent;
GthMetadataProviderExiv2Private *priv;
};
struct _GthMetadataProviderExiv2Class
......
......@@ -21,23 +21,31 @@
*/
#include <config.h>
#include <string.h>
#include <glib/gi18n.h>
#include <glib.h>
#include <gthumb.h>
#include "gstreamer-utils.h"
#include "gth-metadata-provider-gstreamer.h"
#define GTH_METADATA_PROVIDER_GSTREAMER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTH_TYPE_METADATA_PROVIDER_GSTREAMER, GthMetadataProviderGstreamerPrivate))
static GthMetadataProviderClass *parent_class = NULL;
struct _GthMetadataProviderGstreamerPrivate {
int dummy;
};
static gboolean
gth_metadata_provider_gstreamer_can_read (GthMetadataProvider *self,
const char *mime_type,
char **attribute_v)
{
if (! _g_content_type_is_a (mime_type, "audio/*")
&& ! _g_content_type_is_a (mime_type, "video/*"))
{
return FALSE;
}
static GthMetadataProviderClass *parent_class = NULL;
return _g_file_attributes_matches_any_v ("general::format,"
"general::dimensions,"
"audio-video::*",
attribute_v);
}
static void
......@@ -58,55 +66,16 @@ gth_metadata_provider_gstreamer_read (GthMetadataProvider *self,
}
static void
gth_metadata_provider_gstreamer_finalize (GObject *object)
{
/*GthMetadataProviderGstreamer *comment = GTH_METADATA_PROVIDER_GSTREAMER (object);*/
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static GObject *
gth_metadata_provider_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
GthMetadataProviderClass *klass;
GObjectClass *parent_class;
GObject *obj;
GthMetadataProvider *self;
klass = GTH_METADATA_PROVIDER_CLASS (g_type_class_peek (GTH_TYPE_METADATA_PROVIDER));
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
obj = parent_class->constructor (type, n_construct_properties, construct_properties);
self = GTH_METADATA_PROVIDER (obj);
g_object_set (self, "readable-attributes", "general::format,general::dimensions,audio-video::*", NULL);
return obj;
}
static void
gth_metadata_provider_gstreamer_class_init (GthMetadataProviderGstreamerClass *klass)
{
parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (GthMetadataProviderGstreamerPrivate));
G_OBJECT_CLASS (klass)->finalize = gth_metadata_provider_gstreamer_finalize;
G_OBJECT_CLASS (klass)->constructor = gth_metadata_provider_constructor;
GTH_METADATA_PROVIDER_CLASS (klass)->can_read = gth_metadata_provider_gstreamer_can_read;
GTH_METADATA_PROVIDER_CLASS (klass)->read = gth_metadata_provider_gstreamer_read;
}
static void
gth_metadata_provider_gstreamer_init (GthMetadataProviderGstreamer *catalogs)
{
}
GType
gth_metadata_provider_gstreamer_get_type (void)
{
......@@ -122,7 +91,7 @@ gth_metadata_provider_gstreamer_get_type (void)
NULL,
sizeof (GthMetadataProviderGstreamer),
0,
(GInstanceInitFunc) gth_metadata_provider_gstreamer_init
(GInstanceInitFunc) NULL
};
type = g_type_register_static (GTH_TYPE_METADATA_PROVIDER,
......
......@@ -35,13 +35,11 @@
#define GTH_METADATA_PROVIDER_GSTREAMER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GTH_TYPE_METADATA_PROVIDER_GSTREAMER, GthMetadataProviderGstreamerClass))
typedef struct _GthMetadataProviderGstreamer GthMetadataProviderGstreamer;
typedef struct _GthMetadataProviderGstreamerPrivate GthMetadataProviderGstreamerPrivate;
typedef struct _GthMetadataProviderGstreamerClass GthMetadataProviderGstreamerClass;
struct _GthMetadataProviderGstreamer
{
GthMetadataProvider __parent;
GthMetadataProviderGstreamerPrivate *priv;
};
struct _GthMetadataProviderGstreamerClass
......
......@@ -21,23 +21,29 @@
*/
#include <config.h>
#include <string.h>
#include <glib/gi18n.h>
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gthumb.h>
#include "gth-metadata-provider-image.h"
#define GTH_METADATA_PROVIDER_IMAGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTH_TYPE_METADATA_PROVIDER_IMAGE, GthMetadataProviderImagePrivate))
struct _GthMetadataProviderImagePrivate {
int dummy;
};
static GthMetadataProviderClass *parent_class = NULL;
static GthMetadataProviderClass *parent_class = NULL;
static gboolean
gth_metadata_provider_image_can_read (GthMetadataProvider *self,
const char *mime_type,
char **attribute_v)
{
if (! _g_content_type_is_a (mime_type, "image/*"))
return FALSE;
return _g_file_attributes_matches_any_v ("general::format,"
"general::dimensions,"
"image::width,"
"image::height",
attribute_v);
}
static void
......@@ -72,55 +78,16 @@ gth_metadata_provider_image_read (GthMetadataProvider *self,
}
static void
gth_metadata_provider_image_finalize (GObject *object)
{
/*GthMetadataProviderImage *image = GTH_METADATA_PROVIDER_IMAGE (object);*/
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static GObject *
gth_metadata_provider_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
GthMetadataProviderClass *klass;
GObjectClass *parent_class;
GObject *obj;
GthMetadataProvider *self;
klass = GTH_METADATA_PROVIDER_CLASS (g_type_class_peek (GTH_TYPE_METADATA_PROVIDER));
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
obj = parent_class->constructor (type, n_construct_properties, construct_properties);
self = GTH_METADATA_PROVIDER (obj);
g_object_set (self, "readable-attributes", "general::format,general::dimensions,image::width,image::height", NULL);
return obj;
}
static void
gth_metadata_provider_image_class_init (GthMetadataProviderImageClass *klass)
{
parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (GthMetadataProviderImagePrivate));
G_OBJECT_CLASS (klass)->finalize = gth_metadata_provider_image_finalize;
G_OBJECT_CLASS (klass)->constructor = gth_metadata_provider_constructor;
GTH_METADATA_PROVIDER_CLASS (klass)->can_read = gth_metadata_provider_image_can_read;
GTH_METADATA_PROVIDER_CLASS (klass)->read = gth_metadata_provider_image_read;
}
static void
gth_metadata_provider_image_init (GthMetadataProviderImage *catalogs)
{
}
GType
gth_metadata_provider_image_get_type (void)
{
......@@ -136,7 +103,7 @@ gth_metadata_provider_image_get_type (void)
NULL,
sizeof (GthMetadataProviderImage),
0,
(GInstanceInitFunc) gth_metadata_provider_image_init
(GInstanceInitFunc) NULL
};
type = g_type_register_static (GTH_TYPE_METADATA_PROVIDER,
......
......@@ -35,13 +35,11 @@
#define GTH_METADATA_PROVIDER_IMAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GTH_TYPE_METADATA_PROVIDER_IMAGE, GthMetadataProviderImageClass))
typedef struct _GthMetadataProviderImage GthMetadataProviderImage;
typedef struct _GthMetadataProviderImagePrivate GthMetadataProviderImagePrivate;
typedef struct _GthMetadataProviderImageClass GthMetadataProviderImageClass;
struct _GthMetadataProviderImage
{
GthMetadataProvider __parent;
GthMetadataProviderImagePrivate *priv;
};
struct _GthMetadataProviderImageClass
......
......@@ -526,7 +526,8 @@ gth_main_get_metadata_attributes (const char *mask)
GthMetadataProvider *
gth_main_get_metadata_reader (const char *id)
gth_main_get_metadata_reader (const char *id,
const char *mime_type)
{
GthMetadataProvider *metadata = NULL;
GList *scan;
......@@ -535,7 +536,28 @@ gth_main_get_metadata_reader (const char *id)
for (scan = Main->priv->metadata_provider; scan; scan = scan->next) {
GthMetadataProvider *registered_metadata = scan->data;
if (gth_metadata_provider_can_read (registered_metadata, (char **)attribute_v)) {
if (gth_metadata_provider_can_read (registered_metadata, mime_type, (char **)attribute_v)) {
metadata = g_object_new (G_OBJECT_TYPE (registered_metadata), NULL);
break;
}
}
return metadata;
}
GthMetadataProvider *
gth_main_get_metadata_writer (const char *id,
const char *mime_type)
{
GthMetadataProvider *metadata = NULL;
GList *scan;
const char *attribute_v[] = { id, NULL };
for (scan = Main->priv->metadata_provider; scan; scan = scan->next) {
GthMetadataProvider *registered_metadata = scan->data;
if (gth_metadata_provider_can_write (registered_metadata, mime_type, (char **)attribute_v)) {
metadata = g_object_new (G_OBJECT_TYPE (registered_metadata), NULL);
break;
}
......@@ -1261,8 +1283,8 @@ gth_main_extension_is_active (const char *extension_name)
gboolean
attribute_list_reaload_required (const char *old_attributes,
const char *new_attributes)
attribute_list_reload_required (const char *old_attributes,
const char *new_attributes)
{
char **old_attributes_v;
char **new_attributes_v;
......@@ -1285,7 +1307,7 @@ attribute_list_reaload_required (const char *old_attributes,
GthMetadataProvider *provider;
int j;
provider = gth_main_get_metadata_reader (old_attributes_v[i]);
provider = gth_main_get_metadata_reader (old_attributes_v[i], "*");
if (provider == NULL)
continue;
......@@ -1298,7 +1320,7 @@ attribute_list_reaload_required (const char *old_attributes,
attr_v[0] = new_attributes_v[j];
attr_v[1] = NULL;
if (gth_metadata_provider_can_read (provider, attr_v)) {
if (gth_metadata_provider_can_read (provider, "*", attr_v)) {
g_free (new_attributes_v[j]);
new_attributes_v[j] = NULL;
}
......
......@@ -80,7 +80,10 @@ void gth_main_register_metadata_info_v (GthMetadataInfo
void gth_main_register_metadata_provider (GType metadata_provider_type);
GList * gth_main_get_all_metadata_providers (void);
char ** gth_main_get_metadata_attributes (const char *mask);
GthMetadataProvider * gth_main_get_metadata_reader (const char *id);
GthMetadataProvider * gth_main_get_metadata_reader (const char *id,
const char *mime_type);
GthMetadataProvider * gth_main_get_metadata_writer (const char *id,
const char *mime_type);
GthMetadataCategory * gth_main_get_metadata_category (const char *id);
GthMetadataInfo * gth_main_get_metadata_info (const char *id);
GPtrArray * gth_main_get_all_metadata_info (void);
......@@ -126,7 +129,7 @@ gboolean gth_main_extension_is_active (const char *exten
/* utilities */
gboolean attribute_list_reaload_required (const char *old_attributes,
gboolean attribute_list_reload_required (const char *old_attributes,
const char *new_attributes);
G_END_DECLS
......
......@@ -21,8 +21,6 @@
*/
#include <config.h>
#include <string.h>
#include <glib/gi18n.h>
#include <glib.h>
#include "glib-utils.h"
#include "gth-metadata-provider-file.h"
......@@ -31,12 +29,21 @@
#define GTH_METADATA_PROVIDER_FILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTH_TYPE_METADATA_PROVIDER_COMMENT, GthMetadataProviderFilePrivate))
struct _GthMetadataProviderFilePrivate {
int dummy;
};
static GthMetadataProviderClass *parent_class = NULL;