diff options
author | Andy Hertzfeld <andy@src.gnome.org> | 2001-03-15 01:40:35 +0000 |
---|---|---|
committer | Andy Hertzfeld <andy@src.gnome.org> | 2001-03-15 01:40:35 +0000 |
commit | 8344ebff0bcd6adef29d68eabd304ff3b9b89b78 (patch) | |
tree | ed04497b299c97a4ab27813a05f649a1c7fc7551 | |
parent | 453aabc32634fe6c984f8b12125dca81ade52eb9 (diff) | |
download | nautilus-8344ebff0bcd6adef29d68eabd304ff3b9b89b78.tar.gz |
added preferences to control annotation fetching and display
added preferences to control annotation fetching and display
* libnautilus-extensions/nautilus-annotation.c:
(digest_file_close_callback), (read_file_open_callback),
(calculate_file_digest), (got_annotations_callback),
(get_annotation_from_server), (nautilus_annotation_get_annotation),
(nautilus_annotation_has_annotation):
* libnautilus-extensions/nautilus-global-preferences.c:
(global_preferences_install_descriptions),
(global_preferences_install_defaults),
(global_preferences_create_dialog):
* libnautilus-extensions/nautilus-global-preferences.h:
* libnautilus-extensions/nautilus-icon-container.c: (destroy),
(nautilus_icon_container_initialize), (update_label_color),
(nautilus_icon_container_annotation_changed):
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-annotation.c | 26 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-global-preferences.c | 33 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-global-preferences.h | 4 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-icon-container.c | 18 | ||||
-rw-r--r-- | libnautilus-private/nautilus-annotation.c | 26 | ||||
-rw-r--r-- | libnautilus-private/nautilus-global-preferences.c | 33 | ||||
-rw-r--r-- | libnautilus-private/nautilus-global-preferences.h | 4 | ||||
-rw-r--r-- | libnautilus-private/nautilus-icon-container.c | 18 |
9 files changed, 170 insertions, 12 deletions
@@ -1,3 +1,23 @@ +2001-03-14 Andy Hertzfeld <andy@eazel.com> + + added preferences to control annotation fetching and display + + * libnautilus-extensions/nautilus-annotation.c: + (digest_file_close_callback), (read_file_open_callback), + (calculate_file_digest), (got_annotations_callback), + (get_annotation_from_server), (nautilus_annotation_get_annotation), + (nautilus_annotation_has_annotation): + + * libnautilus-extensions/nautilus-global-preferences.c: + (global_preferences_install_descriptions), + (global_preferences_install_defaults), + (global_preferences_create_dialog): + + * libnautilus-extensions/nautilus-global-preferences.h: + * libnautilus-extensions/nautilus-icon-container.c: (destroy), + (nautilus_icon_container_initialize), (update_label_color), + (nautilus_icon_container_annotation_changed): + 2001-03-12 Andy Hertzfeld <andy@eazel.com> * components/rss-control/nautilus-rss-control.c: diff --git a/libnautilus-extensions/nautilus-annotation.c b/libnautilus-extensions/nautilus-annotation.c index 0280239fe..2327abe10 100644 --- a/libnautilus-extensions/nautilus-annotation.c +++ b/libnautilus-extensions/nautilus-annotation.c @@ -89,6 +89,8 @@ struct NautilusDigestFileHandle { #define READ_CHUNK_SIZE 65536 #define SERVER_URI_TEMPLATE "http://dellbert.differnet.com/get_notes.cgi?ids=%s" +static int open_count = 0; +static int close_count = 0; static GList* annotation_request_queue = NULL; static GHashTable *files_awaiting_annotation = NULL; @@ -364,6 +366,8 @@ digest_file_close_callback (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer callback_data) { + close_count += 1; + g_message ("opened %d, closed %d", open_count, close_count); } /* Close the file and then tell the caller we succeeded, handing off @@ -476,12 +480,14 @@ read_file_open_callback (GnomeVFSAsyncHandle *handle, /* Handle the failure case. */ if (result != GNOME_VFS_OK) { + g_message ("open failed, error was %d", result); digest_file_failed (digest_handle, result); return; } /* read in the first chunk of the file */ digest_handle->opened = TRUE; + open_count += 1; gnome_vfs_async_read (digest_handle->handle, digest_handle->buffer, READ_CHUNK_SIZE, @@ -498,6 +504,11 @@ calculate_file_digest (NautilusFile *file, NautilusCalculateDigestCallback callb { NautilusDigestFileHandle *handle; char *uri; + + /* if annotation lookup is disabled, don't bother to do all this work */ + if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS)) { + return 0; + } /* allocate a digest-handle structure to keep our state */ @@ -702,9 +713,7 @@ got_annotations_callback (GnomeVFSResult result, } /* write the annotation out to our cache area, if necessary */ - if (annotation_count > 0) { - g_message ("got annotation, count is %d", annotation_count); - + if (annotation_count > 0) { saved_annotation = xmlCopyNode (next_annotation, TRUE); add_annotations_to_file (saved_annotation, digest); } @@ -784,6 +793,12 @@ get_annotation_from_server (NautilusFile *file, const char *file_digest) return; } + /* only do this if lookups are enabled */ + /* if annotation lookup is disabled, don't bother to do all this work */ + if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS)) { + return; + } + /* add the request to the queue, and kick it off it there's enough of them */ annotation_request_queue = g_list_prepend (annotation_request_queue, g_strdup (file_digest)); @@ -845,7 +860,6 @@ char *nautilus_annotation_get_annotation (NautilusFile *file) /* there's a digest, so we if we have the annotations for the file cached locally */ annotations = look_up_local_annotation (file, digest); if (annotations != NULL) { - g_message ("already got local annotation for digest %s", digest); g_free (digest); return annotations; } @@ -872,6 +886,10 @@ int nautilus_annotation_has_annotation (NautilusFile *file) char *digest_info, *digits, *temp_str; int count; + if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS)) { + return 0; + } + digest_info = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_NOTES_INFO, NULL); if (digest_info != NULL) { diff --git a/libnautilus-extensions/nautilus-global-preferences.c b/libnautilus-extensions/nautilus-global-preferences.c index 2ae55a2d5..fd7d434b1 100644 --- a/libnautilus-extensions/nautilus-global-preferences.c +++ b/libnautilus-extensions/nautilus-global-preferences.c @@ -220,6 +220,11 @@ global_preferences_install_descriptions (void) nautilus_preferences_set_description (NAUTILUS_PREFERENCES_HOME_URI, _("Location:")); + + nautilus_preferences_set_description (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS, + _("Look-up remote file annotations")); + nautilus_preferences_set_description (NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS, + _("Display file annotations")); global_preferences_install_sidebar_panel_descriptions (); @@ -362,6 +367,14 @@ global_preferences_install_defaults (void) NAUTILUS_USER_LEVEL_NOVICE, FALSE); + nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS, + NAUTILUS_USER_LEVEL_NOVICE, + FALSE); + + nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS, + NAUTILUS_USER_LEVEL_NOVICE, + FALSE); + /* Add the gnome-vfs path to the list of monitored directories - for proxy settings */ nautilus_preferences_monitor_directory (SYSTEM_GNOME_VFS_PATH); @@ -506,7 +519,8 @@ global_preferences_create_dialog (void) GtkWidget *appearance_pane; GtkWidget *tradeoffs_pane; GtkWidget *navigation_pane; - + GtkWidget *annotation_pane; + /* * In the soon to come star trek future, the following widgetry * might be either fetched from a glade file or generated from @@ -760,6 +774,23 @@ global_preferences_create_dialog (void) NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM); + /* annotation preferences */ + + annotation_pane = nautilus_preferences_box_add_pane (preference_box, + _("Annotations")); + + nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (annotation_pane), _("File Annotations")); + + nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (annotation_pane), + 0, + NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS, + NAUTILUS_PREFERENCE_ITEM_BOOLEAN); + + nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (annotation_pane), + 0, + NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS, + NAUTILUS_PREFERENCE_ITEM_BOOLEAN); + /* Update the dialog so that the right items show up based on the current user level */ nautilus_preferences_dialog_update (NAUTILUS_PREFERENCES_DIALOG (prefs_dialog)); diff --git a/libnautilus-extensions/nautilus-global-preferences.h b/libnautilus-extensions/nautilus-global-preferences.h index 9409b1f03..9f1f5a18b 100644 --- a/libnautilus-extensions/nautilus-global-preferences.h +++ b/libnautilus-extensions/nautilus-global-preferences.h @@ -83,6 +83,10 @@ BEGIN_GNOME_DECLS #define NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR "preferences/start_with_status_bar" #define NAUTILUS_PREFERENCES_START_WITH_SIDEBAR "preferences/start_with_sidebar" +/* enabling annotations */ +#define NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS "preferences/lookup_annotations" +#define NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS "preferences/display_annotations" + /* The sidebar panel preferences are computed from their oafids, which aren't known at * compile time. We publish the namespace so that interested parties can monitor changes * to all of them collectively, without having to know the exact oaf iids. diff --git a/libnautilus-extensions/nautilus-icon-container.c b/libnautilus-extensions/nautilus-icon-container.c index 66a5b5ba5..4f009576b 100644 --- a/libnautilus-extensions/nautilus-icon-container.c +++ b/libnautilus-extensions/nautilus-icon-container.c @@ -123,6 +123,7 @@ static void activate_selected_items (NautilusIconConta static void nautilus_icon_container_initialize_class (NautilusIconContainerClass *class); static void nautilus_icon_container_initialize (NautilusIconContainer *container); static void nautilus_icon_container_theme_changed (gpointer user_data); +static void nautilus_icon_container_annotation_changed (gpointer user_data); static void compute_stretch (StretchState *start, StretchState *current); @@ -147,6 +148,7 @@ static gboolean is_renaming (NautilusIconContainer *contain static gboolean is_renaming_pending (NautilusIconContainer *container); static void process_pending_icon_to_rename (NautilusIconContainer *container); + NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusIconContainer, nautilus_icon_container, GNOME_TYPE_CANVAS) @@ -2273,7 +2275,6 @@ select_previous_or_next_name (NautilusIconContainer *container, } /* GtkObject methods. */ - static void destroy (GtkObject *object) { @@ -2320,6 +2321,10 @@ destroy (GtkObject *object) gtk_object_destroy (GTK_OBJECT (container->details->rename_widget)); } + /* remove the annotation preference callbacks */ + nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS, nautilus_icon_container_annotation_changed, container); + nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS, nautilus_icon_container_annotation_changed, container); + /* FIXME: The code to extract colors from the theme should be in FMDirectoryView, not here. * The NautilusIconContainer class should simply provide calls to set the colors. */ @@ -3383,6 +3388,10 @@ nautilus_icon_container_initialize (NautilusIconContainer *container) gtk_signal_connect (GTK_OBJECT (container), "focus-out-event", handle_focus_out_event, NULL); + /* add callbacks to notify us when the annotation state changes */ + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS, nautilus_icon_container_annotation_changed, container); + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS, nautilus_icon_container_annotation_changed, container); + /* FIXME: The code to extract colors from the theme should be in FMDirectoryView, not here. * The NautilusIconContainer class should simply provide calls to set the colors. */ @@ -5084,6 +5093,13 @@ update_label_color (NautilusBackground *background, } } +/* handle the annotation preference changes by updating the icons */ +static void +nautilus_icon_container_annotation_changed (gpointer user_data) +{ + nautilus_icon_container_request_update_all (NAUTILUS_ICON_CONTAINER (user_data)); +} + /* Return if the icon container is a fixed size */ gboolean diff --git a/libnautilus-private/nautilus-annotation.c b/libnautilus-private/nautilus-annotation.c index 0280239fe..2327abe10 100644 --- a/libnautilus-private/nautilus-annotation.c +++ b/libnautilus-private/nautilus-annotation.c @@ -89,6 +89,8 @@ struct NautilusDigestFileHandle { #define READ_CHUNK_SIZE 65536 #define SERVER_URI_TEMPLATE "http://dellbert.differnet.com/get_notes.cgi?ids=%s" +static int open_count = 0; +static int close_count = 0; static GList* annotation_request_queue = NULL; static GHashTable *files_awaiting_annotation = NULL; @@ -364,6 +366,8 @@ digest_file_close_callback (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer callback_data) { + close_count += 1; + g_message ("opened %d, closed %d", open_count, close_count); } /* Close the file and then tell the caller we succeeded, handing off @@ -476,12 +480,14 @@ read_file_open_callback (GnomeVFSAsyncHandle *handle, /* Handle the failure case. */ if (result != GNOME_VFS_OK) { + g_message ("open failed, error was %d", result); digest_file_failed (digest_handle, result); return; } /* read in the first chunk of the file */ digest_handle->opened = TRUE; + open_count += 1; gnome_vfs_async_read (digest_handle->handle, digest_handle->buffer, READ_CHUNK_SIZE, @@ -498,6 +504,11 @@ calculate_file_digest (NautilusFile *file, NautilusCalculateDigestCallback callb { NautilusDigestFileHandle *handle; char *uri; + + /* if annotation lookup is disabled, don't bother to do all this work */ + if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS)) { + return 0; + } /* allocate a digest-handle structure to keep our state */ @@ -702,9 +713,7 @@ got_annotations_callback (GnomeVFSResult result, } /* write the annotation out to our cache area, if necessary */ - if (annotation_count > 0) { - g_message ("got annotation, count is %d", annotation_count); - + if (annotation_count > 0) { saved_annotation = xmlCopyNode (next_annotation, TRUE); add_annotations_to_file (saved_annotation, digest); } @@ -784,6 +793,12 @@ get_annotation_from_server (NautilusFile *file, const char *file_digest) return; } + /* only do this if lookups are enabled */ + /* if annotation lookup is disabled, don't bother to do all this work */ + if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS)) { + return; + } + /* add the request to the queue, and kick it off it there's enough of them */ annotation_request_queue = g_list_prepend (annotation_request_queue, g_strdup (file_digest)); @@ -845,7 +860,6 @@ char *nautilus_annotation_get_annotation (NautilusFile *file) /* there's a digest, so we if we have the annotations for the file cached locally */ annotations = look_up_local_annotation (file, digest); if (annotations != NULL) { - g_message ("already got local annotation for digest %s", digest); g_free (digest); return annotations; } @@ -872,6 +886,10 @@ int nautilus_annotation_has_annotation (NautilusFile *file) char *digest_info, *digits, *temp_str; int count; + if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS)) { + return 0; + } + digest_info = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_NOTES_INFO, NULL); if (digest_info != NULL) { diff --git a/libnautilus-private/nautilus-global-preferences.c b/libnautilus-private/nautilus-global-preferences.c index 2ae55a2d5..fd7d434b1 100644 --- a/libnautilus-private/nautilus-global-preferences.c +++ b/libnautilus-private/nautilus-global-preferences.c @@ -220,6 +220,11 @@ global_preferences_install_descriptions (void) nautilus_preferences_set_description (NAUTILUS_PREFERENCES_HOME_URI, _("Location:")); + + nautilus_preferences_set_description (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS, + _("Look-up remote file annotations")); + nautilus_preferences_set_description (NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS, + _("Display file annotations")); global_preferences_install_sidebar_panel_descriptions (); @@ -362,6 +367,14 @@ global_preferences_install_defaults (void) NAUTILUS_USER_LEVEL_NOVICE, FALSE); + nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS, + NAUTILUS_USER_LEVEL_NOVICE, + FALSE); + + nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS, + NAUTILUS_USER_LEVEL_NOVICE, + FALSE); + /* Add the gnome-vfs path to the list of monitored directories - for proxy settings */ nautilus_preferences_monitor_directory (SYSTEM_GNOME_VFS_PATH); @@ -506,7 +519,8 @@ global_preferences_create_dialog (void) GtkWidget *appearance_pane; GtkWidget *tradeoffs_pane; GtkWidget *navigation_pane; - + GtkWidget *annotation_pane; + /* * In the soon to come star trek future, the following widgetry * might be either fetched from a glade file or generated from @@ -760,6 +774,23 @@ global_preferences_create_dialog (void) NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM); + /* annotation preferences */ + + annotation_pane = nautilus_preferences_box_add_pane (preference_box, + _("Annotations")); + + nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (annotation_pane), _("File Annotations")); + + nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (annotation_pane), + 0, + NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS, + NAUTILUS_PREFERENCE_ITEM_BOOLEAN); + + nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (annotation_pane), + 0, + NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS, + NAUTILUS_PREFERENCE_ITEM_BOOLEAN); + /* Update the dialog so that the right items show up based on the current user level */ nautilus_preferences_dialog_update (NAUTILUS_PREFERENCES_DIALOG (prefs_dialog)); diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h index 9409b1f03..9f1f5a18b 100644 --- a/libnautilus-private/nautilus-global-preferences.h +++ b/libnautilus-private/nautilus-global-preferences.h @@ -83,6 +83,10 @@ BEGIN_GNOME_DECLS #define NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR "preferences/start_with_status_bar" #define NAUTILUS_PREFERENCES_START_WITH_SIDEBAR "preferences/start_with_sidebar" +/* enabling annotations */ +#define NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS "preferences/lookup_annotations" +#define NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS "preferences/display_annotations" + /* The sidebar panel preferences are computed from their oafids, which aren't known at * compile time. We publish the namespace so that interested parties can monitor changes * to all of them collectively, without having to know the exact oaf iids. diff --git a/libnautilus-private/nautilus-icon-container.c b/libnautilus-private/nautilus-icon-container.c index 66a5b5ba5..4f009576b 100644 --- a/libnautilus-private/nautilus-icon-container.c +++ b/libnautilus-private/nautilus-icon-container.c @@ -123,6 +123,7 @@ static void activate_selected_items (NautilusIconConta static void nautilus_icon_container_initialize_class (NautilusIconContainerClass *class); static void nautilus_icon_container_initialize (NautilusIconContainer *container); static void nautilus_icon_container_theme_changed (gpointer user_data); +static void nautilus_icon_container_annotation_changed (gpointer user_data); static void compute_stretch (StretchState *start, StretchState *current); @@ -147,6 +148,7 @@ static gboolean is_renaming (NautilusIconContainer *contain static gboolean is_renaming_pending (NautilusIconContainer *container); static void process_pending_icon_to_rename (NautilusIconContainer *container); + NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusIconContainer, nautilus_icon_container, GNOME_TYPE_CANVAS) @@ -2273,7 +2275,6 @@ select_previous_or_next_name (NautilusIconContainer *container, } /* GtkObject methods. */ - static void destroy (GtkObject *object) { @@ -2320,6 +2321,10 @@ destroy (GtkObject *object) gtk_object_destroy (GTK_OBJECT (container->details->rename_widget)); } + /* remove the annotation preference callbacks */ + nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS, nautilus_icon_container_annotation_changed, container); + nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS, nautilus_icon_container_annotation_changed, container); + /* FIXME: The code to extract colors from the theme should be in FMDirectoryView, not here. * The NautilusIconContainer class should simply provide calls to set the colors. */ @@ -3383,6 +3388,10 @@ nautilus_icon_container_initialize (NautilusIconContainer *container) gtk_signal_connect (GTK_OBJECT (container), "focus-out-event", handle_focus_out_event, NULL); + /* add callbacks to notify us when the annotation state changes */ + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS, nautilus_icon_container_annotation_changed, container); + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_DISPLAY_ANNOTATIONS, nautilus_icon_container_annotation_changed, container); + /* FIXME: The code to extract colors from the theme should be in FMDirectoryView, not here. * The NautilusIconContainer class should simply provide calls to set the colors. */ @@ -5084,6 +5093,13 @@ update_label_color (NautilusBackground *background, } } +/* handle the annotation preference changes by updating the icons */ +static void +nautilus_icon_container_annotation_changed (gpointer user_data) +{ + nautilus_icon_container_request_update_all (NAUTILUS_ICON_CONTAINER (user_data)); +} + /* Return if the icon container is a fixed size */ gboolean |