From 4a3501a2790723a54e2e34a212a00d1c161021c2 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Mon, 27 Oct 2008 04:23:41 +0100 Subject: [PATCH] Share net between browser and views --- midori/midori-browser.c | 21 +++++++---------- midori/midori-view.c | 50 +++++++++++++++++++++++++++-------------- midori/midori-view.h | 2 +- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index e7b43ee9..4ef511c0 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -1845,7 +1845,7 @@ _action_source_view_activate (GtkAction* action, { uri = g_strdup_printf ("view-source:%s", midori_view_get_display_uri (MIDORI_VIEW (view))); - source_view = midori_view_new (); + source_view = midori_view_new (browser->net); midori_view_set_settings (MIDORI_VIEW (source_view), browser->settings); midori_view_set_uri (MIDORI_VIEW (source_view), uri); midori_view_notify_icon_cb (MIDORI_VIEW (source_view), NULL, browser); @@ -3687,7 +3687,7 @@ midori_browser_init (MidoriBrowser* browser) STOCK_BOOKMARKS, _("Bookmarks")); /* Transfers */ - GtkWidget* panel = midori_view_new (); + GtkWidget* panel = midori_view_new (browser->net); gtk_widget_show (panel); midori_panel_append_page (MIDORI_PANEL (browser->panel), panel, NULL, @@ -3741,7 +3741,7 @@ midori_browser_init (MidoriBrowser* browser) STOCK_HISTORY, _("History")); /* Pageholder */ - browser->panel_pageholder = midori_view_new (); + browser->panel_pageholder = midori_view_new (browser->net); midori_view_set_settings (MIDORI_VIEW (browser->panel_pageholder), browser->settings); gtk_widget_show (browser->panel_pageholder); @@ -4357,8 +4357,7 @@ midori_browser_set_property (GObject* object, g_signal_handlers_disconnect_by_func (browser->settings, midori_browser_settings_notify, browser); - katze_object_assign (browser->settings, g_value_get_object (value)); - g_object_ref (browser->settings); + katze_object_assign (browser->settings, g_value_dup_object (value)); _midori_browser_update_settings (browser); g_signal_connect (browser->settings, "notify", G_CALLBACK (midori_browser_settings_notify), browser); @@ -4367,8 +4366,7 @@ midori_browser_set_property (GObject* object, break; case PROP_BOOKMARKS: ; /* FIXME: Disconnect handlers */ - katze_object_assign (browser->bookmarks, g_value_get_object (value)); - g_object_ref (browser->bookmarks); + katze_object_assign (browser->bookmarks, g_value_dup_object (value)); g_object_set (_action_by_name (browser, "Bookmarks"), "array", browser->bookmarks, NULL); midori_browser_load_bookmarks (browser); @@ -4376,8 +4374,7 @@ midori_browser_set_property (GObject* object, break; case PROP_TRASH: ; /* FIXME: Disconnect handlers */ - katze_object_assign (browser->trash, g_value_get_object (value)); - g_object_ref (browser->trash); + katze_object_assign (browser->trash, g_value_dup_object (value)); g_object_set (_action_by_name (browser, "Trash"), "array", browser->trash, NULL); /* FIXME: Connect to updates */ @@ -4385,8 +4382,7 @@ midori_browser_set_property (GObject* object, break; case PROP_SEARCH_ENGINES: ; /* FIXME: Disconnect handlers */ - katze_object_assign (browser->search_engines, g_value_get_object (value)); - g_object_ref (browser->search_engines); + katze_object_assign (browser->search_engines, g_value_dup_object (value)); midori_search_action_set_search_engines (MIDORI_SEARCH_ACTION ( _action_by_name (browser, "Search")), browser->search_engines); /* FIXME: Connect to updates */ @@ -4402,8 +4398,7 @@ midori_browser_set_property (GObject* object, break; case PROP_HISTORY: ; /* FIXME: Disconnect handlers */ - katze_object_assign (browser->history, g_value_get_object (value)); - g_object_ref (browser->history); + katze_object_assign (browser->history, g_value_dup_object (value)); midori_browser_load_history (browser); g_object_set (_action_by_name (browser, "RecentlyVisited"), "array", browser->history, NULL); diff --git a/midori/midori-view.c b/midori/midori-view.c index f505f248..2fa72822 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -99,7 +99,8 @@ enum PROP_PROGRESS, PROP_ZOOM_LEVEL, PROP_STATUSBAR_TEXT, - PROP_SETTINGS + PROP_SETTINGS, + PROP_NET }; enum { @@ -418,6 +419,15 @@ midori_view_class_init (MidoriViewClass* class) "The associated settings", MIDORI_TYPE_WEB_SETTINGS, G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, + PROP_NET, + g_param_spec_object ( + "net", + "Net", + "The associated net", + KATZE_TYPE_NET, + G_PARAM_READWRITE)); } static void @@ -979,21 +989,19 @@ midori_view_finalize (GObject* object) g_signal_handlers_disconnect_by_func (view->settings, midori_view_settings_notify_cb, view); - g_free (view->uri); - g_free (view->title); - if (view->icon) - g_object_unref (view->icon); - g_free (view->statusbar_text); - g_free (view->link_uri); - g_free (view->selected_text); - if (view->settings) - g_object_unref (view->settings); - if (view->item) - g_object_unref (view->item); + katze_assign (view->uri, NULL); + katze_assign (view->title, NULL); + katze_object_assign (view->icon, NULL); + katze_assign (view->statusbar_text, NULL); + katze_assign (view->link_uri, NULL); + katze_assign (view->selected_text, NULL); - g_free (view->download_manager); + katze_object_assign (view->settings, NULL); + katze_object_assign (view->item, NULL); - g_object_unref (view->net); + katze_assign (view->download_manager, NULL); + + katze_object_assign (view->net, NULL); /* web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view)); @@ -1039,6 +1047,11 @@ midori_view_set_property (GObject* object, case PROP_SETTINGS: midori_view_set_settings (view, g_value_get_object (value)); break; + case PROP_NET: + katze_object_assign (view->net, g_value_dup_object (value)); + if (!view->net) + view->net = katze_net_new (); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1076,6 +1089,9 @@ midori_view_get_property (GObject* object, case PROP_SETTINGS: g_value_set_object (value, view->settings); break; + case PROP_NET: + g_value_set_object (value, view->net); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1084,16 +1100,16 @@ midori_view_get_property (GObject* object, /** * midori_view_new: - * @view: a #MidoriView + * @net: a #KatzeNet * * Creates a new view. * * Return value: a new #MidoriView **/ GtkWidget* -midori_view_new (void) +midori_view_new (KatzeNet* net) { - return g_object_new (MIDORI_TYPE_VIEW, NULL); + return g_object_new (MIDORI_TYPE_VIEW, "net", net, NULL); } static void diff --git a/midori/midori-view.h b/midori/midori-view.h index 02220dbd..13a8c4ba 100644 --- a/midori/midori-view.h +++ b/midori/midori-view.h @@ -51,7 +51,7 @@ GType midori_view_get_type (void); GtkWidget* -midori_view_new (void); +midori_view_new (KatzeNet* net); void midori_view_set_settings (MidoriView* view, -- 2.39.5