From ea2271c2945063d30c4a5f48893f322e4fd3fef4 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 9 Jun 2020 18:59:58 +0200 Subject: [PATCH] Add arguments for :report --- doc/changelog.asciidoc | 2 ++ doc/help/commands.asciidoc | 7 +++++++ qutebrowser/misc/crashdialog.py | 18 ++++++++++++------ qutebrowser/misc/crashsignal.py | 17 ++++++++++++++--- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index daed2fda7..f1f5e0dea 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -25,6 +25,8 @@ Changed a new `-c` flag to customize the Tor control port. - `:config-write-py` now adds a note about `config.py` files being targeted at advanced users. +- `:report` now takes two optional arguments for bug/contact information, so + that it can be used without the report window popping up. Added ~~~~~ diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index dc40c76a6..9b2cae6c6 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -1015,8 +1015,15 @@ Which count to pass the command. [[report]] === report +Syntax: +:report ['info'] ['contact']+ + Report a bug in qutebrowser. +==== positional arguments +* +'info'+: Information about the bug report. If given, no report dialog shows up. + +* +'contact'+: Contact information for the report. + [[restart]] === restart Restart qutebrowser while keeping existing tabs open. diff --git a/qutebrowser/misc/crashdialog.py b/qutebrowser/misc/crashdialog.py index 0f6d02712..4387e479a 100644 --- a/qutebrowser/misc/crashdialog.py +++ b/qutebrowser/misc/crashdialog.py @@ -125,9 +125,13 @@ class _CrashDialog(QDialog): self.setWindowTitle("Whoops!") self.resize(QSize(640, 600)) self._vbox = QVBoxLayout(self) + http_client = httpclient.HTTPClient() self._paste_client = pastebin.PastebinClient(http_client, self) self._pypi_client = autoupdate.PyPIVersionClient(self) + self._paste_client.success.connect(self.on_paste_success) + self._paste_client.error.connect(self.show_error) + self._init_text() self._init_contact_input() @@ -296,13 +300,17 @@ class _CrashDialog(QDialog): except Exception: log.misc.exception("Failed to save contact information!") - def report(self): - """Paste the crash info into the pastebin.""" + def report(self, *, info=None, contact=None): + """Paste the crash info into the pastebin. + + If info/contact are given as arguments, they override the values + entered in the dialog. + """ lines = [] lines.append("========== Report ==========") - lines.append(self._info.toPlainText()) + lines.append(info or self._info.toPlainText()) lines.append("========== Contact ==========") - lines.append(self._contact.toPlainText()) + lines.append(contact or self._contact.toPlainText()) lines.append("========== Debug log ==========") lines.append(self._debug_log.toPlainText()) self._paste_text = '\n\n'.join(lines) @@ -326,8 +334,6 @@ class _CrashDialog(QDialog): self._btn_report.setEnabled(False) self._btn_cancel.setEnabled(False) self._btn_report.setText("Reporting...") - self._paste_client.success.connect(self.on_paste_success) - self._paste_client.error.connect(self.show_error) self.report() @pyqtSlot() diff --git a/qutebrowser/misc/crashsignal.py b/qutebrowser/misc/crashsignal.py index 5d8bd0ff5..3f80db769 100644 --- a/qutebrowser/misc/crashsignal.py +++ b/qutebrowser/misc/crashsignal.py @@ -162,14 +162,25 @@ class CrashHandler(QObject): earlyinit.init_faulthandler(self._crash_log_file) @cmdutils.register(instance='crash-handler') - def report(self): - """Report a bug in qutebrowser.""" + def report(self, info=None, contact=None): + """Report a bug in qutebrowser. + + Args: + info: Information about the bug report. If given, no report dialog + shows up. + contact: Contact information for the report. + """ pages = self._recover_pages() cmd_history = objreg.get('command-history')[-5:] all_objects = debug.get_all_objects() + self._crash_dialog = crashdialog.ReportDialog(pages, cmd_history, all_objects) - self._crash_dialog.show() + + if info is None: + self._crash_dialog.show() + else: + self._crash_dialog.report(info=info, contact=contact) @pyqtSlot() def shutdown(self):