diff options
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-annotation.c | 76 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-canvas-note-item.c | 5 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-icon-canvas-item.c | 9 | ||||
-rw-r--r-- | libnautilus-private/nautilus-annotation.c | 76 | ||||
-rw-r--r-- | libnautilus-private/nautilus-canvas-note-item.c | 5 | ||||
-rw-r--r-- | libnautilus-private/nautilus-icon-canvas-item.c | 9 |
7 files changed, 147 insertions, 50 deletions
@@ -1,3 +1,20 @@ +2001-03-21 Andy Hertzfeld <andy@eazel.com> + + added queuing for` digest requests, so we can control the number + of simultaneous requests, so we don't choke in large directories. + + also, removed some debug statements and clean-up + + * libnautilus-extensions/nautilus-annotation.c: + (digest_file_completed), (digest_file_failed), + (calculate_file_digest), (process_digest_requests), + (queue_file_digest_request), (got_annotations_callback), + (nautilus_annotation_get_annotation): + * libnautilus-extensions/nautilus-canvas-note-item.c: + (nautilus_canvas_note_item_set_note_text), (get_display_text): + * libnautilus-extensions/nautilus-icon-canvas-item.c: + (create_annotation): + 2001-03-20 Andy Hertzfeld <andy@eazel.com> * libnautilus-extensions/nautilus-canvas-note-item.c: diff --git a/libnautilus-extensions/nautilus-annotation.c b/libnautilus-extensions/nautilus-annotation.c index d89b0b9af..be8643bf0 100644 --- a/libnautilus-extensions/nautilus-annotation.c +++ b/libnautilus-extensions/nautilus-annotation.c @@ -87,12 +87,16 @@ struct NautilusDigestFileHandle { }; #define READ_CHUNK_SIZE 65536 -#define SERVER_URI_TEMPLATE "http://dellbert.differnet.com/get_notes.cgi?ids=%s" +#define MAX_DIGESTS_IN_PROGRESS 16 +#define SERVER_URI_TEMPLATE "http://dellbert.differnet.com/get_notes.cgi?ids=%s" static int open_count = 0; static int close_count = 0; +static int digests_in_progress = 0; +static GList* digest_request_queue = NULL; static GList* annotation_request_queue = NULL; + static GHashTable *files_awaiting_annotation = NULL; static void md5_transform (guint32 buf[4], const guint32 in[16]); @@ -102,6 +106,8 @@ static union _endian { int i; char b[4]; } *_endian = (union _endian *)&_ie; #define IS_BIG_ENDIAN() (_endian->b[0] == '\x44') #define IS_LITTLE_ENDIAN() (_endian->b[0] == '\x11') +static void got_file_digest (NautilusFile *file, const char *file_digest); +static void process_digest_requests (void); /* * Note: this code is harmless on little-endian machines. @@ -389,6 +395,8 @@ digest_file_completed (NautilusDigestFileHandle *digest_handle) NULL); } + digests_in_progress -= 1; + /* Invoke the callback to continue processing the annotation */ md5_final (&digest_handle->digest_context, digest_result); @@ -406,15 +414,14 @@ digest_file_completed (NautilusDigestFileHandle *digest_handle) } (* digest_handle->callback) (digest_handle->file, &digest_string[0]); - - { - char* name = nautilus_file_get_name (digest_handle->file); - g_free (name); - } nautilus_file_unref (digest_handle->file); g_free (digest_handle->buffer); g_free (digest_handle); + + /* start new digest requests if necessary */ + process_digest_requests (); + } /* Tell the caller we failed. */ @@ -427,11 +434,16 @@ digest_file_failed (NautilusDigestFileHandle *digest_handle, GnomeVFSResult resu NULL); } g_free (digest_handle->buffer); + + digests_in_progress -= 1; (* digest_handle->callback) (digest_handle->file, NULL); nautilus_file_unref (digest_handle->file); g_free (digest_handle); + + /* start new digest requests if necessary */ + process_digest_requests (); } /* Here is the callback from the file read routine, where we actually accumulate the checksum */ @@ -504,7 +516,6 @@ read_file_open_callback (GnomeVFSAsyncHandle *handle, digest_handle); } - /* calculate the digest for the passed-in file asynchronously, invoking the passed in * callback when the calculation has been completed. */ @@ -514,11 +525,7 @@ 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 */ handle = g_new0 (NautilusDigestFileHandle, 1); @@ -545,6 +552,47 @@ calculate_file_digest (NautilusFile *file, NautilusCalculateDigestCallback callb return handle; } +/* process the digest request queue, launching as many requests as we can handle */ +static void +process_digest_requests (void) +{ + GList *current_entry; + NautilusFile *file; + + while (digests_in_progress < MAX_DIGESTS_IN_PROGRESS && digest_request_queue != NULL) + { + /* pull entry off queue */ + current_entry = digest_request_queue; + digest_request_queue = current_entry->next; + + file = NAUTILUS_FILE (current_entry->data); + + /* initiate request */ + calculate_file_digest (file, (NautilusCalculateDigestCallback) got_file_digest); + + /* dispose of queue entry */ + nautilus_file_unref (file); + g_list_free_1 (current_entry); + + digests_in_progress += 1; + } +} + +/* queue the digest request, and start processing it if we haven't exceeded the limit of requests + * in progress + */ +static void +queue_file_digest_request (NautilusFile *file) +{ + /* if annotation lookup is disabled, don't bother to do all this work */ + if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS)) { + return; + } + nautilus_file_ref (file); + digest_request_queue = g_list_prepend (digest_request_queue, file); + process_digest_requests (); +} + /* given a digest, retrieve an associated file object from the hash table */ static NautilusFile * get_file_from_digest (const char *digest) @@ -700,8 +748,6 @@ got_annotations_callback (GnomeVFSResult result, return; } - g_message ("got annotation response %s", file_contents); - /* inexplicably, the gnome-xml parser requires a zero-terminated array, so add the null at the end. */ buffer = g_realloc (file_contents, file_size + 1); buffer[file_size] = '\0'; @@ -867,7 +913,7 @@ char *nautilus_annotation_get_annotation (NautilusFile *file) /* there isn't a digest, so start a request for one going, and return NULL */ if (digest == NULL) { - calculate_file_digest (file, (NautilusCalculateDigestCallback) got_file_digest); + queue_file_digest_request (file); return NULL; } diff --git a/libnautilus-extensions/nautilus-canvas-note-item.c b/libnautilus-extensions/nautilus-canvas-note-item.c index 6e465466e..b466e0bb7 100644 --- a/libnautilus-extensions/nautilus-canvas-note-item.c +++ b/libnautilus-extensions/nautilus-canvas-note-item.c @@ -322,7 +322,7 @@ nautilus_canvas_note_item_set_note_text (NautilusCanvasNoteItem *note_item, cons /* set the width and height based on the display text */ /* this will get more sophisticated as we get fancier */ - display_text = get_display_text (new_text); + display_text = get_display_text (new_text); total_width = 8 * strlen (display_text); height = 16 * (1 + (total_width / ANNOTATION_WIDTH)); @@ -690,8 +690,7 @@ get_display_text (const char *note_text) } } else { display_text = g_strdup (note_text); - } - + } return display_text; } diff --git a/libnautilus-extensions/nautilus-icon-canvas-item.c b/libnautilus-extensions/nautilus-icon-canvas-item.c index 83437d07c..2353e4f1b 100644 --- a/libnautilus-extensions/nautilus-icon-canvas-item.c +++ b/libnautilus-extensions/nautilus-icon-canvas-item.c @@ -1860,19 +1860,16 @@ static void create_annotation (NautilusIconCanvasItem *icon_item, int emblem_index) { uint fill_color, outline_color; - double top, left, bottom, right; + double top, left; ArtDRect icon_rect; char *note_text; GnomeCanvas *canvas; /* compute the position for the top left of the annotation */ - nautilus_icon_canvas_item_get_icon_rectangle (icon_item, &icon_rect); left = icon_rect.x0 + 8.0; top = icon_rect.y0 + 8.0; - right = left + 220.0; - bottom = top + 24.0; - + fill_color = 0xDDDD99E0; outline_color = 0x000000FF; @@ -1884,8 +1881,6 @@ create_annotation (NautilusIconCanvasItem *icon_item, int emblem_index) nautilus_canvas_note_item_get_type (), "x1", left, "y1", top, - "x2", right, - "y2", bottom, "fill_color_rgba", fill_color, "outline_color_rgba", outline_color, "note_text", note_text, diff --git a/libnautilus-private/nautilus-annotation.c b/libnautilus-private/nautilus-annotation.c index d89b0b9af..be8643bf0 100644 --- a/libnautilus-private/nautilus-annotation.c +++ b/libnautilus-private/nautilus-annotation.c @@ -87,12 +87,16 @@ struct NautilusDigestFileHandle { }; #define READ_CHUNK_SIZE 65536 -#define SERVER_URI_TEMPLATE "http://dellbert.differnet.com/get_notes.cgi?ids=%s" +#define MAX_DIGESTS_IN_PROGRESS 16 +#define SERVER_URI_TEMPLATE "http://dellbert.differnet.com/get_notes.cgi?ids=%s" static int open_count = 0; static int close_count = 0; +static int digests_in_progress = 0; +static GList* digest_request_queue = NULL; static GList* annotation_request_queue = NULL; + static GHashTable *files_awaiting_annotation = NULL; static void md5_transform (guint32 buf[4], const guint32 in[16]); @@ -102,6 +106,8 @@ static union _endian { int i; char b[4]; } *_endian = (union _endian *)&_ie; #define IS_BIG_ENDIAN() (_endian->b[0] == '\x44') #define IS_LITTLE_ENDIAN() (_endian->b[0] == '\x11') +static void got_file_digest (NautilusFile *file, const char *file_digest); +static void process_digest_requests (void); /* * Note: this code is harmless on little-endian machines. @@ -389,6 +395,8 @@ digest_file_completed (NautilusDigestFileHandle *digest_handle) NULL); } + digests_in_progress -= 1; + /* Invoke the callback to continue processing the annotation */ md5_final (&digest_handle->digest_context, digest_result); @@ -406,15 +414,14 @@ digest_file_completed (NautilusDigestFileHandle *digest_handle) } (* digest_handle->callback) (digest_handle->file, &digest_string[0]); - - { - char* name = nautilus_file_get_name (digest_handle->file); - g_free (name); - } nautilus_file_unref (digest_handle->file); g_free (digest_handle->buffer); g_free (digest_handle); + + /* start new digest requests if necessary */ + process_digest_requests (); + } /* Tell the caller we failed. */ @@ -427,11 +434,16 @@ digest_file_failed (NautilusDigestFileHandle *digest_handle, GnomeVFSResult resu NULL); } g_free (digest_handle->buffer); + + digests_in_progress -= 1; (* digest_handle->callback) (digest_handle->file, NULL); nautilus_file_unref (digest_handle->file); g_free (digest_handle); + + /* start new digest requests if necessary */ + process_digest_requests (); } /* Here is the callback from the file read routine, where we actually accumulate the checksum */ @@ -504,7 +516,6 @@ read_file_open_callback (GnomeVFSAsyncHandle *handle, digest_handle); } - /* calculate the digest for the passed-in file asynchronously, invoking the passed in * callback when the calculation has been completed. */ @@ -514,11 +525,7 @@ 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 */ handle = g_new0 (NautilusDigestFileHandle, 1); @@ -545,6 +552,47 @@ calculate_file_digest (NautilusFile *file, NautilusCalculateDigestCallback callb return handle; } +/* process the digest request queue, launching as many requests as we can handle */ +static void +process_digest_requests (void) +{ + GList *current_entry; + NautilusFile *file; + + while (digests_in_progress < MAX_DIGESTS_IN_PROGRESS && digest_request_queue != NULL) + { + /* pull entry off queue */ + current_entry = digest_request_queue; + digest_request_queue = current_entry->next; + + file = NAUTILUS_FILE (current_entry->data); + + /* initiate request */ + calculate_file_digest (file, (NautilusCalculateDigestCallback) got_file_digest); + + /* dispose of queue entry */ + nautilus_file_unref (file); + g_list_free_1 (current_entry); + + digests_in_progress += 1; + } +} + +/* queue the digest request, and start processing it if we haven't exceeded the limit of requests + * in progress + */ +static void +queue_file_digest_request (NautilusFile *file) +{ + /* if annotation lookup is disabled, don't bother to do all this work */ + if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_LOOKUP_ANNOTATIONS)) { + return; + } + nautilus_file_ref (file); + digest_request_queue = g_list_prepend (digest_request_queue, file); + process_digest_requests (); +} + /* given a digest, retrieve an associated file object from the hash table */ static NautilusFile * get_file_from_digest (const char *digest) @@ -700,8 +748,6 @@ got_annotations_callback (GnomeVFSResult result, return; } - g_message ("got annotation response %s", file_contents); - /* inexplicably, the gnome-xml parser requires a zero-terminated array, so add the null at the end. */ buffer = g_realloc (file_contents, file_size + 1); buffer[file_size] = '\0'; @@ -867,7 +913,7 @@ char *nautilus_annotation_get_annotation (NautilusFile *file) /* there isn't a digest, so start a request for one going, and return NULL */ if (digest == NULL) { - calculate_file_digest (file, (NautilusCalculateDigestCallback) got_file_digest); + queue_file_digest_request (file); return NULL; } diff --git a/libnautilus-private/nautilus-canvas-note-item.c b/libnautilus-private/nautilus-canvas-note-item.c index 6e465466e..b466e0bb7 100644 --- a/libnautilus-private/nautilus-canvas-note-item.c +++ b/libnautilus-private/nautilus-canvas-note-item.c @@ -322,7 +322,7 @@ nautilus_canvas_note_item_set_note_text (NautilusCanvasNoteItem *note_item, cons /* set the width and height based on the display text */ /* this will get more sophisticated as we get fancier */ - display_text = get_display_text (new_text); + display_text = get_display_text (new_text); total_width = 8 * strlen (display_text); height = 16 * (1 + (total_width / ANNOTATION_WIDTH)); @@ -690,8 +690,7 @@ get_display_text (const char *note_text) } } else { display_text = g_strdup (note_text); - } - + } return display_text; } diff --git a/libnautilus-private/nautilus-icon-canvas-item.c b/libnautilus-private/nautilus-icon-canvas-item.c index 83437d07c..2353e4f1b 100644 --- a/libnautilus-private/nautilus-icon-canvas-item.c +++ b/libnautilus-private/nautilus-icon-canvas-item.c @@ -1860,19 +1860,16 @@ static void create_annotation (NautilusIconCanvasItem *icon_item, int emblem_index) { uint fill_color, outline_color; - double top, left, bottom, right; + double top, left; ArtDRect icon_rect; char *note_text; GnomeCanvas *canvas; /* compute the position for the top left of the annotation */ - nautilus_icon_canvas_item_get_icon_rectangle (icon_item, &icon_rect); left = icon_rect.x0 + 8.0; top = icon_rect.y0 + 8.0; - right = left + 220.0; - bottom = top + 24.0; - + fill_color = 0xDDDD99E0; outline_color = 0x000000FF; @@ -1884,8 +1881,6 @@ create_annotation (NautilusIconCanvasItem *icon_item, int emblem_index) nautilus_canvas_note_item_get_type (), "x1", left, "y1", top, - "x2", right, - "y2", bottom, "fill_color_rgba", fill_color, "outline_color_rgba", outline_color, "note_text", note_text, |