Commit 5baaa578 authored by Darin Adler's avatar Darin Adler

More prep work for the trash directory.

	* libnautilus-extensions/Makefile.am:
	* libnautilus-extensions/nautilus-trash-directory.c:
	(nautilus_trash_directory_initialize_class),
	(nautilus_trash_directory_initialize),
	(nautilus_trash_directory_destroy):
	* libnautilus-extensions/nautilus-trash-directory.h:
	* libnautilus-extensions/nautilus-vfs-directory.c:
	(nautilus_vfs_directory_initialize_class),
	(nautilus_vfs_directory_initialize),
	(nautilus_vfs_directory_destroy):
	* libnautilus-extensions/nautilus-vfs-directory.h:
	Add subclasses for the trash and for general VFS directories.
	Using refactoring techniques to move code down into these
	subclasses. This is not intended to be a general framework,
	but should be good enough to handle both these cases.

	* libnautilus-extensions/nautilus-directory-async.c:
	(can_use_public_metafile), (metafile_read_check_for_directory),
	(metafile_read_failed), (metafile_read_start), (allow_metafile),
	(metafile_write_success_close_callback),
	(nautilus_metafile_write_start), (start_monitoring_file_list),
	(get_corresponding_file), (start_getting_file_info):
	* libnautilus-extensions/nautilus-directory-private.h:
	* libnautilus-extensions/nautilus-directory.c:
	(nautilus_directory_destroy), (make_uri_canonical),
	(nautilus_directory_get_internal), (nautilus_directory_get_uri),
	(construct_private_metafile_uri), (nautilus_directory_new),
	(nautilus_directory_is_local), (nautilus_directory_is_not_empty),
	(nautilus_self_check_directory):
	* libnautilus-extensions/nautilus-directory.h:
	* libnautilus-extensions/nautilus-file.c:
	(nautilus_file_get_internal), (nautilus_file_rename),
	(nautilus_file_get_gnome_vfs_uri), (nautilus_file_matches_uri),
	(nautilus_file_compare_by_name),
	(nautilus_file_compare_by_directory_name),
	(nautilus_file_compare_for_sort), (nautilus_file_get_uri),
	(nautilus_file_set_permissions),
	(nautilus_file_get_string_attribute),
	(nautilus_file_get_mime_type), (nautilus_file_is_in_trash),
	(nautilus_file_contains_text), (nautilus_file_get_directory_name),
	(nautilus_file_mark_gone), (nautilus_file_changed):
	* libnautilus-extensions/nautilus-file.h:
	Add code to handle case of directory that can't be handled by
	gnome-vfs. Mostly some NULL checks. Also renamed fields to make
	it clear that the text URI is the "real" one. Added code to
	handle the "gnome-trash:" and "trash:" schemes specially in the
	code to make URIs canonical.

	* libnautilus-extensions/nautilus-mime-actions.c:
	(get_mime_type_from_uri): Return "application/octet-stream"
	instead of NULL for unknown MIME type.

	* src/file-manager/fm-directory-view.c:
	(fm_directory_view_display_selection_info): Eliminated the
	nautilus_file_get_real_name call.
	* src/nautilus-switchable-navigation-bar.c:
	(nautilus_switchable_navigation_bar_set_location): Eliminated
	the nautilus_directory_is_search_directory call.

	* src/file-manager/fm-search-list-view.c: (real_adding_file):
	Fixed formatting mistake.

	* src/nautilus-view-frame.c: (set_up_for_new_location): Emit
	the title_changed signal for each change in location.
