Use object registry for cache/cookiejar.

This commit is contained in:
Florian Bruhin 2014-09-23 07:32:14 +02:00
parent 3b3675d1af
commit ca2be960df
3 changed files with 24 additions and 12 deletions

View File

@ -61,8 +61,6 @@ class Application(QApplication):
cmd_history: The "cmd_history" LineConfigParser instance. cmd_history: The "cmd_history" LineConfigParser instance.
messagebridge: The global MessageBridge instance. messagebridge: The global MessageBridge instance.
modeman: The global ModeManager instance. modeman: The global ModeManager instance.
cookiejar: The global CookieJar instance.
cache: The global DiskCache instance.
rl_bridge: The ReadlineBridge being used. rl_bridge: The ReadlineBridge being used.
args: ArgumentParser instance. args: ArgumentParser instance.
_commandrunner: The main CommandRunner instance. _commandrunner: The main CommandRunner instance.
@ -131,9 +129,11 @@ class Application(QApplication):
log.init.debug("Initializing utility commands...") log.init.debug("Initializing utility commands...")
utilcmds.init() utilcmds.init()
log.init.debug("Initializing cookies...") log.init.debug("Initializing cookies...")
self.cookiejar = cookies.CookieJar(self) cookiejar = cookies.CookieJar(self)
self.obj.register('cookiejar', cookiejar)
log.init.debug("Initializing cache...") log.init.debug("Initializing cache...")
self.cache = cache.DiskCache(self) diskcache = cache.DiskCache(self)
self.obj.register('cache', diskcache)
log.init.debug("Initializing commands...") log.init.debug("Initializing commands...")
self._commandrunner = runners.CommandRunner() self._commandrunner = runners.CommandRunner()
log.init.debug("Initializing search...") log.init.debug("Initializing search...")
@ -756,8 +756,12 @@ class Application(QApplication):
to_save.append(("command history", self.cmd_history.save)) to_save.append(("command history", self.cmd_history.save))
if hasattr(self, 'stateconfig'): if hasattr(self, 'stateconfig'):
to_save.append(("window geometry", self.stateconfig.save)) to_save.append(("window geometry", self.stateconfig.save))
if hasattr(self, 'cookiejar'): try:
to_save.append(("cookies", self.cookiejar.save)) cookiejar = self.obj.get('cookiejar')
except KeyError:
pass
else:
to_save.append(("cookies", cookiejar.save))
for what, handler in to_save: for what, handler in to_save:
log.destroy.debug("Saving {} (handler: {})".format( log.destroy.debug("Saving {} (handler: {})".format(
what, handler.__qualname__)) what, handler.__qualname__))

View File

@ -51,13 +51,17 @@ class NetworkManager(QNetworkAccessManager):
self._scheme_handlers = { self._scheme_handlers = {
'qute': qutescheme.QuteSchemeHandler(), 'qute': qutescheme.QuteSchemeHandler(),
} }
# We have a shared cookie jar and cache - we restore their parents so
# we don't take ownership of them.
app = QCoreApplication.instance() app = QCoreApplication.instance()
self.setCookieJar(app.cookiejar) cookiejar = utils.get_object('cookiejar')
self.setCache(app.cache) self.setCookieJar(cookiejar)
# We have a shared cookie jar and cache , so we don't want the cookiejar.setParent(app)
# NetworkManager to take ownership of them. cache = utils.get_object('cache')
app.cookiejar.setParent(app) self.setCache(cache)
app.cache.setParent(app) cache.setParent(app)
if SSL_AVAILABLE: if SSL_AVAILABLE:
self.sslErrors.connect(self.on_ssl_errors) self.sslErrors.connect(self.on_ssl_errors)
self.authenticationRequired.connect(self.on_authentication_required) self.authenticationRequired.connect(self.on_authentication_required)

View File

@ -388,6 +388,10 @@ class ObjectRegistry:
"""A registry of long-living objects in qutebrowser. """A registry of long-living objects in qutebrowser.
Inspired by the eric IDE code (E5Gui/E5Application.py). Inspired by the eric IDE code (E5Gui/E5Application.py).
Objects registered globally:
cookiejar: CookieJar instance.
cache: DiskCache instance.
""" """
def __init__(self): def __init__(self):