Re: [PATCH] Add DnD files onto archiver files with help of file-roller



Alexander Larsson escribió:
> On Sun, 2006-11-19 at 22:53 +0000, Nelson Benítez wrote:
>> Hi, please see http://bugs.gnome.org/377157 for details and also a
>> screencast of the feature. I also attach patch here.
> 
> Interesting. This interfers with implementing similar features using
> chained uris. However, since those never really worked I guess we could
> go this route instead.
> 
> nautilus_is_archiver_file() is pretty weird, it looks for e.e.g "zip"
> anywhere in a filename, not ".zip" at the end. Also we should probably
> be using mimetypes, not extensions if possible.

Now I added code so it looks for "zip" at the end of filename so now
even 'photos.zip.backup' filename is not matched.
I don't like very much using mimetypes because if I recall right mime
functions make the code slow . Also strange things could happen like
OpenOffice files are zip and so be offered as drop target, I think these
well known archivers extensions are enough for the job, anyway I don't
mind adding mime functions if you want that...

> +	} else if (nautilus_is_archiver_file (target_uri_string)) {
> +		*action = GDK_ACTION_LINK;
> +		return;
> Why default to link? Surely this is a copy operation.
> Also, LINK might not be in the set of allowed actions, you need to check

I just change the action to GDK_ACTION_COPY and works fine!, I swear
when I made the patch in 2.12 just the GDK_ACTION_LINK worked for me...
yay for using latest versions...

> that. Also, there seems to not be any support for listview dnd.

I moved the code that calls file-roller to fm-directory-view and now
it's used by both icon view and list view.
I noticed that other dnd actions like executing commands and desktop
files is duplicated in nautilus-icon-dnd.c and fm-directory-view.c, as
in my case it could only be in the later because it gets shared for both
icon|list view.

> In general it seems like you're just adding some special case hacks
> instead of working with the existing DnD code. Take a look at things
> like nautilus_drag_can_accept_files() and try to work from that instead.

Now I think I'm making the same things that are done for other dnd
special cases like desktop files, my patch has always used
nautilus_drag_can_accept_files() to accept archiver files as dropable items.

I attach new patch, thanks for reviewing it.
Index: libnautilus-private/nautilus-dnd.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-dnd.c,v
retrieving revision 1.26
diff -p -u -r1.26 nautilus-dnd.c
--- libnautilus-private/nautilus-dnd.c	27 Jul 2006 21:58:41 -0000	1.26
+++ libnautilus-private/nautilus-dnd.c	25 Nov 2006 16:11:22 -0000
@@ -29,6 +29,7 @@
 #include <config.h>
 #include "nautilus-dnd.h"
 
+#include "nautilus-file-utilities.h"
 #include "nautilus-program-choosing.h"
 #include "nautilus-link.h"
 #include <eel/eel-glib-extensions.h>
@@ -369,6 +370,9 @@ nautilus_drag_default_drop_action_for_ic
 		desktop_uri = nautilus_get_desktop_directory_uri ();
 		target_uri = gnome_vfs_uri_new (desktop_uri);
 		g_free (desktop_uri);
+	} else if (nautilus_is_archiver_file (target_uri_string)) {
+		*action = GDK_ACTION_COPY;
+		return;
 	} else {
 		target_uri = gnome_vfs_uri_new (target_uri_string);
 	}
Index: libnautilus-private/nautilus-file-dnd.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-dnd.c,v
retrieving revision 1.9
diff -p -u -r1.9 nautilus-file-dnd.c
--- libnautilus-private/nautilus-file-dnd.c	27 Jul 2006 21:58:41 -0000	1.9
+++ libnautilus-private/nautilus-file-dnd.c	25 Nov 2006 16:11:22 -0000
@@ -25,6 +25,7 @@
 
 #include <config.h>
 #include "nautilus-file-dnd.h"
+#include "nautilus-file-utilities.h"
 #include "nautilus-desktop-icon-file.h"
 
 #include "nautilus-dnd.h"
@@ -36,6 +37,7 @@ static gboolean
 nautilus_drag_can_accept_files (NautilusFile *drop_target_item)
 {
 	NautilusDirectory *directory;
+	char *uri;
 
 	if (nautilus_file_is_directory (drop_target_item)) {
 		gboolean res;
@@ -61,6 +63,13 @@ nautilus_drag_can_accept_files (Nautilus
 		return TRUE;
 	}
 	
+	uri = nautilus_file_get_uri (drop_target_item);
+
+	if (nautilus_is_archiver_file (uri)) {
+		g_free (uri);
+		return TRUE;
+	}
+	g_free (uri);
 	return FALSE;
 }
 
Index: libnautilus-private/nautilus-file-utilities.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-utilities.c,v
retrieving revision 1.135
diff -p -u -r1.135 nautilus-file-utilities.c
--- libnautilus-private/nautilus-file-utilities.c	19 Oct 2006 13:27:21 -0000	1.135
+++ libnautilus-private/nautilus-file-utilities.c	25 Nov 2006 16:11:22 -0000
@@ -49,6 +49,18 @@
 #define LEGACY_DESKTOP_DIRECTORY_NAME ".gnome-desktop"
 #define DEFAULT_DESKTOP_DIRECTORY_MODE (0755)
 
+#define FILE_ROLLER_SUPPORTED_ARCHIVERS	"tar.gz",\
+					"tgz",\
+					"tar.bz2",\
+					"zip",\
+					"tar",\
+					"7z",\
+					"rar",\
+					"jar",\
+					"war",\
+					"ear",\
+					"arj"
+
 
 char *
 nautilus_compute_title_for_uri (const char *text_uri)
@@ -624,6 +636,29 @@ nautilus_get_uri_shortname_for_display (
 	}
 
 	return name;
+}
+
+gboolean
+nautilus_is_archiver_file (const char *uri)
+{
+	int i,tot;
+	char *p;
+	g_return_val_if_fail (uri != NULL, FALSE);
+
+	static const char* archivers [] = { FILE_ROLLER_SUPPORTED_ARCHIVERS };
+	
+	tot = G_N_ELEMENTS (archivers);
+	for (i=0;i<tot;i++) {
+		p = g_strrstr (uri, archivers[i]);
+		if (p != NULL) {
+			if (sizeof(p) == sizeof(archivers[i])) {
+				//make sure the match is at the end, to not match e.g. 'photos.zip.backup'
+				return TRUE;
+			}
+		}
+	}
+
+	return FALSE;
 }
 
 #if !defined (NAUTILUS_OMIT_SELF_CHECK)
Index: libnautilus-private/nautilus-file-utilities.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-utilities.h,v
retrieving revision 1.61
diff -p -u -r1.61 nautilus-file-utilities.h
--- libnautilus-private/nautilus-file-utilities.h	8 Jul 2006 08:38:17 -0000	1.61
+++ libnautilus-private/nautilus-file-utilities.h	25 Nov 2006 16:11:22 -0000
@@ -46,6 +46,7 @@ gboolean nautilus_is_desktop_directory_f
 gboolean nautilus_is_desktop_directory_escaped       (char *escaped_dir);
 gboolean nautilus_is_home_directory_file_escaped     (char *escaped_dirname,
 						      char *escaped_file);
+gboolean nautilus_is_archiver_file		     (const char *uri);
 char *   nautilus_get_gmc_desktop_directory          (void);
 char *   nautilus_get_pixmap_directory               (void);
 
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.753
diff -p -u -r1.753 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	23 Nov 2006 13:57:01 -0000	1.753
+++ src/file-manager/fm-directory-view.c	25 Nov 2006 16:11:40 -0000
@@ -9569,6 +9496,31 @@ fm_directory_view_move_copy_items (const
 
 	if (eel_uri_is_trash (target_uri) && copy_action == GDK_ACTION_MOVE) {
 		trash_or_delete_files_common (view, item_uris, relative_item_points, FALSE);
+	} else if (copy_action == GDK_ACTION_COPY && nautilus_is_archiver_file (target_uri)) {
+		//file-roller only handles local files (no gnomevfs support yet)
+		if (g_str_has_prefix (target_uri,"file://") && 
+			g_str_has_prefix ((char *) item_uris->data,"file://")) {
+			GList *p;
+			char *command, *tmp, *tmp2, *tmp3;
+			tmp = gnome_vfs_get_local_path_from_uri (target_uri);
+			tmp2 = g_shell_quote (tmp);
+			command = g_strconcat ("file-roller -a ", tmp2, NULL);
+			g_free (tmp);
+			g_free (tmp2);
+			for (p = (GList *) item_uris; p != NULL; p = p->next) {
+				tmp = gnome_vfs_get_local_path_from_uri ((char *) p->data);
+				tmp2 = g_shell_quote (tmp);
+				tmp3 = g_strconcat (command, " ", tmp2, NULL);
+				g_free (command);
+				command = tmp3;
+				tmp3 = NULL;
+				g_free (tmp);
+				g_free (tmp2);
+			} 
+			eel_gnome_shell_execute_on_screen (command, 
+						gtk_widget_get_screen (GTK_WIDGET (view)));
+			g_free (command);
+		}
 	} else {
 		nautilus_file_operations_copy_move
 			(item_uris, relative_item_points, 


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