Add stop/reload buttons.
This commit is contained in:
parent
bb4085373c
commit
e4c6a5befa
@ -40,6 +40,12 @@ class Toolbar(gtk.Toolbar):
|
||||
self.insert(self._forward, -1)
|
||||
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.set_draw(False)
|
||||
self.insert(separator, -1)
|
||||
@ -75,19 +81,31 @@ class Toolbar(gtk.Toolbar):
|
||||
|
||||
self._embed = embed
|
||||
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::can-go-back",
|
||||
self._can_go_back_changed_cb)
|
||||
self._embed.connect("notify::can-go-forward",
|
||||
self._can_go_forward_changed_cb)
|
||||
|
||||
self._update_stop_and_reload_icon()
|
||||
|
||||
def set_links_controller(self, links_controller):
|
||||
self._links_controller = links_controller
|
||||
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):
|
||||
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):
|
||||
self._entry.set_text(embed.props.address)
|
||||
|
||||
@ -106,6 +124,12 @@ class Toolbar(gtk.Toolbar):
|
||||
def _go_forward_cb(self, button):
|
||||
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):
|
||||
title = self._embed.get_title()
|
||||
address = self._embed.get_location()
|
||||
|
@ -33,7 +33,8 @@ enum {
|
||||
PROP_TITLE,
|
||||
PROP_ADDRESS,
|
||||
PROP_CAN_GO_BACK,
|
||||
PROP_CAN_GO_FORWARD
|
||||
PROP_CAN_GO_FORWARD,
|
||||
PROP_LOADING
|
||||
};
|
||||
|
||||
void
|
||||
@ -87,6 +88,9 @@ sugar_browser_get_property(GObject *object,
|
||||
case PROP_CAN_GO_FORWARD:
|
||||
g_value_set_boolean(value, browser->can_go_forward);
|
||||
break;
|
||||
case PROP_LOADING:
|
||||
g_value_set_boolean(value, browser->loading);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@ -135,6 +139,13 @@ sugar_browser_class_init(SugarBrowserClass *browser_class)
|
||||
"Can go forward",
|
||||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_LOADING,
|
||||
g_param_spec_boolean ("loading",
|
||||
"Loading",
|
||||
"Loading",
|
||||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
}
|
||||
|
||||
SugarBrowser *
|
||||
@ -184,6 +195,15 @@ sugar_browser_set_progress(SugarBrowser *browser, float 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
|
||||
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) {
|
||||
browser->total_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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ struct _SugarBrowser {
|
||||
char *title;
|
||||
gboolean can_go_back;
|
||||
gboolean can_go_forward;
|
||||
gboolean loading;
|
||||
};
|
||||
|
||||
struct _SugarBrowserClass {
|
||||
|
Loading…
Reference in New Issue
Block a user