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 18:16:11 +0100
On Thu, 2005-01-13 at 17:08 +0100, Alexander Larsson wrote:
> On Thu, 2005-01-13 at 15:44 +0100, Jorn Baayen wrote:
> > On Thu, 2005-01-13 at 14:32 +0100, Alexander Larsson wrote:
> > >
> > > > 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.
>
> I think it makes more sense if escaping the filename (and extension) is
> done in nautilus_unique_file_name. Also, i'd prefer if the filenames
> looked less "random". At the very least it should start by trying to use
> the specified name without adding anything.
I adapted this stuff from the desktop file generation code in
gnome-panel. However, here's a new patch which generates cleaner
filenames and checks the specified name first.
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 17:09:52 -0000
@@ -366,6 +366,54 @@
return NULL;
}
+static gboolean
+test_uri_exists (const char *path)
+{
+ GnomeVFSURI *uri;
+ gboolean exists;
+
+ uri = gnome_vfs_uri_new (path);
+ exists = gnome_vfs_uri_exists (uri);
+ gnome_vfs_uri_unref (uri);
+
+ return exists;
+}
+
+char *
+nautilus_unique_file_name (const char *directory_uri,
+ const char *base_name,
+ const char *extension)
+{
+ char *path, *escaped_name;
+ gboolean exists;
+ int copy = 0;
+
+ escaped_name = gnome_vfs_escape_string (base_name);
+
+ path = g_strdup_printf ("%s/%s%s",
+ directory_uri,
+ escaped_name,
+ extension);
+ exists = test_uri_exists (path);
+
+ while (exists) {
+ g_free (path);
+ path = g_strdup_printf ("%s/%s-%d%s",
+ directory_uri,
+ escaped_name,
+ copy,
+ extension);
+
+ exists = test_uri_exists (path);
+
+ copy++;
+ }
+
+ g_free (escaped_name);
+
+ return path;
+}
+
char *
nautilus_unique_temporary_file_name (void)
{
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 17:09:52 -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 17:09:53 -0000
@@ -79,26 +79,25 @@
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,
const GdkPoint *point,
int screen)
{
- char *uri, *contents, *escaped_name;
+ char *uri, *contents;
GnomeDesktopItem *desktop_item;
GList dummy_list;
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);
- g_free (escaped_name);
+ uri = nautilus_unique_file_name (directory_uri,
+ base_name, ".desktop");
contents = g_strdup_printf ("[Desktop Entry]\n"
"Encoding=UTF-8\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 17:09:53 -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 17:09:55 -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]