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);
MidoriNewView where = MIDORI_NEW_VIEW_TAB;
GtkWidget* new_view = g_object_new (MIDORI_TYPE_VIEW,
"settings", browser->settings, NULL);
midori_view_set_uri (MIDORI_VIEW (new_view),
midori_view_get_display_uri (MIDORI_VIEW (view)));
gtk_widget_show (new_view);
GtkWidget* new_view = midori_view_new_with_uri (
midori_view_get_display_uri (MIDORI_VIEW (view)),
NULL, browser->settings);
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))
{
gint n;
GtkWidget* view;
view = g_object_new (MIDORI_TYPE_VIEW,
"settings", browser->settings,
NULL);
midori_view_set_uri (MIDORI_VIEW (view), "");
gtk_widget_show (view);
GtkWidget* view = midori_view_new_with_uri ("", NULL, browser->settings);
g_object_set_data (G_OBJECT (view), "midori-view-append", (void*)1);
n = midori_browser_add_tab (browser, view);
midori_browser_set_current_page (browser, n);
@ -6711,23 +6703,16 @@ midori_browser_add_item (MidoriBrowser* browser,
uri = katze_item_get_uri (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 */
if (katze_item_get_meta_integer (item, "delay") > 0
&& uri != NULL && strcmp (uri, "about:blank") != 0)
{
gchar* new_uri;
new_uri = g_strdup_printf ("pause:%s", uri);
midori_view_set_uri (MIDORI_VIEW (view), new_uri);
gchar* new_uri = g_strdup_printf ("pause:%s", uri);
view = midori_view_new_with_uri (new_uri, title, browser->settings);
g_free (new_uri);
}
else
midori_view_set_uri (MIDORI_VIEW (view), uri);
gtk_widget_show (view);
view = midori_view_new_with_uri (uri, title, browser->settings);
/* FIXME: We should have public API for that */
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 (uri != NULL, -1);
view = g_object_new (MIDORI_TYPE_VIEW, "settings", browser->settings,
NULL);
midori_view_set_uri (MIDORI_VIEW (view), uri);
gtk_widget_show (view);
view = midori_view_new_with_uri (uri, NULL, browser->settings);
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;
else
{
new_view = g_object_new (MIDORI_TYPE_VIEW,
"settings", view->settings,
NULL);
new_view = (MidoriView*)midori_view_new_with_uri (NULL, NULL,
view->settings);
midori_view_construct_web_view (new_view);
g_signal_connect (new_view->web_view, "web-view-ready",
G_CALLBACK (webkit_web_view_web_view_ready_cb), view);
@ -2971,11 +2970,13 @@ midori_view_focus_in_event (GtkWidget* widget,
/**
* midori_view_new:
* @net: a #KatzeNet, or %NULL
* @net: %NULL
*
* Creates a new view.
*
* Return value: a new #MidoriView
*
* Deprecated: 0.2.8: Use midori_view_new_with_uri() instead.
**/
GtkWidget*
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);
}
/**
* 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
midori_view_settings_notify_cb (MidoriWebSettings* settings,
GParamSpec* pspec,
@ -3934,11 +3970,9 @@ midori_view_tab_label_menu_duplicate_tab_cb (GtkWidget* menuitem,
MidoriView* view)
{
MidoriNewView where = MIDORI_NEW_VIEW_TAB;
GtkWidget* new_view = g_object_new (MIDORI_TYPE_VIEW,
"settings", view->settings, NULL);
midori_view_set_uri (MIDORI_VIEW (new_view),
midori_view_get_display_uri (view));
gtk_widget_show (new_view);
GtkWidget* new_view = midori_view_new_with_uri (
midori_view_get_display_uri (view),
NULL, view->settings);
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*
midori_view_new (KatzeNet* net);
GtkWidget*
midori_view_new_with_uri (const gchar* uri,
const gchar* title,
MidoriWebSettings* settings);
void
midori_view_set_settings (MidoriView* view,
MidoriWebSettings* settings);