[tracker/writeback: 54/54] Refactored content-type check to abstract TrackerWritebackFile
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/writeback: 54/54] Refactored content-type check to abstract TrackerWritebackFile
- Date: Tue, 24 Nov 2009 11:33:24 +0000 (UTC)
commit a3e08d73a92e0c3027087c74480554de9df0dcb5
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Nov 24 12:31:44 2009 +0100
Refactored content-type check to abstract TrackerWritebackFile
src/tracker-writeback/tracker-writeback-file.c | 50 ++++++++++++++++---
src/tracker-writeback/tracker-writeback-file.h | 8 ++-
src/tracker-writeback/tracker-writeback-mp3.c | 44 +++++++----------
src/tracker-writeback/tracker-writeback-xmp.c | 62 ++++++++++-------------
4 files changed, 92 insertions(+), 72 deletions(-)
---
diff --git a/src/tracker-writeback/tracker-writeback-file.c b/src/tracker-writeback/tracker-writeback-file.c
index cae2736..5ce1ef7 100644
--- a/src/tracker-writeback/tracker-writeback-file.c
+++ b/src/tracker-writeback/tracker-writeback-file.c
@@ -64,9 +64,13 @@ tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
TrackerWritebackFileClass *writeback_file_class;
gboolean retval;
GFile *file;
+ GFileInfo *file_info;
const gchar *subjects[2] = { NULL, NULL };
GStrv row;
TrackerWritebackFile *self;
+ const gchar **content_types;
+ const gchar *mime_type;
+ guint n;
writeback_file_class = TRACKER_WRITEBACK_FILE_GET_CLASS (writeback);
self = TRACKER_WRITEBACK_FILE (writeback);
@@ -77,22 +81,52 @@ tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
return FALSE;
}
+ if (!writeback_file_class->content_types) {
+ g_critical ("%s doesn't implement content_types()",
+ G_OBJECT_TYPE_NAME (writeback));
+ return FALSE;
+ }
+
/* Get the file from the first row */
row = g_ptr_array_index (values, 0);
file = g_file_new_for_uri (row[0]);
- tracker_file_lock (file);
+ file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, NULL);
+
+ if (!file_info) {
+ return FALSE;
+ }
+
+ mime_type = g_file_info_get_content_type (file_info);
+ content_types = (writeback_file_class->content_types) (TRACKER_WRITEBACK_FILE (writeback));
+
+ retval = FALSE;
+
+ for (n = 0; content_types[n] != NULL; n++) {
+ if (g_strcmp0 (mime_type, content_types[n]) == 0) {
+ retval = TRUE;
+ break;
+ }
+ }
- subjects[0] = row[0];
+ g_object_unref (file_info);
- tracker_miner_manager_writeback (tracker_writeback_get_miner_manager (),
- "org.freedesktop.Tracker1.Miner.Files",
- subjects);
+ if (retval) {
+ tracker_file_lock (file);
- retval = (writeback_file_class->update_file_metadata) (TRACKER_WRITEBACK_FILE (writeback),
- file, values);
+ subjects[0] = row[0];
- g_timeout_add_seconds (3, (GSourceFunc) unlock_file_cb, g_object_ref (file));
+ tracker_miner_manager_writeback (tracker_writeback_get_miner_manager (),
+ "org.freedesktop.Tracker1.Miner.Files",
+ subjects);
+
+ retval = (writeback_file_class->update_file_metadata) (TRACKER_WRITEBACK_FILE (writeback),
+ file, values);
+
+ g_timeout_add_seconds (3, (GSourceFunc) unlock_file_cb, g_object_ref (file));
+ }
g_object_unref (file);
diff --git a/src/tracker-writeback/tracker-writeback-file.h b/src/tracker-writeback/tracker-writeback-file.h
index c646066..140951e 100644
--- a/src/tracker-writeback/tracker-writeback-file.h
+++ b/src/tracker-writeback/tracker-writeback-file.h
@@ -44,9 +44,11 @@ struct TrackerWritebackFile {
struct TrackerWritebackFileClass {
TrackerWritebackClass parent_class;
- gboolean (* update_file_metadata) (TrackerWritebackFile *writeback_file,
- GFile *file,
- GPtrArray *values);
+ gboolean (* update_file_metadata) (TrackerWritebackFile *writeback_file,
+ GFile *file,
+ GPtrArray *values);
+ const gchar** (* content_types) (TrackerWritebackFile *writeback_file);
+
};
GType tracker_writeback_file_get_type (void) G_GNUC_CONST;
diff --git a/src/tracker-writeback/tracker-writeback-mp3.c b/src/tracker-writeback/tracker-writeback-mp3.c
index ee2c69c..58702c6 100644
--- a/src/tracker-writeback/tracker-writeback-mp3.c
+++ b/src/tracker-writeback/tracker-writeback-mp3.c
@@ -39,10 +39,11 @@ struct TrackerWritebackMP3Class {
TrackerWritebackFileClass parent_class;
};
-static GType tracker_writeback_mp3_get_type (void) G_GNUC_CONST;
-static gboolean tracker_writeback_mp3_update_file_metadata (TrackerWritebackFile *writeback_file,
- GFile *file,
- GPtrArray *values);
+static GType tracker_writeback_mp3_get_type (void) G_GNUC_CONST;
+static gboolean tracker_writeback_mp3_update_file_metadata (TrackerWritebackFile *writeback_file,
+ GFile *file,
+ GPtrArray *values);
+static const gchar** tracker_writeback_mp3_content_types (TrackerWritebackFile *writeback_file);
G_DEFINE_DYNAMIC_TYPE (TrackerWritebackMP3, tracker_writeback_mp3, TRACKER_TYPE_WRITEBACK_FILE);
@@ -52,6 +53,7 @@ tracker_writeback_mp3_class_init (TrackerWritebackMP3Class *klass)
TrackerWritebackFileClass *writeback_file_class = TRACKER_WRITEBACK_FILE_CLASS (klass);
writeback_file_class->update_file_metadata = tracker_writeback_mp3_update_file_metadata;
+ writeback_file_class->content_types = tracker_writeback_mp3_content_types;
}
static void
@@ -64,34 +66,24 @@ tracker_writeback_mp3_init (TrackerWritebackMP3 *mp3)
{
}
+static const gchar**
+tracker_writeback_mp3_content_types (TrackerWritebackFile *writeback_file)
+{
+ static const gchar *content_types[] = { "audio/mpeg",
+ "audio/x-mp3",
+ NULL };
+
+ return content_types;
+}
+
static gboolean
tracker_writeback_mp3_update_file_metadata (TrackerWritebackFile *writeback_file,
- GFile *file,
- GPtrArray *values)
+ GFile *file,
+ GPtrArray *values)
{
- GFileInfo *file_info;
- const gchar *mime_type;
gchar *path;
guint n;
- file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL, NULL);
-
- if (!file_info) {
- return FALSE;
- }
-
- mime_type = g_file_info_get_content_type (file_info);
-
- if (g_strcmp0 (mime_type, "audio/mpeg") != 0 && /* .mp3 files */
- g_strcmp0 (mime_type, "audio/x-mp3") != 0) { /* .mp3 files */
-
- g_object_unref (file_info);
- return FALSE;
- }
-
- g_object_unref (file_info);
path = g_file_get_path (file);
for (n = 0; n < values->len; n++) {
diff --git a/src/tracker-writeback/tracker-writeback-xmp.c b/src/tracker-writeback/tracker-writeback-xmp.c
index b2701d7..974ef0e 100644
--- a/src/tracker-writeback/tracker-writeback-xmp.c
+++ b/src/tracker-writeback/tracker-writeback-xmp.c
@@ -53,10 +53,11 @@ struct TrackerWritebackXMPClass {
};
-static GType tracker_writeback_xmp_get_type (void) G_GNUC_CONST;
-static gboolean tracker_writeback_xmp_update_file_metadata (TrackerWritebackFile *writeback_file,
- GFile *file,
- GPtrArray *values);
+static GType tracker_writeback_xmp_get_type (void) G_GNUC_CONST;
+static gboolean tracker_writeback_xmp_update_file_metadata (TrackerWritebackFile *writeback_file,
+ GFile *file,
+ GPtrArray *values);
+static const gchar** tracker_writeback_xmp_content_types (TrackerWritebackFile *writeback_file);
G_DEFINE_DYNAMIC_TYPE (TrackerWritebackXMP, tracker_writeback_xmp, TRACKER_TYPE_WRITEBACK_FILE);
@@ -67,6 +68,7 @@ tracker_writeback_xmp_class_init (TrackerWritebackXMPClass *klass)
xmp_init ();
writeback_file_class->update_file_metadata = tracker_writeback_xmp_update_file_metadata;
+ writeback_file_class->content_types = tracker_writeback_xmp_content_types;
}
static void
@@ -80,13 +82,32 @@ tracker_writeback_xmp_init (TrackerWritebackXMP *xmp)
{
}
+static const gchar**
+tracker_writeback_xmp_content_types (TrackerWritebackFile *writeback_file)
+{
+ 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
tracker_writeback_xmp_update_file_metadata (TrackerWritebackFile *writeback_file,
GFile *file,
GPtrArray *values)
{
- GFileInfo *file_info;
- const gchar *mime_type;
gchar *path;
guint n;
XmpFilePtr xmp_files;
@@ -95,35 +116,6 @@ tracker_writeback_xmp_update_file_metadata (TrackerWritebackFile *writeback_file
XmpStringPtr str;
#endif
- file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL, NULL);
-
- if (!file_info) {
- return FALSE;
- }
-
- mime_type = g_file_info_get_content_type (file_info);
-
- if (g_strcmp0 (mime_type, "image/png") != 0 && /* .png files */
- g_strcmp0 (mime_type, "sketch/png") != 0 && /* .sketch.png files on Maemo*/
- g_strcmp0 (mime_type, "image/jpeg") != 0 && /* .jpg & .jpeg files */
- g_strcmp0 (mime_type, "image/tiff") != 0 ) { /* .tiff & .tif files */
-
- /* g_strcmp0 (mime_type, "image/gif") != 0 && * .gif files *
- g_strcmp0 (mime_type, "application/pdf") != 0 && * .pdf files *
- g_strcmp0 (mime_type, "application/rdf+xml") != 0 && * .xmp files *
- g_strcmp0 (mime_type, "application/postscript") != 0 && * .ps files *
- g_strcmp0 (mime_type, "application/x-shockwave-flash") != 0 && * .swf files *
- g_strcmp0 (mime_type, "video/quicktime") != 0 && * .mov files *
- g_strcmp0 (mime_type, "video/mpeg") != 0 && * .mpeg & .mpg files *
- g_strcmp0 (mime_type, "audio/mpeg") != 0 ) { * .mp3, etc files */
-
- g_object_unref (file_info);
- return FALSE;
- }
-
- g_object_unref (file_info);
path = g_file_get_path (file);
xmp_files = xmp_files_open_new (path, XMP_OPEN_FORUPDATE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]