parent 925ddd40
2000-08-14 Darin Adler <darin@eazel.com>
More prep work for the trash directory.
* libnautilus-extensions/Makefile.am:
* libnautilus-extensions/nautilus-trash-directory.c:
(nautilus_trash_directory_initialize_class),
(nautilus_trash_directory_initialize),
(nautilus_trash_directory_destroy):
* libnautilus-extensions/nautilus-trash-directory.h:
* libnautilus-extensions/nautilus-vfs-directory.c:
(nautilus_vfs_directory_initialize_class),
(nautilus_vfs_directory_initialize),
(nautilus_vfs_directory_destroy):
* libnautilus-extensions/nautilus-vfs-directory.h:
Add subclasses for the trash and for general VFS directories.
Using refactoring techniques to move code down into these
subclasses. This is not intended to be a general framework,
but should be good enough to handle both these cases.
* libnautilus-extensions/nautilus-directory-async.c:
(can_use_public_metafile), (metafile_read_check_for_directory),
(metafile_read_failed), (metafile_read_start), (allow_metafile),
(metafile_write_success_close_callback),
(nautilus_metafile_write_start), (start_monitoring_file_list),
(get_corresponding_file), (start_getting_file_info):
* libnautilus-extensions/nautilus-directory-private.h:
* libnautilus-extensions/nautilus-directory.c:
(nautilus_directory_destroy), (make_uri_canonical),
(nautilus_directory_get_internal), (nautilus_directory_get_uri),
(construct_private_metafile_uri), (nautilus_directory_new),
(nautilus_directory_is_local), (nautilus_directory_is_not_empty),
(nautilus_self_check_directory):
* libnautilus-extensions/nautilus-directory.h:
* libnautilus-extensions/nautilus-file.c:
(nautilus_file_get_internal), (nautilus_file_rename),
(nautilus_file_get_gnome_vfs_uri), (nautilus_file_matches_uri),
(nautilus_file_compare_by_name),
(nautilus_file_compare_by_directory_name),
(nautilus_file_compare_for_sort), (nautilus_file_get_uri),
(nautilus_file_set_permissions),
(nautilus_file_get_string_attribute),
(nautilus_file_get_mime_type), (nautilus_file_is_in_trash),
(nautilus_file_contains_text), (nautilus_file_get_directory_name),
(nautilus_file_mark_gone), (nautilus_file_changed):
* libnautilus-extensions/nautilus-file.h:
Add code to handle case of directory that can't be handled by
gnome-vfs. Mostly some NULL checks. Also renamed fields to make
it clear that the text URI is the "real" one. Added code to
handle the "gnome-trash:" and "trash:" schemes specially in the
code to make URIs canonical.
* libnautilus-extensions/nautilus-mime-actions.c:
(get_mime_type_from_uri): Return "application/octet-stream"
instead of NULL for unknown MIME type.
* src/file-manager/fm-directory-view.c:
(fm_directory_view_display_selection_info): Eliminated the
nautilus_file_get_real_name call.
* src/nautilus-switchable-navigation-bar.c:
(nautilus_switchable_navigation_bar_set_location): Eliminated
the nautilus_directory_is_search_directory call.
* src/file-manager/fm-search-list-view.c: (real_adding_file):
Fixed formatting mistake.
* src/nautilus-view-frame.c: (set_up_for_new_location): Emit
the title_changed signal for each change in location.
2000-08-14 Gene Z. Ragan <gzr@eazel.com>
* libnautilus-extensions/nautilus-icon-container.c:
......
......@@ -98,6 +98,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-string-picker.c \
nautilus-string.c \
nautilus-text-caption.c \
nautilus-trash-directory.c \
nautilus-theme.c \
nautilus-undo-context.c \
nautilus-undo-manager.c \
......@@ -105,6 +106,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-user-level-manager.c \
nautilus-view-identifier.c \
nautilus-volume-monitor.c \
nautilus-vfs-directory.c \
nautilus-xml-extensions.c \
$(NULL)
......@@ -115,22 +117,23 @@ noinst_HEADERS = \
nautilus-background.h \
nautilus-bonobo-extensions.h \
nautilus-bookmark.h \
nautilus-caption-table.h \
nautilus-caption.h \
nautilus-caption-table.h \
nautilus-cdrom-extensions.h \
nautilus-debug.h \
nautilus-default-file-icon.h \
nautilus-directory-background.h \
nautilus-directory.h \
nautilus-directory-metafile.h \
nautilus-directory-notify.h \
nautilus-directory-private.h \
nautilus-directory.h \
nautilus-drag.h \
nautilus-entry.h \
nautilus-file-attributes.h \
nautilus-file-changes-queue.h \
nautilus-file.h \
nautilus-file-private.h \
nautilus-file-utilities.h \
nautilus-file.h \
nautilus-font-factory.h \
nautilus-gdk-extensions.h \
nautilus-gdk-pixbuf-extensions.h \
......@@ -149,10 +152,11 @@ noinst_HEADERS = \
nautilus-icon-private.h \
nautilus-icon-text-item.h \
nautilus-image.h \
nautilus-iso9660.h \
nautilus-keep-last-vertical-box.h \
nautilus-lib-self-check-functions.h \
nautilus-link-set.h \
nautilus-link.h \
nautilus-link-set.h \
nautilus-list-column-title.h \
nautilus-list.h \
nautilus-metadata.h \
......@@ -162,28 +166,28 @@ noinst_HEADERS = \
nautilus-preferences-box.h \
nautilus-preferences-dialog.h \
nautilus-preferences-group.h \
nautilus-preferences.h \
nautilus-preferences-item.h \
nautilus-preferences-pane.h \
nautilus-preferences.h \
nautilus-program-chooser.h \
nautilus-program-choosing.h \
nautilus-radio-button-group.h \
nautilus-search-bar-criterion.h \
nautilus-search-bar-criterion-private.h \
nautilus-self-checks.h \
nautilus-stock-dialogs.h \
nautilus-string.h \
nautilus-string-list.h \
nautilus-string-picker.h \
nautilus-string.h \
nautilus-text-caption.h \
nautilus-theme.h \
nautilus-trash-directory.h \
nautilus-undo-context.h \
nautilus-undo-manager.h \
nautilus-undo-signal-handlers.h \
nautilus-user-level-manager.h \
nautilus-vfs-directory.h \
nautilus-view-identifier.h \
nautilus-xml-extensions.h \
nautilus-cdrom-extensions.h \
nautilus-iso9660.h \
nautilus-search-bar-criterion-private.h \
nautilus-volume-monitor.h \
nautilus-xml-extensions.h \
$(NULL)
......@@ -197,6 +197,10 @@ can_use_public_metafile (NautilusDirectory *directory)
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
if (directory->details->public_metafile_vfs_uri == NULL) {
return FALSE;
}
preference_value = nautilus_preferences_get_enum
(NAUTILUS_PREFERENCES_USE_PUBLIC_METADATA,
NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);
......@@ -270,9 +274,15 @@ static void
metafile_read_check_for_directory (NautilusDirectory *directory)
{
GList fake_list;
/* We only get here if the public metafile is in question,
* which in turn only happens if the URI is one that gnome-vfs
* can handle.
*/
g_assert (directory->details->vfs_uri != NULL);
/* We have to do a get_info call to check if this a directory. */
fake_list.data = directory->details->uri;
fake_list.data = directory->details->vfs_uri;
fake_list.next = NULL;
fake_list.prev = NULL;
gnome_vfs_async_get_file_info
......@@ -301,7 +311,7 @@ metafile_read_failed (NautilusDirectory *directory)
*/
/* First, check if we already know if it a directory. */
file = nautilus_file_get (directory->details->uri_text);
file = nautilus_file_get (directory->details->uri);
if (file == NULL || file->details->is_gone) {
need_directory_check = FALSE;
is_directory = FALSE;
......@@ -374,8 +384,8 @@ metafile_read_start (NautilusDirectory *directory)
text_uri = gnome_vfs_uri_to_string
(directory->details->metafile_read_state->use_public_metafile
? directory->details->public_metafile_uri
: directory->details->private_metafile_uri,
? directory->details->public_metafile_vfs_uri
: directory->details->private_metafile_vfs_uri,
GNOME_VFS_URI_HIDE_NONE);
directory->details->metafile_read_state->handle = nautilus_read_entire_file_async
......@@ -387,7 +397,9 @@ metafile_read_start (NautilusDirectory *directory)
static gboolean
allow_metafile (NautilusDirectory *directory)
{
const char *scheme;
const char *uri;
g_assert (NAUTILUS_IS_DIRECTORY (directory));
/* Note that this inhibits both reading and writing metadata
* completely. In the future we may want to inhibit writing to
......@@ -395,8 +407,6 @@ allow_metafile (NautilusDirectory *directory)
* metadata.
*/
g_assert (NAUTILUS_IS_DIRECTORY (directory));
/* For now, hard-code these schemes. Perhaps we should
* hardcode the schemes that are good for metadata instead of
* the schemes that are bad for it.
......@@ -405,13 +415,13 @@ allow_metafile (NautilusDirectory *directory)
* better way can wait until we have support for metadata
* access inside gnome-vfs.
*/
scheme = gnome_vfs_uri_get_scheme (directory->details->uri);
if (nautilus_strcasecmp (scheme, "info") == 0
|| nautilus_strcasecmp (scheme, "help") == 0
|| nautilus_strcasecmp (scheme, "man") == 0
|| nautilus_strcasecmp (scheme, "pipe") == 0
|| nautilus_strcasecmp (scheme, "search") == 0
|| nautilus_strcasecmp (scheme, "gnome-search") == 0) {
uri = directory->details->uri;
if (nautilus_istr_has_prefix (uri, "info:")
|| nautilus_istr_has_prefix (uri, "help:")
|| nautilus_istr_has_prefix (uri, "man:")
|| nautilus_istr_has_prefix (uri, "pipe:")
|| nautilus_istr_has_prefix (uri, "search:")
|| nautilus_istr_has_prefix (uri, "gnome-search:")) {
return FALSE;
}
......@@ -498,7 +508,7 @@ metafile_write_success_close_callback (GnomeVFSAsyncHandle *handle,
/* A synchronous unlink is OK here because the private
* metafiles are local, so an unlink is very fast.
*/
gnome_vfs_unlink_from_uri (directory->details->private_metafile_uri);
gnome_vfs_unlink_from_uri (directory->details->private_metafile_vfs_uri);
}
metafile_write_done (directory);
......@@ -561,8 +571,8 @@ nautilus_metafile_write_start (NautilusDirectory *directory)
gnome_vfs_async_create_uri
(&directory->details->metafile_write_state->handle,
directory->details->metafile_write_state->use_public_metafile
? directory->details->public_metafile_uri
: directory->details->private_metafile_uri,
? directory->details->public_metafile_vfs_uri
: directory->details->private_metafile_vfs_uri,
GNOME_VFS_OPEN_WRITE, FALSE, METAFILE_PERMISSIONS,
metafile_write_create_callback, directory);
}
......@@ -1605,13 +1615,13 @@ start_monitoring_file_list (NautilusDirectory *directory)
mark_all_files_unconfirmed (directory);
g_assert (directory->details->uri_text != NULL);
g_assert (directory->details->uri != NULL);
directory->details->directory_load_list_last_handled
= GNOME_VFS_DIRECTORY_LIST_POSITION_NONE;
gnome_vfs_async_load_directory
(&directory->details->directory_load_in_progress, /* handle */
directory->details->uri_text, /* uri */
directory->details->uri, /* uri */
(GNOME_VFS_FILE_INFO_GET_MIME_TYPE /* options */
| GNOME_VFS_FILE_INFO_FOLLOW_LINKS),
NULL, /* sort_rules */
......@@ -1650,7 +1660,7 @@ get_corresponding_file (NautilusDirectory *directory)
return file;
}
return nautilus_file_get_existing (directory->details->uri_text);
return nautilus_file_get_existing (directory->details->uri);
}
void
......@@ -2199,15 +2209,24 @@ start_getting_file_info (NautilusDirectory *directory)
}
/* Figure out which file to get file info for. */
file = select_needy_file (directory, lacks_info, wants_info);
if (file == NULL) {
return;
}
do {
file = select_needy_file (directory, lacks_info, wants_info);
if (file == NULL) {
return;
}
uri = nautilus_file_get_uri (file);
vfs_uri = gnome_vfs_uri_new (uri);
g_free (uri);
if (vfs_uri == NULL) {
file->details->get_info_failed = TRUE;
start_getting_file_info (directory);
}
} while (vfs_uri == NULL);
/* Found one we need to get the info for. */
directory->details->get_info_file = file;
uri = nautilus_file_get_uri (file);
vfs_uri = gnome_vfs_uri_new (uri);
g_free (uri);
fake_list.data = vfs_uri;
fake_list.prev = NULL;
fake_list.next = NULL;
......
......@@ -41,10 +41,10 @@ typedef struct TopLeftTextReadState TopLeftTextReadState;
struct NautilusDirectoryDetails
{
/* The location. */
char *uri_text;
GnomeVFSURI *uri;
GnomeVFSURI *private_metafile_uri;
GnomeVFSURI *public_metafile_uri;
char *uri;
GnomeVFSURI *vfs_uri;
GnomeVFSURI *private_metafile_vfs_uri;
GnomeVFSURI *public_metafile_vfs_uri;
/* The file objects. */
NautilusFile *as_file;
......
......@@ -33,6 +33,8 @@
#include "nautilus-gtk-macros.h"
#include "nautilus-lib-self-check-functions.h"
#include "nautilus-string.h"
#include "nautilus-trash-directory.h"
#include "nautilus-vfs-directory.h"
#include <ctype.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
......@@ -60,7 +62,6 @@ static guint signals[LAST_SIGNAL];
static GHashTable *directories;
static GnomeVFSURI * construct_private_metafile_uri (GnomeVFSURI *uri);
static void nautilus_directory_destroy (GtkObject *object);
static void nautilus_directory_initialize (gpointer object,
gpointer klass);
......@@ -166,16 +167,20 @@ nautilus_directory_destroy (GtkObject *object)
nautilus_g_list_free_deep (directory->details->monitor_list);
}
g_hash_table_remove (directories, directory->details->uri_text);
g_hash_table_remove (directories, directory->details->uri);
if (directory->details->dequeue_pending_idle_id != 0) {
gtk_idle_remove (directory->details->dequeue_pending_idle_id);
}
g_free (directory->details->uri_text);
gnome_vfs_uri_unref (directory->details->uri);
gnome_vfs_uri_unref (directory->details->private_metafile_uri);
gnome_vfs_uri_unref (directory->details->public_metafile_uri);
g_free (directory->details->uri);
gnome_vfs_uri_unref (directory->details->private_metafile_vfs_uri);
if (directory->details->vfs_uri != NULL) {
gnome_vfs_uri_unref (directory->details->vfs_uri);
}
if (directory->details->public_metafile_vfs_uri != NULL) {
gnome_vfs_uri_unref (directory->details->public_metafile_vfs_uri);
}
g_assert (directory->details->files == NULL);
nautilus_directory_metafile_destroy (directory);
g_assert (directory->details->directory_load_in_progress == NULL);
......@@ -195,6 +200,14 @@ make_uri_canonical (const char *uri)
size_t length;
char *canonical_uri, *old_uri, *with_slashes, *p;
/* Convert "gnome-trash:<anything>" and "trash:<anything>" to
* "gnome-trash:<anything>".
*/
if (nautilus_istr_has_prefix (uri, "trash:")
|| nautilus_istr_has_prefix (uri, "gnome-trash:")) {
return g_strdup ("gnome-trash:");
}
/* FIXME bugzilla.eazel.com 648:
* This currently ignores the issue of two uris that are not identical but point
* to the same data except for the specific cases of trailing '/' characters,
......@@ -317,11 +330,11 @@ nautilus_directory_get_internal (const char *uri, gboolean create)
return NULL;
}
g_assert (strcmp (directory->details->uri_text, canonical_uri) == 0);
g_assert (strcmp (directory->details->uri, canonical_uri) == 0);
/* Put it in the hash table. */
g_hash_table_insert (directories,
directory->details->uri_text,
directory->details->uri,
directory);
}
......@@ -347,7 +360,7 @@ nautilus_directory_get_uri (NautilusDirectory *directory)
{
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
return g_strdup (directory->details->uri_text);
return g_strdup (directory->details->uri);
}
static GnomeVFSResult
......@@ -387,21 +400,21 @@ nautilus_make_directory_and_parents (GnomeVFSURI *uri, guint permissions)
}
static GnomeVFSURI *
construct_private_metafile_uri (GnomeVFSURI *uri)
construct_private_metafile_uri (const char *uri)
{
GnomeVFSResult result;
GnomeVFSURI *nautilus_directory_uri, *metafiles_directory_uri, *alternate_uri;
char *uri_as_string, *escaped_uri, *file_name;
char *user_directory;
GnomeVFSURI *user_directory_uri, *metafiles_directory_uri, *alternate_uri;
char *escaped_uri, *file_name;
/* Ensure that the metafiles directory exists. */
user_directory = nautilus_get_user_directory ();
nautilus_directory_uri = gnome_vfs_uri_new (user_directory);
user_directory_uri = gnome_vfs_uri_new (user_directory);
g_free (user_directory);
metafiles_directory_uri = gnome_vfs_uri_append_file_name (nautilus_directory_uri,
metafiles_directory_uri = gnome_vfs_uri_append_file_name (user_directory_uri,
METAFILES_DIRECTORY_NAME);
gnome_vfs_uri_unref (nautilus_directory_uri);
gnome_vfs_uri_unref (user_directory_uri);
result = nautilus_make_directory_and_parents (metafiles_directory_uri,
METAFILES_DIRECTORY_PERMISSIONS);
if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_FILE_EXISTS) {
......@@ -410,9 +423,7 @@ construct_private_metafile_uri (GnomeVFSURI *uri)
}
/* Construct a file name from the URI. */
uri_as_string = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
escaped_uri = nautilus_str_escape_slashes (uri_as_string);
g_free (uri_as_string);
escaped_uri = nautilus_str_escape_slashes (uri);
file_name = g_strconcat (escaped_uri, ".xml", NULL);
g_free (escaped_uri);
......@@ -425,27 +436,27 @@ construct_private_metafile_uri (GnomeVFSURI *uri)
}
static NautilusDirectory *
nautilus_directory_new (const char* uri)
nautilus_directory_new (const char *uri)
{
NautilusDirectory *directory;
GnomeVFSURI *vfs_uri;
GnomeVFSURI *private_metafile_uri;
GnomeVFSURI *public_metafile_uri;
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL) {
return NULL;
g_assert (uri != NULL);
if (strcmp (uri, "gnome-trash:") == 0) {
directory = NAUTILUS_DIRECTORY (gtk_type_new (NAUTILUS_TYPE_TRASH_DIRECTORY));
} else {
directory = NAUTILUS_DIRECTORY (gtk_type_new (NAUTILUS_TYPE_VFS_DIRECTORY));
}
private_metafile_uri = construct_private_metafile_uri (vfs_uri);
public_metafile_uri = gnome_vfs_uri_append_file_name (vfs_uri, METAFILE_NAME);
directory->details->uri = g_strdup (uri);
directory->details->private_metafile_vfs_uri = construct_private_metafile_uri (uri);
directory = gtk_type_new (NAUTILUS_TYPE_DIRECTORY);
vfs_uri = gnome_vfs_uri_new (uri);
directory->details->uri_text = g_strdup (uri);
directory->details->uri = vfs_uri;
directory->details->private_metafile_uri = private_metafile_uri;
directory->details->public_metafile_uri = public_metafile_uri;
directory->details->vfs_uri = vfs_uri;
directory->details->public_metafile_vfs_uri = vfs_uri == NULL ? NULL
: gnome_vfs_uri_append_file_name (vfs_uri, METAFILE_NAME);
return directory;
}
......@@ -455,53 +466,10 @@ nautilus_directory_is_local (NautilusDirectory *directory)
{
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
return gnome_vfs_uri_is_local (directory->details->uri);
}
/* FIXME: I think this should be named _is_virtual_directory. */
gboolean
nautilus_directory_is_search_directory (NautilusDirectory *directory)
{
if (directory == NULL) {
return FALSE;
if (directory->details->vfs_uri == NULL) {
return TRUE;
}
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
/* Two hard-coded schemes for now. */
/* FIXME: Later we gnome-vfs will tell us somehow that this is
* a virtual directory.
*/
return nautilus_istr_has_prefix (directory->details->uri_text, "search:")
|| nautilus_istr_has_prefix (directory->details->uri_text, "gnome-search:");
#if 0
GnomeVFSFileInfo *info;
gboolean is_search_directory;
GnomeVFSResult result;
info = gnome_vfs_file_info_new ();
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
/* FIXME bugzilla.eazel.com 1263: We can't just do sync. I/O
* here! The model is that get_ functions in
* NautilusDirectory/File are supposed to do no I/O. The
* aforementioned bug talks about this a bit.
*/
/* FIXME bugzilla.eazel.com 1263: Should make use of some sort
* of NautilusDirectory cover for getting the mime type.
*/
result = gnome_vfs_get_file_info_uri (directory->details->uri,
info,
GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
is_search_directory = result == GNOME_VFS_OK &&
nautilus_strcasecmp (info->mime_type, "x-directory/search") == 0;
gnome_vfs_file_info_unref (info);
return is_search_directory;
#endif
return gnome_vfs_uri_is_local (directory->details->vfs_uri);
}
gboolean
......@@ -576,7 +544,6 @@ nautilus_directory_emit_done_loading (NautilusDirectory *directory)
signals[DONE_LOADING]);
}
static char *
uri_get_directory_part (const char *uri)
{
......@@ -1016,7 +983,7 @@ any_non_metafile_item (gconstpointer item, gconstpointer callback_data)
gboolean
nautilus_directory_is_not_empty (NautilusDirectory *directory)
{
char *public_metafile_uri_string;
char *public_metafile_uri;
gboolean not_empty;
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
......@@ -1024,16 +991,20 @@ nautilus_directory_is_not_empty (NautilusDirectory *directory)
/* Directory must be monitored for this call to be correct. */
g_return_val_if_fail (nautilus_directory_is_file_list_monitored (directory), FALSE);
public_metafile_uri_string = gnome_vfs_uri_to_string
(directory->details->public_metafile_uri,
GNOME_VFS_URI_HIDE_NONE);
/* Return TRUE if the directory contains anything besides a metafile. */
not_empty = g_list_find_custom (directory->details->files,
public_metafile_uri_string,
any_non_metafile_item) != NULL;
g_free (public_metafile_uri_string);
if (directory->details->public_metafile_vfs_uri == NULL) {
not_empty = directory->details->files != NULL;
} else {
public_metafile_uri = gnome_vfs_uri_to_string
(directory->details->public_metafile_vfs_uri,
GNOME_VFS_URI_HIDE_NONE);
/* Return TRUE if the directory contains anything besides a metafile. */
not_empty = g_list_find_custom (directory->details->files,
public_metafile_uri,
any_non_metafile_item) != NULL;
g_free (public_metafile_uri);
}
return not_empty;
}
......@@ -1194,6 +1165,7 @@ nautilus_self_check_directory (void)
NAUTILUS_CHECK_STRING_RESULT (make_uri_canonical (""), "file:");
NAUTILUS_CHECK_STRING_RESULT (make_uri_canonical ("file:/"), "file:///");
NAUTILUS_CHECK_STRING_RESULT (make_uri_canonical ("file:///"), "file:///");
NAUTILUS_CHECK_STRING_RESULT (make_uri_canonical ("TRASH:XXX"), "gnome-trash:");
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
......@@ -42,9 +42,6 @@
information available from other means.
*/
typedef struct NautilusDirectory NautilusDirectory;
typedef struct NautilusDirectoryClass NautilusDirectoryClass;
#define NAUTILUS_TYPE_DIRECTORY \
(nautilus_directory_get_type ())
#define NAUTILUS_DIRECTORY(obj) \
......@@ -62,10 +59,78 @@ typedef struct NautilusDirectoryClass NautilusDirectoryClass;
typedef struct NautilusFile NautilusFile;
#endif
typedef struct NautilusDirectoryDetails NautilusDirectoryDetails;
typedef struct
{
GtkObject object;
NautilusDirectoryDetails *details;
} NautilusDirectory;
typedef void (*NautilusDirectoryCallback) (NautilusDirectory *directory,
GList *files,
gpointer callback_data);
typedef struct
{
GtkObjectClass parent_class;
/*** Notification signals for clients to connect to. ***/
/* The files_added signal is emitted as the directory model
* discovers new files.
*/
void (* files_added) (NautilusDirectory *directory,
GList *added_files);
/* The files_changed signal is emitted as changes occur to
* existing files that are noticed by the synchronization framework,
* including when an old file has been deleted. When an old file
* has been deleted, this is the last chance to forget about these
* file objects, which are about to be unref'd. Use a call to
* nautilus_file_is_gone () to test for this case.
*/
void (* files_changed) (NautilusDirectory *directory,
GList *changed_files);
/* The metadata_changed signal is emitted when changes to the metadata
* for the directory itself are made. Changes to file metadata just
* result in calls to files_changed.
*/
void (* metadata_changed) (NautilusDirectory *directory);
/* The done_loading signal is emitted when a directory load
* request completes. This is needed because, at least in the
* case where the directory is empty, the caller will receive
* no kind of notification at all when a directory load
* initiated by `nautilus_directory_file_monitor_add' completes.
*/
void (* done_loading) (NautilusDirectory *directory);
/*** Virtual functions for subclasses to override. ***/
gboolean (* contains_file) (NautilusDirectory *directory,
NautilusFile *file);
void (* call_when_ready) (NautilusDirectory *directory,
GList *file_attributes,
gboolean wait_for_metadata,
NautilusDirectoryCallback callback,
gpointer callback_data);
void (* cancel_callback) (NautilusDirectory *directory,
NautilusDirectoryCallback callback,
gpointer callback_data);
void (* file_monitor_add) (NautilusDirectory *directory,
gconstpointer client,
GList *monitor_attributes,
gboolean monitor_metadata,
gboolean force_reload,
NautilusDirectoryCallback initial_files_callback,
gpointer callback_data);
void (* file_monitor_remove) (NautilusDirectory *directory,
gconstpointer client);
gboolean (* are_all_files_seen) (NautilusDirectory *directory);
gboolean (* is_not_empty) (NautilusDirectory *directory);
} NautilusDirectoryClass;
/* Basic GtkObject requirements. */
GtkType nautilus_directory_get_type (void);
......@@ -152,68 +217,12 @@ void nautilus_directory_file_monitor_remove (NautilusDirectory
*/
gboolean nautilus_directory_are_all_files_seen (NautilusDirectory *directory);
/* Return true if the directory metadata has been loaded.
* Until this is true, get_metadata calls will return defaults.
* (We could have another way to indicate "don't know".)
*/
gboolean nautilus_directory_metadata_loaded (NautilusDirectory *directory);
/* Return true if the directory is local. */
gboolean nautilus_directory_is_local (NautilusDirectory *directory);
gboolean nautilus_directory_is_search_directory (NautilusDirectory *directory);
/* Return false if directory contains anything besides a nautilus metafile.
* Only valid if directory is monitored.
* Used by the Trash monitor
/* Return false if directory contains anything besides a Nautilus metafile.
* Only valid if directory is monitored. Used by the Trash monitor.
*/
gboolean nautilus_directory_is_not_empty (NautilusDirectory *directory);
typedef struct NautilusDirectoryDetails NautilusDirectoryDetails;