[tracker/writeback: 23/23] Merge branch 'master' into writeback



commit fc92a18c540b86e3b78e62b066b253b0ccfa7999
Merge: e5488f2... f34e0da...
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Nov 25 11:01:32 2009 +0100

    Merge branch 'master' into writeback
    
    Conflicts:
    	src/libtracker-miner/tracker-miner.h

 src/libtracker-miner/tracker-miner-fs.c       |  107 ++++++-----
 src/libtracker-miner/tracker-miner.c          |  254 +++++++++++++++++++------
 src/libtracker-miner/tracker-miner.h          |   99 +++++-----
 src/tracker-miner-fs/tracker-miner-files.c    |   39 +++--
 src/tracker-search-tool/tracker-entry.gs      |    3 +-
 src/tracker-writeback/tracker-writeback-xmp.c |    2 -
 6 files changed, 335 insertions(+), 169 deletions(-)
---
diff --cc src/libtracker-miner/tracker-miner-fs.c
index 662d975,d3bd1db..31587c9
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@@ -1069,108 -1024,16 +1082,110 @@@ item_remove (TrackerMinerFS *fs
  	return FALSE;
  }
  
 +static gboolean
 +item_writeback (TrackerMinerFS *fs,
 +                GFile          *file,
 +                GFile          *source_file)
 +{
 +	TrackerSparqlBuilder *sparql;
 +	gchar *uri;
 +	gboolean success = FALSE;
 +	GCancellable *cancellable;
 +	GFile *working_file;
 +
 +	/* While we are in writeback:
 +	 * o. We always ignore deletes because it's never the final operation
 +	 *    of a writeback. We have a delete when both are null.
 +	 * o. A create means the writeback used rename(). This is the final 
 +	 *    operation of a writeback and thus we make the update query.
 +	 *    We have a create when file == null and source_file != null
 +	 * o. A move means the writeback used rename(). This is the final 
 +	 *    operation of a writeback and thus we make the update query.
 +	 *    We have a move when both file and source_file aren't null.
 +	 * o. A update means the writeback didn't use rename(). This is the
 +	 *    final operation of a writeback and thus we make the update query.
 +	 *    An update means that file != null and source_file == null. */
 +
 +	/* Happens on delete while in writeback */
 +	if (!file && !source_file) {
 +		return TRUE;
 +	}
 +
 +	/* Create or update, we are the final one so we make the update query */
 +
 +	if (!file && source_file) {
 +		/* Happens on create while in writeback */
 +		working_file = source_file;
 +	} else {
 +		/* Happens on update while in writeback */
 +		working_file = file;
 +	}
 +
 +	uri = g_file_get_uri (working_file);
 +
 +	g_debug ("Updating item: '%s' (Writeback event)", uri);
 +
 +	if (!item_query_exists (fs, working_file)) {
 +		g_debug ("  File does not exist anyway (uri:'%s')", uri);
 +		return TRUE;
 +	}
 +
 +	cancellable = g_cancellable_new ();
 +	sparql = tracker_sparql_builder_new_update ();
 +	g_object_ref (working_file);
 +
 +	/* Writeback */
 +	g_signal_emit (fs, signals[WRITEBACK_FILE], 0,
 +	               working_file, sparql, cancellable, &success);
 +
 +	if (success) {
 +		gchar *query;
 +
 +		/* Perhaps we should move the DELETE to tracker-miner-files.c? 
 +		 * Or we add support for DELETE to TrackerSparqlBuilder ofcrs */
 +
 +		query = g_strdup_printf ("DELETE FROM <%s> { <%s> "
 +		                           "nfo:fileSize ?unknown1 ;\n\t"
 +		                           "nfo:fileLastModified ?unknown2 ;\n\t"
 +		                           "nfo:fileLastAccessed ?unknown3 ;\n\t"
 +		                           "nie:mimeType ?unknown4 \n"
 +		                         "} WHERE { <%s> "
 +		                           "nfo:fileSize ?unknown1 ;\n\t"
 +		                           "nfo:fileLastModified ?unknown2 ;\n\t"
 +		                           "nfo:fileLastAccessed ?unknown3 ;\n\t"
 +		                           "nie:mimeType ?unknown4 \n"
 +		                         "} \n %s", 
 +		                         uri, uri, uri,
 +		                         tracker_sparql_builder_get_result (sparql));
 +
 +		tracker_miner_execute_batch_update (TRACKER_MINER (fs),
 +		                                    query,
 +		                                    NULL, NULL, NULL);
 +
 +		g_free (query);
 +	}
 +
 +	g_hash_table_remove (fs->private->items_writeback, uri);
 +
 +	g_object_unref (sparql);
 +	g_object_unref (working_file);
 +	g_object_unref (cancellable);
 +
 +	g_free (uri);
 +
 +	return FALSE;
 +}
 +
  static void
