From 12d798d54da3c4f9637a7c12b967dc4395a4b01e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 1 Nov 2016 16:35:22 +0100 Subject: [PATCH] Continue download splitting --- qutebrowser/browser/downloads.py | 40 +++++++++++++++++++++++++ qutebrowser/browser/webkit/downloads.py | 23 ++------------ 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index b1cf085e1..25a5655e9 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -499,3 +499,43 @@ class AbstractDownloadItem(QObject): self._ask_confirm_question("Overwrite special file?", txt) else: self._after_set_filename() + + def _open_if_successful(self, cmdline): + """Open the downloaded file, but only if it was successful. + + Args: + cmdline: Passed to DownloadItem.open_file(). + """ + if not self.successful: + log.downloads.debug("{} finished but not successful, not opening!" + .format(self)) + return + self.open_file(cmdline) + + def set_target(self, target): + """Set the target for a given download. + + Args: + target: The usertypes.DownloadTarget for this download. + """ + raise NotImplementedError + + +class AbstractDownloadManager(QObject): + + """Backend-independent download manager code. + + Attributes: + downloads: A list of active DownloadItems. + questions: A list of Question objects to not GC them. + _networkmanager: A NetworkManager for generic downloads. + _win_id: The window ID the DownloadManager runs in. + + Signals: + begin_remove_rows: Emitted before downloads are removed. + end_remove_rows: Emitted after downloads are removed. + begin_insert_rows: Emitted before downloads are inserted. + end_insert_rows: Emitted after downloads are inserted. + data_changed: Emitted when the data of the model changed. + The arguments are int indices to the downloads. + """ diff --git a/qutebrowser/browser/webkit/downloads.py b/qutebrowser/browser/webkit/downloads.py index 958b6e122..a71ea6741 100644 --- a/qutebrowser/browser/webkit/downloads.py +++ b/qutebrowser/browser/webkit/downloads.py @@ -372,7 +372,7 @@ class DownloadItem(downloads.AbstractDownloadItem): old_reply.deleteLater() return True - def uses_nam(self, nam): + def _uses_nam(self, nam): """Check if this download uses the given QNetworkAccessManager.""" running_nam = self._reply is not None and self._reply.manager() is nam # user could request retry after tab is closed. @@ -380,24 +380,7 @@ class DownloadItem(downloads.AbstractDownloadItem): self._retry_info.manager is nam) return running_nam or retry_nam - def _open_if_successful(self, cmdline): - """Open the downloaded file, but only if it was successful. - - Args: - cmdline: Passed to DownloadItem.open_file(). - """ - if not self.successful: - log.downloads.debug("{} finished but not successful, not opening!" - .format(self)) - return - self.open_file(cmdline) - def set_target(self, target): - """Set the target for a given download. - - Args: - target: The usertypes.DownloadTarget for this download. - """ if isinstance(target, usertypes.FileObjDownloadTarget): self._set_fileobj(target.fileobj) self.autoclose = False @@ -417,7 +400,7 @@ class DownloadItem(downloads.AbstractDownloadItem): self.autoclose = True self._set_fileobj(fobj) else: # pragma: no cover - raise ValueError("Unknown download target: {}".format(target)) + raise ValueError("Unsupported download target: {}".format(target)) class DownloadManager(QObject): @@ -654,7 +637,7 @@ class DownloadManager(QObject): """ assert nam.adopted_downloads == 0 for download in self.downloads: - if download.uses_nam(nam): + if download._uses_nam(nam): # pylint: disable=protected-access nam.adopt_download(download) return nam.adopted_downloads