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