changeset 167:05bf5d364dba

fixed filelist refresh
author nadvornik
date Sat, 22 Dec 2007 20:33:09 +0000
parents 4d14387b7bb7
children a55ada12322a
files src/filelist.c src/filelist.h src/view_file_icon.c src/view_file_list.c
diffstat 4 files changed, 155 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/src/filelist.c	Sat Dec 22 10:10:40 2007 +0000
+++ b/src/filelist.c	Sat Dec 22 20:33:09 2007 +0000
@@ -628,6 +628,8 @@
  */
 
 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source);
+static void file_data_check_sidecars(FileData *fd);
+FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd);
 
 
 static void file_data_set_path(FileData *fd, const gchar *path)
@@ -668,8 +670,9 @@
 		fd->extension = fd->name + strlen(fd->name);
 }
 
-static void file_data_check_update(FileData *fd, struct stat *st)
+static void file_data_check_changed_files(FileData *fd, struct stat *st)
 {
+	GList *work;
 	if (fd->size != st->st_size ||
 	    fd->date != st->st_mtime)
 		{
@@ -678,9 +681,23 @@
 		if (fd->pixbuf) g_object_unref(fd->pixbuf);
 		fd->pixbuf = NULL;
 		}
+
+	work = fd->sidecar_files;
+	while (work)
+		{
+		FileData *sfd = work->data;
+		struct stat st;
+
+		if (!stat_utf8(sfd->path, &st))
+			{
+			file_data_disconnect_sidecar_file(fd, sfd);
+			}
+			
+		file_data_check_changed_files(sfd, &st);
+		work = work->next;
+		}
 }
 
-static void file_data_check_sidecars(FileData *fd);
 static GHashTable *file_data_pool = NULL;
 
 static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean check_sidecars)
@@ -695,7 +712,7 @@
 	fd = g_hash_table_lookup(file_data_pool, path_utf8);
 	if (fd)
 		{
-		file_data_check_update(fd, st);
+		file_data_check_changed_files(fd, st);
 		printf("file_data_pool hit: '%s'\n", fd->path);
 		return file_data_ref(fd);
 		}
@@ -794,6 +811,7 @@
 	return target;
 }
 
+
 FileData *file_data_merge_sidecar_files(FileData *target, FileData *source)
 {
 	GList *work;
@@ -809,10 +827,13 @@
 
 	g_list_free(source->sidecar_files);
 	source->sidecar_files = NULL;
-	
+
+	target->sidecar_files = filelist_sort(target->sidecar_files, SORT_NAME, TRUE); 	
 	return target;
 }
 
+
+
 FileData *file_data_ref(FileData *fd)
 {
 	if (fd == NULL) return NULL;
@@ -885,6 +906,22 @@
 		}
 }
 
+FileData *file_data_disconnect_sidecar_file(FileData *target, FileData *sfd)
+{
+	sfd->parent = target;
+	g_assert(g_list_find(target->sidecar_files, sfd));
+
+	target->sidecar_files = g_list_remove(target->sidecar_files, sfd);
+	sfd->parent = NULL;
+
+	if (sfd->ref == 0) {
+		file_data_free(sfd);
+		return NULL;
+	}
+
+	return sfd;
+}
+
 /* compare name without extension */
 gint file_data_compare_name_without_ext(FileData *fd1, FileData *fd2)
 {
@@ -1022,12 +1059,12 @@
 		case SORT_SIZE:
 			if (fa->size < fb->size) return -1;
 			if (fa->size > fb->size) return 1;
-			return 0;
+			return CASE_SORT(fa->name, fb->name); /* fall back to name */
 			break;
 		case SORT_TIME:
 			if (fa->date < fb->date) return -1;
 			if (fa->date > fb->date) return 1;
-			return 0;
+			return CASE_SORT(fa->name, fb->name); /* fall back to name */
 			break;
 #ifdef HAVE_STRVERSCMP
 		case SORT_NUMBER:
@@ -1041,6 +1078,13 @@
 		}
 }
 
