changeset 1929:6d8d5ea87cc2

simplified grouping of sidecars
author Vladimir Nadvornik <nadvornik@suse.cz>
date Sat, 01 Oct 2011 16:31:58 +0200
parents 51d96f795ecc
children f96b5dfa3ec2
files src/filedata.c
diffstat 1 files changed, 18 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/filedata.c	Fri Sep 30 23:57:31 2011 +0200
+++ b/src/filedata.c	Sat Oct 01 16:31:58 2011 +0200
@@ -138,7 +138,7 @@
  */
 
 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source);
-static void file_data_check_sidecars(FileData *fd, GHashTable *basename_hash);
+static void file_data_check_sidecars(const GList *basename_list);
 FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd);
 
 
@@ -166,7 +166,7 @@
 	return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 }
 
-static void file_data_basename_hash_insert(GHashTable *basename_hash, FileData *fd)
+static GList * file_data_basename_hash_insert(GHashTable *basename_hash, FileData *fd)
 {
 	GList *list;
     	const gchar *ext = extension_from_path(fd->path);
@@ -183,6 +183,7 @@
 		{
 		g_free(basename);
 		}
+	return list;
 }
 
 #if 0
@@ -370,7 +371,7 @@
 		
 			file_data_disconnect_sidecar_file(fd, sfd);
 			}
-		if (sfd) file_data_check_sidecars(sfd, NULL); /* this will group the sidecars back together */
+		file_data_check_sidecars(sidecars); /* this will group the sidecars back together */
 		/* now we can release the sidecars */
 		filelist_free(sidecars);
 		file_data_send_notification(fd, NOTIFY_REREAD);
@@ -417,19 +418,18 @@
 		
 		if (disable_sidecars) file_data_disable_grouping(fd, TRUE);
 		
-		if (basename_hash) 
-			{
-			file_data_basename_hash_insert(basename_hash, fd);
-			if (!disable_sidecars)
-				file_data_check_sidecars(fd, basename_hash);
-			}
 		
 		if (fd->parent)
 			changed = file_data_check_changed_files(fd);
 		else
 			changed = file_data_check_changed_files_recursive(fd, st);
-		if (changed && !disable_sidecars && sidecar_file_priority(fd->extension))
-			file_data_check_sidecars(fd, basename_hash);
+
+		if (basename_hash) 
+			{
+			GList *list = file_data_basename_hash_insert(basename_hash, fd);
+			if (!disable_sidecars)
+				file_data_check_sidecars(list);
+			}
 		DEBUG_2("file_data_pool hit: '%s' %s", fd->path, changed ? "(changed)" : "");
 		
 		return fd;
@@ -446,34 +446,22 @@
 	if (disable_sidecars) fd->disable_grouping = TRUE;
 
 	file_data_set_path(fd, path_utf8); /* set path, name, collate_key_*, original_path */
-	if (basename_hash) file_data_basename_hash_insert(basename_hash, fd);
-
-	if (!disable_sidecars)
+
+	if (!disable_sidecars && !fd->disable_grouping && sidecar_file_priority(fd->extension))
 		{
-		g_assert(basename_hash);
-		file_data_check_sidecars(fd, basename_hash);
+		GList *list = file_data_basename_hash_insert(basename_hash, fd);
+		file_data_check_sidecars(list);
 		}
 
 	return fd;
 }
 
 
-static void file_data_check_sidecars(FileData *fd, GHashTable *basename_hash)
+static void file_data_check_sidecars(const GList *basename_list)
 {
-	gint base_len;
-	GString *fname;
 	FileData *parent_fd = NULL;
 	GList *work;
-	const GList *basename_list = NULL;
 	GList *group_list = NULL;
-	if (fd->disable_grouping || !sidecar_file_priority(fd->extension))
-		return;
-
-	base_len = fd->extension - fd->path;
-	fname = g_string_new_len(fd->path, base_len);
-
-	basename_list = g_hash_table_lookup(basename_hash, fname->str);
-
 
 	/* check for possible sidecar files;
 	   the sidecar files created here are referenced only via fd->sidecar_files or fd->parent,
@@ -504,7 +492,6 @@
 			work2 = work2->next;
 			}
 		}
-	g_string_free(fname, TRUE);
 
 	/* process the group list - the first one is the parent file, others are sidecars */
 	work = group_list;
@@ -713,7 +700,7 @@
 				file_data_disconnect_sidecar_file(fd, sfd);
 				file_data_send_notification(sfd, NOTIFY_GROUPING);
 				}
-			file_data_check_sidecars((FileData *)sidecar_files->data, FALSE); /* this will group the sidecars back together */
+			file_data_check_sidecars(sidecar_files); /* this will group the sidecars back together */
 			filelist_free(sidecar_files);
 			}
 		else
@@ -724,7 +711,7 @@
 	else
 		{
 		file_data_increment_version(fd);
-		file_data_check_sidecars(fd, FALSE);
+		/* file_data_check_sidecars call is not necessary - the file will be re-grouped on next dir read */
 		}
 	file_data_send_notification(fd, NOTIFY_GROUPING);
 }