diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 7be64122a..7fe53cb1e 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -18,6 +18,7 @@ |<>|Delete the last/[count]th download from disk. |<>|Open the last/[count]th download. |<>|Remove the last/[count]th download from the list. +|<>|Retry the first failed/[count]th download. |<>|Go forward in the history of the current tab. |<>|Toggle fullscreen mode. |<>|Show help about a command or setting. @@ -189,6 +190,13 @@ Remove the last/[count]th download from the list. ==== count The index of the download to cancel. +[[download-retry]] +=== download-retry +Retry the first failed/[count]th download. + +==== count +The index of the download to cancel. + [[forward]] === forward Syntax: +:forward [*--tab*] [*--bg*] [*--window*]+ diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index c8f434072..ac42de1c6 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -909,6 +909,31 @@ class DownloadManager(QAbstractListModel): raise cmdexc.CommandError("Download {} is not done!".format(count)) download.open_file() + @cmdutils.register(instance='download-manager', scope='window', + count='count') + def download_retry(self, count=0): + """Retry the first failed/[count]th download. + + Args: + count: The index of the download to cancel. + """ + if count: + try: + download = self.downloads[count - 1] + except IndexError: + self.raise_no_download(count) + if download.successful or not download.done: + raise cmdexc.CommandError("Download {} did not fail!".format( + count)) + else: + to_retry = [d for d in self.downloads + if d.done and not d.successful] + if not to_retry: + raise cmdexc.CommandError("No failed downloads!") + else: + download = to_retry[0] + download.retry() + @pyqtSlot(QNetworkRequest, QNetworkReply) def on_redirect(self, download, request, reply): """Handle a HTTP redirect of a download.