[tracker/index-optical-discs] Fixes GB#611556, Need to support CD/DVD index



commit d83af1d33c2c31a3b81796a396472a36ea9315bc
Author: Martyn Russell <martyn lanedo com>
Date:   Thu Mar 4 16:35:07 2010 +0000

    Fixes GB#611556, Need to support CD/DVD index

 src/libtracker-miner/tracker-marshal.list        |    3 +-
 src/libtracker-miner/tracker-storage.c           |  211 +++++++++++++++++++---
 src/libtracker-miner/tracker-storage.h           |   22 ++-
 src/tracker-extract/tracker-albumart.c           |   10 +-
 src/tracker-miner-fs/tracker-config.c            |   52 +++++-
 src/tracker-miner-fs/tracker-config.h            |    3 +
 src/tracker-miner-fs/tracker-miner-files.c       |   53 +++++--
 src/tracker-preferences/tracker-config.vapi      |    1 +
 src/tracker-preferences/tracker-preferences.ui   |   28 +++-
 src/tracker-preferences/tracker-preferences.vala |    9 +
 10 files changed, 335 insertions(+), 57 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-marshal.list b/src/libtracker-miner/tracker-marshal.list
index 05c6728..9c85140 100644
--- a/src/libtracker-miner/tracker-marshal.list
+++ b/src/libtracker-miner/tracker-marshal.list
@@ -2,9 +2,10 @@ VOID:OBJECT,BOOLEAN
 VOID:OBJECT,OBJECT,BOOLEAN,BOOLEAN
 VOID:OBJECT,POINTER,UINT,UINT,UINT,UINT
 VOID:DOUBLE,UINT,UINT,UINT,UINT
-VOID:STRING,STRING,DOUBLE
 VOID:STRING,DOUBLE
 VOID:STRING,STRING
+VOID:STRING,STRING,DOUBLE
+VOID:STRING,STRING,BOOLEAN,BOOLEAN
 BOOL:OBJECT,OBJECT,OBJECT
 BOOL:OBJECT,OBJECT
 BOOL:OBJECT,POINTER
diff --git a/src/libtracker-miner/tracker-storage.c b/src/libtracker-miner/tracker-storage.c
index 31ee229..727bc6c 100644
--- a/src/libtracker-miner/tracker-storage.c
+++ b/src/libtracker-miner/tracker-storage.c
@@ -42,6 +42,7 @@ typedef struct {
 	gchar *mount_point;
 	gchar *uuid;
 	guint removable : 1;
+	guint optical : 1;
 } MountInfo;
 
 typedef struct {
@@ -51,7 +52,9 @@ typedef struct {
 
 typedef struct {
 	GSList *roots;
-	gboolean only_removable;
+	guint either_condition : 1;
+	guint removable : 1;
+	guint optical : 1;
 } GetRoots;
 
 static void     tracker_storage_finalize (GObject        *object);
@@ -94,11 +97,13 @@ tracker_storage_class_init (TrackerStorageClass *klass)
 		              G_SIGNAL_RUN_LAST,
 		              0,
 		              NULL, NULL,
-		              tracker_marshal_VOID__STRING_STRING,
+		              tracker_marshal_VOID__STRING_STRING_BOOLEAN_BOOLEAN,
 		              G_TYPE_NONE,
-		              2,
+		              4,
 		              G_TYPE_STRING,
-		              G_TYPE_STRING);
+		              G_TYPE_STRING,
+		              G_TYPE_BOOLEAN,
+		              G_TYPE_BOOLEAN);
 
 	signals[MOUNT_POINT_REMOVED] =
 		g_signal_new ("mount-point-removed",
@@ -272,7 +277,8 @@ static GNode *
 mount_add_hierarchy (GNode       *root,
                      const gchar *uuid,
                      const gchar *mount_point,
-                     gboolean     removable)
+                     gboolean     removable,
+                     gboolean     optical)
 {
 	MountInfo *info;
 	GNode *node;
@@ -289,6 +295,7 @@ mount_add_hierarchy (GNode       *root,
 	info->mount_point = mp;
 	info->uuid = g_strdup (uuid);
 	info->removable = removable;
+	info->optical = optical;
 
 	return g_node_append_data (node, info);
 }
@@ -297,17 +304,92 @@ static void
 mount_add (TrackerStorage *storage,
            const gchar    *uuid,
            const gchar    *mount_point,
-           gboolean        removable_device)
+           gboolean        removable_device,
+           gboolean        optical_disc)
 {
 	TrackerStoragePrivate *priv;
 	GNode *node;
 
 	priv = TRACKER_STORAGE_GET_PRIVATE (storage);
 
-	node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device);
+	node = mount_add_hierarchy (priv->mounts, uuid, mount_point, removable_device, optical_disc);
 	g_hash_table_insert (priv->mounts_by_uuid, g_strdup (uuid), node);
 
