From a083fe69dbd9861b5249c13988466406f040db41 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 25 Jun 2014 22:22:30 +0200 Subject: [PATCH] Add a :report command --- qutebrowser/app.py | 13 ++++++- qutebrowser/models/cmdhistory.py | 3 ++ qutebrowser/widgets/crash.py | 62 ++++++++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index fd5b87ab9..ace945891 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -49,7 +49,8 @@ from qutebrowser.network.networkmanager import NetworkManager from qutebrowser.config.config import ConfigManager from qutebrowser.keyinput.modeman import ModeManager from qutebrowser.widgets.mainwindow import MainWindow -from qutebrowser.widgets.crash import ExceptionCrashDialog, FatalCrashDialog +from qutebrowser.widgets.crash import (ExceptionCrashDialog, FatalCrashDialog, + ReportDialog) from qutebrowser.keyinput.modeparsers import (NormalKeyParser, HintKeyParser, PromptKeyParser) from qutebrowser.keyinput.keyparser import PassthroughKeyParser @@ -633,6 +634,16 @@ class Application(QApplication): qutescheme.pyeval_output = out self.mainwindow.tabs.openurl(QUrl('qute:pyeval'), newtab=True) + @cmdutils.register(instance='') + def report(self): + """Report a bug in qutebrowser.""" + pages = self._recover_pages() + history = self.mainwindow.status.cmd.history[-5:] + widgets = self.get_all_widgets() + objects = self.get_all_objects() + self._crashdlg = ReportDialog(pages, history, widgets, objects) + self._crashdlg.show() + @pyqtSlot() def shutdown(self): """Try to shutdown everything cleanly. diff --git a/qutebrowser/models/cmdhistory.py b/qutebrowser/models/cmdhistory.py index 3bf484cdf..576492f9b 100644 --- a/qutebrowser/models/cmdhistory.py +++ b/qutebrowser/models/cmdhistory.py @@ -57,6 +57,9 @@ class History: else: self._history = history + def __getitem__(self, idx): + return self._history[idx] + @property def browsing(self): """Check _tmphist to see if we're browsing.""" diff --git a/qutebrowser/widgets/crash.py b/qutebrowser/widgets/crash.py index 58944e263..ee4ef8fb2 100644 --- a/qutebrowser/widgets/crash.py +++ b/qutebrowser/widgets/crash.py @@ -137,8 +137,8 @@ class _CrashDialog(QDialog): Return: The string to display. """ - chunks = ["Please edit this crash report to remove sensitive info, " - "and add as much info as possible about how it happened.\n" + chunks = ["Please edit this report to remove sensitive info, and add " + "as much info as possible about how it happened.\n" "If it's okay if I contact you about this bug report, " "please also add your contact info (Mail/IRC/Jabber)."] for (header, body) in self._crash_info: @@ -269,3 +269,61 @@ class FatalCrashDialog(_CrashDialog): self._crash_info += [ ("Fault log", self._log), ] + + +class ReportDialog(_CrashDialog): + + """Dialog which gets shown when the user wants to report an issue by hand. + + Attributes: + _btn_ok: The OK button. + _btn_pastebin: The pastebin button. + _pages: A list of the open pages (URLs as strings) + _cmdhist: A list with the command history (as strings) + _widgets: A list of active widgets as string. + _objects: A list of all QObjects as string. + """ + + def __init__(self, pages, cmdhist, widgets, objects, parent=None): + self._pages = pages + self._cmdhist = cmdhist + self._btn_ok = None + self._btn_pastebin = None + self._widgets = widgets + self._objects = objects + super().__init__(parent) + + def _init_text(self): + super()._init_text() + text = ("Please describe the bug you encountered below, then either " + "submit it to " + "crash@qutebrowser.org or click 'Report'.") + self._lbl.setText(text) + + def _init_buttons(self): + super()._init_buttons() + self._btn_ok = QPushButton() + self._btn_ok.setText("OK") + self._btn_ok.clicked.connect(self.accept) + self._hbox.addWidget(self._btn_ok) + self._btn_pastebin = QPushButton() + self._btn_pastebin.setText("Report") + self._btn_pastebin.clicked.connect(self.pastebin) + self._btn_pastebin.setDefault(True) + self._hbox.addWidget(self._btn_pastebin) + + def _gather_crash_info(self): + super()._gather_crash_info() + self._crash_info += [ + ("Commandline args", ' '.join(sys.argv[1:])), + ("Open Pages", '\n'.join(self._pages)), + ("Command history", '\n'.join(self._cmdhist)), + ("Widgets", self._widgets), + ("Objects", self._objects), + ] + try: + self._crash_info.append(("Debug log", + logutils.ram_handler.dump_log())) + except AttributeError as e: + self._crash_info.append(("Debug log", "{}: {}".format( + e.__class__.__name__, e)))