changeset 799:278962ba162a

use the new notification for collections
author nadvornik
date Sat, 07 Jun 2008 10:45:33 +0000
parents 5055b5b0d75d
children a25b228978a0
files src/collect-io.c src/collect-io.h src/collect.c src/collect.h src/main.c src/utilops.c
diffstat 6 files changed, 54 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/src/collect-io.c	Sat Jun 07 10:18:30 2008 +0000
+++ b/src/collect-io.c	Sat Jun 07 10:45:33 2008 +0000
@@ -888,7 +888,7 @@
 	cw = collection_window_find_by_path(collection);
 	if (cw)
 		{
-		if (collection_list_find(cw->cd->list, fd->path) == NULL)
+		if (collection_list_find_fd(cw->cd->list, fd) == NULL)
 			{
 			collection_add(cw->cd, fd, FALSE);
 			}
@@ -924,3 +924,26 @@
 	DEBUG_1("collection manager flushing");
 	while (collect_manager_process_cb(NULL));
 }
+
+void collect_manager_notify_cb(FileData *fd, NotifyType type, gpointer data)
+{
+
+	if (!fd->change) return;
+	
+	switch(fd->change->type)
+		{
+		case FILEDATA_CHANGE_MOVE:
+			collect_manager_moved(fd);
+			break;
+		case FILEDATA_CHANGE_COPY:
+			break;
+		case FILEDATA_CHANGE_RENAME:
+			collect_manager_moved(fd);
+			break;
+		case FILEDATA_CHANGE_DELETE:
+			break;
+		case FILEDATA_CHANGE_UNSPECIFIED:
+			break;
+		}
+
+}
--- a/src/collect-io.h	Sat Jun 07 10:18:30 2008 +0000
+++ b/src/collect-io.h	Sat Jun 07 10:45:33 2008 +0000
@@ -48,6 +48,7 @@
 /* commit pending operations to disk */
 void collect_manager_flush(void);
 
+void collect_manager_notify_cb(FileData *fd, NotifyType type, gpointer data);
 
 
 #endif
--- a/src/collect.c	Sat Jun 07 10:18:30 2008 +0000
+++ b/src/collect.c	Sat Jun 07 10:45:33 2008 +0000
@@ -49,6 +49,8 @@
 
 static void collection_window_close(CollectWindow *cw);
 
+static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data);
+
 /*
  *-------------------------------------------------------------------
  * data, list handling
@@ -214,14 +216,14 @@
 	return list;
 }
 
-CollectInfo *collection_list_find(GList *list, const gchar *path)
+CollectInfo *collection_list_find_fd(GList *list, FileData *fd)
 {
 	GList *work = list;
 
 	while (work)
 		{
 		CollectInfo *ci = work->data;
-		if (strcmp(ci->fd->path, path) == 0) return ci;
+		if (ci->fd == fd) return ci;
 		work = work->next;
 		}
 
@@ -362,6 +364,8 @@
 		untitled_counter++;
 		}
 
+	file_data_register_notify_func(collection_notify_cb, cd, NOTIFY_PRIORITY_MEDIUM);
+
 	return cd;
 }
 
@@ -373,6 +377,8 @@
 
 	collection_load_stop(cd);
 	collection_list_free(cd->list);
+	
+	file_data_unregister_notify_func(collection_notify_cb, cd);
 
 	collection_list = g_list_remove(collection_list, cd);
 
@@ -681,7 +687,7 @@
 {
 	CollectInfo *ci;
 
-	ci = collection_list_find(cd->list, fd->path);
+	ci = collection_list_find_fd(cd->list, fd);
 
 	if (!ci) return FALSE;
 
@@ -734,14 +740,10 @@
 gint collection_rename(CollectionData *cd, FileData *fd)
 {
 	CollectInfo *ci;
-	const gchar *source = fd->change->source;
-//	const gchar *dest = fd->change->dest;
-	ci = collection_list_find(cd->list, source);
+	ci = collection_list_find_fd(cd->list, fd);
 
 	if (!ci) return FALSE;
 
-//	g_free(ci->path);
-//	ci->path = g_strdup(dest); FIXME
 	cd->changed = TRUE;
 
 	collection_window_update(collection_window_find(cd), ci);
@@ -760,41 +762,29 @@
  *-------------------------------------------------------------------
  */
 
-void collection_maint_removed(FileData *fd)
+static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data)
 {
-	GList *work;
+	CollectionData *cd = data;
 
-	work = collection_list;
-	while (work)
+	if (!fd->change) return;
+	
+	switch(fd->change->type)
 		{
-		CollectionData *cd = work->data;
-		work = work->next;
-
-		while (collection_remove(cd, fd));
+		case FILEDATA_CHANGE_MOVE:
+		case FILEDATA_CHANGE_RENAME:
+			collection_rename(cd, fd);
+			break;
+		case FILEDATA_CHANGE_COPY:
+			break;
+		case FILEDATA_CHANGE_DELETE:
+			while (collection_remove(cd, fd));
+			break;
+		case FILEDATA_CHANGE_UNSPECIFIED:
+			break;
 		}
-#if 0
-	/* Do we really need to do this? removed files are
-	 * automatically ignored when loading a collection.
-	 */
-	collect_manager_moved(fd, NULL);
-#endif
+
 }
 
-void collection_maint_renamed(FileData *fd)
-{
-	GList *work;
-
-	work = collection_list;
-	while (work)
-		{
-		CollectionData *cd = work->data;
-		work = work->next;
-
-		while (collection_rename(cd, fd));
-		}
-
-	collect_manager_moved(fd);
-}
 
 /*
  *-------------------------------------------------------------------
--- a/src/collect.h	Sat Jun 07 10:18:30 2008 +0000
+++ b/src/collect.h	Sat Jun 07 10:45:33 2008 +0000
@@ -29,7 +29,7 @@
 GList *collection_list_add(GList *list, CollectInfo *ci, SortType method);
 GList *collection_list_insert(GList *list, CollectInfo *ci, CollectInfo *insert_ci, SortType method);
 GList *collection_list_remove(GList *list, CollectInfo *ci);
-CollectInfo *collection_list_find(GList *list, const gchar *path);
+CollectInfo *collection_list_find_fd(GList *list, FileData *fd);
 GList *collection_list_to_filelist(GList *list);
 
 CollectionData *collection_new(const gchar *path);
@@ -71,9 +71,6 @@
 
 void collection_update_geometry(CollectionData *cd);
 
-void collection_maint_removed(FileData *fd);
-void collection_maint_renamed(FileData *fd);
-
 CollectWindow *collection_window_new(const gchar *path);
 void collection_window_close_by_collection(CollectionData *cd);
 CollectWindow *collection_window_find(CollectionData *cd);
--- a/src/main.c	Sat Jun 07 10:18:30 2008 +0000
+++ b/src/main.c	Sat Jun 07 10:45:33 2008 +0000
@@ -683,6 +683,7 @@
 
 	/* register global notify functions */
 	file_data_register_notify_func(cache_notify_cb, NULL, NOTIFY_PRIORITY_HIGH);
+	file_data_register_notify_func(collect_manager_notify_cb, NULL, NOTIFY_PRIORITY_LOW);
 
 	parse_command_line_for_debug_option(argc, argv);
 
--- a/src/utilops.c	Sat Jun 07 10:18:30 2008 +0000
+++ b/src/utilops.c	Sat Jun 07 10:45:33 2008 +0000
@@ -239,28 +239,6 @@
 /* FIXME this is a temporary solution */
 void file_data_notify_ci(FileData *fd)
 {
-	FileDataChangeType type = fd->change->type;
-	switch (type)
-		{
-		case FILEDATA_CHANGE_MOVE:
-			collection_maint_renamed(fd);
-
-			break;
-		case FILEDATA_CHANGE_COPY:
-			break;
-		case FILEDATA_CHANGE_RENAME:
-			collection_maint_renamed(fd);
-
-			break;
-		case FILEDATA_CHANGE_DELETE:
-
-			collection_maint_removed(fd);
-			break;
-		case FILEDATA_CHANGE_UNSPECIFIED:
-			/* FIXME */
-			break;
-		}
-
 
 	/* this is the new way: */
 	file_data_send_notification(fd, NOTIFY_TYPE_CHANGE);