-	g_signal_emit (storage, signals[MOUNT_POINT_ADDED], 0, uuid, mount_point, NULL);
+	g_signal_emit (storage, 
+	               signals[MOUNT_POINT_ADDED], 
+	               0,
+	               uuid,
+	               mount_point,
+	               removable_device,
+	               optical_disc,
+	               NULL);
+}
+
+static gchar *
+mount_guess_content_type (GFile    *mount_root,
+                          gboolean *is_multimedia)
+{
+	gchar *content_type = NULL;
+
+	/* Set defaults */
+	*is_multimedia = FALSE;
+
+	if (g_file_has_uri_scheme (mount_root, "cdda")) {
+		*is_multimedia = TRUE;
+
+		content_type = g_strdup ("x-content/audio-cdda");
+	} else {
+		gchar **guess_type;
+		gint i;
+		
+		guess_type = g_content_type_guess_for_tree (mount_root);
+		
+		for (i = 0; guess_type && guess_type[i]; i++) {
+			if (!g_strcmp0 (guess_type[i], "x-content/image-picturecd")) {
+				/* Images */
+				content_type = g_strdup (guess_type[i]);
+				break;
+			} else if (!g_strcmp0 (guess_type[i], "x-content/video-bluray") ||
+			           !g_strcmp0 (guess_type[i], "x-content/video-dvd") ||
+			           !g_strcmp0 (guess_type[i], "x-content/video-hddvd") ||
+			           !g_strcmp0 (guess_type[i], "x-content/video-svcd") ||
+			           !g_strcmp0 (guess_type[i], "x-content/video-vcd")) {
+				/* Videos */
+				*is_multimedia = TRUE;
+				content_type = g_strdup (guess_type[i]);
+				break;
+			} else if (!g_strcmp0 (guess_type[i], "x-content/audio-cdda") ||
+			           !g_strcmp0 (guess_type[i], "x-content/audio-dvd") ||
+			           !g_strcmp0 (guess_type[i], "x-content/audio-player")) {
+				/* Audios */
+				*is_multimedia = TRUE;
+				content_type = g_strdup (guess_type[i]);
+				break;
+			} else if (!g_strcmp0 (guess_type[i], "x-content/blank-bd") ||
+			           !g_strcmp0 (guess_type[i], "x-content/blank-cd") ||
+			           !g_strcmp0 (guess_type[i], "x-content/blank-dvd") ||
+			           !g_strcmp0 (guess_type[i], "x-content/blank-hddvd")) {
+				/* Blank */
+				content_type = g_strdup (guess_type[i]);
+			} else if (!g_strcmp0 (guess_type[i], "x-content/software") ||
+			           !g_strcmp0 (guess_type[i], "x-content/unix-software") ||
+			           !g_strcmp0 (guess_type[i], "x-content/win32-software")) {
+				/* NOTE: This one is a guess, can we
+				 * have this content type on
+				 * none-optical mount points?
+				 */
+				content_type = g_strdup (guess_type[i]);
+			} else if (!content_type) {
+				content_type = g_strdup (guess_type[i]);
+			}
+		}
+		
+		if (guess_type) {
+			g_strfreev (guess_type);
+		}
+	}
+
+	return content_type;
 }
 
 static void
@@ -317,8 +399,9 @@ volume_add (TrackerStorage *storage,
 {
 	TrackerStoragePrivate *priv;
 	GMount *mount;
-	gchar *str;
+	gchar *name;
 	gboolean is_mounted;
+	gboolean is_optical;
 	gchar *uuid;
 	gchar *mount_point;
 	gchar *device_file;
@@ -336,22 +419,64 @@ volume_add (TrackerStorage *storage,
 		}
 	}
 
-	str = g_volume_get_name (volume);
-	g_debug ("  Volume:'%s' found", str);
-	g_free (str);
+	name = g_volume_get_name (volume);
+	g_debug ("  Volume:'%s' found", name);
 		
 	if (!g_volume_should_automount (volume) ||
 	    !g_volume_can_mount (volume)) {
 		g_debug ("    Ignoring, volume can not be automatically mounted or mounted at all");
+		g_free (name);
 		return;
 	}
 
 	uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID);
 	if (!uuid) {
-		g_debug ("    Ignoring, volume has no UUID");
-		return;
+		GFile *file;
+		gchar *content_type;
+		gboolean is_multimedia;
+
+		mount = g_volume_get_mount (volume); 
+		
+		if (mount) {
+			file = g_mount_get_root (mount);
+			g_object_unref (mount);
+		} else {
+			g_debug ("  Being ignored because there is no mount point and no UUID");
+			g_free (name);
+			return;
+		}
+
+		content_type = mount_guess_content_type (file, &is_multimedia);
+		g_object_unref (file);
+
+		g_debug ("  No UUID, guessed content type:'%s', has music/video:%s",
+		           content_type,
+		           is_multimedia ? "yes" : "no");
+
+		if (!is_multimedia) {
+			uuid = g_strdup (name);
+			g_debug ("  Using UUID:'%s' for optical disc", uuid);
+		}
+
+		g_free (content_type);
+
+		if (!uuid) {
+			g_debug ("  Being ignored because mount is not optical media or is music/video");
+			g_free (name);
+			return;
+		}
+
+		is_optical = TRUE;
+	} else {
+		/* We assume that all devices that are non-optical
+		 * have UUIDS already. Since optical devices are the
+		 * only ones which seem to have no UUID.
+		 */
+		is_optical = FALSE;
 	}
 