- item_update_uri_recursively_cb (TrackerMiner *miner,
- 				GPtrArray    *result,
- 				const GError *error,
- 				gpointer      user_data)
+ item_update_uri_recursively_cb (GObject      *object,
+                                 GAsyncResult *result,
+                                 gpointer      user_data)
  {
- 	TrackerMinerFS *fs = TRACKER_MINER_FS (miner);
+ 	TrackerMinerFS *fs = TRACKER_MINER_FS (object);
  	RecursiveMoveData *data = user_data;
+ 	GError *error = NULL;
+ 
+ 	const GPtrArray *query_results = tracker_miner_execute_sparql_finish (TRACKER_MINER (object), result, &error);
  
  	if (error) {
  		g_critical ("Could not query children: %s", error->message);
diff --cc src/libtracker-miner/tracker-miner.h
index 04f456e,cecf438..d3e7ca0
--- a/src/libtracker-miner/tracker-miner.h
+++ b/src/libtracker-miner/tracker-miner.h
@@@ -81,57 -81,62 +81,64 @@@ typedef struct 
  
  	void (* error)      (TrackerMiner *miner,
  			     GError       *error);
 +	void (* writeback)  (TrackerMiner *miner,
 +			     const GStrv   subjects);
 +
  } TrackerMinerClass;
  
- typedef void (* TrackerMinerUpdateCallback) (TrackerMiner *miner,
- 					     const GError *error,
- 					     gpointer      user_data);
- typedef void (* TrackerMinerQueryCallback)  (TrackerMiner *miner,
- 					     GPtrArray    *result,
- 					     const GError *error,
- 					     gpointer      user_data);
- 
- GType          tracker_miner_get_type       (void) G_GNUC_CONST;
- GQuark	       tracker_miner_error_quark    (void);
- 
- void           tracker_miner_start          (TrackerMiner  *miner);
- void           tracker_miner_stop           (TrackerMiner  *miner);
- void           tracker_miner_writeback      (TrackerMiner  *miner,
-                                              const GStrv    subjects);
- 
- gboolean       tracker_miner_is_started     (TrackerMiner  *miner);
- 
- gint           tracker_miner_pause          (TrackerMiner  *miner,
- 					     const gchar   *reason,
- 					     GError       **error);
- gboolean       tracker_miner_resume         (TrackerMiner  *miner,
- 					     gint           cookie,
- 					     GError       **error);
- 
- void           tracker_miner_execute_update       (TrackerMiner               *miner,
- 						   const gchar                *sparql,
- 						   GCancellable               *cancellable,
- 						   TrackerMinerUpdateCallback  callback,
- 						   gpointer                    user_data);
- void           tracker_miner_execute_sparql       (TrackerMiner               *miner,
- 						   const gchar                *sparql,
- 						   GCancellable               *cancellable,
- 						   TrackerMinerQueryCallback   callback,
- 						   gpointer                    user_data);
- void           tracker_miner_execute_batch_update (TrackerMiner               *miner,
- 						   const gchar                *sparql,
- 						   GCancellable               *cancellable,
- 						   TrackerMinerUpdateCallback  callback,
- 						   gpointer                    user_data);
- void           tracker_miner_commit               (TrackerMiner               *miner,
- 						   GCancellable               *cancellable,
- 						   TrackerMinerUpdateCallback  callback,
- 						   gpointer                    user_data);
- 
- 
+ GType            tracker_miner_get_type       (void) G_GNUC_CONST;
+ GQuark	         tracker_miner_error_quark    (void);
+ 
+ void             tracker_miner_start          (TrackerMiner  *miner);
+ void             tracker_miner_stop           (TrackerMiner  *miner);
+ 
+ gboolean         tracker_miner_is_started     (TrackerMiner  *miner);
+ 
+ gint             tracker_miner_pause          (TrackerMiner  *miner,
+                                                const gchar   *reason,
+                                                GError       **error);
+ gboolean         tracker_miner_resume         (TrackerMiner  *miner,
+                                                gint           cookie,
+                                                GError       **error);
+ 
+ void             tracker_miner_execute_update              (TrackerMiner        *miner,
+                                                             const gchar         *sparql,
+                                                             GCancellable        *cancellable,
+                                                             GAsyncReadyCallback  callback,
+                                                             gpointer             user_data);
+ 
+ void             tracker_miner_execute_update_finish       (TrackerMiner        *miner,
+                                                             GAsyncResult        *result,
+                                                             GError             **error);
+ 
+ void             tracker_miner_execute_sparql              (TrackerMiner        *miner,
+                                                             const gchar         *sparql,
+                                                             GCancellable        *cancellable,
+                                                             GAsyncReadyCallback  callback,
+                                                             gpointer             user_data);
+ 
+ const GPtrArray* tracker_miner_execute_sparql_finish       (TrackerMiner        *miner,
+                                                             GAsyncResult        *result,
+                                                             GError             **error);
+ 
+ void             tracker_miner_execute_batch_update        (TrackerMiner        *miner,
+                                                             const gchar         *sparql,
+                                                             GCancellable        *cancellable,
+                                                             GAsyncReadyCallback  callback,
+                                                             gpointer             user_data);
+ 
+ void             tracker_miner_execute_batch_update_finish (TrackerMiner        *miner,
+                                                             GAsyncResult        *result,
+                                                             GError             **error);
+ 
+ void             tracker_miner_commit                      (TrackerMiner        *miner,
+                                                             GCancellable        *cancellable,
+                                                             GAsyncReadyCallback  callback,
+                                                             gpointer             user_data);
+ 
+ void             tracker_miner_commit_finish               (TrackerMiner        *miner,
+                                                             GAsyncResult        *result,
+                                                             GError             **error);
 -
  G_END_DECLS
  
  #endif /* __LIBTRACKERMINER_MINER_H__ */
diff --cc src/tracker-writeback/tracker-writeback-xmp.c
index 9c7aa6d,0000000..ed03590
mode 100644,000000..100644
--- a/src/tracker-writeback/tracker-writeback-xmp.c
+++ b/src/tracker-writeback/tracker-writeback-xmp.c
@@@ -1,200 -1,0 +1,198 @@@
 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 +/*
 + * Copyright (C) 2009, Nokia
 + *
 + * This library is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public
 + * License as published by the Free Software Foundation; either
 + * version 2 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
 + * General Public License for more details.
 + *
 + * You should have received a copy of the GNU 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: Philip Van Hoof <philip codeminded be>
 + */
 +
 +#include "config.h"
 +
 +#include <locale.h>
 +#include <string.h>
 +
 +#include <exempi/xmp.h>
 +#include <exempi/xmpconsts.h>
 +
 +#include <glib-object.h>
 +#include <gio/gio.h>
 +
 +#include <libtracker-common/tracker-ontology.h>
 +
 +#include "tracker-writeback-file.h"
 +
 +#define TRACKER_TYPE_WRITEBACK_XMP (tracker_writeback_xmp_get_type ())
 +
- #define DEBUG_XMP
- 
 +typedef struct TrackerWritebackXMP TrackerWritebackXMP;
 +typedef struct TrackerWritebackXMPClass TrackerWritebackXMPClass;
 +
 +struct TrackerWritebackXMP {
 +	TrackerWritebackFile parent_instance;
 +};
 +
 +struct TrackerWritebackXMPClass {
 +	TrackerWritebackFileClass parent_class;
 +};
 +
 +static GType                tracker_writeback_xmp_get_type     (void) G_GNUC_CONST;
 +static gboolean             writeback_xmp_update_file_metadata (TrackerWritebackFile *writeback_file,
 +                                                                GFile                *file,
 +                                                                GPtrArray            *values);
 +static const gchar * const *writeback_xmp_content_types        (TrackerWritebackFile *writeback_file);
 +
 +G_DEFINE_DYNAMIC_TYPE (TrackerWritebackXMP, tracker_writeback_xmp, TRACKER_TYPE_WRITEBACK_FILE);
 +
 +static void
 +tracker_writeback_xmp_class_init (TrackerWritebackXMPClass *klass)
 +{
 +	TrackerWritebackFileClass *writeback_file_class = TRACKER_WRITEBACK_FILE_CLASS (klass);
 +
 +	xmp_init ();
 +
 +	writeback_file_class->update_file_metadata = writeback_xmp_update_file_metadata;
 +	writeback_file_class->content_types = writeback_xmp_content_types;
 +}
 +
 +static void
 +tracker_writeback_xmp_class_finalize (TrackerWritebackXMPClass *klass)
 +{
 +	xmp_terminate ();
 +}
 +
 +static void
 +tracker_writeback_xmp_init (TrackerWritebackXMP *wbx)
 +{
 +}
 +
 +static const gchar * const *
 +writeback_xmp_content_types (TrackerWritebackFile *wbf)
 +{
 +	static const gchar *content_types[] = {
 +	        "image/png",   /* .png files */
 +	        "sketch/png",  /* .sketch.png files on Maemo*/
 +	        "image/jpeg",  /* .jpg & .jpeg files */
 +	        "image/tiff",  /* .tiff & .tif files */
 +	        NULL 
 +	};
 +
 +	/* "image/gif"                        .gif files 
 +	   "application/pdf"                  .pdf files 
 +	   "application/rdf+xml"              .xmp files 
 +	   "application/postscript"           .ps files  
 +	   "application/x-shockwave-flash"    .swf files 
 +	   "video/quicktime"                  .mov files 
 +	   "video/mpeg"                       .mpeg & .mpg files 
 +	   "audio/mpeg"                       .mp3, etc files */
 +
 +	return content_types;
 +}
 +
 +static gboolean
 +writeback_xmp_update_file_metadata (TrackerWritebackFile *wbf,
 +				    GFile                *file,
 +				    GPtrArray            *values)
 +{
 +	gchar *path;
 +	guint n;
 +	XmpFilePtr xmp_files;
 +	XmpPtr xmp;
 +#ifdef DEBUG_XMP
 +	XmpStringPtr str;
 +#endif
 +
 +	path = g_file_get_path (file);
 +
 +	xmp_files = xmp_files_open_new (path, XMP_OPEN_FORUPDATE);
 +
 +	if (!xmp_files) {
 +		g_free (path);
 +		return FALSE;
 +	}
 +
 +	xmp = xmp_files_get_new_xmp (xmp_files);
 +
 +	if (!xmp) {
 +		g_free (path);
 +		return FALSE;
 +	}
 +
 +#ifdef DEBUG_XMP
 +	str = xmp_string_new ();
 +	g_print ("\nBEFORE: ---- \n");
 +	xmp_serialize_and_format (xmp, str, 0, 0, "\n", "\t", 1);
 +	g_print ("%s\n", xmp_string_cstr (str));
 +	xmp_string_free (str);
 +#endif
 +
 +	for (n = 0; n < values->len; n++) {
 +		const GStrv row = g_ptr_array_index (values, n);
 +
 +		if (g_strcmp0 (row[1], TRACKER_NIE_PREFIX "title") == 0) {
 +			xmp_delete_property (xmp, NS_EXIF, "Title");
 +			xmp_set_property (xmp, NS_EXIF, "Title", row[2], 0);
 +
 +			/* I have no idea why I have to set this, but without
 +			 * it seems that exiftool doesn't see the change */
 +			 xmp_set_array_item (xmp, NS_DC, "title", 1, row[2], 0); 
 +
 +		}
 +
 +		/* TODO: Add more */
 +	}
 +
 +#ifdef DEBUG_XMP
 +	g_print ("\nAFTER: ---- \n");
 +	str = xmp_string_new ();
 +	xmp_serialize_and_format (xmp, str, 0, 0, "\n", "\t", 1);
 +	g_print ("%s\n", xmp_string_cstr (str));
 +	xmp_string_free (str);
 +	g_print ("\n --------- \n");
 +#endif
 +
 +	if (xmp_files_can_put_xmp (xmp_files, xmp)) {
 +		xmp_files_put_xmp (xmp_files, xmp);
 +	}
 +
 +	xmp_files_close (xmp_files, XMP_CLOSE_SAFEUPDATE);
 +
 +	xmp_free (xmp);
 +	xmp_files_free (xmp_files);
 +	g_free (path);
 +
 +	return TRUE;
 +}
 +
 +TrackerWriteback *
 +writeback_module_create (GTypeModule *module)
 +{
 +	tracker_writeback_xmp_register_type (module);
 +
 +	return g_object_new (TRACKER_TYPE_WRITEBACK_XMP, NULL);
 +}
 +
 +const gchar * const *
 +writeback_module_get_rdf_types (void)
 +{
 +	static const gchar *rdf_types[] = { 
 +	        TRACKER_NFO_PREFIX "Image",
 +	        TRACKER_NFO_PREFIX "Audio",
 +	        TRACKER_NFO_PREFIX "Video",
 +	        NULL 
 +	};
 +
 +	return rdf_types;
 +}



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