+gint filelist_sort_compare_filedata_full(FileData *fa, FileData *fb, SortType method, gint ascend)
+{
+	filelist_sort_method = method;
+	filelist_sort_ascend = ascend;
+	return filelist_sort_compare_filedata(fa, fb);
+}
+
 static gint filelist_sort_file_cb(void *a, void *b)
 {
 	return filelist_sort_compare_filedata(a, b);
--- a/src/filelist.h	Sat Dec 22 10:10:40 2007 +0000
+++ b/src/filelist.h	Sat Dec 22 20:33:09 2007 +0000
@@ -67,6 +67,7 @@
 gchar *sidecar_file_data_list_to_string(FileData *fd);
 
 gint filelist_sort_compare_filedata(FileData *fa, FileData *fb);
+gint filelist_sort_compare_filedata_full(FileData *fa, FileData *fb, SortType method, gint ascend);
 GList *filelist_sort(GList *list, SortType method, gint ascend);
 GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gint ascend);
 GList *filelist_sort_full(GList *list, SortType method, gint ascend, GCompareFunc cb);
--- a/src/view_file_icon.c	Sat Dec 22 10:10:40 2007 +0000
+++ b/src/view_file_icon.c	Sat Dec 22 20:33:09 2007 +0000
@@ -2184,22 +2184,12 @@
 			{
 			IconData *idn = needle->data;
 			FileData *fdn = idn->fd;
-			if (strcmp(fd->name, fdn->name) == 0)
+			if (fdn == fd)
 				{
 				/* swap, to retain old thumb, selection */
 				needle->data = id;
 				work->data = idn;
 				needle = NULL;
-
-				if (fd->date != fdn->date || fd->size != fdn->size)
-					{
-					/* file changed, update */
-					/* FIXME
-					fd->date = fdn->date;
-					fd->size = fdn->size;
-					vficon_set_thumb(vfi, fd, NULL);
-					*/
-					}
 				}
 			else
 				{
--- a/src/view_file_list.c	Sat Dec 22 10:10:40 2007 +0000
+++ b/src/view_file_list.c	Sat Dec 22 20:33:09 2007 +0000
@@ -867,26 +867,16 @@
 }
 
 
-
-void vflist_setup_iter(ViewFileList *vfl, GtkTreeStore *store, GtkTreeIter *iter, FileData *fd, GtkTreeIter *before)
+void vflist_setup_iter(ViewFileList *vfl, GtkTreeStore *store, GtkTreeIter *iter, FileData *fd)
 {
+	int i;
 	gchar *size;
-	gchar *sidecars;
-	int i;
-	GList *work;
-    		
-	sidecars = sidecar_file_data_list_to_string(fd);
+	gchar *sidecars = NULL;
+
+	if (fd->sidecar_files)
+		sidecars = sidecar_file_data_list_to_string(fd);
 	size = text_from_size(fd->size);
 	
-	if (before)
-		{
-		gtk_tree_store_insert_before(store, iter, NULL, before);
-		}
-		else
-		{
-		gtk_tree_store_append(store, iter, NULL);
-		}
-	
 	gtk_tree_store_set(store, iter, FILE_COLUMN_POINTER, fd,
 					FILE_COLUMN_THUMB, (vfl->thumbs_enabled) ? fd->pixbuf : NULL,
 					FILE_COLUMN_NAME, fd->name,
@@ -898,28 +888,93 @@
 		gtk_tree_store_set(store, iter, FILE_COLUMN_MARKS + i, fd->marks[i], -1);
             
 	g_free(size);
-	g_free(sidecars);
+	if (sidecars)
+		g_free(sidecars);
+}
 
+void vflist_setup_iter_with_sidecars(ViewFileList *vfl, GtkTreeStore *store, GtkTreeIter *iter, FileData *fd)
+{
+	GList *work;
+	GtkTreeIter new;
+	GtkTreeIter s_iter;
+	gint valid;
+
+    	vflist_setup_iter(vfl, store, iter, fd);
+
+
+	/* this is almost the same code as in vflist_populate_view 
+	   maybe it should be made more generic and used in both places */
+	
+	
+	valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(store), &s_iter, iter);
 
 	work = fd->sidecar_files;
 	while (work)
 		{
-		GtkTreeIter s_iter;
-		
+		gint match;
 		FileData *sfd = work->data;
-		work = work->next;
+		gint done = FALSE;
+
+		while (!done)
+			{
+			FileData *old_sfd = NULL;
+            
+			if (valid)
+				{
+				gtk_tree_model_get(GTK_TREE_MODEL(store), &s_iter, FILE_COLUMN_POINTER, &old_sfd, -1);
+				
+				if (sfd == old_sfd)
+					{
+					match = 0;
+					}
+				else
+					{
+					match = filelist_sort_compare_filedata_full(sfd, old_sfd, SORT_NAME, TRUE);
+					}
+				}
+					
+			else
+				{
+				match = -1;
+				}
 
-		size = text_from_size(sfd->size);
-		gtk_tree_store_append(store, &s_iter, iter);
-		gtk_tree_store_set(store, &s_iter, 
-					FILE_COLUMN_POINTER, sfd,
-					FILE_COLUMN_NAME, sfd->name,
-					FILE_COLUMN_SIZE, size,
-					FILE_COLUMN_DATE, text_from_time(sfd->date),
-					-1);
-		g_free(size);
+			if (match < 0)
+				{
+				GtkTreeIter new;
+				
+				if (valid)
+					{
+					gtk_tree_store_insert_before(store, &new, iter, &s_iter);
+					}
+				else
+					{
+					gtk_tree_store_append(store, &new, iter);
+					}
+				
+				vflist_setup_iter(vfl, store, &new, sfd);
+
+				done = TRUE;
+				}
+			else if (match > 0)
+				{
+				valid = gtk_tree_store_remove(store, &s_iter);
+				}
+			else
+				{
+				vflist_setup_iter(vfl, store, &s_iter, sfd);
+
+				if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &s_iter);
+
+				done = TRUE;
+				}
+			}
+		work = work->next;
 		}
-	
+
+	while (valid)
+		{
+		valid = gtk_tree_store_remove(store, &s_iter);
+		}
 }
 
 
@@ -1008,7 +1063,8 @@
 		{
 		FileData *fd = work->data;
 		
-		vflist_setup_iter(vfl, store, &iter, fd, NULL);
+		gtk_tree_store_append(store, &iter, NULL);
+		vflist_setup_iter_with_sidecars(vfl, store, &iter, fd);
 
 		if (select_list && select_list->data == fd)
 			{
@@ -1627,13 +1683,23 @@
 		while (!done)
 			{
 			FileData *old_fd = NULL;
-            int i;
             
 			if (valid)
 				{
 				gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &old_fd, -1);
-				match = CASE_SORT(fd->name, old_fd->name);
+				
+				if (fd == old_fd)
+					{
+					match = 0;
+					}
+				else
+					{
+					match = filelist_sort_compare_filedata_full(fd, old_fd, vfl->sort_method, vfl->sort_ascend);
+					if (match == 0)
+						match = -1; /* probably should not happen*/
+					}
 				}
+					
 			else
 				{
 				match = -1;
@@ -1645,12 +1711,13 @@
 				
 				if (valid)
 					{
-					vflist_setup_iter(vfl, store, &new, fd, &iter); 
+					gtk_tree_store_insert_before(store, &new, NULL, &iter);
 					}
 				else
 					{
-					vflist_setup_iter(vfl, store, &new, fd, NULL);
+					gtk_tree_store_append(store, &new, NULL);
 					}
+				vflist_setup_iter_with_sidecars(vfl, store, &new, fd);
 
 				done = TRUE;
 				}
@@ -1660,28 +1727,7 @@
 				}
 			else
 				{
-				gtk_tree_store_set(store, &iter, FILE_COLUMN_POINTER, fd, -1);
-				if (fd->date != old_fd->date)
-					{
-					gchar *size;
-
-					/* update, file changed */
-					size = text_from_size(fd->size);
-					gtk_tree_store_set(store, &iter, FILE_COLUMN_SIZE, size,
-									 FILE_COLUMN_DATE, text_from_time(fd->date), -1);
-					g_free(size);
-					}
-				else if (fd != old_fd)
-					{
-					/* preserve thumbnail */
-					if (fd->pixbuf) g_object_unref(fd->pixbuf);
-					fd->pixbuf = old_fd->pixbuf;
-					if (fd->pixbuf) g_object_ref(fd->pixbuf);
-					}
-
-				gtk_tree_store_set(store, &iter, FILE_COLUMN_THUMB, (thumbs) ? fd->pixbuf : NULL, -1);
-
-				if (vfl->select_fd == old_fd) vfl->select_fd = fd;
+				vflist_setup_iter_with_sidecars(vfl, store, &iter, fd);
 
 				if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);