diff --git a/qutebrowser/browser/webpage.py b/qutebrowser/browser/webpage.py index 16460eaad..32e56d798 100644 --- a/qutebrowser/browser/webpage.py +++ b/qutebrowser/browser/webpage.py @@ -503,8 +503,16 @@ class BrowserPage(QWebPage): def javaScriptConsoleMessage(self, msg, line, source): """Override javaScriptConsoleMessage to use debug log.""" - if config.get('general', 'log-javascript-console'): - log.js.debug("[{}:{}] {}".format(source, line, msg)) + + log_javascript_console = config.get('general', + 'log-javascript-console' ) + logstring = "[{}:{}] {}".format(source, line, msg) + logmap = { + 'debug': log.js.debug, + 'info': log.js.info, + 'none': lambda arg: None + } + logmap[log_javascript_console](logstring) def chooseFile(self, _frame, suggested_file): """Override QWebPage's chooseFile to be able to chose a file to upload. diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index aea69494b..88ca89e5d 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -356,7 +356,9 @@ class ConfigManager(QObject): ('tabs', 'position'): _transform_position, ('ui', 'downloads-position'): _transform_position, ('ui', 'remove-finished-downloads'): - _get_value_transformer({'false': '-1', 'true': '1000'}) + _get_value_transformer({'false': '-1', 'true': '1000'}), + ('general', 'log-javascript-console'): + _get_value_transformer({'false': 'none', 'true': 'debug'}), } changed = pyqtSignal(str, str) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 7a89b042a..d5083c8f6 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -214,8 +214,13 @@ def data(readonly=False): "launched."), ('log-javascript-console', - SettingValue(typ.Bool(), 'false'), - "Whether to log javascript console messages."), + SettingValue( + typ.String( + valid_values=typ.ValidValues('none', 'debug', 'info')), + 'debug'), + "How to log javascript console messages. " + "None suppresses output, debug logs to stdout if in debug mode, " + "info always logs to stdout."), ('save-session', SettingValue(typ.Bool(), 'false'), diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 4c6a3b4c8..b287c5fb8 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -121,11 +121,11 @@ class BaseType: mentioned in the config file. """ - valid_values = None special = False - def __init__(self, none_ok=False): + def __init__(self, none_ok=False, valid_values=None): self.none_ok = none_ok + self.valid_values = valid_values def _basic_validation(self, value): """Do some basic validation for the value (empty, non-printable chars). @@ -243,8 +243,8 @@ class String(BaseType): """ def __init__(self, minlen=None, maxlen=None, forbidden=None, - none_ok=False, completions=None): - super().__init__(none_ok) + none_ok=False, completions=None, valid_values=None): + super().__init__(none_ok, valid_values) if minlen is not None and minlen < 1: raise ValueError("minlen ({}) needs to be >= 1!".format(minlen)) elif maxlen is not None and maxlen < 1: @@ -650,10 +650,13 @@ class ColorSystem(MappingType): """Color systems for interpolation.""" special = True - valid_values = ValidValues(('rgb', "Interpolate in the RGB color system."), - ('hsv', "Interpolate in the HSV color system."), - ('hsl', "Interpolate in the HSL color system."), - ('none', "Don't show a gradient.")) + + def __init__(self): + self.valid_values = \ + ValidValues(('rgb', "Interpolate in the RGB color system."), + ('hsv', "Interpolate in the HSV color system."), + ('hsl', "Interpolate in the HSL color system."), + ('none', "Don't show a gradient.")) MAPPING = { 'rgb': QColor.Rgb, @@ -1092,9 +1095,12 @@ class HintMode(BaseType): """Base class for the hints -> mode setting.""" special = True - valid_values = ValidValues(('number', "Use numeric hints."), - ('letter', "Use the chars in the hints -> " - "chars setting.")) + + def __init__(self): + self.valid_values = \ + ValidValues(('number', "Use numeric hints."), + ('letter', "Use the chars in the hints -> " + "chars setting.")) class Proxy(BaseType): @@ -1102,8 +1108,11 @@ class Proxy(BaseType): """A proxy URL or special value.""" special = True - valid_values = ValidValues(('system', "Use the system wide proxy."), - ('none', "Don't use any proxy")) + + def __init__(self): + self.valid_values = \ + ValidValues(('system', "Use the system wide proxy."), + ('none', "Don't use any proxy")) PROXY_TYPES = { 'http': QNetworkProxy.HttpProxy, @@ -1330,7 +1339,8 @@ class Position(MappingType): """The position of the tab bar.""" - valid_values = ValidValues('top', 'bottom', 'left', 'right') + def __init__(self): + self.valid_values = ValidValues('top', 'bottom', 'left', 'right') MAPPING = { 'top': QTabWidget.North, @@ -1344,7 +1354,8 @@ class VerticalPosition(BaseType): """The position of the download bar.""" - valid_values = ValidValues('top', 'bottom') + def __init__(self): + self.valid_values = ValidValues('top', 'bottom') class UrlList(List): @@ -1389,10 +1400,11 @@ class SelectOnRemove(MappingType): """Which tab to select when the focused tab is removed.""" special = True - valid_values = ValidValues( - ('left', "Select the tab on the left."), - ('right', "Select the tab on the right."), - ('previous', "Select the previously selected tab.")) + def __init__(self): + self.valid_values = ValidValues( + ('left', "Select the tab on the left."), + ('right', "Select the tab on the right."), + ('previous', "Select the previously selected tab.")) MAPPING = { 'left': QTabBar.SelectLeftTab, @@ -1406,11 +1418,14 @@ class LastClose(BaseType): """Behavior when the last tab is closed.""" special = True - valid_values = ValidValues(('ignore', "Don't do anything."), - ('blank', "Load a blank page."), - ('startpage', "Load the start page."), - ('default-page', "Load the default page."), - ('close', "Close the window.")) + + def __init__(self): + self.valid_values = \ + ValidValues(('ignore', "Don't do anything."), + ('blank', "Load a blank page."), + ('startpage', "Load the start page."), + ('default-page', "Load the default page."), + ('close', "Close the window.")) class AcceptCookies(BaseType): @@ -1418,13 +1433,16 @@ class AcceptCookies(BaseType): """Control which cookies to accept.""" special = True - valid_values = ValidValues(('all', "Accept all cookies."), - ('no-3rdparty', "Accept cookies from the same" - " origin only."), - ('no-unknown-3rdparty', "Accept cookies from " - "the same origin only, unless a cookie is " - "already set for the domain."), - ('never', "Don't accept cookies at all.")) + + def __init__(self): + self.valid_values = \ + ValidValues(('all', "Accept all cookies."), + ('no-3rdparty', "Accept cookies from the same" + " origin only."), + ('no-unknown-3rdparty', "Accept cookies from " + "the same origin only, unless a cookie is " + "already set for the domain."), + ('never', "Don't accept cookies at all.")) class ConfirmQuit(FlagList): @@ -1432,12 +1450,14 @@ class ConfirmQuit(FlagList): """Whether to display a confirmation when the window is closed.""" special = True - valid_values = ValidValues(('always', "Always show a confirmation."), - ('multiple-tabs', "Show a confirmation if " - "multiple tabs are opened."), - ('downloads', "Show a confirmation if " - "downloads are running"), - ('never', "Never show a confirmation.")) + + def __init__(self): + self.valid_values = ValidValues(('always', "Always show a confirmation."), + ('multiple-tabs', "Show a confirmation if " + "multiple tabs are opened."), + ('downloads', "Show a confirmation if " + "downloads are running"), + ('never', "Never show a confirmation.")) # Values that can be combined with commas combinable_values = ('multiple-tabs', 'downloads') @@ -1462,10 +1482,13 @@ class ForwardUnboundKeys(BaseType): """Whether to forward unbound keys.""" special = True - valid_values = ValidValues(('all', "Forward all unbound keys."), - ('auto', "Forward unbound non-alphanumeric " - "keys."), - ('none', "Don't forward any keys.")) + + def __init__(self): + self.valid_values = \ + ValidValues(('all', "Forward all unbound keys."), + ('auto', "Forward unbound non-alphanumeric " + "keys."), + ('none', "Don't forward any keys.")) class CloseButton(BaseType): @@ -1473,9 +1496,12 @@ class CloseButton(BaseType): """Mouse button used to close tabs.""" special = True - valid_values = ValidValues(('right', "Close tabs on right-click."), - ('middle', "Close tabs on middle-click."), - ('none', "Don't close tabs using the mouse.")) + + def __init__(self): + self.valid_values = \ + ValidValues(('right', "Close tabs on right-click."), + ('middle', "Close tabs on middle-click."), + ('none', "Don't close tabs using the mouse.")) class NewTabPosition(BaseType): @@ -1483,10 +1509,13 @@ class NewTabPosition(BaseType): """How new tabs are positioned.""" special = True - valid_values = ValidValues(('left', "On the left of the current tab."), - ('right', "On the right of the current tab."), - ('first', "At the left end."), - ('last', "At the right end.")) + + def __init__(self): + self.valid_values = \ + ValidValues(('left', "On the left of the current tab."), + ('right', "On the right of the current tab."), + ('first', "At the left end."), + ('last', "At the right end.")) class IgnoreCase(Bool): @@ -1494,10 +1523,13 @@ class IgnoreCase(Bool): """Whether to ignore case when searching.""" special = True - valid_values = ValidValues(('true', "Search case-insensitively"), - ('false', "Search case-sensitively"), - ('smart', "Search case-sensitively if there " - "are capital chars")) + + def __init__(self): + self.valid_values = \ + ValidValues(('true', "Search case-insensitively"), + ('false', "Search case-sensitively"), + ('smart', "Search case-sensitively if there " + "are capital chars")) def transform(self, value): if value.lower() == 'smart': @@ -1520,19 +1552,22 @@ class NewInstanceOpenTarget(BaseType): """How to open links in an existing instance if a new one is launched.""" special = True - valid_values = ValidValues(('tab', "Open a new tab in the existing " - "window and activate the window."), - ('tab-bg', "Open a new background tab in the " - "existing window and activate the " - "window."), - ('tab-silent', "Open a new tab in the existing " - "window without activating " - "the window."), - ('tab-bg-silent', "Open a new background tab " - "in the existing window " - "without activating the " - "window."), - ('window', "Open in a new window.")) + + def __init__(self): + self.valid_values = \ + ValidValues(('tab', "Open a new tab in the existing " + "window and activate the window."), + ('tab-bg', "Open a new background tab in the " + "existing window and activate the " + "window."), + ('tab-silent', "Open a new tab in the existing " + "window without activating " + "the window."), + ('tab-bg-silent', "Open a new background tab " + "in the existing window " + "without activating the " + "window."), + ('window', "Open in a new window.")) class DownloadPathSuggestion(BaseType): @@ -1540,21 +1575,26 @@ class DownloadPathSuggestion(BaseType): """How to format the question when downloading.""" special = True - valid_values = ValidValues(('path', "Show only the download path."), - ('filename', "Show only download filename."), - ('both', "Show download path and filename.")) + + def __init__(self): + self.valid_values = \ + ValidValues(('path', "Show only the download path."), + ('filename', "Show only download filename."), + ('both', "Show download path and filename.")) class Referer(BaseType): """Send the Referer header.""" - valid_values = ValidValues(('always', "Always send."), - ('never', "Never send; this is not recommended," - " as some sites may break."), - ('same-domain', "Only send for the same domain." - " This will still protect your privacy, but" - " shouldn't break any sites.")) + def __init__(self): + self.valid_values = \ + ValidValues(('always', "Always send."), + ('never', "Never send; this is not recommended," + " as some sites may break."), + ('same-domain', "Only send for the same domain." + " This will still protect your privacy, but" + " shouldn't break any sites.")) class UserAgent(BaseType): @@ -1624,19 +1664,23 @@ class TabBarShow(BaseType): """When to show the tab bar.""" - valid_values = ValidValues(('always', "Always show the tab bar."), - ('never', "Always hide the tab bar."), - ('multiple', "Hide the tab bar if only one tab " - "is open."), - ('switching', "Show the tab bar when switching " - "tabs.")) + def __init__(self): + self.valid_values = \ + ValidValues(('always', "Always show the tab bar."), + ('never', "Always hide the tab bar."), + ('multiple', "Hide the tab bar if only one tab " + "is open."), + ('switching', "Show the tab bar when switching " + "tabs.")) class URLSegmentList(FlagList): """A list of URL segments.""" - valid_values = ValidValues('host', 'path', 'query', 'anchor') + def __init__(self, none_ok=False): + super().__init__(none_ok) + self.valid_values = ValidValues('host', 'path', 'query', 'anchor') class TimestampTemplate(BaseType):