Commit c45feba1 authored by Cédric Bellegarde's avatar Cédric Bellegarde

Rework shown indicator

parent 2d60fbea
......@@ -102,7 +102,6 @@ class Container(Gtk.Overlay):
if self.__expose_stack.get_visible_child_name() == "expose":
window_type = Gdk.WindowType.OFFSCREEN
if window_type == Gdk.WindowType.CHILD:
webview.mark_shown()
self.__current = view
self.__stack.add(view)
self.__pages_manager.update_visible_child()
......
......@@ -27,14 +27,14 @@ class LabelIndicator(Gtk.Label):
Gtk.Label.__init__(self)
self.set_xalign(0.0)
self.set_yalign(0.80)
self.__show = False
self.__show = True
def show_indicator(self, show):
def shown(self, shown):
"""
Show indicator
Show indicator if not shown
@param show as bool
"""
self.__show = show
self.__show = not shown
self.queue_draw()
def do_get_preferred_width(self):
......
......@@ -73,7 +73,6 @@ class PagesManager(Gtk.EventBox):
@return child
"""
child = PagesManagerChild(view, self.__window)
child.label_indicator.show_indicator(not view.webview.shown)
child.show()
self.__box.add(child)
return child
......@@ -94,7 +93,6 @@ class PagesManager(Gtk.EventBox):
style_context.add_class(class_name)
else:
style_context.remove_class(class_name)
child.label_indicator.show_indicator(not child.view.webview.shown)
def destroy(self):
"""
......
......@@ -37,14 +37,14 @@ class PagesManagerChild(Gtk.FlowBoxChild):
builder = Gtk.Builder()
builder.add_from_resource("/org/gnome/Eolie/PagesManagerChild.ui")
builder.connect_signals(self)
self.__title = LabelIndicator()
self.__title.set_hexpand(True)
self.__title.set_margin_right(4)
self.__title.set_property("halign", Gtk.Align.CENTER)
self.__title.set_property("valign", Gtk.Align.CENTER)
self.__title.set_ellipsize(Pango.EllipsizeMode.END)
self.__title.show()
builder.get_object("grid").attach(self.__title, 0, 0, 1, 1)
self.__indicator_label = LabelIndicator()
self.__indicator_label.set_hexpand(True)
self.__indicator_label.set_margin_right(4)
self.__indicator_label.set_property("halign", Gtk.Align.CENTER)
self.__indicator_label.set_property("valign", Gtk.Align.CENTER)
self.__indicator_label.set_ellipsize(Pango.EllipsizeMode.END)
self.__indicator_label.show()
builder.get_object("grid").attach(self.__indicator_label, 0, 0, 1, 1)
self.__image = builder.get_object("image")
self.__close_button = builder.get_object("close_button")
self.__audio_indicator = builder.get_object("audio_indicator")
......@@ -77,35 +77,31 @@ class PagesManagerChild(Gtk.FlowBoxChild):
self.__connected_ids.append(
self.__view.webview.connect(
"favicon-changed",
self.__on_notify_favicon))
self.__on_webview_notify_favicon))
self.__connected_ids.append(
self.__view.webview.connect(
"notify::is-playing-audio",
self.__on_notify_is_playing_audio))
self.__on_webview_notify_is_playing_audio))
self.__connected_ids.append(
self.__view.webview.connect(
"uri-changed",
self.__on_uri_changed))
self.__on_webview_uri_changed))
self.__connected_ids.append(
self.__view.webview.connect(
"title-changed",
self.__on_title_changed))
self.__on_webview_title_changed))
self.__connected_ids.append(
self.__view.webview.connect(
"scroll-event",
self.__on_scroll_event))
self.__on_webview_scroll_event))
self.__connected_ids.append(
self.__view.webview.connect(
"load-changed",
self.__on_load_changed))
@property
def label_indicator(self):
"""
Get label indicator
@return LabelIndicator
"""
return self.__title
self.__on_webview_load_changed))
self.__connected_ids.append(
self.__view.webview.connect(
"shown",
self.__on_webview_shown))
@property
def view(self):
......@@ -210,7 +206,7 @@ class PagesManagerChild(Gtk.FlowBoxChild):
@param tooltip as Gtk.Tooltip
"""
text = ""
label = self.__title.get_text()
label = self.__indicator_label.get_text()
uri = self.__view.webview.get_uri()
# GLib.markup_escape_text
if uri is None:
......@@ -242,7 +238,8 @@ class PagesManagerChild(Gtk.FlowBoxChild):
self.__window.container.sites_manager.remove_view(self.__view)
GLib.idle_add(self.destroy)
def __on_notify_favicon(self, webview, favicon, icon_theme_artwork):
def __on_webview_notify_favicon(self, webview, favicon,
icon_theme_artwork):
"""
Set favicon
@param webview as WebView
......@@ -261,7 +258,7 @@ class PagesManagerChild(Gtk.FlowBoxChild):
icon_theme_artwork,
Gtk.IconSize.INVALID)
def __on_notify_is_playing_audio(self, webview, playing):
def __on_webview_notify_is_playing_audio(self, webview, playing):
"""
Update status
@param webview as WebView
......@@ -272,7 +269,7 @@ class PagesManagerChild(Gtk.FlowBoxChild):
else:
self.__audio_indicator.hide()
def __on_scroll_event(self, webview, event):
def __on_webview_scroll_event(self, webview, event):
"""
Update snapshot
@param webview as WebView
......@@ -290,7 +287,7 @@ class PagesManagerChild(Gtk.FlowBoxChild):
"""
self.__image.set_from_surface(surface)
def __on_uri_changed(self, webview, uri):
def __on_webview_uri_changed(self, webview, uri):
"""
Update uri
@param webview as WebView
......@@ -300,17 +297,17 @@ class PagesManagerChild(Gtk.FlowBoxChild):
if not webview.is_loading() and not webview.ephemeral:
GLib.timeout_add(500, self.__set_snapshot)
def __on_title_changed(self, webview, title):
def __on_webview_title_changed(self, webview, title):
"""
Update title
@param webview as WebView
@param title as str
"""
self.__title.set_text(title)
self.__indicator_label.set_text(title)
self.__window.container.sites_manager.update_label(
self.__window.container.current)
def __on_load_changed(self, webview, event):
def __on_webview_load_changed(self, webview, event):
"""
Update widget content
@param webview as WebView
......@@ -325,9 +322,9 @@ class PagesManagerChild(Gtk.FlowBoxChild):
self.__image.clear()
self.__audio_indicator.hide()
self.__spinner.start()
self.__title.set_text(uri)
self.__indicator_label.set_text(uri)
elif event == WebKit2.LoadEvent.COMMITTED:
self.__title.set_text(uri)
self.__indicator_label.set_text(uri)
self.__window.container.sites_manager.add_view_for_uri(
self.__view,
uri)
......@@ -338,3 +335,9 @@ class PagesManagerChild(Gtk.FlowBoxChild):
if self.__favicon is None:
GLib.timeout_add(500, webview.set_favicon)
GLib.timeout_add(500, self.__set_snapshot)
def __on_webview_shown(self, webview):
"""
Remove indicator
"""
self.__indicator_label.shown(True)
......@@ -141,15 +141,6 @@ class SitesManager(Gtk.EventBox):
child.update_label()
break
def update_indicator(self):
"""
Update indicator for current view
"""
for child in self.__box.get_children():
if self.__window.container.current in child.views:
child.update_indicator(self.__window.container.current)
break
def remove_view(self, view):
"""
Remove view
......
......@@ -83,7 +83,9 @@ class SitesManagerChild(Gtk.ListBoxRow):
"""
if view not in self.__views:
self.__views.append(view)
self.update_indicator(view)
view.webview.connect("shown", self.__on_webview_shown)
self.__indicator_label.shown(view.webview.shown)
self.__update_indicator(view)
self.update_label()
def remove_view(self, view):
......@@ -93,7 +95,7 @@ class SitesManagerChild(Gtk.ListBoxRow):
"""
if view in self.__views:
self.__views.remove(view)
self.update_indicator(view)
self.__update_indicator(view)
self.update_label()
def set_minimal(self, minimal):
......@@ -140,26 +142,6 @@ class SitesManagerChild(Gtk.ListBoxRow):
else:
self.__netloc_label.set_text(self.__netloc)
def update_indicator(self, view):
"""
Update indicator (count and color)
@param view as View
"""
i = 0
unread = False
for view in self.__views:
if not view.webview.shown:
unread = True
i += 1
if unread:
self.__indicator_label.show_indicator(True)
else:
self.__indicator_label.show_indicator(False)
# We force value to 1, Eolie is going to add a new view
if i == 0:
i = 1
self.__indicator_label.set_text(str(i))
def set_favicon(self, surface):
"""
Set favicon
......@@ -245,6 +227,17 @@ class SitesManagerChild(Gtk.ListBoxRow):
#######################
# PRIVATE #
#######################
def __update_indicator(self, view):
"""
Update indicator (count and color)
@param view as View
"""
count = len(self.__views)
# We force value to 1, Eolie is going to add a new view
if count == 0:
count = 1
self.__indicator_label.set_text(str(count))
def __update_popover_internals(self, widget):
"""
Little hack to manage Gtk.ModelButton text
......@@ -368,3 +361,9 @@ class SitesManagerChild(Gtk.ListBoxRow):
"""
self.get_style_context().remove_class("drag-up")
self.get_style_context().remove_class("drag-down")
def __on_webview_shown(self, webview):
"""
Remove indicator
"""
self.__indicator_label.shown(True)
......@@ -242,18 +242,6 @@ class WebView(WebKit2.WebView):
"""
self.__rtime = time
def set_atime(self):
"""
Update access time
"""
self._atime = int(time())
def mark_shown(self):
"""
Mark view as shown
"""
self.__shown = True
@property
def rtime(self):
"""
......@@ -275,7 +263,7 @@ class WebView(WebKit2.WebView):
"""
True if page already shown on screen (one time)
"""
return self.__shown
return self._shown
@property
def cancelled(self):
......@@ -346,7 +334,7 @@ class WebView(WebKit2.WebView):
self.__related_view = related_view
self.__input_source = Gdk.InputSource.MOUSE
self._cancelled = False
self.__shown = False
self._shown = False
self.set_hexpand(True)
self.set_vexpand(True)
self.clear_text_entry()
......
......@@ -31,6 +31,7 @@ class WebViewSignals(WebViewMenuSignals, WebViewJsSignals,
gsignals = {
"readable": (GObject.SignalFlags.RUN_FIRST, None, ()),
"shown": (GObject.SignalFlags.RUN_FIRST, None, ()),
"title-changed": (GObject.SignalFlags.RUN_FIRST, None, (str,)),
"uri-changed": (GObject.SignalFlags.RUN_FIRST, None, (str,)),
"favicon-changed": (GObject.SignalFlags.RUN_FIRST, None,
......@@ -80,6 +81,9 @@ class WebViewSignals(WebViewMenuSignals, WebViewJsSignals,
# We are offscreen
if self._window != self.get_toplevel():
return
self.emit("shown")
self._shown = True
self._atime = int(time())
self._window.update(webview)
self.connect("button-press-event", self._on_button_press_event)
self.connect("enter-fullscreen", self.__on_enter_fullscreen)
......
......@@ -123,17 +123,11 @@ class Window(Gtk.ApplicationWindow):
Update window
@param webview as WebView
"""
if self.__container.current is None or\
webview != self.__container.current.webview:
return
webview.mark_shown()
webview.set_atime()
uri = webview.delayed_uri
if uri is None:
uri = webview.get_uri()
else:
webview.load_uri(uri)
self.container.sites_manager.update_indicator()
title = webview.get_title()
self.toolbar.title.update_load_indicator(webview)
if webview.popups:
......
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