Move tabhistory.TabHistoryItem to misc.sessions
This makes browser.webkit.tabhistory contain only QtWebKit-specific code.
This commit is contained in:
parent
9f5c8957aa
commit
f6ba859896
@ -22,42 +22,13 @@
|
||||
|
||||
from PyQt5.QtCore import QByteArray, QDataStream, QIODevice, QUrl
|
||||
|
||||
from qutebrowser.utils import utils, qtutils
|
||||
from qutebrowser.utils import qtutils
|
||||
|
||||
|
||||
HISTORY_STREAM_VERSION = 2
|
||||
BACK_FORWARD_TREE_VERSION = 2
|
||||
|
||||
|
||||
class TabHistoryItem:
|
||||
|
||||
"""A single item in the tab history.
|
||||
|
||||
Attributes:
|
||||
url: The QUrl of this item.
|
||||
original_url: The QUrl of this item which was originally requested.
|
||||
title: The title as string of this item.
|
||||
active: Whether this item is the item currently navigated to.
|
||||
user_data: The user data for this item.
|
||||
"""
|
||||
|
||||
def __init__(self, url, title, *, original_url=None, active=False,
|
||||
user_data=None):
|
||||
self.url = url
|
||||
if original_url is None:
|
||||
self.original_url = url
|
||||
else:
|
||||
self.original_url = original_url
|
||||
self.title = title
|
||||
self.active = active
|
||||
self.user_data = user_data
|
||||
|
||||
def __repr__(self):
|
||||
return utils.get_repr(self, constructor=True, url=self.url,
|
||||
original_url=self.original_url, title=self.title,
|
||||
active=self.active, user_data=self.user_data)
|
||||
|
||||
|
||||
def _encode_url(url):
|
||||
"""Encode a QUrl suitable to pass to QWebHistory."""
|
||||
data = bytes(QUrl.toPercentEncoding(url.toString(), b':/#?&+=@%*'))
|
||||
|
@ -33,7 +33,7 @@ except ImportError: # pragma: no cover
|
||||
|
||||
from qutebrowser.browser.webkit import tabhistory
|
||||
from qutebrowser.utils import (standarddir, objreg, qtutils, log, usertypes,
|
||||
message)
|
||||
message, utils)
|
||||
from qutebrowser.commands import cmdexc, cmdutils
|
||||
from qutebrowser.mainwindow import mainwindow
|
||||
from qutebrowser.config import config
|
||||
@ -72,6 +72,35 @@ class SessionNotFoundError(SessionError):
|
||||
"""Exception raised when a session to be loaded was not found."""
|
||||
|
||||
|
||||
class TabHistoryItem:
|
||||
|
||||
"""A single item in the tab history.
|
||||
|
||||
Attributes:
|
||||
url: The QUrl of this item.
|
||||
original_url: The QUrl of this item which was originally requested.
|
||||
title: The title as string of this item.
|
||||
active: Whether this item is the item currently navigated to.
|
||||
user_data: The user data for this item.
|
||||
"""
|
||||
|
||||
def __init__(self, url, title, *, original_url=None, active=False,
|
||||
user_data=None):
|
||||
self.url = url
|
||||
if original_url is None:
|
||||
self.original_url = url
|
||||
else:
|
||||
self.original_url = original_url
|
||||
self.title = title
|
||||
self.active = active
|
||||
self.user_data = user_data
|
||||
|
||||
def __repr__(self):
|
||||
return utils.get_repr(self, constructor=True, url=self.url,
|
||||
original_url=self.original_url, title=self.title,
|
||||
active=self.active, user_data=self.user_data)
|
||||
|
||||
|
||||
class SessionManager(QObject):
|
||||
|
||||
"""Manager for sessions.
|
||||
@ -311,9 +340,9 @@ class SessionManager(QObject):
|
||||
histentry['original-url'].encode('ascii'))
|
||||
else:
|
||||
orig_url = url
|
||||
entry = tabhistory.TabHistoryItem(
|
||||
url=url, original_url=orig_url, title=histentry['title'],
|
||||
active=active, user_data=user_data)
|
||||
entry = TabHistoryItem(url=url, original_url=orig_url,
|
||||
title=histentry['title'], active=active,
|
||||
user_data=user_data)
|
||||
entries.append(entry)
|
||||
if active:
|
||||
new_tab.title_changed.emit(histentry['title'])
|
||||
|
@ -25,7 +25,7 @@ from PyQt5.QtCore import QUrl, QPoint
|
||||
import pytest
|
||||
|
||||
from qutebrowser.browser.webkit import tabhistory
|
||||
from qutebrowser.browser.webkit.tabhistory import TabHistoryItem as Item
|
||||
from qutebrowser.misc.sessions import TabHistoryItem as Item
|
||||
from qutebrowser.utils import qtutils
|
||||
|
||||
|
||||
|
@ -29,9 +29,9 @@ from PyQt5.QtCore import QUrl, QPoint, QByteArray, QObject
|
||||
QWebView = pytest.importorskip('PyQt5.QtWebKitWidgets').QWebView
|
||||
|
||||
from qutebrowser.misc import sessions
|
||||
from qutebrowser.misc.sessions import TabHistoryItem as Item
|
||||
from qutebrowser.utils import objreg, qtutils
|
||||
from qutebrowser.browser.webkit import tabhistory
|
||||
from qutebrowser.browser.webkit.tabhistory import TabHistoryItem as Item
|
||||
from qutebrowser.commands import cmdexc
|
||||
|
||||
|
||||
@ -128,9 +128,8 @@ class HistTester:
|
||||
|
||||
"""Helper object for the hist_tester fixture.
|
||||
|
||||
Makes it possible to use tabhistory.TabHistoryItem objects to easily load
|
||||
data into a QWebHistory, does some basic checks, and provides the
|
||||
serialized history.
|
||||
Makes it possible to use TabHistoryItem objects to easily load data into a
|
||||
QWebHistory, does some basic checks, and provides the serialized history.
|
||||
|
||||
Attributes:
|
||||
sess_man: The SessionManager which is used.
|
||||
|
Loading…
Reference in New Issue
Block a user