Reduce the mount of casts in the browser
This commit is contained in:
parent
0e0ce115f9
commit
df88be1aff
1 changed files with 43 additions and 51 deletions
|
@ -262,49 +262,44 @@ midori_browser_view_can_set_encoding (MidoriView* view)
|
||||||
static void
|
static void
|
||||||
_midori_browser_update_interface (MidoriBrowser* browser)
|
_midori_browser_update_interface (MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
GtkWidget* view;
|
GtkWidget* widget;
|
||||||
|
MidoriView* view;
|
||||||
gboolean loading;
|
gboolean loading;
|
||||||
gboolean can_reload;
|
gboolean can_reload;
|
||||||
GtkAction* action;
|
GtkAction* action;
|
||||||
|
|
||||||
view = midori_browser_get_current_tab (browser);
|
widget = midori_browser_get_current_tab (browser);
|
||||||
loading = midori_view_get_load_status (MIDORI_VIEW (view))
|
view = MIDORI_VIEW (widget);
|
||||||
!= MIDORI_LOAD_FINISHED;
|
loading = midori_view_get_load_status (view) != MIDORI_LOAD_FINISHED;
|
||||||
can_reload = midori_view_can_reload (MIDORI_VIEW (view));
|
can_reload = midori_view_can_reload (view);
|
||||||
|
|
||||||
_action_set_sensitive (browser, "Reload", can_reload && !loading);
|
_action_set_sensitive (browser, "Reload", can_reload && !loading);
|
||||||
_action_set_sensitive (browser, "Stop", can_reload && loading);
|
_action_set_sensitive (browser, "Stop", can_reload && loading);
|
||||||
_action_set_sensitive (browser, "Back",
|
_action_set_sensitive (browser, "Back", midori_view_can_go_back (view));
|
||||||
midori_view_can_go_back (MIDORI_VIEW (view)));
|
_action_set_sensitive (browser, "Forward", midori_view_can_go_forward (view));
|
||||||
_action_set_sensitive (browser, "Forward",
|
|
||||||
midori_view_can_go_forward (MIDORI_VIEW (view)));
|
|
||||||
|
|
||||||
gtk_action_set_visible (_action_by_name (browser, "AddSpeedDial"),
|
gtk_action_set_visible (_action_by_name (browser, "AddSpeedDial"),
|
||||||
browser->speed_dial_in_new_tabs && !midori_view_is_blank (MIDORI_VIEW (view)));
|
browser->speed_dial_in_new_tabs && !midori_view_is_blank (view));
|
||||||
/* Currently views that don't support source, don't support
|
/* Currently views that don't support source, don't support
|
||||||
saving either. If that changes, we need to think of something. */
|
saving either. If that changes, we need to think of something. */
|
||||||
_action_set_sensitive (browser, "SaveAs",
|
_action_set_sensitive (browser, "SaveAs", midori_view_can_view_source (view));
|
||||||
midori_view_can_view_source (MIDORI_VIEW (view)));
|
_action_set_sensitive (browser, "Print", midori_view_can_print (view));
|
||||||
_action_set_sensitive (browser, "Print",
|
_action_set_sensitive (browser, "ZoomIn", midori_view_can_zoom_in (view));
|
||||||
midori_view_can_print (MIDORI_VIEW (view)));
|
_action_set_sensitive (browser, "ZoomOut", midori_view_can_zoom_out (view));
|
||||||
_action_set_sensitive (browser, "ZoomIn",
|
|
||||||
midori_view_can_zoom_in (MIDORI_VIEW (view)));
|
|
||||||
_action_set_sensitive (browser, "ZoomOut",
|
|
||||||
midori_view_can_zoom_out (MIDORI_VIEW (view)));
|
|
||||||
_action_set_sensitive (browser, "ZoomNormal",
|
_action_set_sensitive (browser, "ZoomNormal",
|
||||||
midori_view_get_zoom_level (MIDORI_VIEW (view)) != 1.0f);
|
midori_view_get_zoom_level (view) != 1.0f);
|
||||||
_action_set_sensitive (browser, "Encoding",
|
_action_set_sensitive (browser, "Encoding",
|
||||||
midori_browser_view_can_set_encoding (MIDORI_VIEW (view)));
|
midori_browser_view_can_set_encoding (view));
|
||||||
_action_set_sensitive (browser, "SourceView",
|
_action_set_sensitive (browser, "SourceView",
|
||||||
midori_view_can_view_source (MIDORI_VIEW (view)));
|
midori_view_can_view_source (view));
|
||||||
_action_set_sensitive (browser, "Find",
|
_action_set_sensitive (browser, "Find",
|
||||||
midori_view_can_find (MIDORI_VIEW (view)));
|
midori_view_can_find (view));
|
||||||
_action_set_sensitive (browser, "FindNext",
|
_action_set_sensitive (browser, "FindNext",
|
||||||
midori_view_can_find (MIDORI_VIEW (view)));
|
midori_view_can_find (view));
|
||||||
_action_set_sensitive (browser, "FindPrevious",
|
_action_set_sensitive (browser, "FindPrevious",
|
||||||
midori_view_can_find (MIDORI_VIEW (view)));
|
midori_view_can_find (view));
|
||||||
gtk_widget_set_sensitive (GTK_WIDGET (browser->find_highlight),
|
gtk_widget_set_sensitive (GTK_WIDGET (browser->find_highlight),
|
||||||
midori_view_can_find (MIDORI_VIEW (view)));
|
midori_view_can_find (view));
|
||||||
|
|
||||||
action = gtk_action_group_get_action (browser->action_group, "ReloadStop");
|
action = gtk_action_group_get_action (browser->action_group, "ReloadStop");
|
||||||
if (!loading)
|
if (!loading)
|
||||||
|
@ -334,7 +329,7 @@ _midori_browser_update_interface (MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
action = _action_by_name (browser, "Location");
|
action = _action_by_name (browser, "Location");
|
||||||
midori_location_action_set_progress (MIDORI_LOCATION_ACTION (action),
|
midori_location_action_set_progress (MIDORI_LOCATION_ACTION (action),
|
||||||
midori_view_get_progress (MIDORI_VIEW (view)));
|
midori_view_get_progress (view));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading);
|
katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading);
|
||||||
|
@ -462,27 +457,26 @@ midori_view_notify_icon_cb (MidoriView* view,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_view_notify_load_status_cb (GtkWidget* view,
|
midori_view_notify_load_status_cb (GtkWidget* widget,
|
||||||
GParamSpec* pspec,
|
GParamSpec* pspec,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
|
MidoriView* view = MIDORI_VIEW (widget);
|
||||||
const gchar* uri;
|
const gchar* uri;
|
||||||
GtkAction* action;
|
GtkAction* action;
|
||||||
|
|
||||||
uri = midori_view_get_display_uri (MIDORI_VIEW (view));
|
uri = midori_view_get_display_uri (view);
|
||||||
action = _action_by_name (browser, "Location");
|
action = _action_by_name (browser, "Location");
|
||||||
|
|
||||||
if (midori_view_get_load_status (MIDORI_VIEW (view))
|
if (midori_view_get_load_status (view) == MIDORI_LOAD_COMMITTED)
|
||||||
== MIDORI_LOAD_COMMITTED)
|
|
||||||
{
|
{
|
||||||
if (browser->remember_last_visited_pages)
|
if (browser->remember_last_visited_pages)
|
||||||
midori_location_action_add_uri (MIDORI_LOCATION_ACTION (action), uri);
|
midori_location_action_add_uri (MIDORI_LOCATION_ACTION (action), uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view == midori_browser_get_current_tab (browser))
|
if (widget == midori_browser_get_current_tab (browser))
|
||||||
{
|
{
|
||||||
if (midori_view_get_load_status (MIDORI_VIEW (view))
|
if (midori_view_get_load_status (view) == MIDORI_LOAD_COMMITTED)
|
||||||
== MIDORI_LOAD_COMMITTED)
|
|
||||||
{
|
{
|
||||||
midori_location_action_set_uri (
|
midori_location_action_set_uri (
|
||||||
MIDORI_LOCATION_ACTION (action), uri);
|
MIDORI_LOCATION_ACTION (action), uri);
|
||||||
|
@ -496,7 +490,7 @@ midori_view_notify_load_status_cb (GtkWidget* view,
|
||||||
|
|
||||||
/* This is a hack to ensure that the address entry is focussed
|
/* This is a hack to ensure that the address entry is focussed
|
||||||
with speed dial open. */
|
with speed dial open. */
|
||||||
if (midori_view_is_blank (MIDORI_VIEW (view)))
|
if (midori_view_is_blank (view))
|
||||||
gtk_action_activate (_action_by_name (browser, "Location"));
|
gtk_action_activate (_action_by_name (browser, "Location"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,22 +529,23 @@ midori_view_notify_uri_cb (GtkWidget* view,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_view_notify_title_cb (GtkWidget* view,
|
midori_view_notify_title_cb (GtkWidget* widget,
|
||||||
GParamSpec* pspec,
|
GParamSpec* pspec,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
|
MidoriView* view = MIDORI_VIEW (widget);
|
||||||
const gchar* uri;
|
const gchar* uri;
|
||||||
const gchar* title;
|
const gchar* title;
|
||||||
GtkAction* action;
|
GtkAction* action;
|
||||||
gchar* window_title;
|
gchar* window_title;
|
||||||
|
|
||||||
uri = midori_view_get_display_uri (MIDORI_VIEW (view));
|
uri = midori_view_get_display_uri (view);
|
||||||
title = midori_view_get_display_title (MIDORI_VIEW (view));
|
title = midori_view_get_display_title (view);
|
||||||
action = _action_by_name (browser, "Location");
|
action = _action_by_name (browser, "Location");
|
||||||
if (browser->remember_last_visited_pages)
|
if (browser->remember_last_visited_pages)
|
||||||
midori_location_action_set_title_for_uri (
|
midori_location_action_set_title_for_uri (
|
||||||
MIDORI_LOCATION_ACTION (action), title, uri);
|
MIDORI_LOCATION_ACTION (action), title, uri);
|
||||||
if (midori_view_get_load_status (MIDORI_VIEW (view)) == MIDORI_LOAD_COMMITTED)
|
if (midori_view_get_load_status (view) == MIDORI_LOAD_COMMITTED)
|
||||||
{
|
{
|
||||||
KatzeItem* item;
|
KatzeItem* item;
|
||||||
KatzeItem* proxy;
|
KatzeItem* proxy;
|
||||||
|
@ -558,7 +553,7 @@ midori_view_notify_title_cb (GtkWidget* view,
|
||||||
if (browser->history && browser->remember_last_visited_pages)
|
if (browser->history && browser->remember_last_visited_pages)
|
||||||
{
|
{
|
||||||
item = g_object_get_data (G_OBJECT (view), "history-item-added");
|
item = g_object_get_data (G_OBJECT (view), "history-item-added");
|
||||||
proxy = midori_view_get_proxy_item (MIDORI_VIEW (view));
|
proxy = midori_view_get_proxy_item (view);
|
||||||
if (item && katze_item_get_added (item) == katze_item_get_added (proxy))
|
if (item && katze_item_get_added (item) == katze_item_get_added (proxy))
|
||||||
katze_item_set_name (item, katze_item_get_name (proxy));
|
katze_item_set_name (item, katze_item_get_name (proxy));
|
||||||
else
|
else
|
||||||
|
@ -571,7 +566,7 @@ midori_view_notify_title_cb (GtkWidget* view,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view == midori_browser_get_current_tab (browser))
|
if (widget == midori_browser_get_current_tab (browser))
|
||||||
{
|
{
|
||||||
window_title = g_strconcat (title, " - ",
|
window_title = g_strconcat (title, " - ",
|
||||||
g_get_application_name (), NULL);
|
g_get_application_name (), NULL);
|
||||||
|
@ -591,13 +586,13 @@ midori_view_notify_zoom_level_cb (GtkWidget* view,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_view_notify_statusbar_text_cb (MidoriView* view,
|
midori_view_notify_statusbar_text_cb (GtkWidget* view,
|
||||||
GParamSpec* pspec,
|
GParamSpec* pspec,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
gchar* text;
|
gchar* text;
|
||||||
|
|
||||||
if ((GtkWidget*)view == midori_browser_get_current_tab (browser))
|
if (view == midori_browser_get_current_tab (browser))
|
||||||
{
|
{
|
||||||
g_object_get (view, "statusbar-text", &text, NULL);
|
g_object_get (view, "statusbar-text", &text, NULL);
|
||||||
_midori_browser_set_statusbar_text (browser, text);
|
_midori_browser_set_statusbar_text (browser, text);
|
||||||
|
@ -1550,6 +1545,7 @@ static void
|
||||||
_midori_browser_add_tab (MidoriBrowser* browser,
|
_midori_browser_add_tab (MidoriBrowser* browser,
|
||||||
GtkWidget* view)
|
GtkWidget* view)
|
||||||
{
|
{
|
||||||
|
GtkNotebook* notebook = GTK_NOTEBOOK (browser->notebook);
|
||||||
GtkWidget* tab_label;
|
GtkWidget* tab_label;
|
||||||
KatzeItem* item;
|
KatzeItem* item;
|
||||||
guint n;
|
guint n;
|
||||||
|
@ -1611,18 +1607,14 @@ _midori_browser_add_tab (MidoriBrowser* browser,
|
||||||
browser->settings &&
|
browser->settings &&
|
||||||
katze_object_get_boolean (browser->settings, "open-tabs-next-to-current"))
|
katze_object_get_boolean (browser->settings, "open-tabs-next-to-current"))
|
||||||
{
|
{
|
||||||
n = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
|
n = gtk_notebook_get_current_page (notebook);
|
||||||
gtk_notebook_insert_page (GTK_NOTEBOOK (browser->notebook), view,
|
gtk_notebook_insert_page (notebook, view, tab_label, n + 1);
|
||||||
tab_label, n + 1);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
gtk_notebook_append_page (GTK_NOTEBOOK (browser->notebook), view,
|
gtk_notebook_append_page (notebook, view, tab_label);
|
||||||
tab_label);
|
|
||||||
|
|
||||||
gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (browser->notebook),
|
gtk_notebook_set_tab_reorderable (notebook, view, TRUE);
|
||||||
view, TRUE);
|
gtk_notebook_set_tab_detachable (notebook, view, TRUE);
|
||||||
gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (browser->notebook),
|
|
||||||
view, TRUE);
|
|
||||||
|
|
||||||
/* We want the tab to be removed if the widget is destroyed */
|
/* We want the tab to be removed if the widget is destroyed */
|
||||||
g_signal_connect (view, "destroy",
|
g_signal_connect (view, "destroy",
|
||||||
|
|
Loading…
Reference in a new issue