Implement and use midori_view_new_with_uri

The function provides an optimised and quick way to creating
visible views with uri, title and settings. This is how virtually
all views are created.
This commit is contained in:
Christian Dywan 2010-09-17 20:03:11 +02:00
parent 5806cdb884
commit 648befe7ca
3 changed files with 56 additions and 36 deletions

View file

@ -4431,11 +4431,9 @@ _action_tab_duplicate_activate (GtkAction* action,
{ {
GtkWidget* view = midori_browser_get_current_tab (browser); GtkWidget* view = midori_browser_get_current_tab (browser);
MidoriNewView where = MIDORI_NEW_VIEW_TAB; MidoriNewView where = MIDORI_NEW_VIEW_TAB;
GtkWidget* new_view = g_object_new (MIDORI_TYPE_VIEW, GtkWidget* new_view = midori_view_new_with_uri (
"settings", browser->settings, NULL); midori_view_get_display_uri (MIDORI_VIEW (view)),
midori_view_set_uri (MIDORI_VIEW (new_view), NULL, browser->settings);
midori_view_get_display_uri (MIDORI_VIEW (view)));
gtk_widget_show (new_view);
g_signal_emit_by_name (view, "new-view", new_view, where); g_signal_emit_by_name (view, "new-view", new_view, where);
} }
@ -4777,13 +4775,7 @@ midori_browser_notebook_button_press_event_after_cb (GtkNotebook* notebook,
|| */(event->type == GDK_BUTTON_PRESS && event->button == 2)) || */(event->type == GDK_BUTTON_PRESS && event->button == 2))
{ {
gint n; gint n;
GtkWidget* view; GtkWidget* view = midori_view_new_with_uri ("", NULL, browser->settings);
view = g_object_new (MIDORI_TYPE_VIEW,
"settings", browser->settings,
NULL);
midori_view_set_uri (MIDORI_VIEW (view), "");
gtk_widget_show (view);
g_object_set_data (G_OBJECT (view), "midori-view-append", (void*)1); g_object_set_data (G_OBJECT (view), "midori-view-append", (void*)1);
n = midori_browser_add_tab (browser, view); n = midori_browser_add_tab (browser, view);
midori_browser_set_current_page (browser, n); midori_browser_set_current_page (browser, n);
@ -6711,23 +6703,16 @@ midori_browser_add_item (MidoriBrowser* browser,
uri = katze_item_get_uri (item); uri = katze_item_get_uri (item);
title = katze_item_get_name (item); title = katze_item_get_name (item);
view = g_object_new (MIDORI_TYPE_VIEW,
"title", title,
"settings", browser->settings,
NULL);
/* Blank pages should not be delayed */ /* Blank pages should not be delayed */
if (katze_item_get_meta_integer (item, "delay") > 0 if (katze_item_get_meta_integer (item, "delay") > 0
&& uri != NULL && strcmp (uri, "about:blank") != 0) && uri != NULL && strcmp (uri, "about:blank") != 0)
{ {
gchar* new_uri; gchar* new_uri = g_strdup_printf ("pause:%s", uri);
new_uri = g_strdup_printf ("pause:%s", uri); view = midori_view_new_with_uri (new_uri, title, browser->settings);
midori_view_set_uri (MIDORI_VIEW (view), new_uri);
g_free (new_uri); g_free (new_uri);
} }
else else
midori_view_set_uri (MIDORI_VIEW (view), uri); view = midori_view_new_with_uri (uri, title, browser->settings);
gtk_widget_show (view);
/* FIXME: We should have public API for that */ /* FIXME: We should have public API for that */
if (g_object_get_data (G_OBJECT (item), "midori-view-append")) if (g_object_get_data (G_OBJECT (item), "midori-view-append"))
@ -6765,11 +6750,7 @@ midori_browser_add_uri (MidoriBrowser* browser,
g_return_val_if_fail (MIDORI_IS_BROWSER (browser), -1); g_return_val_if_fail (MIDORI_IS_BROWSER (browser), -1);
g_return_val_if_fail (uri != NULL, -1); g_return_val_if_fail (uri != NULL, -1);
view = g_object_new (MIDORI_TYPE_VIEW, "settings", browser->settings, view = midori_view_new_with_uri (uri, NULL, browser->settings);
NULL);
midori_view_set_uri (MIDORI_VIEW (view), uri);
gtk_widget_show (view);
return midori_browser_add_tab (browser, view); return midori_browser_add_tab (browser, view);
} }

View file

@ -2526,9 +2526,8 @@ webkit_web_view_create_web_view_cb (GtkWidget* web_view,
new_view = view; new_view = view;
else else
{ {
new_view = g_object_new (MIDORI_TYPE_VIEW, new_view = (MidoriView*)midori_view_new_with_uri (NULL, NULL,
"settings", view->settings, view->settings);
NULL);
midori_view_construct_web_view (new_view); midori_view_construct_web_view (new_view);
g_signal_connect (new_view->web_view, "web-view-ready", g_signal_connect (new_view->web_view, "web-view-ready",
G_CALLBACK (webkit_web_view_web_view_ready_cb), view); G_CALLBACK (webkit_web_view_web_view_ready_cb), view);
@ -2971,11 +2970,13 @@ midori_view_focus_in_event (GtkWidget* widget,
/** /**
* midori_view_new: * midori_view_new:
* @net: a #KatzeNet, or %NULL * @net: %NULL
* *
* Creates a new view. * Creates a new view.
* *
* Return value: a new #MidoriView * Return value: a new #MidoriView
*
* Deprecated: 0.2.8: Use midori_view_new_with_uri() instead.
**/ **/
GtkWidget* GtkWidget*
midori_view_new (KatzeNet* net) midori_view_new (KatzeNet* net)
@ -3008,6 +3009,41 @@ _midori_view_update_settings (MidoriView* view)
g_object_set (view->scrolled_window, "kinetic-scrolling", kinetic_scrolling, NULL); g_object_set (view->scrolled_window, "kinetic-scrolling", kinetic_scrolling, NULL);
} }
/**
* midori_view_new_with_uri:
* @uri: an URI string, or %NULL
* @title: a title, or %NULL
* @settings: a #MidoriWebSettings, or %NULL
*
* Creates a new view with the specified parameters that
* is visible by default.
*
* Return value: a new #MidoriView
*
* Since: 0.2.8
**/
GtkWidget*
midori_view_new_with_uri (const gchar* uri,
const gchar* title,
MidoriWebSettings* settings)
{
MidoriView* view = g_object_new (MIDORI_TYPE_VIEW, NULL);
view->title = g_strdup (title);
if (title != NULL)
midori_view_update_title (view);
if (settings)
{
view->settings = g_object_ref (settings);
_midori_view_update_settings (view);
g_signal_connect (settings, "notify",
G_CALLBACK (midori_view_settings_notify_cb), view);
}
if (uri != NULL)
midori_view_set_uri (view, uri);
gtk_widget_show ((GtkWidget*)view);
return (GtkWidget*)view;
}
static void static void
midori_view_settings_notify_cb (MidoriWebSettings* settings, midori_view_settings_notify_cb (MidoriWebSettings* settings,
GParamSpec* pspec, GParamSpec* pspec,
@ -3934,11 +3970,9 @@ midori_view_tab_label_menu_duplicate_tab_cb (GtkWidget* menuitem,
MidoriView* view) MidoriView* view)
{ {
MidoriNewView where = MIDORI_NEW_VIEW_TAB; MidoriNewView where = MIDORI_NEW_VIEW_TAB;
GtkWidget* new_view = g_object_new (MIDORI_TYPE_VIEW, GtkWidget* new_view = midori_view_new_with_uri (
"settings", view->settings, NULL); midori_view_get_display_uri (view),
midori_view_set_uri (MIDORI_VIEW (new_view), NULL, view->settings);
midori_view_get_display_uri (view));
gtk_widget_show (new_view);
g_signal_emit (view, signals[NEW_VIEW], 0, new_view, where); g_signal_emit (view, signals[NEW_VIEW], 0, new_view, where);
} }

View file

@ -80,6 +80,11 @@ midori_view_get_type (void) G_GNUC_CONST;
GtkWidget* GtkWidget*
midori_view_new (KatzeNet* net); midori_view_new (KatzeNet* net);
GtkWidget*
midori_view_new_with_uri (const gchar* uri,
const gchar* title,
MidoriWebSettings* settings);
void void
midori_view_set_settings (MidoriView* view, midori_view_set_settings (MidoriView* view,
MidoriWebSettings* settings); MidoriWebSettings* settings);