From: Dale Whittaker Date: Mon, 27 Oct 2008 02:12:09 +0000 (+0100) Subject: First stab at integration history with the location X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70516f1f5b4d264c3b74664ca1f53c92b20a3c6c;p=midori First stab at integration history with the location For starters, the location contains items from the history and not only from the current session. --- diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 0df54628..e7b43ee9 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -4278,11 +4278,43 @@ midori_browser_new_history_item (MidoriBrowser* browser, } } +static void +_location_action_insert_history_item (MidoriLocationAction* action, + MidoriBrowser* browser, + KatzeItem* item) +{ + KatzeItem* child; + guint i, n; + const gchar* uri; + GdkPixbuf* pixbuf = NULL; + + g_return_if_fail (MIDORI_IS_LOCATION_ACTION (action)); + g_return_if_fail (KATZE_IS_ITEM (item)); + + if (KATZE_IS_ARRAY (item)) + { + n = katze_array_get_length (KATZE_ARRAY (item)); + for (i = n; i > 0; i--) + { + child = katze_array_get_nth_item (KATZE_ARRAY (item), i - 1); + _location_action_insert_history_item (action, browser, child); + } + } + else + { + uri = katze_item_get_uri (item); + pixbuf = katze_net_load_icon (browser->net, katze_item_get_uri (item), + NULL, GTK_WIDGET (browser), NULL); + midori_location_action_add_item (action, uri, pixbuf, katze_item_get_name (item)); + } +} + static void midori_browser_load_history (MidoriBrowser* browser) { GtkTreeView* treeview; GtkTreeModel* treemodel; + GtkAction* action; if (!browser->history) return; @@ -4292,6 +4324,11 @@ midori_browser_load_history (MidoriBrowser* browser) _tree_store_insert_history_item (GTK_TREE_STORE (treemodel), NULL, KATZE_ITEM (browser->history)); + + action = _action_by_name (browser, "Location"); + _location_action_insert_history_item (MIDORI_LOCATION_ACTION (action), + browser, + KATZE_ITEM (browser->history)); } static void diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c index e8b0f406..1e03ea99 100644 --- a/midori/midori-locationaction.c +++ b/midori/midori-locationaction.c @@ -457,12 +457,54 @@ midori_location_action_add_uri (MidoriLocationAction* location_action, item.favicon = NULL; item.uri = uri; item.title = NULL; - midori_location_entry_add_item ( + midori_location_entry_prepend_item ( MIDORI_LOCATION_ENTRY (entry), &item); } while ((proxies = g_slist_next (proxies))); } +void +midori_location_action_add_item (MidoriLocationAction* location_action, + const gchar* uri, + GdkPixbuf* icon, + const gchar* title) +{ + GSList* proxies; + GtkWidget* alignment; + GtkWidget* entry; + GtkWidget* child; + MidoriLocationEntryItem item; + + g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action)); + g_return_if_fail (uri != NULL); + g_return_if_fail (title != NULL); + g_return_if_fail (!icon || GDK_IS_PIXBUF (icon)); + + katze_assign (location_action->uri, g_strdup (uri)); + + proxies = gtk_action_get_proxies (GTK_ACTION (location_action)); + if (!proxies) + return; + + do + if (GTK_IS_TOOL_ITEM (proxies->data)) + { + alignment = gtk_bin_get_child (GTK_BIN (proxies->data)); + entry = gtk_bin_get_child (GTK_BIN (alignment)); + child = gtk_bin_get_child (GTK_BIN (entry)); + + item.favicon = icon; + item.uri = uri; + item.title = title; + midori_location_entry_append_item ( + MIDORI_LOCATION_ENTRY (entry), &item); + if (!g_strcmp0 (location_action->uri, uri)) + gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (child), + GTK_ICON_ENTRY_PRIMARY, icon); + } + while ((proxies = g_slist_next (proxies))); +} + void midori_location_action_set_icon_for_uri (MidoriLocationAction* location_action, GdkPixbuf* icon, @@ -492,7 +534,7 @@ midori_location_action_set_icon_for_uri (MidoriLocationAction* location_action, item.favicon = icon; item.uri = uri; item.title = NULL; - midori_location_entry_add_item ( + midori_location_entry_prepend_item ( MIDORI_LOCATION_ENTRY (entry), &item); if (!g_strcmp0 (location_action->uri, uri)) gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (child), @@ -527,8 +569,8 @@ midori_location_action_set_title_for_uri (MidoriLocationAction* location_action, item.favicon = NULL; item.uri = uri; - item.title = item.uri; - midori_location_entry_add_item ( + item.title = title; + midori_location_entry_prepend_item ( MIDORI_LOCATION_ENTRY (entry), &item); } while ((proxies = g_slist_next (proxies))); diff --git a/midori/midori-locationaction.h b/midori/midori-locationaction.h index 837527d7..ba6da7bb 100644 --- a/midori/midori-locationaction.h +++ b/midori/midori-locationaction.h @@ -49,6 +49,11 @@ midori_location_action_add_uri (MidoriLocationAction* location_action const gchar* uri); void +midori_location_action_add_item (MidoriLocationAction* location_action, + const gchar* uri, + GdkPixbuf* icon, + const gchar* title); +void midori_location_action_set_icon_for_uri (MidoriLocationAction* location_action, GdkPixbuf* icon, const gchar* text); diff --git a/midori/midori-locationentry.c b/midori/midori-locationentry.c index 2f684631..d90e3f88 100644 --- a/midori/midori-locationentry.c +++ b/midori/midori-locationentry.c @@ -726,15 +726,15 @@ midori_location_entry_set_item_from_uri (MidoriLocationEntry* location_entry, } /** - * midori_location_entry_add_item: + * midori_location_entry_prepend_item: * @location_entry: a #MidoriLocationEntry * @item: a MidoriLocationItem * - * Adds @item if it is not already in the list. + * Prepends @item if it is not already in the list. **/ void -midori_location_entry_add_item (MidoriLocationEntry* location_entry, - MidoriLocationEntryItem* item) +midori_location_entry_prepend_item (MidoriLocationEntry* location_entry, + MidoriLocationEntryItem* item) { GtkTreeModel* model; GtkTreeIter iter; @@ -750,3 +750,28 @@ midori_location_entry_add_item (MidoriLocationEntry* location_entry, midori_location_entry_set_item (location_entry, &iter, item); } +/** + * midori_location_entry_append_item: + * @location_entry: a #MidoriLocationEntry + * @item: a MidoriLocationItem + * + * Appends @item if it is not already in the list. + **/ +void +midori_location_entry_append_item (MidoriLocationEntry* location_entry, + MidoriLocationEntryItem* item) +{ + GtkTreeModel* model; + GtkTreeIter iter; + + g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry)); + g_return_if_fail (item->uri != NULL); + + model = gtk_combo_box_get_model (GTK_COMBO_BOX (location_entry)); + + if (!midori_location_entry_item_iter (location_entry, item->uri, &iter)) + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + + midori_location_entry_set_item (location_entry, &iter, item); +} + diff --git a/midori/midori-locationentry.h b/midori/midori-locationentry.h index 53f8a6fc..cc47b9da 100644 --- a/midori/midori-locationentry.h +++ b/midori/midori-locationentry.h @@ -60,7 +60,11 @@ midori_location_entry_set_item_from_uri (MidoriLocationEntry* location_entry, const gchar* uri); void -midori_location_entry_add_item (MidoriLocationEntry* location_entry, +midori_location_entry_prepend_item (MidoriLocationEntry* location_entry, + MidoriLocationEntryItem* item); + +void +midori_location_entry_append_item (MidoriLocationEntry* location_entry, MidoriLocationEntryItem* item); gdouble