diff --git a/TODO b/TODO index ff5683d34..b9ce538d8 100644 --- a/TODO +++ b/TODO @@ -79,6 +79,11 @@ hints - uppercase hint chars without requiring upper case to type (easier to distinguish) +style +===== + +- Add a global none attribute/setting to every ConfigType + dwb keybindings to possibly implement ===================================== diff --git a/qutebrowser/network/networkmanager.py b/qutebrowser/network/networkmanager.py index b3209aea9..737e3a31e 100644 --- a/qutebrowser/network/networkmanager.py +++ b/qutebrowser/network/networkmanager.py @@ -18,12 +18,20 @@ """Our own QNetworkAccessManager.""" from PyQt5.QtCore import pyqtSlot -from PyQt5.QtNetwork import QNetworkAccessManager +from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkReply + +try: + from PyQt5.QtNetwork import QSslSocket +except ImportError: + SSL_AVAILABLE = False +else: + SSL_AVAILABLE = QSslSocket.supportsSsl() import qutebrowser.config.config as config import qutebrowser.utils.message as message import qutebrowser.utils.log as log from qutebrowser.network.qutescheme import QuteSchemeHandler +from qutebrowser.network.schemehandler import ErrorNetworkReply from qutebrowser.utils.usertypes import PromptMode @@ -46,7 +54,8 @@ class NetworkManager(QNetworkAccessManager): } if cookiejar is not None: self.setCookieJar(cookiejar) - self.sslErrors.connect(self.on_ssl_errors) + if SSL_AVAILABLE: + self.sslErrors.connect(self.on_ssl_errors) self.authenticationRequired.connect(self.on_authentication_required) self.proxyAuthenticationRequired.connect( self.on_proxy_authentication_required) @@ -116,7 +125,11 @@ class NetworkManager(QNetworkAccessManager): A QNetworkReply. """ scheme = req.url().scheme() - if scheme in self._scheme_handlers: + if scheme == 'https' and not SSL_AVAILABLE: + return ErrorNetworkReply( + "SSL is not supported by the installed Qt library!", + QNetworkReply.ProtocolUnknownError) + elif scheme in self._scheme_handlers: reply = self._scheme_handlers[scheme].createRequest( op, req, outgoing_data) else: diff --git a/qutebrowser/network/schemehandler.py b/qutebrowser/network/schemehandler.py index 1f96e74dd..595e44fef 100644 --- a/qutebrowser/network/schemehandler.py +++ b/qutebrowser/network/schemehandler.py @@ -110,3 +110,31 @@ class SpecialNetworkReply(QNetworkReply): def isFinished(self): """Check if the reply is finished.""" return True + + +class ErrorNetworkReply(QNetworkReply): + + """QNetworkReply which always returns an error.""" + + def __init__(self, errorstring, error, parent=None): + """Constructor. + + Args: + errorstring: The error string to print. + error: The numerical error value. + parent: The parent to pass to QNetworkReply. + """ + super().__init__(parent) + self.setError(error, errorstring) + # For some reason, a segfault will be triggered if these lambdas aren't + # there. pylint: disable=unnecessary-lambda + QTimer.singleShot(0, lambda: self.error.emit(error)) + QTimer.singleShot(0, lambda: self.finished.emit()) + + def abort(self): + """Do nothing since it's a fake reply.""" + pass + + def bytesAvailable(self): + """We always have 0 bytes available.""" + return 0 diff --git a/qutebrowser/test/utils/test_misc.py b/qutebrowser/test/utils/test_misc.py index d9b042b3f..289d76100 100644 --- a/qutebrowser/test/utils/test_misc.py +++ b/qutebrowser/test/utils/test_misc.py @@ -426,14 +426,11 @@ class GetQtArgsTests(TestCase): """Test commandline with a Qt argument and flag.""" ns = self._namespace(['--qt-stylesheet', 'foobar', '--qt-reverse'], flags=['--qt-reverse'], args=['--qt-stylesheet']) - self.assertEqual(utils.get_qt_args(ns), [sys.argv[0], - '-stylesheet', 'foobar', - '-reverse']) - - def test_qt_unknown(self): - """Test commandline with unknown Qt argument.""" - ns = self._namespace(['--qt-foo'], flags=['--qt-foo']) - self.assertEqual(utils.get_qt_args(ns), [sys.argv[0]]) + qt_args = utils.get_qt_args(ns) + self.assertEqual(qt_args[0], sys.argv[0]) + self.assertIn('-reverse', qt_args) + self.assertIn('-stylesheet', qt_args) + self.assertIn('foobar', qt_args) if __name__ == '__main__': diff --git a/qutebrowser/utils/misc.py b/qutebrowser/utils/misc.py index e2527aa0a..a7d2c5be2 100644 --- a/qutebrowser/utils/misc.py +++ b/qutebrowser/utils/misc.py @@ -272,16 +272,15 @@ def get_qt_args(namespace): The argv list to be passed to Qt. """ argv = [sys.argv[0]] - qt_args = ('style', 'stylesheet', 'widget-count', 'reverse', - 'qmljsdebugger') - for argname in qt_args: - val = getattr(namespace, 'qt_' + argname, None) - if val is None: + for argname, val in vars(namespace).items(): + if not argname.startswith('qt_'): + continue + elif val is None: # flag/argument not given continue elif val is True: - argv.append('-' + argname) + argv.append('-' + argname[3:]) else: - argv.append('-' + argname) + argv.append('-' + argname[3:]) argv.append(val[0]) return argv diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index ecbd602b0..09dc62528 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -206,7 +206,7 @@ def version(): lines += [ '', '{}: {}'.format(platform.python_implementation(), - platform.python_version()), + platform.python_version()), 'Qt: {}, runtime: {}'.format(QT_VERSION_STR, qVersion()), 'PyQt: {}'.format(PYQT_VERSION_STR), ]