+	g_free (name);
+
 	device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
 	g_debug ("    Device file  : %s", device_file);
 		
@@ -380,7 +505,7 @@ volume_add (TrackerStorage *storage,
 	priv = TRACKER_STORAGE_GET_PRIVATE (storage);
 
 	if (mount_point && !g_hash_table_lookup (priv->mounts_by_uuid, uuid)) {
-		mount_add (storage, uuid, mount_point, TRUE);
+		mount_add (storage, uuid, mount_point, TRUE, is_optical);
 	}
 
 	g_free (uuid);
@@ -463,7 +588,7 @@ mount_added_cb (GVolumeMonitor *monitor,
 	if (volume) {
 		gchar *device_file;
 		gchar *uuid;
-		gboolean removable_device = TRUE;
+		gboolean removable_device;
 
 		device_file = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
 		uuid = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UUID);
@@ -478,9 +603,27 @@ mount_added_cb (GVolumeMonitor *monitor,
 		/* We don't have a UUID for CDROMs */
 		if (uuid) {
 			g_message ("  Being added as a tracker resource to index!");
-			mount_add (storage, uuid, mount_point, removable_device);
+			mount_add (storage, uuid, mount_point, removable_device, FALSE);
 		} else {
-			g_message ("  Being ignored because we have no UUID");
+			gchar *content_type;
+			gboolean is_multimedia;
+
+			content_type = mount_guess_content_type (file, &is_multimedia);
+
+			g_message ("  No UUID, guessed content type:'%s', music/video:%s",
+			           content_type,
+			           is_multimedia ? "yes" : "no");
+
+			if (!is_multimedia) {
+				uuid = g_strdup (name);
+
+				g_message ("  Using UUID:'%s' for optical disc", uuid);
+				mount_add (storage, uuid, mount_point, removable_device, TRUE);
+			} else {
+				g_message ("  Being ignored because mount is not optical media or is music/video");
+			}
+
+			g_free (content_type);
 		}
 
 		g_free (uuid);
@@ -579,7 +722,12 @@ get_mount_point_by_uuid_foreach (gpointer key,
 	node = value;
 	info = node->data;
 
-	if (!gr->only_removable || info->removable) {
+	if ((gr->either_condition == TRUE && 
+	     (!gr->removable || info->removable) &&
+	     (!gr->optical || info->optical)) ||
+	    (gr->either_condition == FALSE &&
+	     gr->removable == info->removable &&
+	     gr->optical == info->optical)) {
 		gchar *normalized_mount_point;
 		gint len;
 
@@ -596,7 +744,7 @@ get_mount_point_by_uuid_foreach (gpointer key,
 }
 
 /**
- * tracker_storage_get_removable_device_roots:
+ * tracker_storage_get_device_roots:
  * @storage: A #TrackerStorage
  *
  * Returns a #GSList of strings containing the root directories for
@@ -608,7 +756,10 @@ get_mount_point_by_uuid_foreach (gpointer key,
  * Returns: The list of root directories.
  **/
 GSList *
-tracker_storage_get_removable_device_roots (TrackerStorage *storage)
+tracker_storage_get_device_roots (TrackerStorage *storage,
+                                  gboolean        either_condition,
+                                  gboolean        removable,
+                                  gboolean        optical)
 {
 	TrackerStoragePrivate *priv;
 	GetRoots gr;
@@ -618,7 +769,9 @@ tracker_storage_get_removable_device_roots (TrackerStorage *storage)
 	priv = TRACKER_STORAGE_GET_PRIVATE (storage);
 
 	gr.roots = NULL;
-	gr.only_removable = TRUE;
+	gr.either_condition = either_condition;
+	gr.removable = removable;
+	gr.optical = optical;
 
 	g_hash_table_foreach (priv->mounts_by_uuid,
 	                      get_mount_point_by_uuid_foreach,
@@ -628,7 +781,7 @@ tracker_storage_get_removable_device_roots (TrackerStorage *storage)
 }
 
 /**
- * tracker_storage_get_removable_device_uuids:
+ * tracker_storage_get_device_uuids:
  * @storage: A #TrackerStorage
  *
  * Returns a #GSList of strings containing the UUID for removable devices.
@@ -638,7 +791,10 @@ tracker_storage_get_removable_device_roots (TrackerStorage *storage)
  * Returns: The list of UUIDs.
  **/
 GSList *
-tracker_storage_get_removable_device_uuids (TrackerStorage *storage)
+tracker_storage_get_device_uuids (TrackerStorage *storage,
+                                  gboolean        either_condition,
+                                  gboolean        removable,
+                                  gboolean        optical)
 {
 	TrackerStoragePrivate *priv;
 	GHashTableIter iter;
@@ -662,7 +818,12 @@ tracker_storage_get_removable_device_uuids (TrackerStorage *storage)
 		node = value;
 		info = node->data;
 
-		if (info->removable) {
+		if ((either_condition == TRUE && 
+		     (!removable || info->removable) &&
+		     (!optical || info->optical)) ||
+		    (either_condition == FALSE &&
+		     removable == info->removable &&
+		     optical == info->optical)) {
 			uuids = g_slist_prepend (uuids, g_strdup (uuid));
 		}
 	}
diff --git a/src/libtracker-miner/tracker-storage.h b/src/libtracker-miner/tracker-storage.h
index ee40e91..f65d5b6 100644
--- a/src/libtracker-miner/tracker-storage.h
+++ b/src/libtracker-miner/tracker-storage.h
@@ -43,14 +43,20 @@ struct _TrackerStorageClass {
 	GObjectClass parent_class;
 };
 
-GType           tracker_storage_get_type                   (void) G_GNUC_CONST;
-TrackerStorage *tracker_storage_new                        (void);
-GSList *        tracker_storage_get_removable_device_roots (TrackerStorage *storage);
-GSList *        tracker_storage_get_removable_device_uuids (TrackerStorage *storage);
-const gchar *   tracker_storage_get_mount_point_for_uuid   (TrackerStorage *storage,
-                                                            const gchar    *uuid);
-const gchar*    tracker_storage_get_uuid_for_file          (TrackerStorage *storage,
-                                                            GFile          *file);
+GType           tracker_storage_get_type                 (void) G_GNUC_CONST;
+TrackerStorage *tracker_storage_new                      (void);
+GSList *        tracker_storage_get_device_roots         (TrackerStorage *storage,
+                                                          gboolean        either_condition,
+                                                          gboolean        removable,
+                                                          gboolean        optical);
+GSList *        tracker_storage_get_device_uuids         (TrackerStorage *storage,
+                                                          gboolean        either_condition,
+                                                          gboolean        removable,
+                                                          gboolean        optical);
+const gchar *   tracker_storage_get_mount_point_for_uuid (TrackerStorage *storage,
+                                                          const gchar    *uuid);
+const gchar*    tracker_storage_get_uuid_for_file        (TrackerStorage *storage,
+                                                          GFile          *file);
 
 G_END_DECLS
 
diff --git a/src/tracker-extract/tracker-albumart.c b/src/tracker-extract/tracker-albumart.c
index 35cd6bd..8cf2293 100644
--- a/src/tracker-extract/tracker-albumart.c
+++ b/src/tracker-extract/tracker-albumart.c
@@ -600,7 +600,7 @@ albumart_copy_to_local (TrackerStorage *storage,
                         const gchar    *filename,
                         const gchar    *local_uri)
 {
-	GSList *removable_roots, *l;
+	GSList *roots, *l;
 	gboolean on_removable_device = FALSE;
 	guint flen;
 
@@ -613,11 +613,11 @@ albumart_copy_to_local (TrackerStorage *storage,
 		return;
 	}
 
-	removable_roots = tracker_storage_get_removable_device_roots (storage);
+	roots = tracker_storage_get_device_roots (storage, TRUE, TRUE, FALSE);
 
 	flen = strlen (filename);
 
-	for (l = removable_roots; l; l = l->next) {
+	for (l = roots; l; l = l->next) {
 		guint len;
 
 		len = strlen (l->data);
@@ -628,8 +628,8 @@ albumart_copy_to_local (TrackerStorage *storage,
 		}
 	}
 
-	g_slist_foreach (removable_roots, (GFunc) g_free, NULL);
-	g_slist_free (removable_roots);
+	g_slist_foreach (roots, (GFunc) g_free, NULL);
+	g_slist_free (roots);
 
 	if (on_removable_device) {
 		GFile *local_file, *from;
diff --git a/src/tracker-miner-fs/tracker-config.c b/src/tracker-miner-fs/tracker-config.c
index e12a2bc..6145ce0 100644
--- a/src/tracker-miner-fs/tracker-config.c
+++ b/src/tracker-miner-fs/tracker-config.c
@@ -41,12 +41,13 @@
 /* Default values */
 #define DEFAULT_VERBOSITY                        0
 #define DEFAULT_INITIAL_SLEEP                    15       /* 0->1000 */
-#define DEFAULT_ENABLE_MONITORS                          TRUE
+#define DEFAULT_ENABLE_MONITORS                  TRUE
 #define DEFAULT_THROTTLE                         0        /* 0->20 */
 #define DEFAULT_SCAN_TIMEOUT                     0        /* 0->1000 */
 #define DEFAULT_CACHE_TIMEOUT                    60       /* 0->1000 */
 #define DEFAULT_INDEX_MOUNTED_DIRECTORIES        TRUE
-#define DEFAULT_INDEX_REMOVABLE_DEVICES                  TRUE
+#define DEFAULT_INDEX_REMOVABLE_DEVICES          TRUE
+#define DEFAULT_INDEX_OPTICAL_DISCS              FALSE
 #define DEFAULT_INDEX_ON_BATTERY                 FALSE
 #define DEFAULT_INDEX_ON_BATTERY_FIRST_TIME      TRUE
 #define DEFAULT_LOW_DISK_SPACE_LIMIT             1        /* 0->100 / -1 */
@@ -67,6 +68,7 @@ typedef struct {
 	gboolean  index_on_battery_first_time;
 	gboolean  index_mounted_directories;
 	gboolean  index_removable_devices;
+	gboolean  index_optical_discs;
 	gint      low_disk_space_limit;
 	GSList   *index_recursive_directories;
 	GSList   *index_single_directories;
@@ -124,6 +126,7 @@ enum {
 	PROP_INDEX_ON_BATTERY_FIRST_TIME,
 	PROP_INDEX_MOUNTED_DIRECTORIES,
 	PROP_INDEX_REMOVABLE_DEVICES,
+	PROP_INDEX_OPTICAL_DISCS,
 	PROP_LOW_DISK_SPACE_LIMIT,
 	PROP_INDEX_RECURSIVE_DIRECTORIES,
 	PROP_INDEX_SINGLE_DIRECTORIES,
@@ -146,6 +149,7 @@ static ObjectToKeyFile conversions[] = {
 	{ G_TYPE_BOOLEAN, "index-on-battery-first-time",      GROUP_INDEXING, "IndexOnBatteryFirstTime"   },
 	{ G_TYPE_BOOLEAN, "index-mounted-directories",        GROUP_INDEXING, "IndexMountedDirectories"   },
 	{ G_TYPE_BOOLEAN, "index-removable-devices",          GROUP_INDEXING, "IndexRemovableMedia"       },
+	{ G_TYPE_BOOLEAN, "index-optical-discs",              GROUP_INDEXING, "IndexOpticalDiscs"         },
 	{ G_TYPE_INT,     "low-disk-space-limit",             GROUP_INDEXING, "LowDiskSpaceLimit"         },
 	{ G_TYPE_POINTER, "index-recursive-directories",      GROUP_INDEXING, "IndexRecursiveDirectories" },
 	{ G_TYPE_POINTER, "index-single-directories",         GROUP_INDEXING, "IndexSingleDirectories"    },
@@ -252,10 +256,19 @@ tracker_config_class_init (TrackerConfigClass *klass)
 	                                 PROP_INDEX_REMOVABLE_DEVICES,
 	                                 g_param_spec_boolean ("index-removable-devices",
 	                                                       "index removable devices",
-	                                                       " Set to true to enable traversing mounted directories for removable devices",
+	                                                       " Set to true to enable traversing mounted directories for removable devices\n"
+	                                                       " (this includes optical discs)",
 	                                                       DEFAULT_INDEX_REMOVABLE_DEVICES,
 	                                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 	g_object_class_install_property (object_class,
+	                                 PROP_INDEX_OPTICAL_DISCS,
+	                                 g_param_spec_boolean ("index-optical-discs",
+	                                                       "index optical discs",
+	                                                       " Set to true to enable traversing CDs, DVDs, and generally optical media\n"
+	                                                       " (if removable devices are not indexed, optical discs won't be either)",
+	                                                       DEFAULT_INDEX_OPTICAL_DISCS,
+	                                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+	g_object_class_install_property (object_class,
 	                                 PROP_LOW_DISK_SPACE_LIMIT,
 	                                 g_param_spec_int ("low-disk-space-limit",
 	                                                   "Low disk space limit",
@@ -367,6 +380,10 @@ config_set_property (GObject      *object,
 		tracker_config_set_index_removable_devices (TRACKER_CONFIG (object),
 		                                            g_value_get_boolean (value));
 		break;
+	case PROP_INDEX_OPTICAL_DISCS:
+		tracker_config_set_index_optical_discs (TRACKER_CONFIG (object),
+		                                        g_value_get_boolean (value));
+		break;
 	case PROP_LOW_DISK_SPACE_LIMIT:
 		tracker_config_set_low_disk_space_limit (TRACKER_CONFIG (object),
 		                                         g_value_get_int (value));
@@ -444,6 +461,9 @@ config_get_property (GObject    *object,
 	case PROP_INDEX_REMOVABLE_DEVICES:
 		g_value_set_boolean (value, priv->index_removable_devices);
 		break;
+	case PROP_INDEX_OPTICAL_DISCS:
+		g_value_set_boolean (value, priv->index_optical_discs);
+		break;
 	case PROP_LOW_DISK_SPACE_LIMIT:
 		g_value_set_int (value, priv->low_disk_space_limit);
 		break;
@@ -1173,6 +1193,18 @@ tracker_config_get_index_removable_devices (TrackerConfig *config)
 	return priv->index_removable_devices;
 }
 
+gboolean
+tracker_config_get_index_optical_discs (TrackerConfig *config)
+{
+	TrackerConfigPrivate *priv;
+
+	g_return_val_if_fail (TRACKER_IS_CONFIG (config), DEFAULT_INDEX_OPTICAL_DISCS);
+
+	priv = TRACKER_CONFIG_GET_PRIVATE (config);
+
+	return priv->index_optical_discs;
+}
+
 gint
 tracker_config_get_low_disk_space_limit (TrackerConfig *config)
 {
@@ -1406,6 +1438,20 @@ tracker_config_set_index_removable_devices (TrackerConfig *config,
 }
 
 void
+tracker_config_set_index_optical_discs (TrackerConfig *config,
+                                        gboolean       value)
+{
+	TrackerConfigPrivate *priv;
+
+	g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+	priv = TRACKER_CONFIG_GET_PRIVATE (config);
+
+	priv->index_optical_discs = value;
+	g_object_notify (G_OBJECT (config), "index-optical-discs");
+}
+
+void
 tracker_config_set_low_disk_space_limit (TrackerConfig *config,
                                          gint           value)
 {
diff --git a/src/tracker-miner-fs/tracker-config.h b/src/tracker-miner-fs/tracker-config.h
index 1876324..ca6acde 100644
--- a/src/tracker-miner-fs/tracker-config.h
+++ b/src/tracker-miner-fs/tracker-config.h
@@ -60,6 +60,7 @@ gint           tracker_config_get_throttle                         (TrackerConfi
 gboolean       tracker_config_get_index_on_battery                 (TrackerConfig *config);
 gboolean       tracker_config_get_index_on_battery_first_time      (TrackerConfig *config);
 gboolean       tracker_config_get_index_removable_devices          (TrackerConfig *config);
+gboolean       tracker_config_get_index_optical_discs              (TrackerConfig *config);
 gboolean       tracker_config_get_index_mounted_directories        (TrackerConfig *config);
 gint           tracker_config_get_low_disk_space_limit             (TrackerConfig *config);
 GSList *       tracker_config_get_index_recursive_directories      (TrackerConfig *config);
@@ -86,6 +87,8 @@ void           tracker_config_set_index_on_battery_first_time      (TrackerConfi
                                                                     gboolean       value);
 void           tracker_config_set_index_removable_devices          (TrackerConfig *config,
                                                                     gboolean       value);
+void           tracker_config_set_index_optical_discs              (TrackerConfig *config,
+                                                                    gboolean       value);
 void           tracker_config_set_index_mounted_directories        (TrackerConfig *config,
                                                                     gboolean       value);
 void           tracker_config_set_low_disk_space_limit             (TrackerConfig *config,
diff --git a/src/tracker-miner-fs/tracker-miner-files.c b/src/tracker-miner-fs/tracker-miner-files.c
index 6993f6f..9c3211b 100644
--- a/src/tracker-miner-fs/tracker-miner-files.c
+++ b/src/tracker-miner-fs/tracker-miner-files.c
@@ -108,6 +108,8 @@ static void        mount_pre_unmount_cb                 (GVolumeMonitor       *v
 static void        mount_point_added_cb                 (TrackerStorage       *storage,
                                                          const gchar          *uuid,
                                                          const gchar          *mount_point,
+                                                         gboolean              removable,
+                                                         gboolean              optical,
                                                          gpointer              user_data);
 static void        mount_point_removed_cb               (TrackerStorage       *storage,
                                                          const gchar          *uuid,
@@ -323,6 +325,7 @@ miner_files_constructed (GObject *object)
 	GSList *dirs;
 	GSList *mounts = NULL, *m;
 	gboolean index_removable_devices;
+	gboolean index_optical_discs;
 
 	G_OBJECT_CLASS (tracker_miner_files_parent_class)->constructed (object);
 
@@ -335,10 +338,12 @@ miner_files_constructed (GObject *object)
 	}
 
 	index_removable_devices = tracker_config_get_index_removable_devices (mf->private->config);
+	index_optical_discs = tracker_config_get_index_optical_discs (mf->private->config);
 
-	if (index_removable_devices) {
-		mounts = tracker_storage_get_removable_device_roots (mf->private->storage);
-	}
+	mounts = tracker_storage_get_device_roots (mf->private->storage, 
+	                                           FALSE, 
+	                                           index_removable_devices, 
+	                                           index_optical_discs);
 
 #if defined(HAVE_DEVKIT_POWER) || defined(HAVE_HAL)
 	check_battery_status (mf);
@@ -441,10 +446,15 @@ miner_files_constructed (GObject *object)
 		g_object_unref (file);
 	}
 
-	/* Add removable media */
-	g_message ("Setting up directories to iterate which are removable devices");
+	/* Add mounts */
+	g_message ("Setting up directories to iterate from devices/discs");
+
 	if (!index_removable_devices) {
-		g_message ("  Disabled in the config");
+		g_message ("  Removable devices are disabled in the config");
+	}
+
+	if (!index_optical_discs) {
+		g_message ("  Optical discs are disabled in the config");
 	}
 
 	for (m = mounts; m; m = m->next) {
@@ -466,6 +476,8 @@ miner_files_constructed (GObject *object)
 		g_object_unref (file);
 	}
 
+	/* Add optical media */
+
 	g_signal_connect (mf->private->config, "notify::low-disk-space-limit",
 	                  G_CALLBACK (low_disk_space_limit_cb),
 	                  mf);
@@ -665,9 +677,12 @@ query_mount_points_cb (GObject      *source,
 	g_hash_table_replace (volumes, g_strdup (TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN),
 	                      GINT_TO_POINTER (VOLUME_MOUNTED));
 
-	uuids = tracker_storage_get_removable_device_uuids (priv->storage);
+	uuids = tracker_storage_get_device_uuids (priv->storage, 
+	                                          TRUE, 
+	                                          TRUE,
+	                                          FALSE);
 
-	/* Then, get all currently mounted volumes, according to HAL */
+	/* Then, get all currently mounted volumes, according to GIO */
 	for (u = uuids; u; u = u->next) {
 		const gchar *uuid;
 		gchar *removable_device_urn;
@@ -768,22 +783,38 @@ static void
 mount_point_added_cb (TrackerStorage *storage,
                       const gchar    *uuid,
                       const gchar    *mount_point,
+                      gboolean        removable,
+                      gboolean        optical,
                       gpointer        user_data)
 {
 	TrackerMinerFiles *miner = user_data;
 	TrackerMinerFilesPrivate *priv;
+	GFile *file;
 	gchar *urn;
 	gboolean index_removable_devices;
+	gboolean index_optical_discs;
+	gboolean should_crawl;
 
 	priv = TRACKER_MINER_FILES_GET_PRIVATE (miner);
 
 	index_removable_devices = tracker_config_get_index_removable_devices (priv->config);
+	index_optical_discs = tracker_config_get_index_optical_discs (priv->config);
 
 	g_message ("Added mount point '%s'", mount_point);
 
-	if (index_removable_devices) {
-		GFile *file;
+	should_crawl = TRUE;	
 
+	if (removable && !tracker_config_get_index_removable_devices (priv->config)) {
+		g_message ("  Not crawling, removable devices disabled in config");
+		should_crawl = FALSE;
+	}
+
+	if (optical && !tracker_config_get_index_optical_discs (priv->config)) {
+		g_message ("  Not crawling, optical devices discs disabled in config");
+		should_crawl = FALSE;
+	}
+
+	if (should_crawl) {
 		g_message ("  Adding directory to crawler's queue");
 
 		file = g_file_new_for_path (mount_point);
@@ -800,8 +831,6 @@ mount_point_added_cb (TrackerStorage *storage,
 		                                file,
 		                                TRUE);
 		g_object_unref (file);
-	} else {
-		g_message ("  Not crawling, removable devices disabled in config");
 	}
 
 	urn = g_strdup_printf (TRACKER_DATASOURCE_URN_PREFIX "%s", uuid);
diff --git a/src/tracker-preferences/tracker-config.vapi b/src/tracker-preferences/tracker-config.vapi
index 38cef39..6ef6eca 100644
--- a/src/tracker-preferences/tracker-config.vapi
+++ b/src/tracker-preferences/tracker-config.vapi
@@ -34,6 +34,7 @@ namespace Tracker {
 		public bool index_on_battery { get; set; }
 		public bool index_on_battery_first_time { get; set; }
 		public bool index_removable_devices { get; set; }
+		public bool index_optical_discs { get; set; }
 		public bool index_mounted_directories { get; set; }
 		public int low_disk_space_limit { get; set; }
 		public GLib.SList<string> index_recursive_directories { get; set; }
diff --git a/src/tracker-preferences/tracker-preferences.ui b/src/tracker-preferences/tracker-preferences.ui
index 2eb5fd6..1b814e3 100644
--- a/src/tracker-preferences/tracker-preferences.ui
+++ b/src/tracker-preferences/tracker-preferences.ui
@@ -292,7 +292,7 @@
                               <packing>
                                 <property name="expand">False</property>
                                 <property name="fill">False</property>
-                                <property name="position">2</property>
+                                <property name="position">1</property>
                               </packing>
                             </child>
                             <child>
@@ -314,7 +314,7 @@
                               </object>
                               <packing>
                                 <property name="expand">False</property>
-                                <property name="position">3</property>
+                                <property name="position">2</property>
                               </packing>
                             </child>
                             <child>
@@ -331,7 +331,7 @@
                               <packing>
                                 <property name="expand">False</property>
                                 <property name="fill">False</property>
-                                <property name="position">4</property>
+                                <property name="position">3</property>
                               </packing>
                             </child>
                             <child>
@@ -340,6 +340,7 @@
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
+                                <property name="tooltip_text" translatable="yes">This covers ALL removable media, memory cards, CDs, DVDs, etc.</property>
                                 <property name="use_underline">True</property>
                                 <property name="active">True</property>
                                 <property name="draw_indicator">True</property>
@@ -348,6 +349,27 @@
                               <packing>
                                 <property name="expand">False</property>
                                 <property name="fill">False</property>
+                                <property name="position">4</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkAlignment" id="alignment8">
+                                <property name="visible">True</property>
+                                <property name="left_padding">12</property>
+                                <child>
+                                  <object class="GtkCheckButton" id="checkbutton_index_optical_discs">
+                                    <property name="label" translatable="yes">Include optical di_scs</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="active">True</property>
+                                    <property name="draw_indicator">True</property>
+                                    <signal name="toggled" handler="checkbutton_index_optical_discs_toggled_cb"/>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
                                 <property name="position">5</property>
                               </packing>
                             </child>
diff --git a/src/tracker-preferences/tracker-preferences.vala b/src/tracker-preferences/tracker-preferences.vala
index 5f9dfb0..7b44f8a 100644
--- a/src/tracker-preferences/tracker-preferences.vala
+++ b/src/tracker-preferences/tracker-preferences.vala
@@ -36,6 +36,7 @@ public static SpinButton spinbutton_delay;
 public static CheckButton checkbutton_enable_monitoring;
 public static CheckButton checkbutton_index_mounted_directories;
 public static CheckButton checkbutton_index_removable_media;
+public static CheckButton checkbutton_index_optical_discs;
 public static Scale hscale_disk_space_limit;
 public static Scale hscale_throttle;
 public static ListStore liststore_index_recursively;
@@ -96,6 +97,11 @@ public static void checkbutton_index_mounted_directories_toggled_cb (CheckButton
 
 public static void checkbutton_index_removable_media_toggled_cb (CheckButton source) {
 	config.index_removable_devices = source.active;
+	checkbutton_index_optical_discs.set_sensitive (source.active);
+}
+
+public static void checkbutton_index_optical_discs_toggled_cb (CheckButton source) {
+	config.index_optical_discs = source.active;
 }
 
 public static string hscale_disk_space_limit_format_value_cb (Scale source, double value) {
@@ -347,6 +353,9 @@ static int main (string[] args) {
 		checkbutton_index_mounted_directories.active = config.index_mounted_directories;
 		checkbutton_index_removable_media = builder.get_object ("checkbutton_index_removable_media") as CheckButton;
 		checkbutton_index_removable_media.active = config.index_removable_devices;
+		checkbutton_index_optical_discs = builder.get_object ("checkbutton_index_optical_discs") as CheckButton;
+		checkbutton_index_optical_discs.set_sensitive (checkbutton_index_removable_media.active);
+		checkbutton_index_optical_discs.active = config.index_optical_discs;
 		hscale_disk_space_limit = builder.get_object ("hscale_disk_space_limit") as Scale;
 		hscale_disk_space_limit.set_value ((double) config.low_disk_space_limit);
 		hscale_throttle = builder.get_object ("hscale_throttle") as Scale;



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