Kouhei Sutou
kous****@users*****
Mon Oct 16 00:17:16 JST 2006
Index: kazehakase/src/kz-downloader.c diff -u kazehakase/src/kz-downloader.c:1.28 kazehakase/src/kz-downloader.c:1.29 --- kazehakase/src/kz-downloader.c:1.28 Wed Jul 6 11:09:54 2005 +++ kazehakase/src/kz-downloader.c Mon Oct 16 00:17:16 2006 @@ -384,6 +384,15 @@ return kz_io_get_buffer(downloader->io); } +gsize +kz_downloader_get_size (KzDownloader *downloader) +{ + g_return_val_if_fail(KZ_IS_DOWNLOADER(downloader), NULL); + g_return_val_if_fail(downloader->io, NULL); + + return kz_io_get_file_size(downloader->io); +} + gint kz_downloader_get_percent (KzDownloader *downloader) @@ -426,6 +435,18 @@ return TRUE; } +gboolean +kz_downloader_to_buffer (KzDownloader *downloader) +{ + g_return_val_if_fail(KZ_IS_DOWNLOADER(downloader), FALSE); + + kz_downloader_connect_signals(downloader); + + kz_io_load_to_buffer(downloader->io); + + return TRUE; +} + void kz_downloader_cancel (KzDownloader *downloader) Index: kazehakase/src/kz-downloader.h diff -u kazehakase/src/kz-downloader.h:1.11 kazehakase/src/kz-downloader.h:1.12 --- kazehakase/src/kz-downloader.h:1.11 Thu Nov 25 16:28:47 2004 +++ kazehakase/src/kz-downloader.h Mon Oct 16 00:17:16 2006 @@ -66,7 +66,9 @@ void kz_downloader_cancel (KzDownloader *downloader); gboolean kz_downloader_to_file (KzDownloader *downloader); +gboolean kz_downloader_to_buffer (KzDownloader *downloader); const gchar *kz_downloader_get_string (KzDownloader *downloader); +gsize kz_downloader_get_size (KzDownloader *downloader); gint kz_downloader_get_percent (KzDownloader *downloader); gsize kz_downloader_get_current_progress (KzDownloader *downloader); gsize kz_downloader_get_total_progress (KzDownloader *downloader); Index: kazehakase/src/kz-favicon.c diff -u kazehakase/src/kz-favicon.c:1.35 kazehakase/src/kz-favicon.c:1.36 --- kazehakase/src/kz-favicon.c:1.35 Thu Jul 14 20:35:08 2005 +++ kazehakase/src/kz-favicon.c Mon Oct 16 00:17:16 2006 @@ -49,6 +49,12 @@ #define MAX_FAVICONS 2000 +typedef struct downloader_info +{ + const gchar *document_uri; + gchar *favicon_file_location; +} downloader_info_t; + static void kz_favicon_class_init (KzFaviconClass *klass); static void kz_favicon_init (KzFavicon *kzfav); static void kz_favicon_dispose (GObject *object); @@ -59,9 +65,9 @@ KzFavicon *kzfav); static void cb_downloader_load_complete (KzDownloader *dl, - const gchar *uri); + downloader_info_t *info); static void cb_downloader_load_error (KzDownloader *dl, - const gchar *uri); + downloader_info_t *info); static GObjectClass *parent_class = NULL; static KzFavicon *kzfavicon_single = NULL; @@ -231,44 +237,61 @@ static void -kz_downloader_disconnect_signal(KzDownloader *dl, const gchar *uri) +kz_downloader_disconnect_signal(KzDownloader *dl, downloader_info_t *info) { g_signal_handlers_disconnect_by_func(dl, G_CALLBACK(cb_downloader_load_complete), - (gpointer)uri); + (gpointer)info); g_signal_handlers_disconnect_by_func(dl, G_CALLBACK(cb_downloader_load_error), - (gpointer)uri); + (gpointer)info); } static void -cb_downloader_load_complete (KzDownloader *dl, const gchar *uri) +cb_downloader_load_complete (KzDownloader *dl, downloader_info_t *info) { GQuark quark; + const gchar *uri; + uri = info->document_uri; quark = g_quark_from_string(uri); - kz_downloader_disconnect_signal(dl, uri); + kz_downloader_disconnect_signal(dl, info); + + if (!g_file_set_contents(info->favicon_file_location, + kz_downloader_get_string(dl), + kz_downloader_get_size(dl), + NULL) && + g_file_test(info->favicon_file_location, G_FILE_TEST_EXISTS)) + g_unlink(info->favicon_file_location); + g_free(info->favicon_file_location); + g_free(info); + g_idle_add(idle_unref_dl, dl); /* FIXME! Do not use kzfavicon_sigle object! */ g_signal_emit(kzfavicon_single, kz_favicon_signals[READY_SIGNAL], quark, - uri); + uri); } static void -cb_downloader_load_error (KzDownloader *dl, const gchar *uri) +cb_downloader_load_error (KzDownloader *dl, downloader_info_t *info) { - gchar *hash_key; + gchar *hash_key, *uri; KzFavicon *kzfav = kzfavicon_single; KzFaviconPrivate *priv = KZ_FAVICON_GET_PRIVATE (kzfav); - kz_downloader_disconnect_signal(dl, uri); + uri = info->document_uri; + + kz_downloader_disconnect_signal(dl, info); g_idle_add(idle_unref_dl, dl); + g_free(info->favicon_file_location); + g_free(info); + hash_key = create_profile_key_from_uri(uri); g_hash_table_remove(priv->uri_hash, hash_key); g_free(hash_key); @@ -384,16 +407,20 @@ g_strdup(favicon_file_location)); /* start download */ - dl = kz_downloader_new_with_filename(uri, favicon_file_location); + dl = kz_downloader_new(uri); if (dl) { + downloader_info_t *info = g_new(downloader_info_t, 1); + info->document_uri = document_uri; + info->favicon_file_location = g_strdup(favicon_file_location); + g_signal_connect(dl, "completed", G_CALLBACK(cb_downloader_load_complete), - (gpointer)document_uri); + (gpointer)info); g_signal_connect(dl, "error", G_CALLBACK(cb_downloader_load_error), - (gpointer)document_uri); - kz_downloader_to_file(dl); + (gpointer)info); + kz_downloader_to_buffer(dl); } g_free(hash_key);