Split up SessionManager._save_tab_item
This commit is contained in:
parent
b23ddb31c9
commit
e1bad17f2a
@ -130,6 +130,55 @@ class SessionManager(QObject):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _save_tab_item(self, tab, idx, item):
|
||||||
|
"""Save a single history item in a tab.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
tab: The tab to save.
|
||||||
|
idx: The index of the current history item.
|
||||||
|
item: The history item.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
A dict with the saved data for this item.
|
||||||
|
"""
|
||||||
|
data = {
|
||||||
|
'url': bytes(item.url().toEncoded()).decode('ascii'),
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.title():
|
||||||
|
data['title'] = item.title()
|
||||||
|
else:
|
||||||
|
# https://github.com/The-Compiler/qutebrowser/issues/879
|
||||||
|
if tab.history.current_idx() == idx:
|
||||||
|
data['title'] = tab.title()
|
||||||
|
else:
|
||||||
|
data['title'] = data['url']
|
||||||
|
|
||||||
|
if item.originalUrl() != item.url():
|
||||||
|
encoded = item.originalUrl().toEncoded()
|
||||||
|
data['original-url'] = bytes(encoded).decode('ascii')
|
||||||
|
|
||||||
|
if tab.history.current_idx() == idx:
|
||||||
|
data['active'] = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
user_data = item.userData()
|
||||||
|
except AttributeError:
|
||||||
|
# QtWebEngine
|
||||||
|
user_data = None
|
||||||
|
|
||||||
|
if tab.history.current_idx() == idx:
|
||||||
|
pos = tab.scroll.pos_px()
|
||||||
|
data['zoom'] = tab.zoom.factor()
|
||||||
|
data['scroll-pos'] = {'x': pos.x(), 'y': pos.y()}
|
||||||
|
elif user_data is not None:
|
||||||
|
if 'zoom' in user_data:
|
||||||
|
data['zoom'] = user_data['zoom']
|
||||||
|
if 'scroll-pos' in user_data:
|
||||||
|
pos = user_data['scroll-pos']
|
||||||
|
data['scroll-pos'] = {'x': pos.x(), 'y': pos.y()}
|
||||||
|
return data
|
||||||
|
|
||||||
def _save_tab(self, tab, active):
|
def _save_tab(self, tab, active):
|
||||||
"""Get a dict with data for a single tab.
|
"""Get a dict with data for a single tab.
|
||||||
|
|
||||||
@ -142,44 +191,7 @@ class SessionManager(QObject):
|
|||||||
data['active'] = True
|
data['active'] = True
|
||||||
for idx, item in enumerate(tab.history):
|
for idx, item in enumerate(tab.history):
|
||||||
qtutils.ensure_valid(item)
|
qtutils.ensure_valid(item)
|
||||||
|
item_data = self._save_tab_item(tab, idx, item)
|
||||||
item_data = {
|
|
||||||
'url': bytes(item.url().toEncoded()).decode('ascii'),
|
|
||||||
}
|
|
||||||
|
|
||||||
if item.title():
|
|
||||||
item_data['title'] = item.title()
|
|
||||||
else:
|
|
||||||
# https://github.com/The-Compiler/qutebrowser/issues/879
|
|
||||||
if tab.history.current_idx() == idx:
|
|
||||||
item_data['title'] = tab.title()
|
|
||||||
else:
|
|
||||||
item_data['title'] = item_data['url']
|
|
||||||
|
|
||||||
if item.originalUrl() != item.url():
|
|
||||||
encoded = item.originalUrl().toEncoded()
|
|
||||||
item_data['original-url'] = bytes(encoded).decode('ascii')
|
|
||||||
|
|
||||||
if tab.history.current_idx() == idx:
|
|
||||||
item_data['active'] = True
|
|
||||||
|
|
||||||
try:
|
|
||||||
user_data = item.userData()
|
|
||||||
except AttributeError:
|
|
||||||
# QtWebEngine
|
|
||||||
user_data = None
|
|
||||||
|
|
||||||
if tab.history.current_idx() == idx:
|
|
||||||
pos = tab.scroll.pos_px()
|
|
||||||
item_data['zoom'] = tab.zoom.factor()
|
|
||||||
item_data['scroll-pos'] = {'x': pos.x(), 'y': pos.y()}
|
|
||||||
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()}
|
|
||||||
|
|
||||||
data['history'].append(item_data)
|
data['history'].append(item_data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user