Commit 0fb8dc6d authored by Cédric Bellegarde's avatar Cédric Bellegarde

Do not access SitesManager from PagesManager

parent 5c58652f
......@@ -94,15 +94,6 @@ class PagesManager(Gtk.EventBox):
else:
style_context.remove_class(class_name)
def destroy(self):
"""
Destroy widget and child
"""
# We force child to disconnect from view
for child in self.__box.get_children():
child.destroy()
Gtk.EventBox.destroy(self)
def search_grab_focus(self):
"""
Grab focus on search entry
......@@ -172,7 +163,7 @@ class PagesManager(Gtk.EventBox):
GLib.Variant("(i)", (page_id,)),
self.__on_forms_filled, page_id, view)
def close_view(self, view, animate=True):
def close_view(self, view):
"""
close current view
@param view as View
......@@ -198,11 +189,6 @@ class PagesManager(Gtk.EventBox):
view.webview.ephemeral,
view.webview.get_session_state())
child.destroy()
# Delay view destroy to allow stack animation
if animate:
GLib.timeout_add(1000, view.destroy)
else:
view.destroy()
# Nothing to do if was not current page
if not was_current:
return False
......
......@@ -77,7 +77,7 @@ class PagesManagerChild(Gtk.FlowBoxChild):
self.__connected_ids.append(
self.__view.webview.connect(
"favicon-changed",
self.__on_webview_notify_favicon))
self.__on_webview_favicon_changed))
self.__connected_ids.append(
self.__view.webview.connect(
"notify::is-playing-audio",
......@@ -218,28 +218,27 @@ class PagesManagerChild(Gtk.FlowBoxChild):
def __on_destroy(self, widget):
"""
Disconnect signals
Disconnect signals and destroy view
@param widget as Gtk.Widget
"""
self.__window.container.sites_manager.remove_view(self.__view)
while self.__connected_ids:
connected_id = self.__connected_ids.pop(0)
self.__view.webview.disconnect(connected_id)
if self.__view_destroy_id is not None:
self.__view.disconnect(self.__view_destroy_id)
self.__view.destroy()
def __on_view_destroy(self, view):
"""
Destroy self
Destroy self as view has been destroyed
@param view as View
"""
self.__connected_ids = []
self.__view_destroy_id = None
self.__window.container.sites_manager.remove_view(self.__view)
GLib.idle_add(self.destroy)
self.destroy()
def __on_webview_notify_favicon(self, webview, favicon,
icon_theme_artwork):
def __on_webview_favicon_changed(self, webview, favicon,
icon_theme_artwork):
"""
Set favicon
@param webview as WebView
......@@ -249,10 +248,6 @@ class PagesManagerChild(Gtk.FlowBoxChild):
self.__favicon = favicon
if favicon is not None:
self.__close_button.get_image().set_from_surface(favicon)
# Update site manager favicon (missing or obsolete)
self.__window.container.sites_manager.set_favicon(
self.__view,
favicon)
else:
self.__close_button.get_image().set_from_icon_name(
icon_theme_artwork,
......@@ -304,8 +299,6 @@ class PagesManagerChild(Gtk.FlowBoxChild):
@param title as str
"""
self.__indicator_label.set_text(title)
self.__window.container.sites_manager.update_label(
self.__window.container.current)
def __on_webview_load_changed(self, webview, event):
"""
......
......@@ -84,6 +84,8 @@ class SitesManagerChild(Gtk.ListBoxRow):
if view not in self.__views:
self.__views.append(view)
view.webview.connect("shown", self.__on_webview_shown)
view.webview.connect("favicon-changed",
self.__on_webview_favicon_changed)
self.__indicator_label.shown(view.webview.shown)
self.__update_indicator(view)
self.update_label()
......@@ -142,13 +144,6 @@ class SitesManagerChild(Gtk.ListBoxRow):
else:
self.__netloc_label.set_text(self.__netloc)
def set_favicon(self, surface):
"""
Set favicon
@param surface as cairo.Surface
"""
self.__image.set_from_surface(surface)
@property
def empty(self):
"""
......@@ -268,6 +263,17 @@ class SitesManagerChild(Gtk.ListBoxRow):
resized = get_char_surface(parsed.netloc.lstrip("www.")[0])
self.__image.set_from_surface(resized)
def __on_webview_favicon_changed(self, webview, favicon,
icon_theme_artwork):
"""
Set favicon
@param webview as WebView
@param favicon as cairo.Surface
@param icon_theme_artwork as str
"""
if favicon is not None:
self.__image.set_from_surface(favicon)
def __on_query_tooltip(self, widget, x, y, keyboard, tooltip):
"""
Show tooltip if needed
......
......@@ -42,7 +42,7 @@ class View(Gtk.Overlay):
"""
Gtk.Overlay.__init__(self)
self.__reading_view = None
self._window = window
self.__window = window
self.__webview = webview
webview.set_view(self)
self.__webview.show()
......@@ -115,12 +115,10 @@ class View(Gtk.Overlay):
def destroy(self):
"""
Destroy view and webview
Delayed destroy
"""
Gtk.Overlay.destroy(self)
self.__webview.destroy()
if self.__reading_view is not None:
self.__reading_view.destroy()
self.__window.container.sites_manager.remove_view(self)
GLib.timeout_add(1000, self.__destroy)
@property
def reading(self):
......@@ -149,6 +147,15 @@ class View(Gtk.Overlay):
#######################
# PRIVATE #
#######################
def __destroy(self):
"""
Destroy view and webview
"""
Gtk.Overlay.destroy(self)
self.__webview.destroy()
if self.__reading_view is not None:
self.__reading_view.destroy()
def __on_key_press_event(self, widget, event):
"""
Handle Ctrl+Z and Ctrl+Shift+Z (forms undo/redo)
......@@ -168,7 +175,7 @@ class View(Gtk.Overlay):
@param webview as WebView
"""
if self.get_ancestor(Gtk.Popover) is None:
self._window.container.pages_manager.try_close_view(self)
self.__window.container.pages_manager.try_close_view(self)
def __on_mouse_target_changed(self, webview, hit, modifiers):
"""
......@@ -189,4 +196,4 @@ class View(Gtk.Overlay):
@param webview as WebView
"""
if webview.get_mapped():
self._window.toolbar.title.show_readable_button(True)
self.__window.toolbar.title.show_readable_button(True)
......@@ -201,6 +201,7 @@ class WebViewLoadSignals:
"""
if webview.get_mapped():
self._window.toolbar.title.set_title(title)
self._window.container.sites_manager.update_label(self.view)
def __on_estimated_load_progress(self, webview, value):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment