Re: [PATCH] Fixed drag and drop between Nautilus and Mozilla
- From: Jorn Baayen <jbaayen gnome org>
- To: Alexander Larsson <alexl redhat com>
- Cc: nautilus-list gnome org
- Subject: Re: [PATCH] Fixed drag and drop between Nautilus and Mozilla
- Date: Thu, 13 Jan 2005 15:44:54 +0100
On Thu, 2005-01-13 at 14:32 +0100, Alexander Larsson wrote:
> On Wed, 2005-01-12 at 20:54 +0100, Jorn Baayen wrote:
> > Hi,
> >
> > Thanks for your comments. On the basis of them I have rewritten the
> > patch - attached.
> >
> > It is a lot cleaner now, and it works exactly as you described in that
> > mail. With one exception:
> >
> > The default mozilla drag action is GDK_ACTION_COPY, and the code opens
> > the link-or-download dialog on that. We can't distinguish it from a
> > ctrl-drag, where the dialog will also popup.
> >
> > I removed the (crappy and broken) custom linking code, as I get the
> > feeling it either belongs somewhere else in a more generic place within
> > nautilus, or in gnome-vfs. In a WebDAV window right click->"make link"
> > doesn't work either ..
>
> Nice work. I commited this with some changes:
> * Move up all code to FMDirectoryView so that the same code can be used
> from the list view
> * Fix up the list view to use this
> * Made the default drag action from mozilla be ASK
> * Fixed problem with desktop file naming when creating links to e.g.
> http://foo/. (it got slashes in the filename).
> * Don't use the desktop window as parent for the ask dialog, as it then
> ends up on all desktops.
> * Some changes to the wording on the ask dialog
> * Fixed a bunch of bugs that testing this in various ways exposed
Cool, thanks.
>
> > Then there still is the remaining issue that the .desktop file
> > generation code doesn't do an overwrite check.
>
> Yeah. We should probably make it try to generate a unique name.
Attaching a patch doing that.
Cheers,
Jorn
Index: libnautilus-private/nautilus-file-utilities.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-utilities.c,v
retrieving revision 1.122
diff -u -r1.122 nautilus-file-utilities.c
--- libnautilus-private/nautilus-file-utilities.c 15 Dec 2004 17:10:49 -0000 1.122
+++ libnautilus-private/nautilus-file-utilities.c 13 Jan 2005 14:40:09 -0000
@@ -367,6 +367,35 @@
}
char *
+nautilus_unique_file_name (const char *directory_uri,
+ const char *base_name,
+ const char *extension)
+{
+ char *path = NULL;
+ gboolean exists = TRUE;
+
+ while (exists) {
+ GnomeVFSURI *uri;
+ int rnd;
+
+ rnd = g_random_int ();
+
+ g_free (path);
+ path = g_strdup_printf ("%s/%s-%010x%s",
+ directory_uri,
+ base_name,
+ (guint) rnd,
+ extension);
+
+ uri = gnome_vfs_uri_new (path);
+ exists = gnome_vfs_uri_exists (uri);
+ gnome_vfs_uri_unref (uri);
+ }
+
+ return path;
+}
+
+char *
nautilus_unique_temporary_file_name (void)
{
const char *prefix = "/tmp/nautilus-temp-file";
Index: libnautilus-private/nautilus-file-utilities.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-utilities.h,v
retrieving revision 1.55
diff -u -r1.55 nautilus-file-utilities.h
--- libnautilus-private/nautilus-file-utilities.h 28 Oct 2004 14:00:38 -0000 1.55
+++ libnautilus-private/nautilus-file-utilities.h 13 Jan 2005 14:40:09 -0000
@@ -67,6 +67,9 @@
char * nautilus_get_data_file_path (const char *partial_path);
/* Return an allocated file name that is guranteed to be unique. */
+char * nautilus_unique_file_name (const char *directory_uri,
+ const char *base_name,
+ const char *extension);
char * nautilus_unique_temporary_file_name (void);
char * nautilus_find_file_in_gnome_path (char *file);
GList * nautilus_find_all_files_in_gnome_path (char *file);
Index: libnautilus-private/nautilus-link-desktop-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-link-desktop-file.c,v
retrieving revision 1.31
diff -u -r1.31 nautilus-link-desktop-file.c
--- libnautilus-private/nautilus-link-desktop-file.c 13 Jan 2005 13:27:51 -0000 1.31
+++ libnautilus-private/nautilus-link-desktop-file.c 13 Jan 2005 14:40:09 -0000
@@ -79,7 +79,7 @@
gboolean
nautilus_link_desktop_file_local_create (const char *directory_uri,
- const char *file_name,
+ const char *base_name,
const char *display_name,
const char *image,
const char *target_uri,
@@ -92,12 +92,13 @@
NautilusFileChangesQueuePosition item;
g_return_val_if_fail (directory_uri != NULL, FALSE);
- g_return_val_if_fail (file_name != NULL, FALSE);
+ g_return_val_if_fail (base_name != NULL, FALSE);
g_return_val_if_fail (display_name != NULL, FALSE);
g_return_val_if_fail (target_uri != NULL, FALSE);
- escaped_name = gnome_vfs_escape_string (file_name);
- uri = g_strdup_printf ("%s/%s", directory_uri, escaped_name);
+ escaped_name = gnome_vfs_escape_string (base_name);
+ uri = nautilus_unique_file_name (directory_uri,
+ escaped_name, ".desktop");
g_free (escaped_name);
contents = g_strdup_printf ("[Desktop Entry]\n"
Index: libnautilus-private/nautilus-link-desktop-file.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-link-desktop-file.h,v
retrieving revision 1.14
diff -u -r1.14 nautilus-link-desktop-file.h
--- libnautilus-private/nautilus-link-desktop-file.h 12 Jan 2005 12:32:03 -0000 1.14
+++ libnautilus-private/nautilus-link-desktop-file.h 13 Jan 2005 14:40:09 -0000
@@ -28,7 +28,7 @@
#include <libnautilus-private/nautilus-link.h>
gboolean nautilus_link_desktop_file_local_create (const char *directory_uri,
- const char *file_name,
+ const char *base_name,
const char *display_name,
const char *image,
const char *target_uri,
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.653
diff -u -r1.653 fm-directory-view.c
--- src/file-manager/fm-directory-view.c 13 Jan 2005 13:27:51 -0000 1.653
+++ src/file-manager/fm-directory-view.c 13 Jan 2005 14:40:10 -0000
@@ -7818,7 +7818,7 @@
GdkScreen *screen;
int screen_num;
char *url, *title;
- char *link_name, *link_file_name, *link_display_name;
+ char *link_name, *link_display_name;
char *container_uri;
GArray *points;
char **bits;
@@ -7889,11 +7889,9 @@
if (!eel_str_is_empty (link_name)) {
link_display_name = g_strdup_printf (_("link to %s"), link_name);
- /* FIXME: Handle name conflicts? */
- link_file_name = g_strconcat (link_name, ".desktop", NULL);
/* The filename can't contain slashes, strip em.
(the basename of http://foo/ is http://foo/) */
- revert_slashes (link_file_name);
+ revert_slashes (link_name);
point.x = x;
point.y = y;
@@ -7902,14 +7900,13 @@
screen_num = gdk_screen_get_number (screen);
nautilus_link_local_create (container_uri,
- link_file_name,
+ link_name,
link_display_name,
"gnome-fs-bookmark",
url,
&point,
screen_num);
- g_free (link_file_name);
g_free (link_display_name);
}
g_free (link_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]