PATCH - Add DnD files onto archiver files with help of file-roller



Hi, I would like to have this feature in nautilus, it's in winxp explorer and I like it, you can easily drop files onto a zip or other archiver files, and they get added to the archive.. it's very handy and it's possible thanks to file-roller. Hope you try the feature and enjoy it!.

See http://bugzilla.gnome.org/show_bug.cgi?id=377157  for more info.


Index: src/file-manager/fm-directory-view.c
===================================================================
--- src/file-manager/fm-directory-view.c	(revisión: 14183)
+++ src/file-manager/fm-directory-view.c	(copia de trabajo)
@@ -8569,6 +8569,35 @@ fm_directory_view_move_copy_items (const
 				target_uri, item_uris,
 				fm_directory_view_get_containing_window (view));
 		return;
+	} else if (copy_action == GDK_ACTION_COPY && nautilus_is_archiver_file (target_uri)) {
+		/* Handle dropping onto a file-roller archiver file, instead of starting a move/copy */
+		nautilus_file_unref (target_file);
+		GList *p;
+		char *command, *tmp, *tmp2, *tmp3;
+		GdkScreen  *screen;
+		tmp = uri_to_path (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 = uri_to_path ((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);
+		} 
+		screen = gtk_widget_get_screen (GTK_WIDGET (view));
+		if (screen == NULL) {
+			screen = gdk_screen_get_default ();
+		}
+		gdk_spawn_command_line_on_screen (screen, command, NULL);
+		g_free (command);
+
+		return;
 	}
 	nautilus_file_unref (target_file);
 
Index: libnautilus-private/nautilus-dnd.c
===================================================================
--- libnautilus-private/nautilus-dnd.c	(revisión: 14183)
+++ libnautilus-private/nautilus-dnd.c	(copia de trabajo)
@@ -422,6 +422,9 @@ nautilus_drag_default_drop_action_for_ic
 			nautilus_file_unref (target_file);
 			return;
 		}
+	} else if (nautilus_is_archiver_file (target_uri_string)) {
+		*action = GDK_ACTION_COPY;
+		return;
 	} else {
 		target = g_file_new_for_uri (target_uri_string);
 	}
Index: libnautilus-private/nautilus-file-dnd.c
===================================================================
--- libnautilus-private/nautilus-file-dnd.c	(revisión: 14183)
+++ libnautilus-private/nautilus-file-dnd.c	(copia de trabajo)
@@ -29,6 +29,7 @@
 
 #include "nautilus-dnd.h"
 #include "nautilus-directory.h"
+#include "nautilus-file-utilities.h"
 #include <eel/eel-glib-extensions.h>
 #include <string.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;
@@ -60,6 +62,14 @@ nautilus_drag_can_accept_files (Nautilus
 	if (nautilus_file_is_nautilus_link (drop_target_item)) {
 		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
===================================================================
--- libnautilus-private/nautilus-file-utilities.c	(revisión: 14183)
+++ libnautilus-private/nautilus-file-utilities.c	(copia de trabajo)
@@ -48,6 +48,23 @@
 #define DESKTOP_DIRECTORY_NAME "Desktop"
 #define LEGACY_DESKTOP_DIRECTORY_NAME ".gnome-desktop"
 #define DEFAULT_DESKTOP_DIRECTORY_MODE (0755)
+#define FILE_ROLLER_ARCHIVER_MIME_TYPES "application/x-gtar",\
+					"application/x-gzip",\
+					"application/x-bzip-compressed-tar",\
+					"application/x-zip",\
+					"application/x-zip-compressed",\
+					"application/zip",\
+					"application/x-zip",\
+					"application/x-tar",\
+					"application/x-compressed-tar",\
+					"application/x-7z-compressed",\
+					"application/x-rar",\
+					"application/x-rar-compressed",\
+					"application/x-jar",\
+					"application/x-java-archive",\
+					"application/x-war",\
+					"application/x-ear",\
+					"application/x-arj"
 
 static void update_xdg_dir_cache (void);
 static void schedule_user_dirs_changed (void);
@@ -959,6 +976,46 @@ nautilus_find_file_insensitive_next (GFi
 	return NULL;
 }
 
+gboolean
+nautilus_is_archiver_file (const char *uri)
+{
+	NautilusFile *file;
+	int i;
+	char *mime_compare;
+	static const char* mime_archivers [] = { FILE_ROLLER_ARCHIVER_MIME_TYPES };
+	static int tot = G_N_ELEMENTS (mime_archivers);
+
+	file = nautilus_file_get_existing_by_uri (uri);
+	g_return_val_if_fail (file != NULL, FALSE);
+
+	mime_compare = nautilus_file_get_mime_type (file);
+
+	for (i=0;i<tot;i++) {
+		if (strcmp (mime_compare, mime_archivers[i]) == 0) {
+				g_free (mime_compare);
+				nautilus_file_unref (file);
+				return TRUE;
+		}
+	}
+	g_free (mime_compare);
+	nautilus_file_unref (file);
+
+	return FALSE;
+}
+
+char *
+uri_to_path (const char *uri)
+{
+       GFile *file;
+       char  *path;
+
+       file = g_file_new_for_uri (uri);
+       path = g_file_get_path (file);
+       g_object_unref (file);
+       return path;
+}
+
+
 #if !defined (NAUTILUS_OMIT_SELF_CHECK)
 
 void
Index: libnautilus-private/nautilus-file-utilities.h
===================================================================
--- libnautilus-private/nautilus-file-utilities.h	(revisión: 14183)
+++ libnautilus-private/nautilus-file-utilities.h	(copia de trabajo)
@@ -50,6 +50,8 @@ gboolean nautilus_is_desktop_directory  
 gboolean nautilus_is_home_directory                  (GFile *dir);
 gboolean nautilus_is_home_directory_file             (GFile *dir,
 						      const char *filename);
+gboolean nautilus_is_archiver_file		     (const char *uri);
+char *   uri_to_path	                             (const char *uri);
 char *   nautilus_get_gmc_desktop_directory          (void);
 char *   nautilus_get_pixmap_directory               (void);
 


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