summaryrefslogtreecommitdiff
path: root/libnautilus-extensions
diff options
context:
space:
mode:
authorPavel Cisler <pavel@eazel.com>2000-11-21 10:14:41 +0000
committerPavel Cisler <pce@src.gnome.org>2000-11-21 10:14:41 +0000
commitb43f3c05e0471377b2a6a6b120946a0bae0ce22a (patch)
tree9eaef4120299938fdc65dcb454d31451a8f2372e /libnautilus-extensions
parent464a5feaa08a8cb2029526dd67d45b3f663d5a7c (diff)
downloadnautilus-b43f3c05e0471377b2a6a6b120946a0bae0ce22a.tar.gz
reviewed by: Maciej Stachowiak <mjs@eazel.com>
2000-11-21 Pavel Cisler <pavel@eazel.com> reviewed by: Maciej Stachowiak <mjs@eazel.com> Fixed bugzilla 855 - Renaming a file with thumbnails does not affect the thumbnails and 4654 - Old thumbnails cause problems with renaming. * libnautilus-extensions/nautilus-directory-metafile.c: (nautilus_directory_rename_file_metadata), (nautilus_directory_remove_file_metadata): Finish the metafile rename and metafile remove operation by updating thumbnail files correspondingly, if they exist. * libnautilus-extensions/nautilus-directory.c: * libnautilus-extensions/nautilus-directory.h: (nautilus_directory_get_file_uri): Added a convenience routine. * libnautilus-extensions/nautilus-thumbnails.c: (vfs_file_exists): Tweaked to use the right GnomeVFS call. * libnautilus-extensions/nautilus-thumbnails.h: * libnautilus-extensions/nautilus-thumbnails.c: (nautilus_update_thumbnail_file_renamed_one), (nautilus_update_thumbnail_file_renamed), (nautilus_remove_thumbnail_for_file_one), (nautilus_remove_thumbnail_for_file): Look for an existing thumbnail for a file, if present, rename or remove it respectively to update it to the new state. * libnautilus-extensions/nautilus-thumbnails.c: (make_thumbnail_path), (nautilus_get_thumbnail_uri), (check_for_thumbnails), (make_thumbnails): Added a create_parents_if_needed parameter used by the new thumbnail updating calls.
Diffstat (limited to 'libnautilus-extensions')
-rw-r--r--libnautilus-extensions/nautilus-directory-metafile.c19
-rw-r--r--libnautilus-extensions/nautilus-directory.c27
-rw-r--r--libnautilus-extensions/nautilus-directory.h4
-rw-r--r--libnautilus-extensions/nautilus-thumbnails.c116
-rw-r--r--libnautilus-extensions/nautilus-thumbnails.h5
5 files changed, 151 insertions, 20 deletions
diff --git a/libnautilus-extensions/nautilus-directory-metafile.c b/libnautilus-extensions/nautilus-directory-metafile.c
index 90dff5164..3f6bf1d6f 100644
--- a/libnautilus-extensions/nautilus-directory-metafile.c
+++ b/libnautilus-extensions/nautilus-directory-metafile.c
@@ -29,6 +29,7 @@
#include "nautilus-glib-extensions.h"
#include "nautilus-metadata.h"
#include "nautilus-string.h"
+#include "nautilus-thumbnails.h"
#include "nautilus-xml-extensions.h"
#include <gnome-xml/xmlmemory.h>
#include <stdlib.h>
@@ -641,6 +642,7 @@ nautilus_directory_rename_file_metadata (NautilusDirectory *directory,
GHashTable *directory_table;
gboolean found;
gpointer key, value;
+ char *old_file_uri, *new_file_uri;
if (directory->details->metafile_read) {
/* Move data in XML document if present. */
@@ -661,6 +663,14 @@ nautilus_directory_rename_file_metadata (NautilusDirectory *directory,
g_strdup (new_file_name), value);
}
}
+
+ /* rename the thumbnails for the file, if any */
+ old_file_uri = nautilus_directory_get_file_uri (directory, old_file_name);
+ new_file_uri = nautilus_directory_get_file_uri (directory, new_file_name);
+ nautilus_update_thumbnail_file_renamed (old_file_uri, new_file_uri);
+ g_free (old_file_uri);
+ g_free (new_file_uri);
+
}
typedef struct {
@@ -875,5 +885,14 @@ void
nautilus_directory_remove_file_metadata (NautilusDirectory *directory,
const char *file_name)
{
+ char *file_uri;
+
+ file_uri = nautilus_directory_get_file_uri (directory, file_name);
+
/* FIXME bugzilla.eazel.com 2807: This is not implemented. */
+
+
+ /* delete the thumbnails for the file, if any */
+ nautilus_remove_thumbnail_for_file (file_uri);
+ g_free (file_uri);
}
diff --git a/libnautilus-extensions/nautilus-directory.c b/libnautilus-extensions/nautilus-directory.c
index b4d545715..4a6834d5c 100644
--- a/libnautilus-extensions/nautilus-directory.c
+++ b/libnautilus-extensions/nautilus-directory.c
@@ -1249,6 +1249,33 @@ nautilus_directory_contains_file (NautilusDirectory *directory,
contains_file, (directory, file));
}
+char *
+nautilus_directory_get_file_uri (NautilusDirectory *directory,
+ const char *file_name)
+{
+ GnomeVFSURI *directory_uri, *file_uri;
+ char *result;
+
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
+ g_return_val_if_fail (file_name != NULL, NULL);
+
+ result = NULL;
+
+ directory_uri = gnome_vfs_uri_new (directory->details->uri);
+
+ g_assert (directory_uri != NULL);
+
+ file_uri = gnome_vfs_uri_append_string (directory_uri, file_name);
+ gnome_vfs_uri_unref (directory_uri);
+
+ if (file_uri != NULL) {
+ result = gnome_vfs_uri_to_string (file_uri, GNOME_VFS_URI_HIDE_NONE);
+ gnome_vfs_uri_unref (file_uri);
+ }
+
+ return result;
+}
+
void
nautilus_directory_call_when_ready (NautilusDirectory *directory,
GList *file_attributes,
diff --git a/libnautilus-extensions/nautilus-directory.h b/libnautilus-extensions/nautilus-directory.h
index a91aaa0a9..716244c70 100644
--- a/libnautilus-extensions/nautilus-directory.h
+++ b/libnautilus-extensions/nautilus-directory.h
@@ -149,6 +149,10 @@ char * nautilus_directory_get_uri (NautilusDirector
gboolean nautilus_directory_contains_file (NautilusDirectory *directory,
NautilusFile *file);
+/* Get the uri of the file in the directory, NULL if not found */
+char * nautilus_directory_get_file_uri (NautilusDirectory *directory,
+ const char *file_name);
+
/* Get (and ref) a NautilusFile object for this directory. */
NautilusFile * nautilus_directory_get_corresponding_file (NautilusDirectory *directory);
diff --git a/libnautilus-extensions/nautilus-thumbnails.c b/libnautilus-extensions/nautilus-thumbnails.c
index 4cc71c6c0..463345ad8 100644
--- a/libnautilus-extensions/nautilus-thumbnails.c
+++ b/libnautilus-extensions/nautilus-thumbnails.c
@@ -59,23 +59,27 @@ static int make_thumbnails (gpointer data);
static gboolean
vfs_file_exists (const char *file_uri)
{
- GnomeVFSResult result;
- GnomeVFSFileInfo *file_info;
-
- file_info = gnome_vfs_file_info_new ();
+ gboolean result;
+ GnomeVFSURI *uri;
+ uri = gnome_vfs_uri_new (file_uri);
+ if (uri == NULL) {
+ return FALSE;
+ }
+
/* FIXME bugzilla.eazel.com 3137: the synchronous I/O here means this call is
- unsuitable for use on anything that might be remote. */
+ unsuitable for use on anything that might be remote. */
+ result = gnome_vfs_uri_exists (uri);
+ gnome_vfs_uri_unref (uri);
- result = gnome_vfs_get_file_info (file_uri, file_info, 0);
- gnome_vfs_file_info_unref (file_info);
- return result == GNOME_VFS_OK;
+ return result;
}
/* utility routine that, given the uri of an image, constructs the uri to the corresponding thumbnail */
static char *
-make_thumbnail_path (const char *image_uri, gboolean directory_only, gboolean use_local_directory, gboolean anti_aliased)
+make_thumbnail_path (const char *image_uri, gboolean directory_only, gboolean use_local_directory,
+ gboolean anti_aliased, gboolean create_parents_if_needed)
{
GnomeVFSURI *vfs_uri;
char *thumbnail_uri, *thumbnail_path;
@@ -95,18 +99,24 @@ make_thumbnail_path (const char *image_uri, gboolean directory_only, gboolean us
thumbnail_uri = g_strdup_printf ("%s/.thumbnails", directory_name);
} else {
GnomeVFSResult result;
- GnomeVFSURI *thumbnail_directory_uri;
+ GnomeVFSURI *thumbnail_directory_uri;
- char *escaped_uri = gnome_vfs_escape_slashes (directory_name);
+ char *escaped_uri = gnome_vfs_escape_slashes (directory_name);
thumbnail_path = g_strdup_printf ("%s/.nautilus/thumbnails/%s", g_get_home_dir(), escaped_uri);
thumbnail_uri = gnome_vfs_get_uri_from_local_path (thumbnail_path);
g_free (thumbnail_path);
g_free(escaped_uri);
- /* we must create the directory if it doesnt exist */
+ /* we must create the directory if it doesn't exist */
thumbnail_directory_uri = gnome_vfs_uri_new (thumbnail_uri);
-
+
+ if (!create_parents_if_needed) {
+ if (!gnome_vfs_uri_exists (thumbnail_directory_uri)) {
+ gnome_vfs_uri_unref (thumbnail_directory_uri);
+ return NULL;
+ }
+ }
/* FIXME bugzilla.eazel.com 3137: synchronous I/O - it
looks like the URI will be local-only, but best to
make sure. */
@@ -136,7 +146,7 @@ make_thumbnail_path (const char *image_uri, gboolean directory_only, gboolean us
/* append an image suffix if the correct one isn't already present */
if (!nautilus_istr_has_suffix (image_uri, ".png")) {
- char* old_uri = thumbnail_uri;
+ char *old_uri = thumbnail_uri;
thumbnail_uri = g_strdup_printf ("%s.png", thumbnail_uri);
g_free(old_uri);
}
@@ -231,7 +241,7 @@ nautilus_get_thumbnail_uri (NautilusFile *file, gboolean anti_aliased)
uri_is_local = gnome_vfs_uri_is_local (temp_uri);
gnome_vfs_uri_unref (temp_uri);
- thumbnail_uri = make_thumbnail_path (file_uri, FALSE, uri_is_local, anti_aliased);
+ thumbnail_uri = make_thumbnail_path (file_uri, FALSE, uri_is_local, anti_aliased, TRUE);
/* if the thumbnail file already exists locally, simply return the uri */
@@ -257,7 +267,7 @@ nautilus_get_thumbnail_uri (NautilusFile *file, gboolean anti_aliased)
/* now try it globally */
if (!remake_thumbnail) {
g_free (thumbnail_uri);
- thumbnail_uri = make_thumbnail_path (file_uri, FALSE, FALSE, anti_aliased);
+ thumbnail_uri = make_thumbnail_path (file_uri, FALSE, FALSE, anti_aliased, TRUE);
/* if the thumbnail file already exists in the common area, return that uri, */
/* the uri is guaranteed to be local */
@@ -282,7 +292,7 @@ nautilus_get_thumbnail_uri (NautilusFile *file, gboolean anti_aliased)
/* make the thumbnail directory if necessary, at first try it locally */
g_free (thumbnail_uri);
local_flag = TRUE;
- thumbnail_uri = make_thumbnail_path (file_uri, TRUE, local_flag, anti_aliased);
+ thumbnail_uri = make_thumbnail_path (file_uri, TRUE, local_flag, anti_aliased, TRUE);
/* FIXME bugzilla.eazel.com 3137: more potentially losing
synch I/O - this could be remote */
@@ -301,7 +311,7 @@ nautilus_get_thumbnail_uri (NautilusFile *file, gboolean anti_aliased)
if (!can_write || (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_FILE_EXISTS)) {
g_free (thumbnail_uri);
local_flag = FALSE;
- thumbnail_uri = make_thumbnail_path (file_uri, TRUE, local_flag, anti_aliased);
+ thumbnail_uri = make_thumbnail_path (file_uri, TRUE, local_flag, anti_aliased, TRUE);
/* this is guaranteed to be local, so synch I/O can be tolerated here */
result = gnome_vfs_make_directory (thumbnail_uri, THUMBNAIL_DIR_PERMISSIONS);
}
@@ -338,6 +348,70 @@ nautilus_get_thumbnail_uri (NautilusFile *file, gboolean anti_aliased)
return NULL;
}
+static void
+nautilus_update_thumbnail_file_renamed_one (const char *old_file_name, const char *new_file_name,
+ gboolean anti_aliased)
+{
+ GnomeVFSURI *uri;
+ gboolean is_local;
+ char *old_thumbnail_uri, *new_thumbnail_uri;
+
+ uri = gnome_vfs_uri_new (old_file_name);
+ is_local = gnome_vfs_uri_is_local (uri);
+ gnome_vfs_uri_unref (uri);
+
+ old_thumbnail_uri = make_thumbnail_path (old_file_name, FALSE, is_local, anti_aliased, FALSE);
+ if (old_thumbnail_uri != NULL && vfs_file_exists (old_thumbnail_uri)) {
+ new_thumbnail_uri = make_thumbnail_path (new_file_name, FALSE, is_local, anti_aliased, FALSE);
+
+ g_assert (new_thumbnail_uri != NULL);
+ g_assert (!vfs_file_exists (new_thumbnail_uri));
+
+ gnome_vfs_move (old_thumbnail_uri, new_thumbnail_uri, FALSE);
+
+ g_free (new_thumbnail_uri);
+ }
+
+ g_free (old_thumbnail_uri);
+}
+
+/* update the thumbnail after the thumbnailed file got renamed */
+void
+nautilus_update_thumbnail_file_renamed (const char *old_file_name, const char *new_file_name)
+{
+ /* rename both the AA and non-AA thumbnails, if they exist */
+ nautilus_update_thumbnail_file_renamed_one (old_file_name, new_file_name, FALSE);
+ nautilus_update_thumbnail_file_renamed_one (old_file_name, new_file_name, TRUE);
+}
+
+static void
+nautilus_remove_thumbnail_for_file_one (const char *old_file_name, gboolean anti_aliased)
+{
+ GnomeVFSURI *uri;
+ gboolean is_local;
+ char *thumbnail_uri;
+
+ uri = gnome_vfs_uri_new (old_file_name);
+ is_local = gnome_vfs_uri_is_local (uri);
+ gnome_vfs_uri_unref (uri);
+
+ thumbnail_uri = make_thumbnail_path (old_file_name, FALSE, is_local, anti_aliased, FALSE);
+ if (thumbnail_uri != NULL && vfs_file_exists (thumbnail_uri)) {
+ gnome_vfs_unlink (thumbnail_uri);
+ }
+
+ g_free (thumbnail_uri);
+}
+
+/* remove the thumbnail after the thumbnailed file got deleted */
+void
+nautilus_remove_thumbnail_for_file (const char *old_file_name)
+{
+ /* remove both the AA and non-AA thumbnails, if they exist */
+ nautilus_remove_thumbnail_for_file_one (old_file_name, FALSE);
+ nautilus_remove_thumbnail_for_file_one (old_file_name, TRUE);
+}
+
/* check_for_thumbnails is a utility that checks to see if the current thumbnail task has terminated.
If it has, remove the thumbnail info from the queue and return TRUE; if it's still in progress, return FALSE.
*/
@@ -362,7 +436,8 @@ check_for_thumbnails (void)
/* the thumbnail task has completed, so update the current entry from the list */
file = nautilus_file_get (info->thumbnail_uri);
- current_thumbnail = make_thumbnail_path (info->thumbnail_uri, FALSE, info->is_local, info->anti_aliased);
+ current_thumbnail = make_thumbnail_path (info->thumbnail_uri, FALSE, info->is_local,
+ info->anti_aliased, TRUE);
/* if a thumbnail wasn't successfully made, use the "broken image" icon */
need_update = TRUE;
@@ -450,7 +525,8 @@ make_thumbnails (gpointer data)
/* First, compute the path name of the target thumbnail */
g_free (new_thumbnail_path);
- new_thumbnail_path = make_thumbnail_path (info->thumbnail_uri, FALSE, info->is_local, info->anti_aliased);
+ new_thumbnail_path = make_thumbnail_path (info->thumbnail_uri, FALSE, info->is_local,
+ info->anti_aliased, TRUE);
/* fork a task to make the thumbnail, using gdk-pixbuf to do the scaling */
if (!(info->thumbnail_task = fork())) {
diff --git a/libnautilus-extensions/nautilus-thumbnails.h b/libnautilus-extensions/nautilus-thumbnails.h
index 32f61bf09..8d192e070 100644
--- a/libnautilus-extensions/nautilus-thumbnails.h
+++ b/libnautilus-extensions/nautilus-thumbnails.h
@@ -30,4 +30,9 @@
/* Returns NULL if there's no thumbnail yet. */
char *nautilus_get_thumbnail_uri (NautilusFile *file, gboolean anti_aliased);
+void nautilus_update_thumbnail_file_renamed (const char *old_file_name,
+ const char *new_file_name);
+
+void nautilus_remove_thumbnail_for_file (const char *old_file_name);
+
#endif /* NAUTILUS_THUMBNAILS_H */