From 614365427971fc76eb88905b6f0c6626076374bb Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 7 Dec 2011 21:27:38 +0100 Subject: [PATCH] Introduce and use midori_view_new_with_item --- katze/katze-item.c | 14 ++++++++++++++ midori/midori-browser.c | 28 ++-------------------------- midori/midori-view.c | 36 +++++++++++++++++++++++++++--------- midori/midori-view.h | 5 +++++ 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/katze/katze-item.c b/katze/katze-item.c index e56bc47b..1d3a3ee7 100644 --- a/katze/katze-item.c +++ b/katze/katze-item.c @@ -707,6 +707,8 @@ katze_item_set_parent (KatzeItem* item, * Note that subclass specific features will only * be preserved if the class implements it. * + * Since 0.4.3 meta data is copied. + * * Return value: a new #KatzeItem * * Since: 0.1.3 @@ -715,6 +717,9 @@ KatzeItem* katze_item_copy (KatzeItem* item) { KatzeItem* copy; + GHashTableIter iter; + const gchar* key; + const gchar* value; KatzeItemClass* class; g_return_val_if_fail (KATZE_IS_ITEM (item), NULL); @@ -727,6 +732,15 @@ katze_item_copy (KatzeItem* item) "added", item->added, "parent", item->parent, NULL); + + g_hash_table_iter_init (&iter, item->metadata); + while (g_hash_table_iter_next (&iter, (void*)&key, (void*)&value)) + { + if (g_str_has_prefix (key, "midori:")) + key = &key[7]; + g_hash_table_insert (copy->metadata, g_strdup (key), g_strdup (value)); + } + class = KATZE_ITEM_GET_CLASS (item); return class->copy ? class->copy (copy) : copy; } diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 0b6d5e3f..fa96a55a 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -3418,12 +3418,10 @@ _action_source_view_activate (GtkAction* action, source_uri = g_filename_to_uri (filename, NULL, NULL); g_free (filename); - source = midori_view_new (NULL); - midori_view_set_settings (MIDORI_VIEW (source), browser->settings); + source = midori_view_new_with_title (NULL, browser->settings, FALSE); source_view = midori_view_get_web_view (MIDORI_VIEW (source)); webkit_web_view_set_view_source_mode (WEBKIT_WEB_VIEW (source_view), TRUE); webkit_web_view_load_uri (WEBKIT_WEB_VIEW (source_view), source_uri); - gtk_widget_show (source); midori_browser_add_tab (browser, source); } else @@ -7053,27 +7051,15 @@ midori_browser_add_item (MidoriBrowser* browser, KatzeItem* item) { const gchar* uri; - const gchar* title; GtkWidget* view; gint page; - KatzeItem* proxy_item; - GList* keys; g_return_val_if_fail (MIDORI_IS_BROWSER (browser), -1); g_return_val_if_fail (KATZE_IS_ITEM (item), -1); uri = katze_item_get_uri (item); - if (!uri) - uri = "about:blank"; - title = katze_item_get_name (item); - view = midori_view_new_with_title (title, browser->settings, + view = midori_view_new_with_item (item, browser->settings, g_object_get_data (G_OBJECT (item), "midori-view-append") ? TRUE : FALSE); - - proxy_item = midori_view_get_proxy_item (MIDORI_VIEW (view)); - - if (katze_item_get_meta_boolean (item, "dont-write-history")) - katze_item_set_meta_integer (proxy_item, "dont-write-history", 1); - page = midori_browser_add_tab (browser, view); /* Blank pages should not be delayed */ @@ -7088,16 +7074,6 @@ midori_browser_add_item (MidoriBrowser* browser, else midori_view_set_uri (MIDORI_VIEW (view), uri); - proxy_item = midori_view_get_proxy_item (MIDORI_VIEW (view)); - if ((keys = katze_item_get_meta_keys (item))) - { - guint i = 0; - const gchar* key; - while ((key = g_list_nth_data (keys, i++))) - katze_item_set_meta_string (proxy_item, key, - katze_item_get_meta_string (item, key)); - g_list_free (keys); - } return page; } diff --git a/midori/midori-view.c b/midori/midori-view.c index fd3b56af..f25ce479 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -3251,7 +3251,6 @@ _midori_view_set_settings (MidoriView* view, /** * midori_view_new_with_title: - * @uri: an URI string, or %NULL * @title: a title, or %NULL * @settings: a #MidoriWebSettings, or %NULL * @append: if %TRUE, the view should be appended @@ -3268,11 +3267,35 @@ midori_view_new_with_title (const gchar* title, MidoriWebSettings* settings, gboolean append) { - MidoriView* view = g_object_new (MIDORI_TYPE_VIEW, "title", title, NULL); + KatzeItem* item = katze_item_new (); + item->name = g_strdup (title); + return midori_view_new_with_item (item, settings, append); +} + +/** + * midori_view_new_with_item: + * @item: a #KatzeItem, or %NULL + * @settings: a #MidoriWebSettings, or %NULL + * @append: if %TRUE, the view should be appended + * + * Creates a new view from an item that is visible by default. + * + * Return value: a new #MidoriView + * + * Since: 0.4.3 + **/ +GtkWidget* +midori_view_new_with_item (KatzeItem* item, + MidoriWebSettings* settings, + gboolean append) +{ + MidoriView* view = g_object_new (MIDORI_TYPE_VIEW, NULL); if (settings) _midori_view_set_settings (view, settings); if (append) g_object_set_data (G_OBJECT (view), "midori-view-append", (void*)1); + if (item) + katze_object_assign (view->item, katze_item_copy (item)); gtk_widget_show ((GtkWidget*)view); return (GtkWidget*)view; } @@ -3808,12 +3831,9 @@ midori_view_set_uri (MidoriView* view, g_warning ("Calling %s() before adding the view to a browser. This " "breaks extensions that monitor page loading.", G_STRFUNC); - /* Treat "about:blank" and "" equally, see midori_view_is_blank(). */ - if (!uri || !strcmp (uri, "about:blank")) uri = ""; - if (g_getenv ("MIDORI_UNARMED") == NULL) { - if (!strcmp (uri, "")) + if (!uri || !strcmp (uri, "") || !strcmp (uri, "about:blank")) { #ifdef G_ENABLE_DEBUG GTimer* timer = NULL; @@ -4074,8 +4094,6 @@ midori_view_get_display_uri (MidoriView* view) * as a title. Most of the time this will be the title * or the current URI. * - * An empty page is represented as "about:blank". - * * You can assume that the string is not %NULL. * * Return value: a title string @@ -4841,7 +4859,7 @@ midori_view_reload (MidoriView* view, { g_return_if_fail (MIDORI_IS_VIEW (view)); - if (!(view->uri && *view->uri && strncmp (view->uri, "about:", 6))) + if (midori_uri_is_blank (view->uri)) { gchar* uri = g_strdup (view->uri); midori_view_set_uri (view, uri); diff --git a/midori/midori-view.h b/midori/midori-view.h index bdf21885..9b10d7b0 100644 --- a/midori/midori-view.h +++ b/midori/midori-view.h @@ -78,6 +78,11 @@ midori_view_new_with_title (const gchar* title, MidoriWebSettings* settings, gboolean append); +GtkWidget* +midori_view_new_with_item (KatzeItem* item, + MidoriWebSettings* settings, + gboolean append); + void midori_view_set_settings (MidoriView* view, MidoriWebSettings* settings); -- 2.39.5