Make session saving work
This commit is contained in:
parent
2d590c581d
commit
ed716b2b90
@ -63,6 +63,12 @@ class AbstractHistory:
|
||||
self.tab = tab
|
||||
self.widget = None
|
||||
|
||||
def __iter__(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def current_idx(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def back(self):
|
||||
raise NotImplementedError
|
||||
|
||||
@ -168,6 +174,15 @@ class AbstractTab(QWidget):
|
||||
def shutdown(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def title(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def set_zoom_factor(self, factor):
|
||||
raise NotImplementedError
|
||||
|
||||
def zoom_factor(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def __repr__(self):
|
||||
url = utils.elide(self.cur_url.toDisplayString(QUrl.EncodeUnicode),
|
||||
100)
|
||||
|
@ -33,6 +33,12 @@ from qutebrowser.utils import usertypes, qtutils
|
||||
|
||||
class WebEngineHistory(tab.AbstractHistory):
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.history.items())
|
||||
|
||||
def current_idx(self):
|
||||
return self.history.currentItemIndex()
|
||||
|
||||
def back(self):
|
||||
self.history.back()
|
||||
|
||||
@ -84,6 +90,12 @@ class WebEngineViewTab(tab.AbstractTab):
|
||||
def scroll_pos(self):
|
||||
return (0, 0)
|
||||
|
||||
def set_zoom_factor(self, factor):
|
||||
self._widget.setZoomFactor(factor)
|
||||
|
||||
def zoom_factor(self):
|
||||
return self._widget.zoomFactor()
|
||||
|
||||
def dump_async(self, callback=None, *, plain=False):
|
||||
if plain:
|
||||
self._widget.page().toPlainText(callback)
|
||||
@ -104,6 +116,9 @@ class WebEngineViewTab(tab.AbstractTab):
|
||||
def stop(self):
|
||||
self._widget.stop()
|
||||
|
||||
def title(self):
|
||||
return self._widget.title()
|
||||
|
||||
def _connect_signals(self):
|
||||
view = self._widget
|
||||
page = view.page()
|
||||
|
@ -29,6 +29,12 @@ from qutebrowser.utils import qtutils
|
||||
|
||||
class WebViewHistory(tab.AbstractHistory):
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.history.items())
|
||||
|
||||
def current_idx(self):
|
||||
return self.history.currentItemIndex()
|
||||
|
||||
def back(self):
|
||||
self.history.back()
|
||||
|
||||
@ -110,6 +116,15 @@ class WebViewTab(tab.AbstractTab):
|
||||
def stop(self):
|
||||
self._widget.stop()
|
||||
|
||||
def title(self):
|
||||
return self._widget.title()
|
||||
|
||||
def set_zoom_factor(self, factor):
|
||||
self._widget.setZoomFactor(factor)
|
||||
|
||||
def zoom_factor(self):
|
||||
return self._widget.zoomFactor()
|
||||
|
||||
def _connect_signals(self):
|
||||
view = self._widget
|
||||
page = view.page()
|
||||
|
@ -140,8 +140,7 @@ class SessionManager(QObject):
|
||||
data = {'history': []}
|
||||
if active:
|
||||
data['active'] = True
|
||||
history = tab.page().history()
|
||||
for idx, item in enumerate(history.items()):
|
||||
for idx, item in enumerate(tab.history):
|
||||
qtutils.ensure_valid(item)
|
||||
|
||||
item_data = {
|
||||
@ -152,8 +151,8 @@ class SessionManager(QObject):
|
||||
item_data['title'] = item.title()
|
||||
else:
|
||||
# https://github.com/The-Compiler/qutebrowser/issues/879
|
||||
if history.currentItemIndex() == idx:
|
||||
item_data['title'] = tab.page().mainFrame().title()
|
||||
if tab.history.current_idx() == idx:
|
||||
item_data['title'] = tab.title()
|
||||
else:
|
||||
item_data['title'] = item_data['url']
|
||||
|
||||
@ -161,20 +160,20 @@ class SessionManager(QObject):
|
||||
encoded = item.originalUrl().toEncoded()
|
||||
item_data['original-url'] = bytes(encoded).decode('ascii')
|
||||
|
||||
if history.currentItemIndex() == idx:
|
||||
if tab.history.current_idx() == idx:
|
||||
item_data['active'] = True
|
||||
|
||||
user_data = item.userData()
|
||||
if history.currentItemIndex() == idx:
|
||||
pos = tab.page().mainFrame().scrollPosition()
|
||||
item_data['zoom'] = tab.zoomFactor()
|
||||
item_data['scroll-pos'] = {'x': pos.x(), 'y': pos.y()}
|
||||
if tab.history.current_idx() == idx:
|
||||
pos = tab.scroll_pos
|
||||
item_data['zoom'] = tab.zoom_factor()
|
||||
item_data['scroll-pos'] = {'x': pos[0], 'y': pos[1]}
|
||||
elif user_data is not None:
|
||||
if 'zoom' in user_data:
|
||||
item_data['zoom'] = user_data['zoom']
|
||||
if 'scroll-pos' in user_data:
|
||||
pos = user_data['scroll-pos']
|
||||
item_data['scroll-pos'] = {'x': pos.x(), 'y': pos.y()}
|
||||
item_data['scroll-pos'] = {'x': pos[0], 'y': pos[1]}
|
||||
|
||||
data['history'].append(item_data)
|
||||
return data
|
||||
|
Loading…
Reference in New Issue
Block a user