Re: [PATCH] Improve activation behavior of multiple files, part 1



On Fr, 2005-11-18 at 18:58 +0100, Christian Neumair wrote:
> On Mi, 2005-10-19 at 11:54 +0200, Alexander Larsson wrote:
> > On Tue, 2005-10-04 at 13:10 +0200, Christian Neumair wrote:
> > > The attached two patches change the Nautilus semantics for dealing with
> > > multiple files. The trick is to be notified about all activation URIs
> > > and decide what to do with the individual files later. We can then
> > > cumulate multiple files and pass them to the same application handler.
> > > 
> > > From quickly taking a look at the patch it looks like we sometimes leak
> > > the activation->files list, this can be resolved right before the
> > > commit, though.
> > (review)
> 
> It's frustrating. I fail to see why the refcount is hosed after the file
> activation. I'm sending what I have now back to the list for review.
> Using gdb and printf-debugging didn't yield anything.

The last patch just contained the src/ part.

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.374
diff -u -p -r1.374 nautilus-file.c
--- libnautilus-private/nautilus-file.c	20 Oct 2005 15:22:12 -0000	1.374
+++ libnautilus-private/nautilus-file.c	18 Nov 2005 18:00:17 -0000
@@ -5831,6 +5831,8 @@ nautilus_file_list_sort_by_display_name 
 	return g_list_sort (list, compare_by_display_name_cover);
 }
 
+static GList *ready_data_list = NULL;
+
 typedef struct 
 {
 	GList *file_list;
@@ -5840,11 +5842,45 @@ typedef struct 
 } FileListReadyData;
 
 static void
+file_list_ready_data_free (FileListReadyData *data)
+{
+	GList *l;
+
+	l = g_list_find (ready_data_list, data);
+	if (l != NULL) {
+		ready_data_list = g_list_delete_link (ready_data_list, l);
+		l = g_list_find (ready_data_list, data);
+
+		nautilus_file_list_free (data->file_list);
+		g_list_free (data->remaining_files);
+		g_free (data);
+	}
+}
+
+static FileListReadyData *
+file_list_ready_data_new (GList *file_list,
+			  NautilusFileListCallback callback,
+			  gpointer callback_data)
+{
+	FileListReadyData *data;
+
+	data = g_new0 (FileListReadyData, 1);
+	data->file_list = nautilus_file_list_copy (file_list);
+	data->remaining_files = g_list_copy (file_list);
+	data->callback = callback;
+	data->callback_data = callback_data;
+
+	ready_data_list = g_list_prepend (ready_data_list, data);
+
+	return data;
+}
+
+static void
 file_list_file_ready_callback (NautilusFile *file,
 			       gpointer user_data)
 {
 	FileListReadyData *data;
-	
+
 	data = user_data;
 	data->remaining_files = g_list_remove (data->remaining_files, file);
 	
@@ -5852,13 +5888,12 @@ file_list_file_ready_callback (NautilusF
 		if (data->callback) {
 			(*data->callback) (data->file_list, data->callback_data);
 		}
-		
-		nautilus_file_list_free (data->file_list);
-		g_free (data);
+
+		file_list_ready_data_free (data);
 	}
 }
 
-void
+NautilusFileListHandle *
 nautilus_file_list_call_when_ready (GList *file_list,
 				    NautilusFileAttributes attributes,
 				    NautilusFileListCallback callback,
@@ -5866,20 +5901,44 @@ nautilus_file_list_call_when_ready (GLis
 {
 	GList *l;
 	FileListReadyData *data;
-	
-	g_return_if_fail (file_list != NULL);
 
-	data = g_new0 (FileListReadyData, 1);
-	data->file_list = nautilus_file_list_copy (file_list);
-	data->remaining_files = g_list_copy (file_list);
-	data->callback = callback;
-	data->callback_data = callback_data;
-	
+	g_return_val_if_fail (file_list != NULL, NULL);
+
+	data = file_list_ready_data_new
+		(file_list, callback, callback_data);
+
 	for (l = file_list; l != NULL; l = l->next) {
 		nautilus_file_call_when_ready (NAUTILUS_FILE (l->data),
 					       attributes,
 					       file_list_file_ready_callback,
 					       data);
+	}
+
+	return (NautilusFileListHandle *) data;
+}
+
+void
+nautilus_file_list_cancel_call_when_ready (NautilusFileListHandle *handle)
+{
+	GList *l;
+	NautilusFile *file;
+	FileListReadyData *data;
+
+	g_return_if_fail (handle != NULL);
+
+	data = (FileListReadyData *) handle;
+
+	l = g_list_find (ready_data_list, handle);
+	if (l != NULL) {
+		for (l = data->remaining_files; l != NULL; l = l->next) {
+			file = NAUTILUS_FILE (l->data);
+
+			EEL_CALL_METHOD
+				(NAUTILUS_FILE_CLASS, file,
+				 cancel_call_when_ready, (file, file_list_file_ready_callback, data));
+		}
+
+		file_list_ready_data_free (data);
 	}
 }
 
Index: libnautilus-private/nautilus-file.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.h,v
retrieving revision 1.108
diff -u -p -r1.108 nautilus-file.h
--- libnautilus-private/nautilus-file.h	20 Oct 2005 15:22:12 -0000	1.108
+++ libnautilus-private/nautilus-file.h	18 Nov 2005 18:00:17 -0000
@@ -89,6 +89,8 @@ typedef char * (*NautilusTruncateCallbac
 					       int	      width,
 					       void	     *context);
 
+typedef void NautilusFileListHandle;
+
 /* GObject requirements. */
 GType                   nautilus_file_get_type                          (void);
 
@@ -339,10 +341,11 @@ void                    nautilus_file_li
 void                    nautilus_file_list_free                         (GList                          *file_list);
 GList *                 nautilus_file_list_copy                         (GList                          *file_list);
 GList *			nautilus_file_list_sort_by_display_name		(GList				*file_list);
-void                    nautilus_file_list_call_when_ready              (GList                          *file_list,
+NautilusFileListHandle* nautilus_file_list_call_when_ready              (GList                          *file_list,
 									 NautilusFileAttributes          attributes,
 									 NautilusFileListCallback        callback,
 									 gpointer                        callback_data);
+void                    nautilus_file_list_cancel_call_when_ready       (NautilusFileListHandle         *handle);
 
 /* Debugging */
 void                    nautilus_file_dump                              (NautilusFile                   *file);

Attachment: signature.asc
Description: This is a digitally signed message part



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