svnno****@sourc*****
svnno****@sourc*****
Tue Feb 3 10:57:14 JST 2009
Revision: 3601 http://svn.sourceforge.jp/view?root=kazehakase&view=rev&rev=3601 Author: ikezoe Date: 2009-02-03 10:57:13 +0900 (Tue, 03 Feb 2009) Log Message: ----------- 2009-02-03 Hiroyuki Ikezoe <poinc****@ikezo*****> * module/embed/ie/kz-ie.c: Added many functions related to history. Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/module/embed/ie/kz-ie.c Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2009-02-02 23:05:29 UTC (rev 3600) +++ kazehakase/trunk/ChangeLog 2009-02-03 01:57:13 UTC (rev 3601) @@ -1,3 +1,7 @@ +2009-02-03 Hiroyuki Ikezoe <poinc****@ikezo*****> + + * module/embed/ie/kz-ie.c: Added many functions related to history. + 2009-01-30 Hiroyuki Ikezoe <poinc****@ikezo*****> * src/kz-autoscroller.c, src/sidebar/kz-tabtree.h, src/kz-sidebar.h, Modified: kazehakase/trunk/module/embed/ie/kz-ie.c =================================================================== --- kazehakase/trunk/module/embed/ie/kz-ie.c 2009-02-02 23:05:29 UTC (rev 3600) +++ kazehakase/trunk/module/embed/ie/kz-ie.c 2009-02-03 01:57:13 UTC (rev 3601) @@ -31,6 +31,7 @@ #include "kz-proxy-item.h" #include "gtk-utils.h" #include "kz-missing.h" +#include "kz-bookmark.h" typedef struct _KzIEPrivate KzIEPrivate; struct _KzIEPrivate @@ -73,7 +74,6 @@ static gboolean kz_ie_embed_new_window (GtkIEEmbed *embed, GtkIEEmbed **newembed); static gboolean kz_ie_embed_close_window (GtkIEEmbed *embed); static void kz_ie_embed_selection_changed(GtkIEEmbed *embed); - /* embed iface */ static void kz_ie_load_url (KzEmbed *kzembed, const gchar *url); @@ -101,7 +101,7 @@ static void kz_ie_print (KzEmbed *kzembed); static void kz_ie_print_preview (KzEmbed *kzembed); static void kz_ie_set_text_size (KzEmbed *kzembed, - int zoom, + gint zoom, gboolean reflow); static gint kz_ie_get_text_size (KzEmbed *kzembed); static void kz_ie_set_encoding (KzEmbed *kzembed, @@ -114,12 +114,35 @@ static gchar *kz_ie_get_selection_string (KzEmbed *kzembed); static gboolean kz_ie_find (KzEmbed *kzembed, - const char *keyword, + const gchar *keyword, gboolean backward); static gboolean kz_ie_get_lock (KzEmbed *kzembed); static void kz_ie_set_lock (KzEmbed *kzembed, gboolean lock); +static void get_history (KzEmbed *kzembed, + KzBookmark *history); +static void set_history (KzEmbed *kzembed, + KzBookmark *history); +static void copy_page (KzEmbed *src_embed, + KzEmbed *dest_embed, + KzEmbedCopyType type); +static gboolean shistory_copy (KzEmbed *src_embed, + KzEmbed *dest_embed, + gboolean back_history, + gboolean forward_history, + gboolean set_current); +static gboolean shistory_get_pos (KzEmbed *kzembed, + gint *pos, + gint *count); +static void shistory_get_nth (KzEmbed *kzembed, + gint nth, + gboolean is_relative, + gchar **uri, + gchar **title); +static void go_history_index (KzEmbed *kzembed, + gint index); + /* KzEmbedPrefs interfaces */ /* no functions is implemented yet */ static void kz_ie_prefs_iface_init (KzEmbedPrefsIFace *iface); @@ -231,10 +254,10 @@ iface->incremental_search = NULL; iface->selection_is_collapsed = NULL; iface->get_links = NULL; - iface->copy_page = NULL; - iface->shistory_copy = NULL; - iface->shistory_get_pos = NULL; - iface->shistory_get_nth = NULL; + iface->copy_page = copy_page; + iface->shistory_copy = shistory_copy; + iface->shistory_get_pos = shistory_get_pos; + iface->shistory_get_nth = shistory_get_nth; iface->reload = kz_ie_reload; iface->stop_load = kz_ie_stop_load; iface->go_back = kz_ie_go_back; @@ -249,7 +272,7 @@ iface->get_nav_link = NULL; iface->get_nth_nav_link = NULL; iface->get_nav_links = NULL; - iface->go_history_index = NULL; + iface->go_history_index = go_history_index; iface->do_command = NULL; iface->can_do_command = NULL; iface->get_lock = kz_ie_get_lock; @@ -272,8 +295,8 @@ iface->set_text_size = kz_ie_set_text_size; iface->get_text_size = kz_ie_get_text_size; iface->get_html_with_contents = NULL; - iface->set_history = NULL; - iface->get_history = NULL; + iface->set_history = set_history; + iface->get_history = get_history; iface->get_last_modified = kz_ie_get_last_modified; iface->fine_scroll = NULL; iface->page_up = NULL; @@ -819,3 +842,176 @@ priv->lock = lock; } +static void +merge_to_bookmark_list (const gchar *uri, const gchar *title, + GList **bookmark_list_node, KzBookmark *folder) +{ + if (*bookmark_list_node) + { + kz_bookmark_set_title(KZ_BOOKMARK((*bookmark_list_node)->data), title); + kz_bookmark_set_link(KZ_BOOKMARK((*bookmark_list_node)->data), uri); + *bookmark_list_node = g_list_next(*bookmark_list_node); + } + else + { + KzBookmark *bookmark; + bookmark = kz_bookmark_new_with_attrs(title, uri, NULL); + kz_bookmark_append(folder, bookmark); + g_object_unref(bookmark); + } +} + +static guint +merge_ie_history_list_to_bookmark_list (const GList *history_list, GList **bookmark_list_node, + KzBookmark *folder) +{ + const GList *node; + guint count = 0; + + for (node = history_list; node; node = g_list_next(node)) + { + const gchar *uri, *title; + GtkIEEmbedHistoryItem *item = GTK_IE_EMBED_HISTORY_ITEM(node->data); + + uri = gtk_ie_embed_history_item_get_uri(item); + title = gtk_ie_embed_history_item_get_title(item); + merge_to_bookmark_list(uri, title, bookmark_list_node, folder); + count++; + } + return count; +} + +static void +get_history (KzEmbed *kzembed, KzBookmark *history) +{ + GList *children, *bookmark_node; + GList *backward_history, *forward_history; + gint current_position = 0; + const gchar *uri, *title; + + backward_history = gtk_ie_embed_get_backward_history(GTK_IE_EMBED(kzembed)); + forward_history = gtk_ie_embed_get_forward_history(GTK_IE_EMBED(kzembed)); + + children = kz_bookmark_get_children(history); + bookmark_node = children; + current_position = merge_ie_history_list_to_bookmark_list(backward_history, + &bookmark_node, + history); + + uri = KZ_IE_GET_PRIVATE(kzembed)->location; + title = KZ_IE_GET_PRIVATE(kzembed)->title; + merge_to_bookmark_list(uri, title, &bookmark_node, history); + + merge_ie_history_list_to_bookmark_list(forward_history, + &bookmark_node, + history); + + if (children) + g_list_free(children); + if (backward_history) + g_list_free(backward_history); + if (forward_history) + g_list_free(forward_history); + + kz_bookmark_set_current(history, current_position); +} + +static void +set_history (KzEmbed *kzembed, KzBookmark *history) +{ + GList *children, *node; + gint current_position; + + children = kz_bookmark_get_children(history); + current_position = kz_bookmark_get_current(history); + + for (node = children; node; node = g_list_next(node)) + { + /* FIXME */ + } + + if (children) + g_list_free(children); +} + +static void +copy_page (KzEmbed *src_embed, KzEmbed *dest_embed, KzEmbedCopyType type) +{ + gtk_ie_embed_load_url(GTK_IE_EMBED(dest_embed), + KZ_IE_GET_PRIVATE(src_embed)->location); +} + +static gboolean +shistory_copy (KzEmbed *src_embed, KzEmbed *dest_embed, + gboolean back_history, gboolean forward_history, + gboolean set_current) +{ + GList *backward_history_list, *forward_history_list; + + if (back_history) + { + backward_history_list = gtk_ie_embed_get_backward_history(GTK_IE_EMBED(src_embed)); + gtk_ie_embed_set_backward_history(GTK_IE_EMBED(dest_embed), backward_history_list); + if (backward_history_list) + g_list_free(backward_history_list); + } + + copy_page(src_embed, dest_embed, KZ_EMBED_COPY_NORMAL); + + if (forward_history) + { + forward_history_list = gtk_ie_embed_get_forward_history(GTK_IE_EMBED(src_embed)); + gtk_ie_embed_set_forward_history(GTK_IE_EMBED(dest_embed), forward_history_list); + if (forward_history_list) + g_list_free(forward_history_list); + } + + if (set_current) + { + /* FIXME */ + } + + return TRUE; +} + +static gboolean +shistory_get_pos (KzEmbed *kzembed, gint *pos, gint *count) +{ + GtkIEEmbed *ie = GTK_IE_EMBED(kzembed); + + *pos = (gint)gtk_ie_embed_get_current_position_in_history(ie); + *count = (gint)gtk_ie_embed_get_history_count(ie); + + return TRUE; +} + +static void +shistory_get_nth (KzEmbed *kzembed, + gint nth, gboolean is_relative, + gchar **uri, gchar **title) +{ + GtkIEEmbedHistoryItem *item; + guint current_position; + + current_position = gtk_ie_embed_get_current_position_in_history(GTK_IE_EMBED(kzembed)); + if (!is_relative) + nth -= current_position; + item = gtk_ie_embed_get_history_item_at_relative_position(GTK_IE_EMBED(kzembed), nth); + if (!item) + return; + + *uri = g_strdup(gtk_ie_embed_history_item_get_uri(item)); + *title = g_strdup(gtk_ie_embed_history_item_get_title(item)); + g_object_unref(item); +} + +static void +go_history_index (KzEmbed *kzembed, gint index) +{ + guint current_position; + + current_position = gtk_ie_embed_get_current_position_in_history(GTK_IE_EMBED(kzembed)); + gtk_ie_embed_go_relative_position(GTK_IE_EMBED(kzembed), index - current_position); +} + +