Commit 5040d3f3 authored by Cédric Bellegarde's avatar Cédric Bellegarde

Add pinning support. Fix #309

parent de133df1
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkImage" id="image1">
......@@ -7,8 +7,17 @@
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="pixel_size">22</property>
<property name="icon_name">window-close-symbolic</property>
</object>
<object class="GtkImage" id="pin_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="pixel_size">22</property>
<property name="icon_name">view-pin-symbolic</property>
</object>
<object class="GtkEventBox" id="widget">
<property name="visible">True</property>
<property name="can_focus">False</property>
......@@ -38,6 +47,9 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">end</property>
<property name="margin_left">2</property>
<property name="margin_right">2</property>
<property name="margin_bottom">2</property>
<property name="vexpand">True</property>
<child>
<object class="GtkButton" id="close_button">
......@@ -46,8 +58,6 @@
<property name="receives_default">True</property>
<property name="margin_start">1</property>
<property name="margin_end">1</property>
<property name="margin_top">1</property>
<property name="margin_bottom">1</property>
<property name="image">image1</property>
<property name="relief">none</property>
<signal name="clicked" handler="_on_close_button_clicked" swapped="no"/>
......@@ -56,7 +66,26 @@
</style>
</object>
<packing>
<property name="left_attach">1</property>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="pin_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Pin this page</property>
<property name="opacity">0</property>
<property name="image">pin_image</property>
<property name="relief">none</property>
<signal name="clicked" handler="_on_pin_button_clicked" swapped="no"/>
<style>
<class name="no-padding"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
......
......@@ -60,6 +60,7 @@ class Application(Gtk.Application):
"""
self.__version = version
self.__state_cache = []
self.__pinned = []
self.__ephemeral_context = None
signal(SIGINT, lambda a, b: self.quit())
signal(SIGTERM, lambda a, b: self.quit())
......@@ -179,6 +180,22 @@ class Application(Gtk.Application):
self.__unity.set_property("progress", fraction)
self.__unity.set_property("progress_visible", fraction != 1.0)
def add_to_pinned(self, uri):
"""
Add uri to pinned pages
@param uri as str
"""
if uri not in self.__pinned:
self.__pinned.append(uri)
def remove_from_pinned(self, uri):
"""
Remove uri from pinned pages
@param uri as str
"""
if uri not in self.__pinned:
self.__pinned.remove(uri)
def set_profiles(self):
"""
Set profiles
......@@ -236,6 +253,14 @@ class Application(Gtk.Application):
else:
Gio.Application.quit(self)
@property
def pinned(self):
"""
Get pinned pages
@return [str]
"""
return self.__pinned
@property
def profiles(self):
"""
......@@ -521,6 +546,8 @@ class Application(Gtk.Application):
window_states.append(window_state)
dump(window_states,
open(EOLIE_DATA_PATH + "/session_states.bin", "wb"))
dump(self.__pinned,
open(EOLIE_DATA_PATH + "/pinned.bin", "wb"))
except Exception as e:
Logger.error("Application::__save_state(): %s", e)
......@@ -541,7 +568,10 @@ class Application(Gtk.Application):
"""
size = (800, 600)
maximized = False
pinned = []
try:
pinned = load(
open(EOLIE_DATA_PATH + "/pinned.bin", "rb"))
window_states = load(
open(EOLIE_DATA_PATH + "/session_states.bin", "rb"))
if self.settings.get_value("remember-session"):
......@@ -554,6 +584,8 @@ class Application(Gtk.Application):
i = 0 if foreground else 1
for (uri, title, atime,
ephemeral, state) in window_state["states"]:
if uri in pinned:
pinned.remove(uri)
loading_type = wanted_loading_type(i)
webkit_state = WebKit2.WebViewSessionState(
GLib.Bytes.new(state))
......@@ -572,8 +604,27 @@ class Application(Gtk.Application):
maximized = window_states[0]["maximized"]
except Exception as e:
Logger.error("Application::__create_initial_windows(): %s", e)
if not self.get_windows():
self.get_new_window(size, maximized)
# Create a window if None available and setup pinned pages
# We already removed saved states from pinned
windows = self.get_windows()
if windows:
window = windows[0]
else:
window = self.get_new_window(size, maximized)
window.container.add_webview(
self.start_page,
LoadingType.FOREGROUND,
False)
for uri in pinned:
window.container.add_webview(uri,
LoadingType.BACKGROUND,
False)
# Really setup pinned
try:
self.__pinned = load(
open(EOLIE_DATA_PATH + "/pinned.bin", "rb"))
except:
self.__pinned = []
def __on_handle_local_options(self, app, options):
"""
......
......@@ -46,8 +46,10 @@ class PagesManagerChild(Gtk.FlowBoxChild):
self.__indicator_label.show()
if view.webview.title:
self.__indicator_label.set_text(view.webview.title)
builder.get_object("grid").attach(self.__indicator_label, 0, 0, 1, 1)
builder.get_object("grid").attach(self.__indicator_label, 1, 0, 1, 1)
self.__image = builder.get_object("image")
self.__pin_button = builder.get_object("pin_button")
self.__pin_image = builder.get_object("pin_image")
self.__close_button = builder.get_object("close_button")
self.__close_button.get_image().set_from_icon_name(
"window-close-symbolic",
......@@ -124,6 +126,19 @@ class PagesManagerChild(Gtk.FlowBoxChild):
"""
pass
def _on_pin_button_clicked(self, button):
"""
Pin/Unpin page
@param button as Gtk.Button
"""
if self.view.webview.uri in App().pinned:
self.__pin_image.set_opacity(0.5)
App().remove_from_pinned(self.view.webview.uri)
else:
self.__pin_image.set_opacity(1)
App().add_to_pinned(self.view.webview.uri)
return True
def _on_close_button_clicked(self, button):
"""
Destroy self
......@@ -138,6 +153,11 @@ class PagesManagerChild(Gtk.FlowBoxChild):
@param eventbox as Gtk.EventBox
@param event as Gdk.Event
"""
if self.view.webview.uri in App().pinned:
self.__pin_image.set_opacity(1)
else:
self.__pin_image.set_opacity(0.5)
self.__pin_button.set_opacity(1)
self.__close_button.get_image().set_from_icon_name(
"window-close-symbolic",
Gtk.IconSize.INVALID)
......@@ -153,6 +173,7 @@ class PagesManagerChild(Gtk.FlowBoxChild):
event.x >= allocation.width or\
event.y <= 0 or\
event.y >= allocation.height:
self.__pin_button.set_opacity(0)
self.__on_webview_favicon_changed(self.__view.webview)
#######################
......
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