Re: [PATCH] Add DnD files onto archiver files with help of file-roller
- From: Nelson Benítez <gnel cenobioracing com>
- To: Alexander Larsson <alexl redhat com>
- Cc: nautilus-list gnome org
- Subject: Re: [PATCH] Add DnD files onto archiver files with help of file-roller
- Date: Sun, 03 Dec 2006 20:44:51 +0000
Alexander Larsson escribió:
> On Sat, 2006-11-25 at 22:42 +0000, Nelson Benítez wrote:
>> 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...
>
> The way nautilus handles file types in general is through mimetypes. We
> don't want to have everything use mimetypes except one place, because
> that would make it act different in some particular case, completely
> surprising users.
I've changed nautilus_is_archiver_file() to use mime-types, it tries
first with the sniffed one, if that is not present it uses the guessed
one (based on extension). Now it integrates more with nautilus, as it
can be seen in this screencast[1]. Patch attached.
[1] http://supertux.cenobioracing.com/archivos/roller_mime.gif
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 3 Dec 2006 20:14:10 -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 3 Dec 2006 20:14:11 -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 3 Dec 2006 20:14:11 -0000
@@ -39,6 +39,7 @@
#include <libgnomevfs/gnome-vfs-ops.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-utils.h>
+#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include <unistd.h>
#include <stdlib.h>
@@ -49,6 +50,22 @@
#define LEGACY_DESKTOP_DIRECTORY_NAME ".gnome-desktop"
#define DEFAULT_DESKTOP_DIRECTORY_MODE (0755)
+#define FILE_ROLLER_ARCHIVER_MIME_TYPES "application/x-gtar",\
+ "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"
char *
nautilus_compute_title_for_uri (const char *text_uri)
@@ -624,6 +641,49 @@ nautilus_get_uri_shortname_for_display (
}
return name;
+}
+
+gboolean
+nautilus_is_archiver_file (const char *uri)
+{
+ NautilusFile *file;
+ int i;
+ char *mime_sniff, *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 (uri);
+ g_return_val_if_fail (file != NULL, FALSE);
+
+ mime_sniff = nautilus_file_get_mime_type (file);
+ if (mime_sniff != NULL) {
+ if (strcmp (mime_sniff, GNOME_VFS_MIME_TYPE_UNKNOWN) != 0) {
+ mime_compare = g_strdup (mime_sniff);
+ } else {
+ mime_compare = nautilus_file_get_guessed_mime_type (file);
+ }
+ g_free (mime_sniff);
+ } else {
+ mime_compare = nautilus_file_get_guessed_mime_type (file);
+ }
+
+ if (strcmp (mime_compare, GNOME_VFS_MIME_TYPE_UNKNOWN) == 0) {
+ g_free (mime_compare);
+ nautilus_file_unref (file);
+ return FALSE;
+ }
+
+ 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;
}
#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 3 Dec 2006 20:14:11 -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 3 Dec 2006 20:14:28 -0000
@@ -9569,6 +9569,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]