diff options
author | Darin Adler <darin@src.gnome.org> | 2000-04-06 23:39:11 +0000 |
---|---|---|
committer | Darin Adler <darin@src.gnome.org> | 2000-04-06 23:39:11 +0000 |
commit | 1ae3a2426a4e21d7db61e5e5885cd513c68716c3 (patch) | |
tree | 71d547d56b7e1fe2b1f5e6a1754e68db70567dfc | |
parent | 50206e4a0093a53ceb58ff424cd0e40bd82fcceb (diff) | |
download | nautilus-1ae3a2426a4e21d7db61e5e5885cd513c68716c3.tar.gz |
Added the hooks needed to make metafile reading asynchronous.
Next I'll change the actual metafile access to work that way.
* libnautilus/nautilus-directory.h:
* libnautilus/nautilus-directory.c:
(nautilus_directory_metadata_call_when_ready): Added function
that requests a read of some metadata and calls back when the
data is ready.
* src/ntl-app.c: (nautilus_app_startup): Got rid of call to
nautilus_navinfo_init.
* src/ntl-types.h: Moved the NautilusNavigationInfo struct
and related defines to ntl-uri-map.h.
* src/ntl-uri-map.h:
* src/ntl-uri-map.c:
Reformatted and changed the names of many functions.
Added code to use the new metadata callback.
* src/ntl-index-panel.c:
* src/ntl-main.c:
* src/ntl-view.h:
* src/ntl-window-msgs.c:
* src/ntl-window.c:
* src/ntl-window.h:
Had to change includes a bit because of my changes to what
header files are including.
* src/ntl-window-msgs.c: (nautilus_window_update_state):
* src/ntl-window.h:
Use the new nautilus_navigation_info_cancel call instead of
reaching right in to cancel the underlying call.
* src/ntl-view-private.h:
Reformatting.
35 files changed, 1348 insertions, 1172 deletions
diff --git a/ChangeLog-20000414 b/ChangeLog-20000414 index aeaf39b27..0939a895f 100644 --- a/ChangeLog-20000414 +++ b/ChangeLog-20000414 @@ -1,5 +1,44 @@ 2000-04-06 Darin Adler <darin@eazel.com> + Added the hooks needed to make metafile reading asynchronous. + Next I'll change the actual metafile access to work that way. + + * libnautilus/nautilus-directory.h: + * libnautilus/nautilus-directory.c: + (nautilus_directory_metadata_call_when_ready): Added function + that requests a read of some metadata and calls back when the + data is ready. + + * src/ntl-app.c: (nautilus_app_startup): Got rid of call to + nautilus_navinfo_init. + + * src/ntl-types.h: Moved the NautilusNavigationInfo struct + and related defines to ntl-uri-map.h. + + * src/ntl-uri-map.h: + * src/ntl-uri-map.c: + Reformatted and changed the names of many functions. + Added code to use the new metadata callback. + + * src/ntl-index-panel.c: + * src/ntl-main.c: + * src/ntl-view.h: + * src/ntl-window-msgs.c: + * src/ntl-window.c: + * src/ntl-window.h: + Had to change includes a bit because of my changes to what + header files are including. + + * src/ntl-window-msgs.c: (nautilus_window_update_state): + * src/ntl-window.h: + Use the new nautilus_navigation_info_cancel call instead of + reaching right in to cancel the underlying call. + + * src/ntl-view-private.h: + Reformatting. + +2000-04-06 Darin Adler <darin@eazel.com> + * libnautilus/nautilus-directory-background.c: (nautilus_connect_background_to_directory_metadata): Fixed code that was trying to disconnect the handler from the diff --git a/libnautilus-extensions/nautilus-directory.c b/libnautilus-extensions/nautilus-directory.c index 65de289f0..be2fe0079 100644 --- a/libnautilus-extensions/nautilus-directory.c +++ b/libnautilus-extensions/nautilus-directory.c @@ -1082,6 +1082,23 @@ nautilus_directory_get_file_metadata_node (NautilusDirectory *directory, return NULL; } +void +nautilus_directory_metadata_call_when_ready (NautilusDirectory *directory, + GList *tags, + NautilusMetadataCallback callback, + gpointer callback_data) +{ + /* For now, it's synchronous for testing. */ + (* callback) (directory, callback_data); +} + +void +nautilus_directory_metadata_callback_cancel (NautilusDirectory *directory, + NautilusMetadataCallback callback, + gpointer callback_data) +{ +} + char * nautilus_directory_get_file_metadata (NautilusDirectory *directory, const char *file_name, diff --git a/libnautilus-extensions/nautilus-directory.h b/libnautilus-extensions/nautilus-directory.h index 978c29635..3083e4084 100644 --- a/libnautilus-extensions/nautilus-directory.h +++ b/libnautilus-extensions/nautilus-directory.h @@ -56,66 +56,77 @@ typedef struct NautilusDirectoryClass NautilusDirectoryClass; #define NAUTILUS_IS_DIRECTORY_CLASS(klass) \ (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_DIRECTORY)) +typedef void (*NautilusMetadataCallback) (NautilusDirectory *directory, + gpointer callback_data); typedef void (*NautilusFileListCallback) (NautilusDirectory *directory, GList *files, gpointer callback_data); /* Basic GtkObject requirements. */ -GtkType nautilus_directory_get_type (void); +GtkType nautilus_directory_get_type (void); /* Get a directory given a uri. * Creates the appropriate subclass given the uri mappings. * Returns a referenced object, not a floating one. Unref when finished. * If two windows are viewing the same uri, the directory object is shared. */ -NautilusDirectory *nautilus_directory_get (const char *uri); +NautilusDirectory *nautilus_directory_get (const char *uri); /* Convenience functions, since we do a lot of ref'ing and unref'ing. */ -void nautilus_directory_ref (NautilusDirectory *directory); -void nautilus_directory_unref (NautilusDirectory *directory); +void nautilus_directory_ref (NautilusDirectory *directory); +void nautilus_directory_unref (NautilusDirectory *directory); /* Access to a URI. */ -char * nautilus_directory_get_uri (NautilusDirectory *directory); - -/* Simple preliminary interface for getting and setting metadata. */ -char * nautilus_directory_get_metadata (NautilusDirectory *directory, - const char *tag, - const char *default_metadata); -void nautilus_directory_set_metadata (NautilusDirectory *directory, - const char *tag, - const char *default_metadata, - const char *metadata); -gboolean nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, - const char *tag, - gboolean default_metadata); -void nautilus_directory_set_boolean_metadata (NautilusDirectory *directory, - const char *tag, - gboolean default_metadata, - gboolean metadata); -int nautilus_directory_get_integer_metadata (NautilusDirectory *directory, - const char *tag, - int default_metadata); -void nautilus_directory_set_integer_metadata (NautilusDirectory *directory, - const char *tag, - int default_metadata, - int metadata); +char * nautilus_directory_get_uri (NautilusDirectory *directory); + +/* Getting and setting metadata. */ +char * nautilus_directory_get_metadata (NautilusDirectory *directory, + const char *tag, + const char *default_metadata); +void nautilus_directory_set_metadata (NautilusDirectory *directory, + const char *tag, + const char *default_metadata, + const char *metadata); +void nautilus_directory_metadata_call_when_ready (NautilusDirectory *directory, + GList *tags, + NautilusMetadataCallback callback, + gpointer callback_data); +void nautilus_directory_metadata_callback_cancel (NautilusDirectory *directory, + NautilusMetadataCallback callback, + gpointer callback_data); + +/* Covers for common data types. */ +gboolean nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, + const char *tag, + gboolean default_metadata); +void nautilus_directory_set_boolean_metadata (NautilusDirectory *directory, + const char *tag, + gboolean default_metadata, + gboolean metadata); +int nautilus_directory_get_integer_metadata (NautilusDirectory *directory, + const char *tag, + int default_metadata); +void nautilus_directory_set_integer_metadata (NautilusDirectory *directory, + const char *tag, + int default_metadata, + int metadata); /* Monitor the files in a directory. */ -void nautilus_directory_monitor_files_ref (NautilusDirectory *directory, - NautilusFileListCallback initial_files_callback, - gpointer callback_data); -void nautilus_directory_monitor_files_unref (NautilusDirectory *directory); +void nautilus_directory_monitor_files_ref (NautilusDirectory *directory, + NautilusFileListCallback initial_files_callback, + gpointer callback_data); +void nautilus_directory_monitor_files_unref (NautilusDirectory *directory); /* Return true if the directory has information about all the files. * This will be false until the directory has been read at least once. */ -gboolean nautilus_directory_are_all_files_seen (NautilusDirectory *directory); +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); +gboolean nautilus_directory_metadata_loaded (NautilusDirectory *directory); typedef struct NautilusDirectoryDetails NautilusDirectoryDetails; diff --git a/libnautilus-private/nautilus-directory.c b/libnautilus-private/nautilus-directory.c index 65de289f0..be2fe0079 100644 --- a/libnautilus-private/nautilus-directory.c +++ b/libnautilus-private/nautilus-directory.c @@ -1082,6 +1082,23 @@ nautilus_directory_get_file_metadata_node (NautilusDirectory *directory, return NULL; } +void +nautilus_directory_metadata_call_when_ready (NautilusDirectory *directory, + GList *tags, + NautilusMetadataCallback callback, + gpointer callback_data) +{ + /* For now, it's synchronous for testing. */ + (* callback) (directory, callback_data); +} + +void +nautilus_directory_metadata_callback_cancel (NautilusDirectory *directory, + NautilusMetadataCallback callback, + gpointer callback_data) +{ +} + char * nautilus_directory_get_file_metadata (NautilusDirectory *directory, const char *file_name, diff --git a/libnautilus-private/nautilus-directory.h b/libnautilus-private/nautilus-directory.h index 978c29635..3083e4084 100644 --- a/libnautilus-private/nautilus-directory.h +++ b/libnautilus-private/nautilus-directory.h @@ -56,66 +56,77 @@ typedef struct NautilusDirectoryClass NautilusDirectoryClass; #define NAUTILUS_IS_DIRECTORY_CLASS(klass) \ (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_DIRECTORY)) +typedef void (*NautilusMetadataCallback) (NautilusDirectory *directory, + gpointer callback_data); typedef void (*NautilusFileListCallback) (NautilusDirectory *directory, GList *files, gpointer callback_data); /* Basic GtkObject requirements. */ -GtkType nautilus_directory_get_type (void); +GtkType nautilus_directory_get_type (void); /* Get a directory given a uri. * Creates the appropriate subclass given the uri mappings. * Returns a referenced object, not a floating one. Unref when finished. * If two windows are viewing the same uri, the directory object is shared. */ -NautilusDirectory *nautilus_directory_get (const char *uri); +NautilusDirectory *nautilus_directory_get (const char *uri); /* Convenience functions, since we do a lot of ref'ing and unref'ing. */ -void nautilus_directory_ref (NautilusDirectory *directory); -void nautilus_directory_unref (NautilusDirectory *directory); +void nautilus_directory_ref (NautilusDirectory *directory); +void nautilus_directory_unref (NautilusDirectory *directory); /* Access to a URI. */ -char * nautilus_directory_get_uri (NautilusDirectory *directory); - -/* Simple preliminary interface for getting and setting metadata. */ -char * nautilus_directory_get_metadata (NautilusDirectory *directory, - const char *tag, - const char *default_metadata); -void nautilus_directory_set_metadata (NautilusDirectory *directory, - const char *tag, - const char *default_metadata, - const char *metadata); -gboolean nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, - const char *tag, - gboolean default_metadata); -void nautilus_directory_set_boolean_metadata (NautilusDirectory *directory, - const char *tag, - gboolean default_metadata, - gboolean metadata); -int nautilus_directory_get_integer_metadata (NautilusDirectory *directory, - const char *tag, - int default_metadata); -void nautilus_directory_set_integer_metadata (NautilusDirectory *directory, - const char *tag, - int default_metadata, - int metadata); +char * nautilus_directory_get_uri (NautilusDirectory *directory); + +/* Getting and setting metadata. */ +char * nautilus_directory_get_metadata (NautilusDirectory *directory, + const char *tag, + const char *default_metadata); +void nautilus_directory_set_metadata (NautilusDirectory *directory, + const char *tag, + const char *default_metadata, + const char *metadata); +void nautilus_directory_metadata_call_when_ready (NautilusDirectory *directory, + GList *tags, + NautilusMetadataCallback callback, + gpointer callback_data); +void nautilus_directory_metadata_callback_cancel (NautilusDirectory *directory, + NautilusMetadataCallback callback, + gpointer callback_data); + +/* Covers for common data types. */ +gboolean nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, + const char *tag, + gboolean default_metadata); +void nautilus_directory_set_boolean_metadata (NautilusDirectory *directory, + const char *tag, + gboolean default_metadata, + gboolean metadata); +int nautilus_directory_get_integer_metadata (NautilusDirectory *directory, + const char *tag, + int default_metadata); +void nautilus_directory_set_integer_metadata (NautilusDirectory *directory, + const char *tag, + int default_metadata, + int metadata); /* Monitor the files in a directory. */ -void nautilus_directory_monitor_files_ref (NautilusDirectory *directory, - NautilusFileListCallback initial_files_callback, - gpointer callback_data); -void nautilus_directory_monitor_files_unref (NautilusDirectory *directory); +void nautilus_directory_monitor_files_ref (NautilusDirectory *directory, + NautilusFileListCallback initial_files_callback, + gpointer callback_data); +void nautilus_directory_monitor_files_unref (NautilusDirectory *directory); /* Return true if the directory has information about all the files. * This will be false until the directory has been read at least once. */ -gboolean nautilus_directory_are_all_files_seen (NautilusDirectory *directory); +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); +gboolean nautilus_directory_metadata_loaded (NautilusDirectory *directory); typedef struct NautilusDirectoryDetails NautilusDirectoryDetails; diff --git a/libnautilus/nautilus-directory.c b/libnautilus/nautilus-directory.c index 65de289f0..be2fe0079 100644 --- a/libnautilus/nautilus-directory.c +++ b/libnautilus/nautilus-directory.c @@ -1082,6 +1082,23 @@ nautilus_directory_get_file_metadata_node (NautilusDirectory *directory, return NULL; } +void +nautilus_directory_metadata_call_when_ready (NautilusDirectory *directory, + GList *tags, + NautilusMetadataCallback callback, + gpointer callback_data) +{ + /* For now, it's synchronous for testing. */ + (* callback) (directory, callback_data); +} + +void +nautilus_directory_metadata_callback_cancel (NautilusDirectory *directory, + NautilusMetadataCallback callback, + gpointer callback_data) +{ +} + char * nautilus_directory_get_file_metadata (NautilusDirectory *directory, const char *file_name, diff --git a/libnautilus/nautilus-directory.h b/libnautilus/nautilus-directory.h index 978c29635..3083e4084 100644 --- a/libnautilus/nautilus-directory.h +++ b/libnautilus/nautilus-directory.h @@ -56,66 +56,77 @@ typedef struct NautilusDirectoryClass NautilusDirectoryClass; #define NAUTILUS_IS_DIRECTORY_CLASS(klass) \ (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_DIRECTORY)) +typedef void (*NautilusMetadataCallback) (NautilusDirectory *directory, + gpointer callback_data); typedef void (*NautilusFileListCallback) (NautilusDirectory *directory, GList *files, gpointer callback_data); /* Basic GtkObject requirements. */ -GtkType nautilus_directory_get_type (void); +GtkType nautilus_directory_get_type (void); /* Get a directory given a uri. * Creates the appropriate subclass given the uri mappings. * Returns a referenced object, not a floating one. Unref when finished. * If two windows are viewing the same uri, the directory object is shared. */ -NautilusDirectory *nautilus_directory_get (const char *uri); +NautilusDirectory *nautilus_directory_get (const char *uri); /* Convenience functions, since we do a lot of ref'ing and unref'ing. */ -void nautilus_directory_ref (NautilusDirectory *directory); -void nautilus_directory_unref (NautilusDirectory *directory); +void nautilus_directory_ref (NautilusDirectory *directory); +void nautilus_directory_unref (NautilusDirectory *directory); /* Access to a URI. */ -char * nautilus_directory_get_uri (NautilusDirectory *directory); - -/* Simple preliminary interface for getting and setting metadata. */ -char * nautilus_directory_get_metadata (NautilusDirectory *directory, - const char *tag, - const char *default_metadata); -void nautilus_directory_set_metadata (NautilusDirectory *directory, - const char *tag, - const char *default_metadata, - const char *metadata); -gboolean nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, - const char *tag, - gboolean default_metadata); -void nautilus_directory_set_boolean_metadata (NautilusDirectory *directory, - const char *tag, - gboolean default_metadata, - gboolean metadata); -int nautilus_directory_get_integer_metadata (NautilusDirectory *directory, - const char *tag, - int default_metadata); -void nautilus_directory_set_integer_metadata (NautilusDirectory *directory, - const char *tag, - int default_metadata, - int metadata); +char * nautilus_directory_get_uri (NautilusDirectory *directory); + +/* Getting and setting metadata. */ +char * nautilus_directory_get_metadata (NautilusDirectory *directory, + const char *tag, + const char *default_metadata); +void nautilus_directory_set_metadata (NautilusDirectory *directory, + const char *tag, + const char *default_metadata, + const char *metadata); +void nautilus_directory_metadata_call_when_ready (NautilusDirectory *directory, + GList *tags, + NautilusMetadataCallback callback, + gpointer callback_data); +void nautilus_directory_metadata_callback_cancel (NautilusDirectory *directory, + NautilusMetadataCallback callback, + gpointer callback_data); + +/* Covers for common data types. */ +gboolean nautilus_directory_get_boolean_metadata (NautilusDirectory *directory, + const char *tag, + gboolean default_metadata); +void nautilus_directory_set_boolean_metadata (NautilusDirectory *directory, + const char *tag, + gboolean default_metadata, + gboolean metadata); +int nautilus_directory_get_integer_metadata (NautilusDirectory *directory, + const char *tag, + int default_metadata); +void nautilus_directory_set_integer_metadata (NautilusDirectory *directory, + const char *tag, + int default_metadata, + int metadata); /* Monitor the files in a directory. */ -void nautilus_directory_monitor_files_ref (NautilusDirectory *directory, - NautilusFileListCallback initial_files_callback, - gpointer callback_data); -void nautilus_directory_monitor_files_unref (NautilusDirectory *directory); +void nautilus_directory_monitor_files_ref (NautilusDirectory *directory, + NautilusFileListCallback initial_files_callback, + gpointer callback_data); +void nautilus_directory_monitor_files_unref (NautilusDirectory *directory); /* Return true if the directory has information about all the files. * This will be false until the directory has been read at least once. */ -gboolean nautilus_directory_are_all_files_seen (NautilusDirectory *directory); +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); +gboolean nautilus_directory_metadata_loaded (NautilusDirectory *directory); typedef struct NautilusDirectoryDetails NautilusDirectoryDetails; diff --git a/src/nautilus-applicable-views.c b/src/nautilus-applicable-views.c index c12e94b92..728ae6f98 100644 --- a/src/nautilus-applicable-views.c +++ b/src/nautilus-applicable-views.c @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* * Nautilus @@ -22,6 +22,7 @@ * Author: Elliot Lee <sopwith@redhat.com> * */ + /* ntl-uri-map.c: Implementation of routines for mapping a location change request to a set of views and actual URL to be loaded. */ @@ -32,73 +33,76 @@ #include <libnautilus/nautilus-global-preferences.h> #include <libnautilus/nautilus-string.h> +#include <libgnomevfs/gnome-vfs-file-info.h> +#include <libgnomevfs/gnome-vfs-async-ops.h> + #include <libgnorba/gnorba.h> #include <sys/types.h> #include <dirent.h> #include <limits.h> #include <ctype.h> +#include "ntl-types.h" + /* forward declarations */ -static void add_components_from_metadata(NautilusNavigationInfo *navinfo); -static void add_meta_view_iids_from_preferences(NautilusNavigationInfo *navinfo); +static void add_components_from_metadata (NautilusNavigationInfo *navinfo); +static void add_meta_view_iids_from_preferences (NautilusNavigationInfo *navinfo); /* Nautilus View Identifiers associate a component name with a user displayable name */ static NautilusViewIdentifier * nautilus_view_identifier_new (const char *iid, const char *name) { - NautilusViewIdentifier *new_identifier; - - g_return_val_if_fail (iid != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - new_identifier = g_new0 (NautilusViewIdentifier, 1); - new_identifier->iid = g_strdup (iid); - new_identifier->name = g_strdup (name); - - return new_identifier; + NautilusViewIdentifier *new_identifier; + + g_return_val_if_fail (iid != NULL, NULL); + g_return_val_if_fail (name != NULL, NULL); + + new_identifier = g_new0 (NautilusViewIdentifier, 1); + new_identifier->iid = g_strdup (iid); + new_identifier->name = g_strdup (name); + + return new_identifier; } static void nautilus_view_identifier_free (NautilusViewIdentifier *identifier) { - if (identifier != NULL) - { - g_free (identifier->iid); - g_free (identifier->name); - g_free (identifier); - } + if (identifier != NULL) { + g_free (identifier->iid); + g_free (identifier->name); + g_free (identifier); + } } static NautilusNavigationResult get_nautilus_navigation_result_from_gnome_vfs_result (GnomeVFSResult gnome_vfs_result) { - switch (gnome_vfs_result) - { - case GNOME_VFS_OK: - return NAUTILUS_NAVIGATION_RESULT_OK; - case GNOME_VFS_ERROR_NOTFOUND: - case GNOME_VFS_ERROR_HOSTNOTFOUND: - return NAUTILUS_NAVIGATION_RESULT_NOT_FOUND; - case GNOME_VFS_ERROR_INVALIDURI: - return NAUTILUS_NAVIGATION_RESULT_INVALID_URI; - case GNOME_VFS_ERROR_NOTSUPPORTED: - return NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME; - case GNOME_VFS_ERROR_GENERIC: - /* This one has occurred at least once in the web browser component */ - return NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR; - default: - /* Whenever this message fires, we should consider adding a specific case - * to make the error as comprehensible as possible to the user. Please - * bug me (sullivan@eazel.com) if you see this fire and don't have the - * inclination to immediately make a good message yourself (tell me - * what GnomeVFSResult code the message reported, and what caused it to - * fire). - */ - g_message ("in ntl-uri-map.c, got unhandled GnomeVFSResult %d.", gnome_vfs_result); - return NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR; - } + switch (gnome_vfs_result) { + case GNOME_VFS_OK: + return NAUTILUS_NAVIGATION_RESULT_OK; + case GNOME_VFS_ERROR_NOTFOUND: + case GNOME_VFS_ERROR_HOSTNOTFOUND: + return NAUTILUS_NAVIGATION_RESULT_NOT_FOUND; + case GNOME_VFS_ERROR_INVALIDURI: + return NAUTILUS_NAVIGATION_RESULT_INVALID_URI; + case GNOME_VFS_ERROR_NOTSUPPORTED: + return NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME; + case GNOME_VFS_ERROR_GENERIC: + /* This one has occurred at least once in the web browser component */ + return NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR; + default: + /* Whenever this message fires, we should consider adding a specific case + * to make the error as comprehensible as possible to the user. Please + * bug me (sullivan@eazel.com) if you see this fire and don't have the + * inclination to immediately make a good message yourself (tell me + * what GnomeVFSResult code the message reported, and what caused it to + * fire). + */ + g_message ("in ntl-uri-map.c, got unhandled GnomeVFSResult %d", gnome_vfs_result); + return NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR; + } } /* GCompareFunc-style function for checking whether a given string matches @@ -109,10 +113,10 @@ check_iid (gconstpointer a, gconstpointer b) { NautilusViewIdentifier *identifier; char *string; - + identifier = (NautilusViewIdentifier *)a; string = (char *)b; - + return strcmp (identifier->iid, string) != 0; } @@ -131,7 +135,6 @@ static void set_initial_content_iid (NautilusNavigationInfo *navinfo, const char *fallback_value) { - NautilusDirectory *directory; char *remembered_value = NULL; const char *value = NULL; @@ -144,30 +147,29 @@ set_initial_content_iid (NautilusNavigationInfo *navinfo, * this to work that way. */ - directory = nautilus_directory_get (navinfo->navinfo.requested_uri); - if (directory != NULL) { - remembered_value = nautilus_directory_get_metadata (directory, - NAUTILUS_METADATA_KEY_INITIAL_VIEW, - NULL); - - /* Use the remembered value if it's non-NULL and in the list of choices. */ - if (remembered_value != NULL) { - if (g_slist_find_custom (navinfo->content_identifiers, remembered_value, check_iid)) { - value = remembered_value; - } else { - g_message ("Unknown iid \"%s\" stored for %s", remembered_value, navinfo->navinfo.requested_uri); - } - } - - nautilus_directory_unref (directory); - } - + remembered_value = nautilus_directory_get_metadata (navinfo->directory, + NAUTILUS_METADATA_KEY_INITIAL_VIEW, + NULL); + + /* Use the remembered value if it's non-NULL and in the list of choices. */ + if (remembered_value != NULL) { + if (g_slist_find_custom (navinfo->content_identifiers, + remembered_value, check_iid)) { + value = remembered_value; + } else { + g_message ("Unknown iid \"%s\" stored for %s", + remembered_value, + navinfo->navinfo.requested_uri); + } + } + if (value == NULL) { /* Can't use remembered value, use referring value if * it's non-NULL and in the list of choices. */ if (navinfo->referring_iid != NULL) { - if (g_slist_find_custom (navinfo->content_identifiers, navinfo->referring_iid, check_iid)) { + if (g_slist_find_custom (navinfo->content_identifiers, + navinfo->referring_iid, check_iid)) { value = navinfo->referring_iid; } } @@ -180,185 +182,172 @@ set_initial_content_iid (NautilusNavigationInfo *navinfo, navinfo->initial_content_iid = g_strdup (value); - if (remembered_value) - g_free (remembered_value); + g_free (remembered_value); } static void -my_notify_when_ready(GnomeVFSAsyncHandle *ah, GnomeVFSResult result, - GnomeVFSFileInfo *vfs_fileinfo, - gpointer data) +my_notify_when_ready (GnomeVFSAsyncHandle *ah, + GnomeVFSResult result, + GnomeVFSFileInfo *vfs_fileinfo, + gpointer data) { - NautilusNavigationInfo *navinfo = data; - NautilusNavigationInfoFunc notify_ready = navinfo->notify_ready; - gpointer notify_ready_data = navinfo->data; - const char *fallback_iid; - - if (navinfo->ah) { - gnome_vfs_async_cancel (navinfo->ah); - navinfo->ah = NULL; - } - - if(result != GNOME_VFS_OK) - { - /* Map GnomeVFSResult to one of the types that Nautilus knows how to handle. - * Leave navinfo intact so notify_ready function can access the uri. - * (notify_ready function is responsible for freeing navinfo). - */ - navinfo->result_code = get_nautilus_navigation_result_from_gnome_vfs_result (result); - if(navinfo->result_code == NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME - || navinfo->result_code == NAUTILUS_NAVIGATION_RESULT_INVALID_URI) - { - /* Special scheme mapping stuff */ - if(!strncmp(navinfo->navinfo.requested_uri, "irc://", 6)) - { - navinfo->navinfo.content_type = g_strdup("special/x-irc-session"); - navinfo->result_code = NAUTILUS_NAVIGATION_RESULT_OK; - } - else if (!strncmp(navinfo->navinfo.requested_uri, "eazel:", 6)) - { - navinfo->navinfo.content_type = g_strdup("special/eazel-service"); - navinfo->result_code = NAUTILUS_NAVIGATION_RESULT_OK; - } - else - goto out; + NautilusNavigationInfo *navinfo; + NautilusNavigationCallback notify_ready; + gpointer notify_ready_data; + const char *fallback_iid; + NautilusNavigationResult result_code; + + navinfo = data; + + navinfo->ah = NULL; + + notify_ready = navinfo->callback; + notify_ready_data = navinfo->callback_data; + + /* Get the content type. */ + if (result == GNOME_VFS_OK) { + navinfo->navinfo.content_type = g_strdup (gnome_vfs_file_info_get_mime_type (vfs_fileinfo)); + } else if (result == GNOME_VFS_ERROR_NOTSUPPORTED + || result == GNOME_VFS_ERROR_INVALIDURI) { + /* Special scheme mapping stuff */ + if (nautilus_str_has_prefix (navinfo->navinfo.requested_uri, "irc://")) { + navinfo->navinfo.content_type = g_strdup ("special/x-irc-session"); + result = GNOME_VFS_OK; + } else if (nautilus_str_has_prefix (navinfo->navinfo.requested_uri, "eazel:")) { + navinfo->navinfo.content_type = g_strdup ("special/eazel-service"); + result = GNOME_VFS_OK; + } } - else - goto out; - } - else - navinfo->navinfo.content_type = g_strdup(gnome_vfs_file_info_get_mime_type(vfs_fileinfo)); - - /* Given a content type and a URI, what do we do? Basically the "expert system" below - tries to answer that question - - Check if the URI is in an abnormal scheme (e.g. one not supported by gnome-vfs) - If so - Lookup content views by scheme name, go. - Lookup meta views by scheme name, go. - - If not - Figure out content type. - Lookup content views by content type, go. - Lookup meta views by content type, go. - - The lookup-and-go process works like: - Generate a list of all possibilities ordered by quality. - Put possibilities on menu. - - Find if the user has specified any default(s) globally, modify selection. - Find if the user has specified any default(s) per-page, modify selection. - */ - - /* This is just a hardcoded hack until OAF works with Bonobo. - In the future we will use OAF queries to determine this information. */ + + /* Map GnomeVFSResult to one of the types that Nautilus knows how to handle. */ + result_code = get_nautilus_navigation_result_from_gnome_vfs_result (result); - if (!navinfo->navinfo.content_type) - navinfo->navinfo.content_type = g_strdup("text/plain"); + if (result != GNOME_VFS_OK) { + /* Leave navinfo intact so notify_ready function can access the uri. + * (notify_ready function is responsible for freeing navinfo). + */ + goto out; + } - - if (!strcmp(navinfo->navinfo.content_type, "text/html")) - { - fallback_iid = "ntl_web_browser"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_web_browser", "Web Page")); - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("embeddable:text-plain", "Text")); - } - else if (!strncmp(navinfo->navinfo.content_type, "image/", 6)) - { - fallback_iid = "eog-image-viewer"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("eog-image-viewer", "Image")); - } - else if (!strcmp(navinfo->navinfo.content_type, "special/x-irc-session")) - { - fallback_iid = "xchat"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("xchat", "Chat room")); - } - else if (!strcmp(navinfo->navinfo.content_type, "special/directory") - || !strcmp(navinfo->navinfo.content_type, "application/x-nautilus-vdir")) - { - fallback_iid = "ntl_file_manager_icon_view"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_file_manager_icon_view", "Icons")); - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_file_manager_list_view", "List")); - - /* besides the information in OAF/GConf, we also want to offer components that are specifically refered to in the metadata, - so we ask the metadata for content views here and add them accordingly. */ - - /* FIXME: for now, we just do this for directories but it should apply to all places with available metadata */ - add_components_from_metadata(navinfo); - } - else if (!strcmp(navinfo->navinfo.content_type, "special/webdav-directory")) - { - fallback_iid = "ntl_web_browser"; - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_web_browser", "Web Page")); - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_file_manager_icon_view", "Icons")); - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_file_manager_list_view", "List")); - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new ("embeddable:text-plain", "Text")); - - - /* besides the information in OAF/GConf, we also want to offer components that are specifically refered to in the metadata, - so we ask the metadata for content views here and add them accordingly. */ + /* Given a content type and a URI, what do we do? Basically the "expert system" below + tries to answer that question + + Check if the URI is in an abnormal scheme (e.g. one not supported by gnome-vfs) + If so + Lookup content views by scheme name, go. + Lookup meta views by scheme name, go. + + If not + Figure out content type. + Lookup content views by content type, go. + Lookup meta views by content type, go. + + The lookup-and-go process works like: + Generate a list of all possibilities ordered by quality. + Put possibilities on menu. + + Find if the user has specified any default(s) globally, modify selection. + Find if the user has specified any default(s) per-page, modify selection. + */ + + /* This is just a hardcoded hack until OAF works with Bonobo. + In the future we will use OAF queries to determine this information. */ + + if (navinfo->navinfo.content_type == NULL) { + navinfo->navinfo.content_type = g_strdup ("text/plain"); + } + + if (strcmp (navinfo->navinfo.content_type, "text/html") == 0) { + fallback_iid = "ntl_web_browser"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_web_browser", "Web Page")); + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("embeddable:text-plain", "Text")); + } else if (nautilus_str_has_prefix (navinfo->navinfo.content_type, "image/")) { + fallback_iid = "eog-image-viewer"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("eog-image-viewer", "Image")); + } else if (strcmp (navinfo->navinfo.content_type, "special/x-irc-session") == 0) { + fallback_iid = "xchat"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("xchat", "Chat room")); + } else if (strcmp(navinfo->navinfo.content_type, "special/directory") == 0 + || strcmp(navinfo->navinfo.content_type, "application/x-nautilus-vdir") == 0) { + fallback_iid = "ntl_file_manager_icon_view"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_file_manager_icon_view", "Icons")); + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_file_manager_list_view", "List")); + + /* besides the information in OAF/GConf, we also want to offer components that are specifically refered to in the metadata, + so we ask the metadata for content views here and add them accordingly. */ + + /* FIXME: for now, we just do this for directories but it should apply to all places with available metadata */ + add_components_from_metadata (navinfo); + } else if (strcmp (navinfo->navinfo.content_type, "special/webdav-directory")) { + fallback_iid = "ntl_web_browser"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_web_browser", "Web Page")); + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_file_manager_icon_view", "Icons")); + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_file_manager_list_view", "List")); + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("embeddable:text-plain", "Text")); + + /* besides the information in OAF/GConf, we also want to offer components that are specifically refered to in the metadata, + so we ask the metadata for content views here and add them accordingly. */ - /* FIXME: for now, we just do this for directories but it should apply to all places with available metadata */ - add_components_from_metadata(navinfo); - } - else if (!strcmp(navinfo->navinfo.content_type, "application/x-rpm") || nautilus_str_has_suffix(navinfo->navinfo.requested_uri, ".rpm")) - { - fallback_iid = "nautilus_rpm_view"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("nautilus_rpm_view", "Package")); - } - else if (!strcmp(navinfo->navinfo.content_type, "special/eazel-service")) - { - fallback_iid = "nautilus_service_startup_view"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("nautilus_service_startup_view", "Service")); - } - else if(!strcmp(navinfo->navinfo.content_type, "text/plain")) - { - fallback_iid = "embeddable:text-plain"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("embeddable:text-plain", "Text")); - } - else - { - /* Can't display file; nothing registered to handle this file type. */ - navinfo->result_code = NAUTILUS_NAVIGATION_RESULT_NO_HANDLER_FOR_TYPE; - goto out; - } - - /* FIXME: Should do this only when in some special testing mode or something. */ - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new ("nautilus_sample_content_view", "Sample")); - - /* Now that all the content_identifiers are in place, we're ready to choose - * the initial one. - */ - g_assert (fallback_iid != NULL); - set_initial_content_iid (navinfo, fallback_iid); - - add_meta_view_iids_from_preferences (navinfo); - + /* FIXME: for now, we just do this for directories but it should apply to all places with available metadata */ + add_components_from_metadata (navinfo); + } + else if (strcmp (navinfo->navinfo.content_type, "application/x-rpm") == 0 + || nautilus_str_has_suffix (navinfo->navinfo.requested_uri, ".rpm")) { + fallback_iid = "nautilus_rpm_view"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("nautilus_rpm_view", "Package")); + } else if (strcmp(navinfo->navinfo.content_type, "special/eazel-service")) { + fallback_iid = "nautilus_service_startup_view"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("nautilus_service_startup_view", "Service")); + } else if (strcmp(navinfo->navinfo.content_type, "text/plain") == 0) { + fallback_iid = "embeddable:text-plain"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("embeddable:text-plain", "Text")); + } else { + /* Can't display file; nothing registered to handle this file type. */ + result_code = NAUTILUS_NAVIGATION_RESULT_NO_HANDLER_FOR_TYPE; + goto out; + } + + /* FIXME: Should do this only when in some special testing mode or something. */ + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("nautilus_sample_content_view", "Sample")); + + add_meta_view_iids_from_preferences (navinfo); + + /* Now that all the content_identifiers are in place, we're ready to choose + * the initial one. + */ + g_assert (fallback_iid != NULL); + set_initial_content_iid (navinfo, fallback_iid); + out: - notify_ready(navinfo, notify_ready_data); + (* notify_ready) (result_code, navinfo, notify_ready_data); } /* The following routine uses metadata associated with the current url to add content view components specified in the metadata */ @@ -367,19 +356,20 @@ my_notify_when_ready(GnomeVFSAsyncHandle *ah, GnomeVFSResult result, static void add_components_from_metadata (NautilusNavigationInfo *navinfo) { - NautilusDirectory *directory; char *content_views; + char **pieces; + const char *component_str; + char *colon_pos; + int index; - directory = nautilus_directory_get (navinfo->navinfo.requested_uri); + content_views = nautilus_directory_get_metadata + (navinfo->directory, + NAUTILUS_METADATA_KEY_CONTENT_VIEWS, NULL); - content_views = nautilus_directory_get_metadata (directory, NAUTILUS_METADATA_KEY_CONTENT_VIEWS, NULL); if (content_views != NULL) { - char **pieces; - const char *component_str; - char *colon_pos; - int index; - pieces = g_strsplit (content_views, "\n", 0); + g_free (content_views); + for (index = 0; (component_str = pieces[index]) != NULL; index++) { /* break the component string into the name and label */ colon_pos = strchr(component_str, ':'); @@ -387,128 +377,146 @@ add_components_from_metadata (NautilusNavigationInfo *navinfo) *colon_pos++ = '\0'; /* add it to the list */ - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new (component_str, colon_pos)); - } + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new (component_str, colon_pos)); + } } - g_strfreev (pieces); - g_free (content_views); + g_strfreev (pieces); } - - nautilus_directory_unref (directory); } static void add_meta_view_iids_from_preferences (NautilusNavigationInfo *navinfo) { const NautilusStringList *meta_view_iids; - guint i; - + guint i; + char *iid; + gboolean enabled; + GString *pref_name; + g_assert (navinfo != NULL); - meta_view_iids= nautilus_global_preferences_get_meta_view_iids (); - + meta_view_iids = nautilus_global_preferences_get_meta_view_iids (); g_assert (meta_view_iids != NULL); - for (i = 0; i < nautilus_string_list_get_length (meta_view_iids); i++) - { - char *iid; - gboolean enabled; - GString *pref_name; - + for (i = 0; i < nautilus_string_list_get_length (meta_view_iids); i++) { iid = nautilus_string_list_nth (meta_view_iids, i); - g_assert (iid != NULL); pref_name = g_string_new ("/nautilus/metaviews/"); - g_string_append (pref_name, iid); - enabled = nautilus_preferences_get_boolean (nautilus_preferences_get_global_preferences (), pref_name->str); - - g_string_free (pref_name, TRUE); - if (enabled) - { - navinfo->meta_iids = g_slist_prepend (navinfo->meta_iids, g_strdup (iid)); - } - - g_free (iid); + if (enabled) { + navinfo->meta_iids = g_slist_prepend (navinfo->meta_iids, iid); + } else { + g_free (iid); + } } } +static void +got_metadata_callback (NautilusDirectory *directory, + gpointer callback_data) +{ + NautilusNavigationInfo *info; + GnomeVFSResult result; + + info = callback_data; + g_assert (info->directory == directory); + + result = gnome_vfs_async_get_file_info (&info->ah, + info->navinfo.requested_uri, + (GNOME_VFS_FILE_INFO_GETMIMETYPE + | GNOME_VFS_FILE_INFO_FOLLOWLINKS), + NULL, + my_notify_when_ready, + info); + + if (result != GNOME_VFS_OK) { + /* Note: Not sure if or when this case ever occurs. result == GNOME_VFS_OK + * for normally-handled uris, for non-existent uris, and for uris for which + * Nautilus has no content viewer. + */ + my_notify_when_ready (NULL, result, NULL, info); + } +} -/* navinfo stuff */ +/* NautilusNavigationInfo */ -void -nautilus_navinfo_init(void) +NautilusNavigationInfo * +nautilus_navigation_info_new (Nautilus_NavigationRequestInfo *nri, + Nautilus_NavigationInfo *old_navinfo, + NautilusNavigationCallback notify_when_ready, + gpointer notify_data, + const char *referring_iid) { + NautilusNavigationInfo *navinfo; + GList *metadata_keys; + + navinfo = g_new0 (NautilusNavigationInfo, 1); + + navinfo->callback = notify_when_ready; + navinfo->callback_data = notify_data; + + if (old_navinfo != NULL) { + navinfo->navinfo.referring_uri = old_navinfo->requested_uri; + navinfo->navinfo.actual_referring_uri = old_navinfo->actual_uri; + navinfo->navinfo.referring_content_type = old_navinfo->content_type; + } + + navinfo->referring_iid = g_strdup (referring_iid); + navinfo->navinfo.requested_uri = g_strdup (nri->requested_uri); + + navinfo->directory = nautilus_directory_get (nri->requested_uri); + + /* Arrange for all the metadata we will need. */ + metadata_keys = NULL; + metadata_keys = g_list_prepend (metadata_keys, NAUTILUS_METADATA_KEY_CONTENT_VIEWS); + metadata_keys = g_list_prepend (metadata_keys, NAUTILUS_METADATA_KEY_INITIAL_VIEW); + nautilus_directory_metadata_call_when_ready + (navinfo->directory, + metadata_keys, + got_metadata_callback, + navinfo); + g_list_free (metadata_keys); + + return navinfo; } -gpointer -nautilus_navinfo_new(Nautilus_NavigationRequestInfo *nri, - Nautilus_NavigationInfo *old_navinfo, - NautilusNavigationInfoFunc notify_when_ready, - gpointer notify_data, - const char *referring_iid) +void +nautilus_navigation_info_cancel (NautilusNavigationInfo *info) { - GnomeVFSResult res; - const char *meta_keys[] = {"icon-filename", NULL}; - NautilusNavigationInfo *navinfo; - - navinfo = g_new0(NautilusNavigationInfo, 1); - - navinfo->notify_ready = notify_when_ready; - navinfo->data = notify_data; - - if(old_navinfo) - { - navinfo->navinfo.referring_uri = old_navinfo->requested_uri; - navinfo->navinfo.actual_referring_uri = old_navinfo->actual_uri; - navinfo->navinfo.referring_content_type = old_navinfo->content_type; - } - - if (referring_iid != NULL) - navinfo->referring_iid = g_strdup (referring_iid); - - navinfo->navinfo.requested_uri = g_strdup(nri->requested_uri); - - res = gnome_vfs_async_get_file_info(&navinfo->ah, navinfo->navinfo.requested_uri, - GNOME_VFS_FILE_INFO_GETMIMETYPE - |GNOME_VFS_FILE_INFO_FOLLOWLINKS, - meta_keys, my_notify_when_ready, navinfo); - - if(res != GNOME_VFS_OK) - { - /* Note: Not sure if or when this case ever occurs. res == GNOME_VFS_OK - * for normally-handled uris, for non-existent uris, and for uris for which - * Nautilus has no content viewer. - */ - navinfo->ah = NULL; - my_notify_when_ready(NULL, res, NULL, navinfo); - } - - return navinfo?navinfo->ah:NULL; + g_return_if_fail (info != NULL); + + if (info->ah != NULL) { + gnome_vfs_async_cancel (info->ah); + info->ah = NULL; + } + + nautilus_directory_metadata_callback_cancel + (info->directory, got_metadata_callback, info); } void -nautilus_navinfo_free(NautilusNavigationInfo *navinfo) +nautilus_navigation_info_free (NautilusNavigationInfo *navinfo) { - g_return_if_fail(navinfo != NULL); - - if (navinfo->ah) - gnome_vfs_async_cancel (navinfo->ah); - - g_slist_foreach(navinfo->content_identifiers, (GFunc)nautilus_view_identifier_free, NULL); - g_slist_free(navinfo->content_identifiers); - g_slist_foreach(navinfo->meta_iids, (GFunc)g_free, NULL); - g_slist_free(navinfo->meta_iids); - g_free(navinfo->referring_iid); - g_free(navinfo->initial_content_iid); - g_free(navinfo->navinfo.requested_uri); - g_free(navinfo->navinfo.actual_uri); - g_free(navinfo->navinfo.content_type); - g_free(navinfo); + g_return_if_fail (navinfo != NULL); + + nautilus_navigation_info_cancel (navinfo); + + g_slist_foreach (navinfo->content_identifiers, (GFunc) nautilus_view_identifier_free, NULL); + g_slist_free (navinfo->content_identifiers); + g_slist_foreach (navinfo->meta_iids, (GFunc) g_free, NULL); + g_slist_free (navinfo->meta_iids); + g_free (navinfo->referring_iid); + g_free (navinfo->initial_content_iid); + g_free (navinfo->navinfo.requested_uri); + g_free (navinfo->navinfo.actual_uri); + g_free (navinfo->navinfo.content_type); + nautilus_directory_unref (navinfo->directory); + g_free (navinfo); } diff --git a/src/nautilus-applicable-views.h b/src/nautilus-applicable-views.h index ca659fb24..9d111de51 100644 --- a/src/nautilus-applicable-views.h +++ b/src/nautilus-applicable-views.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* * Nautilus @@ -22,20 +22,59 @@ * Author: Elliot Lee <sopwith@redhat.com> * */ + /* ntl-uri-map.h: Interface for mapping a location change request to a set of views and actual URL to be loaded. */ #ifndef NAUTILUS_URI_MAP_H -#define NAUTILUS_URI_MAP_H 1 - -#include "ntl-types.h" -#include "ntl-view.h" - -void nautilus_navinfo_init(void); -gpointer nautilus_navinfo_new(Nautilus_NavigationRequestInfo *nri, - Nautilus_NavigationInfo *old_navinfo, - NautilusNavigationInfoFunc notify_when_ready, - gpointer notify_data, - const char *referring_iid); -void nautilus_navinfo_free(NautilusNavigationInfo *navinfo); +#define NAUTILUS_URI_MAP_H + +#include <glib.h> +#include <libgnomevfs/gnome-vfs-types.h> +#include <libnautilus/nautilus.h> +#include <libnautilus/nautilus-directory.h> + +typedef struct NautilusNavigationInfo NautilusNavigationInfo; + +/* These are the different ways that Nautilus can fail to + * display the contents of a given uri. NAUTILUS_NAVIGATION_RESULT_OK + * means the uri was displayed successfully. These are similar to + * GnomeVFSResults but there are nautilus-specific codes and many of + * the GnomeVFSResults are treated the same here. + */ +typedef enum { + NAUTILUS_NAVIGATION_RESULT_OK, + NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR, + NAUTILUS_NAVIGATION_RESULT_NO_HANDLER_FOR_TYPE, + NAUTILUS_NAVIGATION_RESULT_NOT_FOUND, + NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME, + NAUTILUS_NAVIGATION_RESULT_INVALID_URI +} NautilusNavigationResult; + +typedef void (*NautilusNavigationCallback) (NautilusNavigationResult result, + NautilusNavigationInfo *info, + gpointer callback_data); + +struct NautilusNavigationInfo { + Nautilus_NavigationInfo navinfo; + + char *referring_iid; /* iid of content view that we're coming from */ + char *initial_content_iid; /* iid to use for content view that we're going to display */ + GSList *content_identifiers; /* list of NautilusViewIdentifiers */ + GSList *meta_iids; /* list of iid strings */ + + /* internal usage */ + NautilusNavigationCallback callback; + gpointer callback_data; + GnomeVFSAsyncHandle *ah; + NautilusDirectory *directory; +}; + +NautilusNavigationInfo *nautilus_navigation_info_new (Nautilus_NavigationRequestInfo *request, + Nautilus_NavigationInfo *previous_location, + NautilusNavigationCallback ready_callback, + gpointer callback_data, + const char *referring_iid); +void nautilus_navigation_info_cancel (NautilusNavigationInfo *info); +void nautilus_navigation_info_free (NautilusNavigationInfo *info); #endif diff --git a/src/nautilus-application.c b/src/nautilus-application.c index b6780a520..f8b0c9a0a 100644 --- a/src/nautilus-application.c +++ b/src/nautilus-application.c @@ -254,8 +254,6 @@ nautilus_app_startup(NautilusApp *app, const char *initial_url) { NautilusWindow *mainwin; - nautilus_navinfo_init(); - /* Set default configuration */ mainwin = nautilus_app_create_window(app); bonobo_activate(); diff --git a/src/nautilus-information-panel.c b/src/nautilus-information-panel.c index 03e3fc6bd..3d2000982 100644 --- a/src/nautilus-information-panel.c +++ b/src/nautilus-information-panel.c @@ -28,6 +28,7 @@ #include "ntl-index-panel.h" #include <math.h> +#include <libgnomevfs/gnome-vfs-types.h> #include <libgnomevfs/gnome-vfs-uri.h> #include <gdk-pixbuf/gdk-pixbuf.h> #include <libnautilus/nautilus-background.h> diff --git a/src/nautilus-main.c b/src/nautilus-main.c index 43d4b25bf..99e24b07d 100644 --- a/src/nautilus-main.c +++ b/src/nautilus-main.c @@ -34,6 +34,7 @@ #include <libnautilus/nautilus-debug.h> #include <libnautilus/nautilus-lib-self-check-functions.h> #include <libnautilus/nautilus-self-checks.h> +#include <libgnomevfs/gnome-vfs-init.h> int main(int argc, char *argv[]) diff --git a/src/nautilus-navigation-window.c b/src/nautilus-navigation-window.c index dcc93dc3b..250b15f55 100644 --- a/src/nautilus-navigation-window.c +++ b/src/nautilus-navigation-window.c @@ -43,6 +43,7 @@ #include <libnautilus/nautilus-string.h> #include "nautilus-zoom-control.h" #include <ctype.h> +#include <libgnomevfs/gnome-vfs-uri.h> enum { diff --git a/src/nautilus-navigation-window.h b/src/nautilus-navigation-window.h index af5e9926a..8b353150b 100644 --- a/src/nautilus-navigation-window.h +++ b/src/nautilus-navigation-window.h @@ -30,7 +30,7 @@ #include <libgnomeui/gnome-app.h> #include <libnautilus/nautilus-bookmark.h> -#include "ntl-types.h" +#include "ntl-uri-map.h" #include "ntl-view.h" #include "ntl-index-panel.h" @@ -106,7 +106,7 @@ struct _NautilusWindow { enum { NW_LOADING_INFO, NW_LOADING_VIEWS, NW_IDLE } state; - gpointer cancel_tag; + NautilusNavigationInfo *cancel_tag; guint action_tag; guint16 made_changes, making_changes; diff --git a/src/nautilus-object-window.c b/src/nautilus-object-window.c index dcc93dc3b..250b15f55 100644 --- a/src/nautilus-object-window.c +++ b/src/nautilus-object-window.c @@ -43,6 +43,7 @@ #include <libnautilus/nautilus-string.h> #include "nautilus-zoom-control.h" #include <ctype.h> +#include <libgnomevfs/gnome-vfs-uri.h> enum { diff --git a/src/nautilus-object-window.h b/src/nautilus-object-window.h index af5e9926a..8b353150b 100644 --- a/src/nautilus-object-window.h +++ b/src/nautilus-object-window.h @@ -30,7 +30,7 @@ #include <libgnomeui/gnome-app.h> #include <libnautilus/nautilus-bookmark.h> -#include "ntl-types.h" +#include "ntl-uri-map.h" #include "ntl-view.h" #include "ntl-index-panel.h" @@ -106,7 +106,7 @@ struct _NautilusWindow { enum { NW_LOADING_INFO, NW_LOADING_VIEWS, NW_IDLE } state; - gpointer cancel_tag; + NautilusNavigationInfo *cancel_tag; guint action_tag; guint16 made_changes, making_changes; diff --git a/src/nautilus-sidebar.c b/src/nautilus-sidebar.c index 03e3fc6bd..3d2000982 100644 --- a/src/nautilus-sidebar.c +++ b/src/nautilus-sidebar.c @@ -28,6 +28,7 @@ #include "ntl-index-panel.h" #include <math.h> +#include <libgnomevfs/gnome-vfs-types.h> #include <libgnomevfs/gnome-vfs-uri.h> #include <gdk-pixbuf/gdk-pixbuf.h> #include <libnautilus/nautilus-background.h> diff --git a/src/nautilus-spatial-window.c b/src/nautilus-spatial-window.c index dcc93dc3b..250b15f55 100644 --- a/src/nautilus-spatial-window.c +++ b/src/nautilus-spatial-window.c @@ -43,6 +43,7 @@ #include <libnautilus/nautilus-string.h> #include "nautilus-zoom-control.h" #include <ctype.h> +#include <libgnomevfs/gnome-vfs-uri.h> enum { diff --git a/src/nautilus-spatial-window.h b/src/nautilus-spatial-window.h index af5e9926a..8b353150b 100644 --- a/src/nautilus-spatial-window.h +++ b/src/nautilus-spatial-window.h @@ -30,7 +30,7 @@ #include <libgnomeui/gnome-app.h> #include <libnautilus/nautilus-bookmark.h> -#include "ntl-types.h" +#include "ntl-uri-map.h" #include "ntl-view.h" #include "ntl-index-panel.h" @@ -106,7 +106,7 @@ struct _NautilusWindow { enum { NW_LOADING_INFO, NW_LOADING_VIEWS, NW_IDLE } state; - gpointer cancel_tag; + NautilusNavigationInfo *cancel_tag; guint action_tag; guint16 made_changes, making_changes; diff --git a/src/nautilus-view-frame-private.h b/src/nautilus-view-frame-private.h index 648ec9369..41c4f0adb 100644 --- a/src/nautilus-view-frame-private.h +++ b/src/nautilus-view-frame-private.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* * Nautilus @@ -23,53 +23,52 @@ * Author: Elliot Lee <sopwith@redhat.com> * */ + /* ntl-view-private.h: Internals of the view proxy that are shared between different implementation files */ + #ifndef NTL_VIEW_PRIVATE_H -#define NTL_VIEW_PRIVATE_H 1 +#define NTL_VIEW_PRIVATE_H #include "nautilus.h" typedef struct { - POA_Nautilus_ViewFrame servant; - gpointer bonobo_object; - - NautilusView *view; + POA_Nautilus_ViewFrame servant; + gpointer bonobo_object; + + NautilusView *view; } impl_POA_Nautilus_ViewFrame; extern POA_Nautilus_ViewFrame__vepv impl_Nautilus_ViewFrame_vepv; extern POA_Nautilus_ZoomableFrame__vepv impl_Nautilus_ZoomableFrame_vepv; -BonoboObject *impl_Nautilus_ViewFrame__create (NautilusView *view, - CORBA_Environment * ev); -BonoboObject *impl_Nautilus_ZoomableFrame__create (NautilusView *view, - CORBA_Environment * ev); - -void nautilus_view_request_location_change (NautilusView *view, - Nautilus_NavigationRequestInfo *loc); -void nautilus_view_request_selection_change (NautilusView *view, - Nautilus_SelectionRequestInfo *loc); -void nautilus_view_request_status_change (NautilusView *view, - Nautilus_StatusRequestInfo *loc); -void nautilus_view_request_progress_change (NautilusView *view, - Nautilus_ProgressRequestInfo *loc); +BonoboObject *impl_Nautilus_ViewFrame__create (NautilusView *view, + CORBA_Environment *ev); +BonoboObject *impl_Nautilus_ZoomableFrame__create (NautilusView *view, + CORBA_Environment *ev); +void nautilus_view_request_location_change (NautilusView *view, + Nautilus_NavigationRequestInfo *loc); +void nautilus_view_request_selection_change (NautilusView *view, + Nautilus_SelectionRequestInfo *loc); +void nautilus_view_request_status_change (NautilusView *view, + Nautilus_StatusRequestInfo *loc); +void nautilus_view_request_progress_change (NautilusView *view, + Nautilus_ProgressRequestInfo *loc); +void nautilus_view_notify_zoom_level (NautilusView *view, + double level); -void nautilus_view_notify_zoom_level (NautilusView *view, - double level); - - -struct _NautilusViewComponentType { - const char *primary_repoid; - gboolean (* try_load)(NautilusView *view, CORBA_Object obj, CORBA_Environment *ev); - void (* destroy) (NautilusView *view, CORBA_Environment *ev); - void (* save_state)(NautilusView *view, const char *config_path, CORBA_Environment *ev); - void (* load_state)(NautilusView *view, const char *config_path, CORBA_Environment *ev); - void (* notify_location_change)(NautilusView *view, Nautilus_NavigationInfo *nav_ctx, CORBA_Environment *ev); - void (* stop_location_change)(NautilusView *view, CORBA_Environment *ev); - void (* notify_selection_change)(NautilusView *view, Nautilus_SelectionInfo *nav_ctx, CORBA_Environment *ev); - void (* show_properties)(NautilusView *view, CORBA_Environment *ev); - - char * (* get_label)(NautilusView *view, CORBA_Environment *ev); +struct NautilusViewComponentType { + const char *primary_repoid; + gboolean (* try_load)(NautilusView *view, CORBA_Object obj, CORBA_Environment *ev); + void (* destroy) (NautilusView *view, CORBA_Environment *ev); + void (* save_state)(NautilusView *view, const char *config_path, CORBA_Environment *ev); + void (* load_state)(NautilusView *view, const char *config_path, CORBA_Environment *ev); + void (* notify_location_change)(NautilusView *view, Nautilus_NavigationInfo *nav_ctx, CORBA_Environment *ev); + void (* stop_location_change)(NautilusView *view, CORBA_Environment *ev); + void (* notify_selection_change)(NautilusView *view, Nautilus_SelectionInfo *nav_ctx, CORBA_Environment *ev); + void (* show_properties)(NautilusView *view, CORBA_Environment *ev); + char * (* get_label)(NautilusView *view, CORBA_Environment *ev); }; -#endif +#endif /* NTL_VIEW_PRIVATE_H */ + diff --git a/src/nautilus-view-frame.h b/src/nautilus-view-frame.h index e6c6d0d47..7472141e6 100644 --- a/src/nautilus-view-frame.h +++ b/src/nautilus-view-frame.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* * Nautilus @@ -23,125 +23,121 @@ * Author: Elliot Lee <sopwith@redhat.com> * */ + /* ntl-view.h: Interface of the object representing a data view. NautilusContentView and NautilusMetaView derive from this class. */ -#ifndef __NAUTILUS_VIEW_H__ -#define __NAUTILUS_VIEW_H__ +#ifndef NAUTILUS_VIEW_H +#define NAUTILUS_VIEW_H #include <gtk/gtkwidget.h> #include <gtk/gtkbin.h> -#include "ntl-types.h" #include <bonobo.h> +#include <libnautilus/nautilus.h> #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -#define NAUTILUS_TYPE_VIEW (nautilus_view_get_type ()) -#define NAUTILUS_VIEW(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_VIEW, NautilusView)) -#define NAUTILUS_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_VIEW, NautilusViewClass)) -#define NAUTILUS_IS_VIEW(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_VIEW)) -#define NAUTILUS_IS_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), NAUTILUS_TYPE_VIEW)) - -typedef struct _NautilusView NautilusView; -typedef struct _NautilusViewClass NautilusViewClass; - -struct _NautilusViewClass -{ - GtkBinClass parent_spot; - - /* These signals correspond to the Natuilus:ViewFrame CORBA interface. They - are requests that the underlying view may make of the framework. */ - - void (*request_location_change) (NautilusView *view, - Nautilus_NavigationRequestInfo *navinfo); - void (*request_selection_change) (NautilusView *view, - Nautilus_SelectionRequestInfo *selinfo); - void (*request_status_change) (NautilusView *view, - Nautilus_StatusRequestInfo *loc); - void (*request_progress_change) (NautilusView *view, - Nautilus_ProgressRequestInfo *loc); - void (*notify_zoom_level) (NautilusView *view, - gdouble zoom_level); - - /* Not a signal. Work-around for Gtk+'s lack of a 'constructed' operation */ - void (*view_constructed) (NautilusView *view); - - GtkBinClass *parent_class; - guint num_construct_args; - - gpointer servant_init_func, servant_destroy_func, vepv; - gpointer zoomable_servant_init_func, zoomable_servant_destroy_func, zoomable_vepv; +#define NAUTILUS_TYPE_VIEW (nautilus_view_get_type ()) +#define NAUTILUS_VIEW(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_VIEW, NautilusView)) +#define NAUTILUS_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_VIEW, NautilusViewClass)) +#define NAUTILUS_IS_VIEW(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_VIEW)) +#define NAUTILUS_IS_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), NAUTILUS_TYPE_VIEW)) + +typedef struct NautilusView NautilusView; +typedef struct NautilusViewClass NautilusViewClass; + +struct NautilusViewClass { + GtkBinClass parent_spot; + + /* These signals correspond to the Natuilus:ViewFrame CORBA interface. They + are requests that the underlying view may make of the framework. */ + + void (*request_location_change) (NautilusView *view, + Nautilus_NavigationRequestInfo *navinfo); + void (*request_selection_change) (NautilusView *view, + Nautilus_SelectionRequestInfo *selinfo); + void (*request_status_change) (NautilusView *view, + Nautilus_StatusRequestInfo *loc); + void (*request_progress_change) (NautilusView *view, + Nautilus_ProgressRequestInfo *loc); + void (*notify_zoom_level) (NautilusView *view, + gdouble zoom_level); + + /* Not a signal. Work-around for Gtk+'s lack of a 'constructed' operation */ + void (*view_constructed) (NautilusView *view); + + GtkBinClass *parent_class; + guint num_construct_args; + + gpointer servant_init_func, servant_destroy_func, vepv; + gpointer zoomable_servant_init_func, zoomable_servant_destroy_func, zoomable_vepv; }; -typedef struct _NautilusViewComponentType NautilusViewComponentType; - -struct _NautilusView -{ - GtkBin parent; - - GtkWidget *main_window; - - char *iid; - - BonoboObjectClient *client_object; - GtkWidget *client_widget; - - BonoboObject *view_frame; - BonoboObject *zoomable_frame; - - Nautilus_Zoomable zoomable; - NautilusViewComponentType *component_class; - gpointer component_data; - - guint construct_arg_count; - - guint timer_id; - guint checking; +typedef struct NautilusViewComponentType NautilusViewComponentType; + +struct NautilusView { + GtkBin parent; + + GtkWidget *main_window; + + char *iid; + + BonoboObjectClient *client_object; + GtkWidget *client_widget; + + BonoboObject *view_frame; + BonoboObject *zoomable_frame; + + Nautilus_Zoomable zoomable; + NautilusViewComponentType *component_class; + gpointer component_data; + + guint construct_arg_count; + + guint timer_id; + guint checking; }; -GtkType nautilus_view_get_type (void); -gboolean nautilus_view_load_client (NautilusView *view, - const char * iid); -const char *nautilus_view_get_iid (NautilusView *view); -CORBA_Object nautilus_view_get_client_objref (NautilusView *view); -BonoboObject *nautilus_view_get_control_frame (NautilusView *view); -CORBA_Object nautilus_view_get_objref (NautilusView *view); +GtkType nautilus_view_get_type (void); +gboolean nautilus_view_load_client (NautilusView *view, + const char *iid); +const char * nautilus_view_get_iid (NautilusView *view); +CORBA_Object nautilus_view_get_client_objref (NautilusView *view); +BonoboObject *nautilus_view_get_control_frame (NautilusView *view); +CORBA_Object nautilus_view_get_objref (NautilusView *view); /* These functions correspond to methods of the Nautilus:View CORBAinterface */ - -void nautilus_view_notify_location_change (NautilusView *view, - Nautilus_NavigationInfo *nav_context); -void nautilus_view_notify_selection_change (NautilusView *view, - Nautilus_SelectionInfo *sel_context); -void nautilus_view_load_state (NautilusView *view, - const char *config_path); -void nautilus_view_save_state (NautilusView *view, - const char *config_path); -void nautilus_view_show_properties (NautilusView *view); -void nautilus_view_stop_location_change (NautilusView *view); -void nautilus_view_set_active_errors (NautilusView *view, gboolean enabled); - - -gboolean nautilus_view_is_zoomable (NautilusView *view); -gdouble nautilus_view_get_zoom_level (NautilusView *view); -void nautilus_view_set_zoom_level (NautilusView *view, - gdouble zoom_level); -gdouble nautilus_view_get_min_zoom_level (NautilusView *view); -gdouble nautilus_view_get_max_zoom_level (NautilusView *view); -gboolean nautilus_view_get_is_continuous (NautilusView *view); -void nautilus_view_zoom_in (NautilusView *view); -void nautilus_view_zoom_out (NautilusView *view); -void nautilus_view_zoom_to_fit (NautilusView *view); - +void nautilus_view_notify_location_change (NautilusView *view, + Nautilus_NavigationInfo *nav_context); +void nautilus_view_notify_selection_change (NautilusView *view, + Nautilus_SelectionInfo *sel_context); +void nautilus_view_load_state (NautilusView *view, + const char *config_path); +void nautilus_view_save_state (NautilusView *view, + const char *config_path); +void nautilus_view_show_properties (NautilusView *view); +void nautilus_view_stop_location_change (NautilusView *view); +void nautilus_view_set_active_errors (NautilusView *view, + gboolean enabled); +gboolean nautilus_view_is_zoomable (NautilusView *view); +gdouble nautilus_view_get_zoom_level (NautilusView *view); +void nautilus_view_set_zoom_level (NautilusView *view, + gdouble zoom_level); +gdouble nautilus_view_get_min_zoom_level (NautilusView *view); +gdouble nautilus_view_get_max_zoom_level (NautilusView *view); +gboolean nautilus_view_get_is_continuous (NautilusView *view); +void nautilus_view_zoom_in (NautilusView *view); +void nautilus_view_zoom_out (NautilusView *view); +void nautilus_view_zoom_to_fit (NautilusView *view); /* This is a "protected" operation */ -void nautilus_view_construct_arg_set(NautilusView *view); +void nautilus_view_construct_arg_set (NautilusView *view); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* __NAUTILUS_VIEW_H__ */ +#endif /* NAUTILUS_VIEW_H */ diff --git a/src/nautilus-window-manage-views.c b/src/nautilus-window-manage-views.c index 6f6953543..776ecfb0f 100644 --- a/src/nautilus-window-manage-views.c +++ b/src/nautilus-window-manage-views.c @@ -36,6 +36,8 @@ #include <stdarg.h> #include <libgnome/gnome-i18n.h> #include <libgnomeui/gnome-dialog-util.h> +#include <libgnomevfs/gnome-vfs-uri.h> +#include <libgnomevfs/gnome-vfs-async-ops.h> #include <libnautilus/nautilus-string.h> #include <libnautilus/nautilus-gtk-extensions.h> #include <libnautilus/nautilus-metadata.h> @@ -45,6 +47,7 @@ #include "ntl-window-private.h" #include "ntl-window-state.h" #include "nautilus-location-bar.h" +#include "ntl-types.h" /* #define EXTREME_DEBUGGING */ @@ -471,10 +474,10 @@ nautilus_window_update_view (NautilusWindow *window, } void -nautilus_window_view_destroyed(NautilusView *view, NautilusWindow *window) +nautilus_window_view_destroyed (NautilusView *view, NautilusWindow *window) { NautilusWindowStateItem item = VIEW_ERROR; - nautilus_window_set_state_info(window, item, view, (NautilusWindowStateItem) 0); + nautilus_window_set_state_info (window, item, view, (NautilusWindowStateItem) 0); } /* This is called when we have decided we can actually change to the new view/location situation. */ @@ -521,7 +524,7 @@ nautilus_window_has_really_changed(NautilusWindow *window) if (window->pending_ni != NULL) { nautilus_window_update_internals (window, window->pending_ni); - nautilus_navinfo_free (window->pending_ni); + nautilus_navigation_info_free (window->pending_ni); window->pending_ni = NULL; } } @@ -532,9 +535,11 @@ nautilus_window_free_load_info (NautilusWindow *window) { x_message (("-> FREE_LOAD_INFO <-")); - if (window->pending_ni) - nautilus_navinfo_free(window->pending_ni); - window->pending_ni = NULL; + if (window->pending_ni != NULL) { + nautilus_navigation_info_free (window->pending_ni); + window->pending_ni = NULL; + } + window->error_views = NULL; window->new_meta_views = NULL; window->new_content_view = NULL; @@ -665,7 +670,7 @@ nautilus_window_load_content_view(NautilusWindow *window, } static gboolean -nautilus_window_update_state(gpointer data) +nautilus_window_update_state (gpointer data) { NautilusWindow *window; GSList *p; @@ -739,15 +744,12 @@ nautilus_window_update_state(gpointer data) window->made_changes++; window->reset_to_idle = FALSE; - if (window->cancel_tag) { - gnome_vfs_async_cancel (window->cancel_tag); - if (window->pending_ni != NULL) { - window->pending_ni->ah = NULL; - } + if (window->cancel_tag != NULL) { + nautilus_navigation_info_cancel (window->cancel_tag); window->cancel_tag = NULL; } - if (window->pending_ni) { + if (window->pending_ni != NULL) { nautilus_window_reset_title_internal (window, window->ni->requested_uri); /* Tell previously-notified views to go back to the old page */ @@ -1004,19 +1006,20 @@ nautilus_window_set_state_info (NautilusWindow *window, ...) } static void -nautilus_window_end_location_change_callback (NautilusNavigationInfo *navi, gpointer data) +nautilus_window_end_location_change_callback (NautilusNavigationResult result_code, + NautilusNavigationInfo *navi, + gpointer data) { NautilusWindow *window = data; char *requested_uri; char *error_message; - char * scheme_string; + char *scheme_string; g_assert (navi != NULL); window->cancel_tag = NULL; - if (navi->result_code == NAUTILUS_NAVIGATION_RESULT_OK) - { + if (result_code == NAUTILUS_NAVIGATION_RESULT_OK) { /* Navigation successful. Show the window to handle the * new-window case. (Doesn't hurt if window is already showing.) * Maybe this should go sometime later so the blank window isn't @@ -1033,7 +1036,7 @@ nautilus_window_end_location_change_callback (NautilusNavigationInfo *navi, gpoi /* Some sort of failure occurred. How 'bout we tell the user? */ requested_uri = navi->navinfo.requested_uri; - switch (navi->result_code) { + switch (result_code) { case NAUTILUS_NAVIGATION_RESULT_NOT_FOUND: error_message = g_strdup_printf (_("Couldn't find \"%s\".\nPlease check the spelling and try again."), requested_uri); @@ -1044,7 +1047,7 @@ nautilus_window_end_location_change_callback (NautilusNavigationInfo *navi, gpoi break; case NAUTILUS_NAVIGATION_RESULT_NO_HANDLER_FOR_TYPE: - error_message = g_strdup_printf ("Couldn't display \"%s\",\nbecause Nautilus cannot handle items of this type.", requested_uri); + error_message = g_strdup_printf (_("Couldn't display \"%s\",\nbecause Nautilus cannot handle items of this type."), requested_uri); break; case NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME: @@ -1053,7 +1056,7 @@ nautilus_window_end_location_change_callback (NautilusNavigationInfo *navi, gpoi */ scheme_string = nautilus_str_get_prefix (requested_uri, ":"); g_assert (scheme_string != NULL); /* Shouldn't have gotten this error unless there's a : separator. */ - error_message = g_strdup_printf ("Couldn't display \"%s\",\nbecause Nautilus cannot handle %s: locations.", + error_message = g_strdup_printf (_("Couldn't display \"%s\",\nbecause Nautilus cannot handle %s: locations."), requested_uri, scheme_string); g_free (scheme_string); break; @@ -1063,11 +1066,11 @@ nautilus_window_end_location_change_callback (NautilusNavigationInfo *navi, gpoi * When this comes up, we should figure out what's really happening * and add another specific case. */ - error_message = g_strdup_printf ("Nautilus cannot display \"%s\".", requested_uri); + error_message = g_strdup_printf (_("Nautilus cannot display \"%s\"."), requested_uri); } if (navi != NULL) { - nautilus_navinfo_free (navi); + nautilus_navigation_info_free (navi); } if (!GTK_WIDGET_VISIBLE (GTK_WIDGET (window))) { @@ -1133,16 +1136,15 @@ nautilus_window_begin_location_change (NautilusWindow *window, current_iid = nautilus_view_get_iid (window->content_view); } - window->cancel_tag = nautilus_navinfo_new + window->cancel_tag = nautilus_navigation_info_new (loc, window->ni, nautilus_window_end_location_change_callback, window, current_iid); } - /******** content view switching **********/ static void -view_menu_switch_views_cb (GtkWidget *widget, gpointer data) +view_menu_switch_views_callback (GtkWidget *widget, gpointer data) { NautilusWindow *window; NautilusView *view; @@ -1212,7 +1214,7 @@ nautilus_window_load_content_view_menu (NautilusWindow *window, nautilus_gtk_signal_connect_free_data (GTK_OBJECT (menu_item), "activate", - GTK_SIGNAL_FUNC (view_menu_switch_views_cb), + GTK_SIGNAL_FUNC (view_menu_switch_views_callback), g_strdup (identifier->iid)); /* Store reference to window in item; no need to free this. */ diff --git a/src/nautilus-window.c b/src/nautilus-window.c index dcc93dc3b..250b15f55 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -43,6 +43,7 @@ #include <libnautilus/nautilus-string.h> #include "nautilus-zoom-control.h" #include <ctype.h> +#include <libgnomevfs/gnome-vfs-uri.h> enum { diff --git a/src/nautilus-window.h b/src/nautilus-window.h index af5e9926a..8b353150b 100644 --- a/src/nautilus-window.h +++ b/src/nautilus-window.h @@ -30,7 +30,7 @@ #include <libgnomeui/gnome-app.h> #include <libnautilus/nautilus-bookmark.h> -#include "ntl-types.h" +#include "ntl-uri-map.h" #include "ntl-view.h" #include "ntl-index-panel.h" @@ -106,7 +106,7 @@ struct _NautilusWindow { enum { NW_LOADING_INFO, NW_LOADING_VIEWS, NW_IDLE } state; - gpointer cancel_tag; + NautilusNavigationInfo *cancel_tag; guint action_tag; guint16 made_changes, making_changes; diff --git a/src/ntl-app.c b/src/ntl-app.c index b6780a520..f8b0c9a0a 100644 --- a/src/ntl-app.c +++ b/src/ntl-app.c @@ -254,8 +254,6 @@ nautilus_app_startup(NautilusApp *app, const char *initial_url) { NautilusWindow *mainwin; - nautilus_navinfo_init(); - /* Set default configuration */ mainwin = nautilus_app_create_window(app); bonobo_activate(); diff --git a/src/ntl-index-panel.c b/src/ntl-index-panel.c index 03e3fc6bd..3d2000982 100644 --- a/src/ntl-index-panel.c +++ b/src/ntl-index-panel.c @@ -28,6 +28,7 @@ #include "ntl-index-panel.h" #include <math.h> +#include <libgnomevfs/gnome-vfs-types.h> #include <libgnomevfs/gnome-vfs-uri.h> #include <gdk-pixbuf/gdk-pixbuf.h> #include <libnautilus/nautilus-background.h> diff --git a/src/ntl-main.c b/src/ntl-main.c index 43d4b25bf..99e24b07d 100644 --- a/src/ntl-main.c +++ b/src/ntl-main.c @@ -34,6 +34,7 @@ #include <libnautilus/nautilus-debug.h> #include <libnautilus/nautilus-lib-self-check-functions.h> #include <libnautilus/nautilus-self-checks.h> +#include <libgnomevfs/gnome-vfs-init.h> int main(int argc, char *argv[]) diff --git a/src/ntl-types.h b/src/ntl-types.h index 51e92881a..e73cc1f09 100644 --- a/src/ntl-types.h +++ b/src/ntl-types.h @@ -25,54 +25,13 @@ /* ntl-types.h: Declarations of basic types */ #ifndef NTL_TYPES_H -#define NTL_TYPES_H 1 - -#include <gtk/gtk.h> -#include <libnautilus/libnautilus.h> -#include <libgnomevfs/gnome-vfs.h> +#define NTL_TYPES_H typedef char *NautilusLocationReference; -typedef struct _NautilusNavigationInfo NautilusNavigationInfo; -typedef struct _NautilusViewIdentifier NautilusViewIdentifier; - -typedef void (*NautilusNavigationInfoFunc)(NautilusNavigationInfo *navinfo, gpointer data); - -struct _NautilusViewIdentifier { +typedef struct { char *iid; /* magic key */ char *name; /* human-readable name */ -}; - -/* These are the different ways that Nautilus can fail to - * display the contents of a given uri. NAUTILUS_NAVIGATION_RESULT_OK - * means the uri was displayed successfully. These are similar to - * GnomeVFSResults but there are nautilus-specific codes and many of - * the GnomeVFSResults are treated the same here. - */ -enum _NautilusNavigationResult { - NAUTILUS_NAVIGATION_RESULT_OK, - NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR, - NAUTILUS_NAVIGATION_RESULT_NO_HANDLER_FOR_TYPE, - NAUTILUS_NAVIGATION_RESULT_NOT_FOUND, - NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME, - NAUTILUS_NAVIGATION_RESULT_INVALID_URI -}; -typedef enum _NautilusNavigationResult NautilusNavigationResult; - -struct _NautilusNavigationInfo { - Nautilus_NavigationInfo navinfo; - - char *referring_iid; /* iid of content view that we're coming from */ - char *initial_content_iid; /* iid to use for content view that we're going to display */ - GSList *content_identifiers; /* list of NautilusViewIdentifiers */ - GSList *meta_iids; /* list of iid strings */ - NautilusNavigationResult result_code; - - /* internal usage */ - NautilusNavigationInfoFunc notify_ready; - gpointer data; - - GnomeVFSAsyncHandle *ah; -}; +} NautilusViewIdentifier; #endif diff --git a/src/ntl-uri-map.c b/src/ntl-uri-map.c index c12e94b92..728ae6f98 100644 --- a/src/ntl-uri-map.c +++ b/src/ntl-uri-map.c @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* * Nautilus @@ -22,6 +22,7 @@ * Author: Elliot Lee <sopwith@redhat.com> * */ + /* ntl-uri-map.c: Implementation of routines for mapping a location change request to a set of views and actual URL to be loaded. */ @@ -32,73 +33,76 @@ #include <libnautilus/nautilus-global-preferences.h> #include <libnautilus/nautilus-string.h> +#include <libgnomevfs/gnome-vfs-file-info.h> +#include <libgnomevfs/gnome-vfs-async-ops.h> + #include <libgnorba/gnorba.h> #include <sys/types.h> #include <dirent.h> #include <limits.h> #include <ctype.h> +#include "ntl-types.h" + /* forward declarations */ -static void add_components_from_metadata(NautilusNavigationInfo *navinfo); -static void add_meta_view_iids_from_preferences(NautilusNavigationInfo *navinfo); +static void add_components_from_metadata (NautilusNavigationInfo *navinfo); +static void add_meta_view_iids_from_preferences (NautilusNavigationInfo *navinfo); /* Nautilus View Identifiers associate a component name with a user displayable name */ static NautilusViewIdentifier * nautilus_view_identifier_new (const char *iid, const char *name) { - NautilusViewIdentifier *new_identifier; - - g_return_val_if_fail (iid != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - new_identifier = g_new0 (NautilusViewIdentifier, 1); - new_identifier->iid = g_strdup (iid); - new_identifier->name = g_strdup (name); - - return new_identifier; + NautilusViewIdentifier *new_identifier; + + g_return_val_if_fail (iid != NULL, NULL); + g_return_val_if_fail (name != NULL, NULL); + + new_identifier = g_new0 (NautilusViewIdentifier, 1); + new_identifier->iid = g_strdup (iid); + new_identifier->name = g_strdup (name); + + return new_identifier; } static void nautilus_view_identifier_free (NautilusViewIdentifier *identifier) { - if (identifier != NULL) - { - g_free (identifier->iid); - g_free (identifier->name); - g_free (identifier); - } + if (identifier != NULL) { + g_free (identifier->iid); + g_free (identifier->name); + g_free (identifier); + } } static NautilusNavigationResult get_nautilus_navigation_result_from_gnome_vfs_result (GnomeVFSResult gnome_vfs_result) { - switch (gnome_vfs_result) - { - case GNOME_VFS_OK: - return NAUTILUS_NAVIGATION_RESULT_OK; - case GNOME_VFS_ERROR_NOTFOUND: - case GNOME_VFS_ERROR_HOSTNOTFOUND: - return NAUTILUS_NAVIGATION_RESULT_NOT_FOUND; - case GNOME_VFS_ERROR_INVALIDURI: - return NAUTILUS_NAVIGATION_RESULT_INVALID_URI; - case GNOME_VFS_ERROR_NOTSUPPORTED: - return NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME; - case GNOME_VFS_ERROR_GENERIC: - /* This one has occurred at least once in the web browser component */ - return NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR; - default: - /* Whenever this message fires, we should consider adding a specific case - * to make the error as comprehensible as possible to the user. Please - * bug me (sullivan@eazel.com) if you see this fire and don't have the - * inclination to immediately make a good message yourself (tell me - * what GnomeVFSResult code the message reported, and what caused it to - * fire). - */ - g_message ("in ntl-uri-map.c, got unhandled GnomeVFSResult %d.", gnome_vfs_result); - return NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR; - } + switch (gnome_vfs_result) { + case GNOME_VFS_OK: + return NAUTILUS_NAVIGATION_RESULT_OK; + case GNOME_VFS_ERROR_NOTFOUND: + case GNOME_VFS_ERROR_HOSTNOTFOUND: + return NAUTILUS_NAVIGATION_RESULT_NOT_FOUND; + case GNOME_VFS_ERROR_INVALIDURI: + return NAUTILUS_NAVIGATION_RESULT_INVALID_URI; + case GNOME_VFS_ERROR_NOTSUPPORTED: + return NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME; + case GNOME_VFS_ERROR_GENERIC: + /* This one has occurred at least once in the web browser component */ + return NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR; + default: + /* Whenever this message fires, we should consider adding a specific case + * to make the error as comprehensible as possible to the user. Please + * bug me (sullivan@eazel.com) if you see this fire and don't have the + * inclination to immediately make a good message yourself (tell me + * what GnomeVFSResult code the message reported, and what caused it to + * fire). + */ + g_message ("in ntl-uri-map.c, got unhandled GnomeVFSResult %d", gnome_vfs_result); + return NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR; + } } /* GCompareFunc-style function for checking whether a given string matches @@ -109,10 +113,10 @@ check_iid (gconstpointer a, gconstpointer b) { NautilusViewIdentifier *identifier; char *string; - + identifier = (NautilusViewIdentifier *)a; string = (char *)b; - + return strcmp (identifier->iid, string) != 0; } @@ -131,7 +135,6 @@ static void set_initial_content_iid (NautilusNavigationInfo *navinfo, const char *fallback_value) { - NautilusDirectory *directory; char *remembered_value = NULL; const char *value = NULL; @@ -144,30 +147,29 @@ set_initial_content_iid (NautilusNavigationInfo *navinfo, * this to work that way. */ - directory = nautilus_directory_get (navinfo->navinfo.requested_uri); - if (directory != NULL) { - remembered_value = nautilus_directory_get_metadata (directory, - NAUTILUS_METADATA_KEY_INITIAL_VIEW, - NULL); - - /* Use the remembered value if it's non-NULL and in the list of choices. */ - if (remembered_value != NULL) { - if (g_slist_find_custom (navinfo->content_identifiers, remembered_value, check_iid)) { - value = remembered_value; - } else { - g_message ("Unknown iid \"%s\" stored for %s", remembered_value, navinfo->navinfo.requested_uri); - } - } - - nautilus_directory_unref (directory); - } - + remembered_value = nautilus_directory_get_metadata (navinfo->directory, + NAUTILUS_METADATA_KEY_INITIAL_VIEW, + NULL); + + /* Use the remembered value if it's non-NULL and in the list of choices. */ + if (remembered_value != NULL) { + if (g_slist_find_custom (navinfo->content_identifiers, + remembered_value, check_iid)) { + value = remembered_value; + } else { + g_message ("Unknown iid \"%s\" stored for %s", + remembered_value, + navinfo->navinfo.requested_uri); + } + } + if (value == NULL) { /* Can't use remembered value, use referring value if * it's non-NULL and in the list of choices. */ if (navinfo->referring_iid != NULL) { - if (g_slist_find_custom (navinfo->content_identifiers, navinfo->referring_iid, check_iid)) { + if (g_slist_find_custom (navinfo->content_identifiers, + navinfo->referring_iid, check_iid)) { value = navinfo->referring_iid; } } @@ -180,185 +182,172 @@ set_initial_content_iid (NautilusNavigationInfo *navinfo, navinfo->initial_content_iid = g_strdup (value); - if (remembered_value) - g_free (remembered_value); + g_free (remembered_value); } static void -my_notify_when_ready(GnomeVFSAsyncHandle *ah, GnomeVFSResult result, - GnomeVFSFileInfo *vfs_fileinfo, - gpointer data) +my_notify_when_ready (GnomeVFSAsyncHandle *ah, + GnomeVFSResult result, + GnomeVFSFileInfo *vfs_fileinfo, + gpointer data) { - NautilusNavigationInfo *navinfo = data; - NautilusNavigationInfoFunc notify_ready = navinfo->notify_ready; - gpointer notify_ready_data = navinfo->data; - const char *fallback_iid; - - if (navinfo->ah) { - gnome_vfs_async_cancel (navinfo->ah); - navinfo->ah = NULL; - } - - if(result != GNOME_VFS_OK) - { - /* Map GnomeVFSResult to one of the types that Nautilus knows how to handle. - * Leave navinfo intact so notify_ready function can access the uri. - * (notify_ready function is responsible for freeing navinfo). - */ - navinfo->result_code = get_nautilus_navigation_result_from_gnome_vfs_result (result); - if(navinfo->result_code == NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME - || navinfo->result_code == NAUTILUS_NAVIGATION_RESULT_INVALID_URI) - { - /* Special scheme mapping stuff */ - if(!strncmp(navinfo->navinfo.requested_uri, "irc://", 6)) - { - navinfo->navinfo.content_type = g_strdup("special/x-irc-session"); - navinfo->result_code = NAUTILUS_NAVIGATION_RESULT_OK; - } - else if (!strncmp(navinfo->navinfo.requested_uri, "eazel:", 6)) - { - navinfo->navinfo.content_type = g_strdup("special/eazel-service"); - navinfo->result_code = NAUTILUS_NAVIGATION_RESULT_OK; - } - else - goto out; + NautilusNavigationInfo *navinfo; + NautilusNavigationCallback notify_ready; + gpointer notify_ready_data; + const char *fallback_iid; + NautilusNavigationResult result_code; + + navinfo = data; + + navinfo->ah = NULL; + + notify_ready = navinfo->callback; + notify_ready_data = navinfo->callback_data; + + /* Get the content type. */ + if (result == GNOME_VFS_OK) { + navinfo->navinfo.content_type = g_strdup (gnome_vfs_file_info_get_mime_type (vfs_fileinfo)); + } else if (result == GNOME_VFS_ERROR_NOTSUPPORTED + || result == GNOME_VFS_ERROR_INVALIDURI) { + /* Special scheme mapping stuff */ + if (nautilus_str_has_prefix (navinfo->navinfo.requested_uri, "irc://")) { + navinfo->navinfo.content_type = g_strdup ("special/x-irc-session"); + result = GNOME_VFS_OK; + } else if (nautilus_str_has_prefix (navinfo->navinfo.requested_uri, "eazel:")) { + navinfo->navinfo.content_type = g_strdup ("special/eazel-service"); + result = GNOME_VFS_OK; + } } - else - goto out; - } - else - navinfo->navinfo.content_type = g_strdup(gnome_vfs_file_info_get_mime_type(vfs_fileinfo)); - - /* Given a content type and a URI, what do we do? Basically the "expert system" below - tries to answer that question - - Check if the URI is in an abnormal scheme (e.g. one not supported by gnome-vfs) - If so - Lookup content views by scheme name, go. - Lookup meta views by scheme name, go. - - If not - Figure out content type. - Lookup content views by content type, go. - Lookup meta views by content type, go. - - The lookup-and-go process works like: - Generate a list of all possibilities ordered by quality. - Put possibilities on menu. - - Find if the user has specified any default(s) globally, modify selection. - Find if the user has specified any default(s) per-page, modify selection. - */ - - /* This is just a hardcoded hack until OAF works with Bonobo. - In the future we will use OAF queries to determine this information. */ + + /* Map GnomeVFSResult to one of the types that Nautilus knows how to handle. */ + result_code = get_nautilus_navigation_result_from_gnome_vfs_result (result); - if (!navinfo->navinfo.content_type) - navinfo->navinfo.content_type = g_strdup("text/plain"); + if (result != GNOME_VFS_OK) { + /* Leave navinfo intact so notify_ready function can access the uri. + * (notify_ready function is responsible for freeing navinfo). + */ + goto out; + } - - if (!strcmp(navinfo->navinfo.content_type, "text/html")) - { - fallback_iid = "ntl_web_browser"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_web_browser", "Web Page")); - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("embeddable:text-plain", "Text")); - } - else if (!strncmp(navinfo->navinfo.content_type, "image/", 6)) - { - fallback_iid = "eog-image-viewer"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("eog-image-viewer", "Image")); - } - else if (!strcmp(navinfo->navinfo.content_type, "special/x-irc-session")) - { - fallback_iid = "xchat"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("xchat", "Chat room")); - } - else if (!strcmp(navinfo->navinfo.content_type, "special/directory") - || !strcmp(navinfo->navinfo.content_type, "application/x-nautilus-vdir")) - { - fallback_iid = "ntl_file_manager_icon_view"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_file_manager_icon_view", "Icons")); - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_file_manager_list_view", "List")); - - /* besides the information in OAF/GConf, we also want to offer components that are specifically refered to in the metadata, - so we ask the metadata for content views here and add them accordingly. */ - - /* FIXME: for now, we just do this for directories but it should apply to all places with available metadata */ - add_components_from_metadata(navinfo); - } - else if (!strcmp(navinfo->navinfo.content_type, "special/webdav-directory")) - { - fallback_iid = "ntl_web_browser"; - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_web_browser", "Web Page")); - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_file_manager_icon_view", "Icons")); - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new ("ntl_file_manager_list_view", "List")); - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new ("embeddable:text-plain", "Text")); - - - /* besides the information in OAF/GConf, we also want to offer components that are specifically refered to in the metadata, - so we ask the metadata for content views here and add them accordingly. */ + /* Given a content type and a URI, what do we do? Basically the "expert system" below + tries to answer that question + + Check if the URI is in an abnormal scheme (e.g. one not supported by gnome-vfs) + If so + Lookup content views by scheme name, go. + Lookup meta views by scheme name, go. + + If not + Figure out content type. + Lookup content views by content type, go. + Lookup meta views by content type, go. + + The lookup-and-go process works like: + Generate a list of all possibilities ordered by quality. + Put possibilities on menu. + + Find if the user has specified any default(s) globally, modify selection. + Find if the user has specified any default(s) per-page, modify selection. + */ + + /* This is just a hardcoded hack until OAF works with Bonobo. + In the future we will use OAF queries to determine this information. */ + + if (navinfo->navinfo.content_type == NULL) { + navinfo->navinfo.content_type = g_strdup ("text/plain"); + } + + if (strcmp (navinfo->navinfo.content_type, "text/html") == 0) { + fallback_iid = "ntl_web_browser"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_web_browser", "Web Page")); + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("embeddable:text-plain", "Text")); + } else if (nautilus_str_has_prefix (navinfo->navinfo.content_type, "image/")) { + fallback_iid = "eog-image-viewer"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("eog-image-viewer", "Image")); + } else if (strcmp (navinfo->navinfo.content_type, "special/x-irc-session") == 0) { + fallback_iid = "xchat"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("xchat", "Chat room")); + } else if (strcmp(navinfo->navinfo.content_type, "special/directory") == 0 + || strcmp(navinfo->navinfo.content_type, "application/x-nautilus-vdir") == 0) { + fallback_iid = "ntl_file_manager_icon_view"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_file_manager_icon_view", "Icons")); + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_file_manager_list_view", "List")); + + /* besides the information in OAF/GConf, we also want to offer components that are specifically refered to in the metadata, + so we ask the metadata for content views here and add them accordingly. */ + + /* FIXME: for now, we just do this for directories but it should apply to all places with available metadata */ + add_components_from_metadata (navinfo); + } else if (strcmp (navinfo->navinfo.content_type, "special/webdav-directory")) { + fallback_iid = "ntl_web_browser"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_web_browser", "Web Page")); + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_file_manager_icon_view", "Icons")); + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("ntl_file_manager_list_view", "List")); + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("embeddable:text-plain", "Text")); + + /* besides the information in OAF/GConf, we also want to offer components that are specifically refered to in the metadata, + so we ask the metadata for content views here and add them accordingly. */ - /* FIXME: for now, we just do this for directories but it should apply to all places with available metadata */ - add_components_from_metadata(navinfo); - } - else if (!strcmp(navinfo->navinfo.content_type, "application/x-rpm") || nautilus_str_has_suffix(navinfo->navinfo.requested_uri, ".rpm")) - { - fallback_iid = "nautilus_rpm_view"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("nautilus_rpm_view", "Package")); - } - else if (!strcmp(navinfo->navinfo.content_type, "special/eazel-service")) - { - fallback_iid = "nautilus_service_startup_view"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("nautilus_service_startup_view", "Service")); - } - else if(!strcmp(navinfo->navinfo.content_type, "text/plain")) - { - fallback_iid = "embeddable:text-plain"; - navinfo->content_identifiers = g_slist_append ( - navinfo->content_identifiers, - nautilus_view_identifier_new ("embeddable:text-plain", "Text")); - } - else - { - /* Can't display file; nothing registered to handle this file type. */ - navinfo->result_code = NAUTILUS_NAVIGATION_RESULT_NO_HANDLER_FOR_TYPE; - goto out; - } - - /* FIXME: Should do this only when in some special testing mode or something. */ - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new ("nautilus_sample_content_view", "Sample")); - - /* Now that all the content_identifiers are in place, we're ready to choose - * the initial one. - */ - g_assert (fallback_iid != NULL); - set_initial_content_iid (navinfo, fallback_iid); - - add_meta_view_iids_from_preferences (navinfo); - + /* FIXME: for now, we just do this for directories but it should apply to all places with available metadata */ + add_components_from_metadata (navinfo); + } + else if (strcmp (navinfo->navinfo.content_type, "application/x-rpm") == 0 + || nautilus_str_has_suffix (navinfo->navinfo.requested_uri, ".rpm")) { + fallback_iid = "nautilus_rpm_view"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("nautilus_rpm_view", "Package")); + } else if (strcmp(navinfo->navinfo.content_type, "special/eazel-service")) { + fallback_iid = "nautilus_service_startup_view"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("nautilus_service_startup_view", "Service")); + } else if (strcmp(navinfo->navinfo.content_type, "text/plain") == 0) { + fallback_iid = "embeddable:text-plain"; + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("embeddable:text-plain", "Text")); + } else { + /* Can't display file; nothing registered to handle this file type. */ + result_code = NAUTILUS_NAVIGATION_RESULT_NO_HANDLER_FOR_TYPE; + goto out; + } + + /* FIXME: Should do this only when in some special testing mode or something. */ + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new ("nautilus_sample_content_view", "Sample")); + + add_meta_view_iids_from_preferences (navinfo); + + /* Now that all the content_identifiers are in place, we're ready to choose + * the initial one. + */ + g_assert (fallback_iid != NULL); + set_initial_content_iid (navinfo, fallback_iid); + out: - notify_ready(navinfo, notify_ready_data); + (* notify_ready) (result_code, navinfo, notify_ready_data); } /* The following routine uses metadata associated with the current url to add content view components specified in the metadata */ @@ -367,19 +356,20 @@ my_notify_when_ready(GnomeVFSAsyncHandle *ah, GnomeVFSResult result, static void add_components_from_metadata (NautilusNavigationInfo *navinfo) { - NautilusDirectory *directory; char *content_views; + char **pieces; + const char *component_str; + char *colon_pos; + int index; - directory = nautilus_directory_get (navinfo->navinfo.requested_uri); + content_views = nautilus_directory_get_metadata + (navinfo->directory, + NAUTILUS_METADATA_KEY_CONTENT_VIEWS, NULL); - content_views = nautilus_directory_get_metadata (directory, NAUTILUS_METADATA_KEY_CONTENT_VIEWS, NULL); if (content_views != NULL) { - char **pieces; - const char *component_str; - char *colon_pos; - int index; - pieces = g_strsplit (content_views, "\n", 0); + g_free (content_views); + for (index = 0; (component_str = pieces[index]) != NULL; index++) { /* break the component string into the name and label */ colon_pos = strchr(component_str, ':'); @@ -387,128 +377,146 @@ add_components_from_metadata (NautilusNavigationInfo *navinfo) *colon_pos++ = '\0'; /* add it to the list */ - navinfo->content_identifiers = g_slist_append (navinfo->content_identifiers, - nautilus_view_identifier_new (component_str, colon_pos)); - } + navinfo->content_identifiers = g_slist_append + (navinfo->content_identifiers, + nautilus_view_identifier_new (component_str, colon_pos)); + } } - g_strfreev (pieces); - g_free (content_views); + g_strfreev (pieces); } - - nautilus_directory_unref (directory); } static void add_meta_view_iids_from_preferences (NautilusNavigationInfo *navinfo) { const NautilusStringList *meta_view_iids; - guint i; - + guint i; + char *iid; + gboolean enabled; + GString *pref_name; + g_assert (navinfo != NULL); - meta_view_iids= nautilus_global_preferences_get_meta_view_iids (); - + meta_view_iids = nautilus_global_preferences_get_meta_view_iids (); g_assert (meta_view_iids != NULL); - for (i = 0; i < nautilus_string_list_get_length (meta_view_iids); i++) - { - char *iid; - gboolean enabled; - GString *pref_name; - + for (i = 0; i < nautilus_string_list_get_length (meta_view_iids); i++) { iid = nautilus_string_list_nth (meta_view_iids, i); - g_assert (iid != NULL); pref_name = g_string_new ("/nautilus/metaviews/"); - g_string_append (pref_name, iid); - enabled = nautilus_preferences_get_boolean (nautilus_preferences_get_global_preferences (), pref_name->str); - - g_string_free (pref_name, TRUE); - if (enabled) - { - navinfo->meta_iids = g_slist_prepend (navinfo->meta_iids, g_strdup (iid)); - } - - g_free (iid); + if (enabled) { + navinfo->meta_iids = g_slist_prepend (navinfo->meta_iids, iid); + } else { + g_free (iid); + } } } +static void +got_metadata_callback (NautilusDirectory *directory, + gpointer callback_data) +{ + NautilusNavigationInfo *info; + GnomeVFSResult result; + + info = callback_data; + g_assert (info->directory == directory); + + result = gnome_vfs_async_get_file_info (&info->ah, + info->navinfo.requested_uri, + (GNOME_VFS_FILE_INFO_GETMIMETYPE + | GNOME_VFS_FILE_INFO_FOLLOWLINKS), + NULL, + my_notify_when_ready, + info); + + if (result != GNOME_VFS_OK) { + /* Note: Not sure if or when this case ever occurs. result == GNOME_VFS_OK + * for normally-handled uris, for non-existent uris, and for uris for which + * Nautilus has no content viewer. + */ + my_notify_when_ready (NULL, result, NULL, info); + } +} -/* navinfo stuff */ +/* NautilusNavigationInfo */ -void -nautilus_navinfo_init(void) +NautilusNavigationInfo * +nautilus_navigation_info_new (Nautilus_NavigationRequestInfo *nri, + Nautilus_NavigationInfo *old_navinfo, + NautilusNavigationCallback notify_when_ready, + gpointer notify_data, + const char *referring_iid) { + NautilusNavigationInfo *navinfo; + GList *metadata_keys; + + navinfo = g_new0 (NautilusNavigationInfo, 1); + + navinfo->callback = notify_when_ready; + navinfo->callback_data = notify_data; + + if (old_navinfo != NULL) { + navinfo->navinfo.referring_uri = old_navinfo->requested_uri; + navinfo->navinfo.actual_referring_uri = old_navinfo->actual_uri; + navinfo->navinfo.referring_content_type = old_navinfo->content_type; + } + + navinfo->referring_iid = g_strdup (referring_iid); + navinfo->navinfo.requested_uri = g_strdup (nri->requested_uri); + + navinfo->directory = nautilus_directory_get (nri->requested_uri); + + /* Arrange for all the metadata we will need. */ + metadata_keys = NULL; + metadata_keys = g_list_prepend (metadata_keys, NAUTILUS_METADATA_KEY_CONTENT_VIEWS); + metadata_keys = g_list_prepend (metadata_keys, NAUTILUS_METADATA_KEY_INITIAL_VIEW); + nautilus_directory_metadata_call_when_ready + (navinfo->directory, + metadata_keys, + got_metadata_callback, + navinfo); + g_list_free (metadata_keys); + + return navinfo; } -gpointer -nautilus_navinfo_new(Nautilus_NavigationRequestInfo *nri, - Nautilus_NavigationInfo *old_navinfo, - NautilusNavigationInfoFunc notify_when_ready, - gpointer notify_data, - const char *referring_iid) +void +nautilus_navigation_info_cancel (NautilusNavigationInfo *info) { - GnomeVFSResult res; - const char *meta_keys[] = {"icon-filename", NULL}; - NautilusNavigationInfo *navinfo; - - navinfo = g_new0(NautilusNavigationInfo, 1); - - navinfo->notify_ready = notify_when_ready; - navinfo->data = notify_data; - - if(old_navinfo) - { - navinfo->navinfo.referring_uri = old_navinfo->requested_uri; - navinfo->navinfo.actual_referring_uri = old_navinfo->actual_uri; - navinfo->navinfo.referring_content_type = old_navinfo->content_type; - } - - if (referring_iid != NULL) - navinfo->referring_iid = g_strdup (referring_iid); - - navinfo->navinfo.requested_uri = g_strdup(nri->requested_uri); - - res = gnome_vfs_async_get_file_info(&navinfo->ah, navinfo->navinfo.requested_uri, - GNOME_VFS_FILE_INFO_GETMIMETYPE - |GNOME_VFS_FILE_INFO_FOLLOWLINKS, - meta_keys, my_notify_when_ready, navinfo); - - if(res != GNOME_VFS_OK) - { - /* Note: Not sure if or when this case ever occurs. res == GNOME_VFS_OK - * for normally-handled uris, for non-existent uris, and for uris for which - * Nautilus has no content viewer. - */ - navinfo->ah = NULL; - my_notify_when_ready(NULL, res, NULL, navinfo); - } - - return navinfo?navinfo->ah:NULL; + g_return_if_fail (info != NULL); + + if (info->ah != NULL) { + gnome_vfs_async_cancel (info->ah); + info->ah = NULL; + } + + nautilus_directory_metadata_callback_cancel + (info->directory, got_metadata_callback, info); } void -nautilus_navinfo_free(NautilusNavigationInfo *navinfo) +nautilus_navigation_info_free (NautilusNavigationInfo *navinfo) { - g_return_if_fail(navinfo != NULL); - - if (navinfo->ah) - gnome_vfs_async_cancel (navinfo->ah); - - g_slist_foreach(navinfo->content_identifiers, (GFunc)nautilus_view_identifier_free, NULL); - g_slist_free(navinfo->content_identifiers); - g_slist_foreach(navinfo->meta_iids, (GFunc)g_free, NULL); - g_slist_free(navinfo->meta_iids); - g_free(navinfo->referring_iid); - g_free(navinfo->initial_content_iid); - g_free(navinfo->navinfo.requested_uri); - g_free(navinfo->navinfo.actual_uri); - g_free(navinfo->navinfo.content_type); - g_free(navinfo); + g_return_if_fail (navinfo != NULL); + + nautilus_navigation_info_cancel (navinfo); + + g_slist_foreach (navinfo->content_identifiers, (GFunc) nautilus_view_identifier_free, NULL); + g_slist_free (navinfo->content_identifiers); + g_slist_foreach (navinfo->meta_iids, (GFunc) g_free, NULL); + g_slist_free (navinfo->meta_iids); + g_free (navinfo->referring_iid); + g_free (navinfo->initial_content_iid); + g_free (navinfo->navinfo.requested_uri); + g_free (navinfo->navinfo.actual_uri); + g_free (navinfo->navinfo.content_type); + nautilus_directory_unref (navinfo->directory); + g_free (navinfo); } diff --git a/src/ntl-uri-map.h b/src/ntl-uri-map.h index ca659fb24..9d111de51 100644 --- a/src/ntl-uri-map.h +++ b/src/ntl-uri-map.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* * Nautilus @@ -22,20 +22,59 @@ * Author: Elliot Lee <sopwith@redhat.com> * */ + /* ntl-uri-map.h: Interface for mapping a location change request to a set of views and actual URL to be loaded. */ #ifndef NAUTILUS_URI_MAP_H -#define NAUTILUS_URI_MAP_H 1 - -#include "ntl-types.h" -#include "ntl-view.h" - -void nautilus_navinfo_init(void); -gpointer nautilus_navinfo_new(Nautilus_NavigationRequestInfo *nri, - Nautilus_NavigationInfo *old_navinfo, - NautilusNavigationInfoFunc notify_when_ready, - gpointer notify_data, - const char *referring_iid); -void nautilus_navinfo_free(NautilusNavigationInfo *navinfo); +#define NAUTILUS_URI_MAP_H + +#include <glib.h> +#include <libgnomevfs/gnome-vfs-types.h> +#include <libnautilus/nautilus.h> +#include <libnautilus/nautilus-directory.h> + +typedef struct NautilusNavigationInfo NautilusNavigationInfo; + +/* These are the different ways that Nautilus can fail to + * display the contents of a given uri. NAUTILUS_NAVIGATION_RESULT_OK + * means the uri was displayed successfully. These are similar to + * GnomeVFSResults but there are nautilus-specific codes and many of + * the GnomeVFSResults are treated the same here. + */ +typedef enum { + NAUTILUS_NAVIGATION_RESULT_OK, + NAUTILUS_NAVIGATION_RESULT_UNSPECIFIC_ERROR, + NAUTILUS_NAVIGATION_RESULT_NO_HANDLER_FOR_TYPE, + NAUTILUS_NAVIGATION_RESULT_NOT_FOUND, + NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME, + NAUTILUS_NAVIGATION_RESULT_INVALID_URI +} NautilusNavigationResult; + +typedef void (*NautilusNavigationCallback) (NautilusNavigationResult result, + NautilusNavigationInfo *info, + gpointer callback_data); + +struct NautilusNavigationInfo { + Nautilus_NavigationInfo navinfo; + + char *referring_iid; /* iid of content view that we're coming from */ + char *initial_content_iid; /* iid to use for content view that we're going to display */ + GSList *content_identifiers; /* list of NautilusViewIdentifiers */ + GSList *meta_iids; /* list of iid strings */ + + /* internal usage */ + NautilusNavigationCallback callback; + gpointer callback_data; + GnomeVFSAsyncHandle *ah; + NautilusDirectory *directory; +}; + +NautilusNavigationInfo *nautilus_navigation_info_new (Nautilus_NavigationRequestInfo *request, + Nautilus_NavigationInfo *previous_location, + NautilusNavigationCallback ready_callback, + gpointer callback_data, + const char *referring_iid); +void nautilus_navigation_info_cancel (NautilusNavigationInfo *info); +void nautilus_navigation_info_free (NautilusNavigationInfo *info); #endif diff --git a/src/ntl-view-private.h b/src/ntl-view-private.h index 648ec9369..41c4f0adb 100644 --- a/src/ntl-view-private.h +++ b/src/ntl-view-private.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* * Nautilus @@ -23,53 +23,52 @@ * Author: Elliot Lee <sopwith@redhat.com> * */ + /* ntl-view-private.h: Internals of the view proxy that are shared between different implementation files */ + #ifndef NTL_VIEW_PRIVATE_H -#define NTL_VIEW_PRIVATE_H 1 +#define NTL_VIEW_PRIVATE_H #include "nautilus.h" typedef struct { - POA_Nautilus_ViewFrame servant; - gpointer bonobo_object; - - NautilusView *view; + POA_Nautilus_ViewFrame servant; + gpointer bonobo_object; + + NautilusView *view; } impl_POA_Nautilus_ViewFrame; extern POA_Nautilus_ViewFrame__vepv impl_Nautilus_ViewFrame_vepv; extern POA_Nautilus_ZoomableFrame__vepv impl_Nautilus_ZoomableFrame_vepv; -BonoboObject *impl_Nautilus_ViewFrame__create (NautilusView *view, - CORBA_Environment * ev); -BonoboObject *impl_Nautilus_ZoomableFrame__create (NautilusView *view, - CORBA_Environment * ev); - -void nautilus_view_request_location_change (NautilusView *view, - Nautilus_NavigationRequestInfo *loc); -void nautilus_view_request_selection_change (NautilusView *view, - Nautilus_SelectionRequestInfo *loc); -void nautilus_view_request_status_change (NautilusView *view, - Nautilus_StatusRequestInfo *loc); -void nautilus_view_request_progress_change (NautilusView *view, - Nautilus_ProgressRequestInfo *loc); +BonoboObject *impl_Nautilus_ViewFrame__create (NautilusView *view, + CORBA_Environment *ev); +BonoboObject *impl_Nautilus_ZoomableFrame__create (NautilusView *view, + CORBA_Environment *ev); +void nautilus_view_request_location_change (NautilusView *view, + Nautilus_NavigationRequestInfo *loc); +void nautilus_view_request_selection_change (NautilusView *view, + Nautilus_SelectionRequestInfo *loc); +void nautilus_view_request_status_change (NautilusView *view, + Nautilus_StatusRequestInfo *loc); +void nautilus_view_request_progress_change (NautilusView *view, + Nautilus_ProgressRequestInfo *loc); +void nautilus_view_notify_zoom_level (NautilusView *view, + double level); -void nautilus_view_notify_zoom_level (NautilusView *view, - double level); - - -struct _NautilusViewComponentType { - const char *primary_repoid; - gboolean (* try_load)(NautilusView *view, CORBA_Object obj, CORBA_Environment *ev); - void (* destroy) (NautilusView *view, CORBA_Environment *ev); - void (* save_state)(NautilusView *view, const char *config_path, CORBA_Environment *ev); - void (* load_state)(NautilusView *view, const char *config_path, CORBA_Environment *ev); - void (* notify_location_change)(NautilusView *view, Nautilus_NavigationInfo *nav_ctx, CORBA_Environment *ev); - void (* stop_location_change)(NautilusView *view, CORBA_Environment *ev); - void (* notify_selection_change)(NautilusView *view, Nautilus_SelectionInfo *nav_ctx, CORBA_Environment *ev); - void (* show_properties)(NautilusView *view, CORBA_Environment *ev); - - char * (* get_label)(NautilusView *view, CORBA_Environment *ev); +struct NautilusViewComponentType { + const char *primary_repoid; + gboolean (* try_load)(NautilusView *view, CORBA_Object obj, CORBA_Environment *ev); + void (* destroy) (NautilusView *view, CORBA_Environment *ev); + void (* save_state)(NautilusView *view, const char *config_path, CORBA_Environment *ev); + void (* load_state)(NautilusView *view, const char *config_path, CORBA_Environment *ev); + void (* notify_location_change)(NautilusView *view, Nautilus_NavigationInfo *nav_ctx, CORBA_Environment *ev); + void (* stop_location_change)(NautilusView *view, CORBA_Environment *ev); + void (* notify_selection_change)(NautilusView *view, Nautilus_SelectionInfo *nav_ctx, CORBA_Environment *ev); + void (* show_properties)(NautilusView *view, CORBA_Environment *ev); + char * (* get_label)(NautilusView *view, CORBA_Environment *ev); }; -#endif +#endif /* NTL_VIEW_PRIVATE_H */ + diff --git a/src/ntl-view.h b/src/ntl-view.h index e6c6d0d47..7472141e6 100644 --- a/src/ntl-view.h +++ b/src/ntl-view.h @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* * Nautilus @@ -23,125 +23,121 @@ * Author: Elliot Lee <sopwith@redhat.com> * */ + /* ntl-view.h: Interface of the object representing a data view. NautilusContentView and NautilusMetaView derive from this class. */ -#ifndef __NAUTILUS_VIEW_H__ -#define __NAUTILUS_VIEW_H__ +#ifndef NAUTILUS_VIEW_H +#define NAUTILUS_VIEW_H #include <gtk/gtkwidget.h> #include <gtk/gtkbin.h> -#include "ntl-types.h" #include <bonobo.h> +#include <libnautilus/nautilus.h> #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -#define NAUTILUS_TYPE_VIEW (nautilus_view_get_type ()) -#define NAUTILUS_VIEW(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_VIEW, NautilusView)) -#define NAUTILUS_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_VIEW, NautilusViewClass)) -#define NAUTILUS_IS_VIEW(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_VIEW)) -#define NAUTILUS_IS_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), NAUTILUS_TYPE_VIEW)) - -typedef struct _NautilusView NautilusView; -typedef struct _NautilusViewClass NautilusViewClass; - -struct _NautilusViewClass -{ - GtkBinClass parent_spot; - - /* These signals correspond to the Natuilus:ViewFrame CORBA interface. They - are requests that the underlying view may make of the framework. */ - - void (*request_location_change) (NautilusView *view, - Nautilus_NavigationRequestInfo *navinfo); - void (*request_selection_change) (NautilusView *view, - Nautilus_SelectionRequestInfo *selinfo); - void (*request_status_change) (NautilusView *view, - Nautilus_StatusRequestInfo *loc); - void (*request_progress_change) (NautilusView *view, - Nautilus_ProgressRequestInfo *loc); - void (*notify_zoom_level) (NautilusView *view, - gdouble zoom_level); - - /* Not a signal. Work-around for Gtk+'s lack of a 'constructed' operation */ - void (*view_constructed) (NautilusView *view); - - GtkBinClass *parent_class; - guint num_construct_args; - - gpointer servant_init_func, servant_destroy_func, vepv; - gpointer zoomable_servant_init_func, zoomable_servant_destroy_func, zoomable_vepv; +#define NAUTILUS_TYPE_VIEW (nautilus_view_get_type ()) +#define NAUTILUS_VIEW(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_VIEW, NautilusView)) +#define NAUTILUS_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_VIEW, NautilusViewClass)) +#define NAUTILUS_IS_VIEW(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_VIEW)) +#define NAUTILUS_IS_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), NAUTILUS_TYPE_VIEW)) + +typedef struct NautilusView NautilusView; +typedef struct NautilusViewClass NautilusViewClass; + +struct NautilusViewClass { + GtkBinClass parent_spot; + + /* These signals correspond to the Natuilus:ViewFrame CORBA interface. They + are requests that the underlying view may make of the framework. */ + + void (*request_location_change) (NautilusView *view, + Nautilus_NavigationRequestInfo *navinfo); + void (*request_selection_change) (NautilusView *view, + Nautilus_SelectionRequestInfo *selinfo); + void (*request_status_change) (NautilusView *view, + Nautilus_StatusRequestInfo *loc); + void (*request_progress_change) (NautilusView *view, + Nautilus_ProgressRequestInfo *loc); + void (*notify_zoom_level) (NautilusView *view, + gdouble zoom_level); + + /* Not a signal. Work-around for Gtk+'s lack of a 'constructed' operation */ + void (*view_constructed) (NautilusView *view); + + GtkBinClass *parent_class; + guint num_construct_args; + + gpointer servant_init_func, servant_destroy_func, vepv; + gpointer zoomable_servant_init_func, zoomable_servant_destroy_func, zoomable_vepv; }; -typedef struct _NautilusViewComponentType NautilusViewComponentType; - -struct _NautilusView -{ - GtkBin parent; - - GtkWidget *main_window; - - char *iid; - - BonoboObjectClient *client_object; - GtkWidget *client_widget; - - BonoboObject *view_frame; - BonoboObject *zoomable_frame; - - Nautilus_Zoomable zoomable; - NautilusViewComponentType *component_class; - gpointer component_data; - - guint construct_arg_count; - - guint timer_id; - guint checking; +typedef struct NautilusViewComponentType NautilusViewComponentType; + +struct NautilusView { + GtkBin parent; + + GtkWidget *main_window; + + char *iid; + + BonoboObjectClient *client_object; + GtkWidget *client_widget; + + BonoboObject *view_frame; + BonoboObject *zoomable_frame; + + Nautilus_Zoomable zoomable; + NautilusViewComponentType *component_class; + gpointer component_data; + + guint construct_arg_count; + + guint timer_id; + guint checking; }; -GtkType nautilus_view_get_type (void); -gboolean nautilus_view_load_client (NautilusView *view, - const char * iid); -const char *nautilus_view_get_iid (NautilusView *view); -CORBA_Object nautilus_view_get_client_objref (NautilusView *view); -BonoboObject *nautilus_view_get_control_frame (NautilusView *view); -CORBA_Object nautilus_view_get_objref (NautilusView *view); +GtkType nautilus_view_get_type (void); +gboolean nautilus_view_load_client (NautilusView *view, + const char *iid); +const char * nautilus_view_get_iid (NautilusView *view); +CORBA_Object nautilus_view_get_client_objref (NautilusView *view); +BonoboObject *nautilus_view_get_control_frame (NautilusView *view); +CORBA_Object nautilus_view_get_objref (NautilusView *view); /* These functions correspond to methods of the Nautilus:View CORBAinterface */ - -void nautilus_view_notify_location_change (NautilusView *view, - Nautilus_NavigationInfo *nav_context); -void nautilus_view_notify_selection_change (NautilusView *view, - Nautilus_SelectionInfo *sel_context); -void nautilus_view_load_state (NautilusView *view, - const char *config_path); -void nautilus_view_save_state (NautilusView *view, - const char *config_path); -void nautilus_view_show_properties (NautilusView *view); -void nautilus_view_stop_location_change (NautilusView *view); -void nautilus_view_set_active_errors (NautilusView *view, gboolean enabled); - - -gboolean nautilus_view_is_zoomable (NautilusView *view); -gdouble nautilus_view_get_zoom_level (NautilusView *view); -void nautilus_view_set_zoom_level (NautilusView *view, - gdouble zoom_level); -gdouble nautilus_view_get_min_zoom_level (NautilusView *view); -gdouble nautilus_view_get_max_zoom_level (NautilusView *view); -gboolean nautilus_view_get_is_continuous (NautilusView *view); -void nautilus_view_zoom_in (NautilusView *view); -void nautilus_view_zoom_out (NautilusView *view); -void nautilus_view_zoom_to_fit (NautilusView *view); - +void nautilus_view_notify_location_change (NautilusView *view, + Nautilus_NavigationInfo *nav_context); +void nautilus_view_notify_selection_change (NautilusView *view, + Nautilus_SelectionInfo *sel_context); +void nautilus_view_load_state (NautilusView *view, + const char *config_path); +void nautilus_view_save_state (NautilusView *view, + const char *config_path); +void nautilus_view_show_properties (NautilusView *view); +void nautilus_view_stop_location_change (NautilusView *view); +void nautilus_view_set_active_errors (NautilusView *view, + gboolean enabled); +gboolean nautilus_view_is_zoomable (NautilusView *view); +gdouble nautilus_view_get_zoom_level (NautilusView *view); +void nautilus_view_set_zoom_level (NautilusView *view, + gdouble zoom_level); +gdouble nautilus_view_get_min_zoom_level (NautilusView *view); +gdouble nautilus_view_get_max_zoom_level (NautilusView *view); +gboolean nautilus_view_get_is_continuous (NautilusView *view); +void nautilus_view_zoom_in (NautilusView *view); +void nautilus_view_zoom_out (NautilusView *view); +void nautilus_view_zoom_to_fit (NautilusView *view); /* This is a "protected" operation */ -void nautilus_view_construct_arg_set(NautilusView *view); +void nautilus_view_construct_arg_set (NautilusView *view); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* __NAUTILUS_VIEW_H__ */ +#endif /* NAUTILUS_VIEW_H */ diff --git a/src/ntl-window-msgs.c b/src/ntl-window-msgs.c index 6f6953543..776ecfb0f 100644 --- a/src/ntl-window-msgs.c +++ b/src/ntl-window-msgs.c @@ -36,6 +36,8 @@ #include <stdarg.h> #include <libgnome/gnome-i18n.h> #include <libgnomeui/gnome-dialog-util.h> +#include <libgnomevfs/gnome-vfs-uri.h> +#include <libgnomevfs/gnome-vfs-async-ops.h> #include <libnautilus/nautilus-string.h> #include <libnautilus/nautilus-gtk-extensions.h> #include <libnautilus/nautilus-metadata.h> @@ -45,6 +47,7 @@ #include "ntl-window-private.h" #include "ntl-window-state.h" #include "nautilus-location-bar.h" +#include "ntl-types.h" /* #define EXTREME_DEBUGGING */ @@ -471,10 +474,10 @@ nautilus_window_update_view (NautilusWindow *window, } void -nautilus_window_view_destroyed(NautilusView *view, NautilusWindow *window) +nautilus_window_view_destroyed (NautilusView *view, NautilusWindow *window) { NautilusWindowStateItem item = VIEW_ERROR; - nautilus_window_set_state_info(window, item, view, (NautilusWindowStateItem) 0); + nautilus_window_set_state_info (window, item, view, (NautilusWindowStateItem) 0); } /* This is called when we have decided we can actually change to the new view/location situation. */ @@ -521,7 +524,7 @@ nautilus_window_has_really_changed(NautilusWindow *window) if (window->pending_ni != NULL) { nautilus_window_update_internals (window, window->pending_ni); - nautilus_navinfo_free (window->pending_ni); + nautilus_navigation_info_free (window->pending_ni); window->pending_ni = NULL; } } @@ -532,9 +535,11 @@ nautilus_window_free_load_info (NautilusWindow *window) { x_message (("-> FREE_LOAD_INFO <-")); - if (window->pending_ni) - nautilus_navinfo_free(window->pending_ni); - window->pending_ni = NULL; + if (window->pending_ni != NULL) { + nautilus_navigation_info_free (window->pending_ni); + window->pending_ni = NULL; + } + window->error_views = NULL; window->new_meta_views = NULL; window->new_content_view = NULL; @@ -665,7 +670,7 @@ nautilus_window_load_content_view(NautilusWindow *window, } static gboolean -nautilus_window_update_state(gpointer data) +nautilus_window_update_state (gpointer data) { NautilusWindow *window; GSList *p; @@ -739,15 +744,12 @@ nautilus_window_update_state(gpointer data) window->made_changes++; window->reset_to_idle = FALSE; - if (window->cancel_tag) { - gnome_vfs_async_cancel (window->cancel_tag); - if (window->pending_ni != NULL) { - window->pending_ni->ah = NULL; - } + if (window->cancel_tag != NULL) { + nautilus_navigation_info_cancel (window->cancel_tag); window->cancel_tag = NULL; } - if (window->pending_ni) { + if (window->pending_ni != NULL) { nautilus_window_reset_title_internal (window, window->ni->requested_uri); /* Tell previously-notified views to go back to the old page */ @@ -1004,19 +1006,20 @@ nautilus_window_set_state_info (NautilusWindow *window, ...) } static void -nautilus_window_end_location_change_callback (NautilusNavigationInfo *navi, gpointer data) +nautilus_window_end_location_change_callback (NautilusNavigationResult result_code, + NautilusNavigationInfo *navi, + gpointer data) { NautilusWindow *window = data; char *requested_uri; char *error_message; - char * scheme_string; + char *scheme_string; g_assert (navi != NULL); window->cancel_tag = NULL; - if (navi->result_code == NAUTILUS_NAVIGATION_RESULT_OK) - { + if (result_code == NAUTILUS_NAVIGATION_RESULT_OK) { /* Navigation successful. Show the window to handle the * new-window case. (Doesn't hurt if window is already showing.) * Maybe this should go sometime later so the blank window isn't @@ -1033,7 +1036,7 @@ nautilus_window_end_location_change_callback (NautilusNavigationInfo *navi, gpoi /* Some sort of failure occurred. How 'bout we tell the user? */ requested_uri = navi->navinfo.requested_uri; - switch (navi->result_code) { + switch (result_code) { case NAUTILUS_NAVIGATION_RESULT_NOT_FOUND: error_message = g_strdup_printf (_("Couldn't find \"%s\".\nPlease check the spelling and try again."), requested_uri); @@ -1044,7 +1047,7 @@ nautilus_window_end_location_change_callback (NautilusNavigationInfo *navi, gpoi break; case NAUTILUS_NAVIGATION_RESULT_NO_HANDLER_FOR_TYPE: - error_message = g_strdup_printf ("Couldn't display \"%s\",\nbecause Nautilus cannot handle items of this type.", requested_uri); + error_message = g_strdup_printf (_("Couldn't display \"%s\",\nbecause Nautilus cannot handle items of this type."), requested_uri); break; case NAUTILUS_NAVIGATION_RESULT_UNSUPPORTED_SCHEME: @@ -1053,7 +1056,7 @@ nautilus_window_end_location_change_callback (NautilusNavigationInfo *navi, gpoi */ scheme_string = nautilus_str_get_prefix (requested_uri, ":"); g_assert (scheme_string != NULL); /* Shouldn't have gotten this error unless there's a : separator. */ - error_message = g_strdup_printf ("Couldn't display \"%s\",\nbecause Nautilus cannot handle %s: locations.", + error_message = g_strdup_printf (_("Couldn't display \"%s\",\nbecause Nautilus cannot handle %s: locations."), requested_uri, scheme_string); g_free (scheme_string); break; @@ -1063,11 +1066,11 @@ nautilus_window_end_location_change_callback (NautilusNavigationInfo *navi, gpoi * When this comes up, we should figure out what's really happening * and add another specific case. */ - error_message = g_strdup_printf ("Nautilus cannot display \"%s\".", requested_uri); + error_message = g_strdup_printf (_("Nautilus cannot display \"%s\"."), requested_uri); } if (navi != NULL) { - nautilus_navinfo_free (navi); + nautilus_navigation_info_free (navi); } if (!GTK_WIDGET_VISIBLE (GTK_WIDGET (window))) { @@ -1133,16 +1136,15 @@ nautilus_window_begin_location_change (NautilusWindow *window, current_iid = nautilus_view_get_iid (window->content_view); } - window->cancel_tag = nautilus_navinfo_new + window->cancel_tag = nautilus_navigation_info_new (loc, window->ni, nautilus_window_end_location_change_callback, window, current_iid); } - /******** content view switching **********/ static void -view_menu_switch_views_cb (GtkWidget *widget, gpointer data) +view_menu_switch_views_callback (GtkWidget *widget, gpointer data) { NautilusWindow *window; NautilusView *view; @@ -1212,7 +1214,7 @@ nautilus_window_load_content_view_menu (NautilusWindow *window, nautilus_gtk_signal_connect_free_data (GTK_OBJECT (menu_item), "activate", - GTK_SIGNAL_FUNC (view_menu_switch_views_cb), + GTK_SIGNAL_FUNC (view_menu_switch_views_callback), g_strdup (identifier->iid)); /* Store reference to window in item; no need to free this. */ diff --git a/src/ntl-window.c b/src/ntl-window.c index dcc93dc3b..250b15f55 100644 --- a/src/ntl-window.c +++ b/src/ntl-window.c @@ -43,6 +43,7 @@ #include <libnautilus/nautilus-string.h> #include "nautilus-zoom-control.h" #include <ctype.h> +#include <libgnomevfs/gnome-vfs-uri.h> enum { diff --git a/src/ntl-window.h b/src/ntl-window.h index af5e9926a..8b353150b 100644 --- a/src/ntl-window.h +++ b/src/ntl-window.h @@ -30,7 +30,7 @@ #include <libgnomeui/gnome-app.h> #include <libnautilus/nautilus-bookmark.h> -#include "ntl-types.h" +#include "ntl-uri-map.h" #include "ntl-view.h" #include "ntl-index-panel.h" @@ -106,7 +106,7 @@ struct _NautilusWindow { enum { NW_LOADING_INFO, NW_LOADING_VIEWS, NW_IDLE } state; - gpointer cancel_tag; + NautilusNavigationInfo *cancel_tag; guint action_tag; guint16 made_changes, making_changes; |