Add stop/reload buttons.

This commit is contained in:
Marco Pesenti Gritti 2006-10-20 15:43:05 +02:00
parent bb4085373c
commit e4c6a5befa
3 changed files with 51 additions and 2 deletions

View File

@ -40,6 +40,12 @@ class Toolbar(gtk.Toolbar):
self.insert(self._forward, -1) self.insert(self._forward, -1)
self._forward.show() self._forward.show()
self._stop_and_reload = gtk.ToolButton()
self._forward.props.sensitive = False
self._stop_and_reload.connect("clicked", self._stop_and_reload_cb)
self.insert(self._stop_and_reload, -1)
self._stop_and_reload.show()
separator = gtk.SeparatorToolItem() separator = gtk.SeparatorToolItem()
separator.set_draw(False) separator.set_draw(False)
self.insert(separator, -1) self.insert(separator, -1)
@ -75,19 +81,31 @@ class Toolbar(gtk.Toolbar):
self._embed = embed self._embed = embed
self._embed.connect("notify::progress", self._progress_changed_cb) self._embed.connect("notify::progress", self._progress_changed_cb)
self._embed.connect("notify::loading", self._loading_changed_cb)
self._embed.connect("notify::address", self._address_changed_cb) self._embed.connect("notify::address", self._address_changed_cb)
self._embed.connect("notify::can-go-back", self._embed.connect("notify::can-go-back",
self._can_go_back_changed_cb) self._can_go_back_changed_cb)
self._embed.connect("notify::can-go-forward", self._embed.connect("notify::can-go-forward",
self._can_go_forward_changed_cb) self._can_go_forward_changed_cb)
self._update_stop_and_reload_icon()
def set_links_controller(self, links_controller): def set_links_controller(self, links_controller):
self._links_controller = links_controller self._links_controller = links_controller
self._post.props.sensitive = True self._post.props.sensitive = True
def _update_stop_and_reload_icon(self):
if self._embed.props.loading:
self._stop_and_reload.set_icon_name('stock-close')
else:
self._stop_and_reload.set_icon_name('stock-continue')
def _progress_changed_cb(self, embed, spec): def _progress_changed_cb(self, embed, spec):
self._entry.props.progress = embed.props.progress self._entry.props.progress = embed.props.progress
def _loading_changed_cb(self, embed, spec):
self._update_stop_and_reload_icon()
def _address_changed_cb(self, embed, spec): def _address_changed_cb(self, embed, spec):
self._entry.set_text(embed.props.address) self._entry.set_text(embed.props.address)
@ -106,6 +124,12 @@ class Toolbar(gtk.Toolbar):
def _go_forward_cb(self, button): def _go_forward_cb(self, button):
self._embed.go_forward() self._embed.go_forward()
def _stop_and_reload_cb(self, button):
if self._embed.props.loading:
self._embed.stop_load()
else:
self._embed.reload(0)
def _post_cb(self, button): def _post_cb(self, button):
title = self._embed.get_title() title = self._embed.get_title()
address = self._embed.get_location() address = self._embed.get_location()

View File

@ -33,7 +33,8 @@ enum {
PROP_TITLE, PROP_TITLE,
PROP_ADDRESS, PROP_ADDRESS,
PROP_CAN_GO_BACK, PROP_CAN_GO_BACK,
PROP_CAN_GO_FORWARD PROP_CAN_GO_FORWARD,
PROP_LOADING
}; };
void void
@ -87,6 +88,9 @@ sugar_browser_get_property(GObject *object,
case PROP_CAN_GO_FORWARD: case PROP_CAN_GO_FORWARD:
g_value_set_boolean(value, browser->can_go_forward); g_value_set_boolean(value, browser->can_go_forward);
break; break;
case PROP_LOADING:
g_value_set_boolean(value, browser->loading);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -135,6 +139,13 @@ sugar_browser_class_init(SugarBrowserClass *browser_class)
"Can go forward", "Can go forward",
FALSE, FALSE,
G_PARAM_READABLE)); G_PARAM_READABLE));
g_object_class_install_property (gobject_class, PROP_LOADING,
g_param_spec_boolean ("loading",
"Loading",
"Loading",
FALSE,
G_PARAM_READABLE));
} }
SugarBrowser * SugarBrowser *
@ -184,6 +195,15 @@ sugar_browser_set_progress(SugarBrowser *browser, float progress)
g_object_notify (G_OBJECT(browser), "progress"); g_object_notify (G_OBJECT(browser), "progress");
} }
static void
sugar_browser_set_loading(SugarBrowser *browser, gboolean loading)
{
g_return_if_fail(SUGAR_IS_BROWSER(browser));
browser->loading = loading;
g_object_notify (G_OBJECT(browser), "loading");
}
static void static void
net_state_cb(GtkMozEmbed *embed, const char *aURI, gint state, guint status) net_state_cb(GtkMozEmbed *embed, const char *aURI, gint state, guint status)
{ {
@ -193,7 +213,11 @@ net_state_cb(GtkMozEmbed *embed, const char *aURI, gint state, guint status)
if (state & GTK_MOZ_EMBED_FLAG_START) { if (state & GTK_MOZ_EMBED_FLAG_START) {
browser->total_requests = 0; browser->total_requests = 0;
browser->current_requests = 0; browser->current_requests = 0;
browser->progress = 0.0;
sugar_browser_set_progress(browser, 0.0);
sugar_browser_set_loading(browser, TRUE);
} else if (state & GTK_MOZ_EMBED_FLAG_STOP) {
sugar_browser_set_loading(browser, FALSE);
} }
} }

View File

@ -44,6 +44,7 @@ struct _SugarBrowser {
char *title; char *title;
gboolean can_go_back; gboolean can_go_back;
gboolean can_go_forward; gboolean can_go_forward;
gboolean loading;
}; };
struct _SugarBrowserClass { struct _SugarBrowserClass {