<commit_before>"""GUI prompt to manage settings"""
from nxdrive.client import Unauthorized
from nxdrive.gui.resources import find_icon
from nxdrive.logging_config import get_logger
from nxdrive.controller import ServerBindingSettings
from nxdrive.controller import ProxySettings
from nxdrive.controller import MissingToken
from nxdrive.client.base_automation_client import get_proxies_for_handler
from nxdrive.client.base_automation_client import get_proxy_handler
import urllib2
import socket

WindowsError = None
try:
    from exceptions import WindowsError
except ImportError:
    pass  # this will never be raised under unix

log = get_logger(__name__)

# Keep Qt an optional dependency for now
QtGui, QDialog = None, object
try:
    from PyQt4 import QtGui
    from PyQt4 import QtCore
    QDialog = QtGui.QDialog
    log.debug("Qt / PyQt4 successfully imported")
except ImportError:
    log.warning("Qt / PyQt4 is not installed: GUI is disabled")
    pass


is_dialog_open = False

PROXY_CONFIGS = ['None', 'System', 'Manual']
PROXY_TYPES = ['http', 'https']
PROXY_TEST_HOST = 'www.google.com'

LICENSE_LINK = (
    '<a href ="http://github.com/nuxeo/nuxeo-drive/blob/master/LICENSE.txt">'
    'LICENSE.txt</a>')
SOURCE_LINK = ('<a href ="http://github.com/nuxeo/nuxeo-drive">'
               'http://github.com/nuxeo/nuxeo-drive</a>')

SETTINGS_DIALOG_WIDTH = 530
ACCOUNT_BOX_HEIGHT = 200
DEFAULT_FIELD_WIDGET_WIDTH = 280
BOLD_STYLE = 'font-weight: bold;'


class Dialog(QDialog):
    """Tabbed dialog box to manage settings

    Available tabs for now: Accounts (server bindings), Proxy settings
    """

    def __init__(self, sb_field_spec, proxy_field_spec, version,
                 title=None, callback=None):
        super(Dialog, self).__init__()
        if QtGui is None:
            raise RuntimeError("PyQt4 is not installed.")
        if title is not None:
            self.setWindowTitle(title)
        icon = find_icon('nuxeo_drive_icon_64.png')
        if icon is not None:
            self.setWindowIcon(QtGui.QIcon(icon))
        self.resize(SETTINGS_DIALOG_WIDTH, -1)
        self.accepted = False
        self.callback = callback

        # Fields
        self.sb_fields = {}
        self.proxy_fields = {}

        # Style sheet
        self.setStyleSheet('QGroupBox {border: none;}')

        # Tabs
        account_box = self.get_account_box(sb_field_spec)
        proxy_box = self.get_proxy_box(proxy_field_spec)
        about_box = self.get_about_box(version)
        self.tabs = QtGui.QTabWidget()
        self.tabs.addTab(account_box, 'Accounts')
        self.tabs.addTab(proxy_box, 'Proxy settings')
        self.tabs.addTab(about_box, 'About')

        # Message
        self.message_area = QtGui.QLabel()
        self.message_area.setWordWrap(True)

        # Buttons
        buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok
                                           | QtGui.QDialogButtonBox.Cancel)
        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(self.tabs)
        mainLayout.addWidget(self.message_area)
        mainLayout.addWidget(buttonBox)
        self.setLayout(mainLayout)

    def get_account_box(self, field_spec):
        box = QtGui.QGroupBox()
        box.setFixedHeight(ACCOUNT_BOX_HEIGHT)
        layout = QtGui.QGridLayout()
        for i, spec in enumerate(field_spec):
            field_id = spec['id']
            value = spec.get('value')
            if field_id == 'update_password':
                if spec.get('display'):
                    field = QtGui.QCheckBox(spec['label'])
                    # Set listener to enable / disable password field
                    field.stateChanged.connect(self.enable_password)
                    layout.addWidget(field, i + 1, 1)
                    self.sb_fields[field_id] = field
            else:
                label = QtGui.QLabel(spec['label'])
                line_edit = QtGui.QLineEdit()
                if value is not None:
                    line_edit.setText(str(value))
                if spec.get('secret', False):
                    line_edit.setEchoMode(QtGui.QLineEdit.Password)
                enabled = spec.get('enabled', True)
                line_edit.setEnabled(enabled)
                line_edit.textChanged.connect(self.clear_message)
                if field_id != 'initialized':
                    layout.addWidget(label, i + 1, 0)
                    layout.addWidget(line_edit, i + 1, 1)
                self.sb_fields[field_id] = line_edit
        box.setLayout(layout)<commit_msg>NXP-12657: Refactor 'line_edit' to 'field' in get_account_box() (clearer)<commit_after>"""GUI prompt to manage settings"""
from nxdrive.client import Unauthorized
from nxdrive.gui.resources import find_icon
from nxdrive.logging_config import get_logger
from nxdrive.controller import ServerBindingSettings
from nxdrive.controller import ProxySettings
from nxdrive.controller import MissingToken
from nxdrive.client.base_automation_client import get_proxies_for_handler
from nxdrive.client.base_automation_client import get_proxy_handler
import urllib2
import socket

WindowsError = None
try:
    from exceptions import WindowsError
except ImportError:
    pass  # this will never be raised under unix

log = get_logger(__name__)

# Keep Qt an optional dependency for now
QtGui, QDialog = None, object
try:
    from PyQt4 import QtGui
    from PyQt4 import QtCore
    QDialog = QtGui.QDialog
    log.debug("Qt / PyQt4 successfully imported")
except ImportError:
    log.warning("Qt / PyQt4 is not installed: GUI is disabled")
    pass


is_dialog_open = False

PROXY_CONFIGS = ['None', 'System', 'Manual']
PROXY_TYPES = ['http', 'https']
PROXY_TEST_HOST = 'www.google.com'

LICENSE_LINK = (
    '<a href ="http://github.com/nuxeo/nuxeo-drive/blob/master/LICENSE.txt">'
    'LICENSE.txt</a>')
SOURCE_LINK = ('<a href ="http://github.com/nuxeo/nuxeo-drive">'
               'http://github.com/nuxeo/nuxeo-drive</a>')

SETTINGS_DIALOG_WIDTH = 530
ACCOUNT_BOX_HEIGHT = 200
DEFAULT_FIELD_WIDGET_WIDTH = 280
BOLD_STYLE = 'font-weight: bold;'


class Dialog(QDialog):
    """Tabbed dialog box to manage settings

    Available tabs for now: Accounts (server bindings), Proxy settings
    """

    def __init__(self, sb_field_spec, proxy_field_spec, version,
                 title=None, callback=None):
        super(Dialog, self).__init__()
        if QtGui is None:
            raise RuntimeError("PyQt4 is not installed.")
        if title is not None:
            self.setWindowTitle(title)
        icon = find_icon('nuxeo_drive_icon_64.png')
        if icon is not None:
            self.setWindowIcon(QtGui.QIcon(icon))
        self.resize(SETTINGS_DIALOG_WIDTH, -1)
        self.accepted = False
        self.callback = callback

        # Fields
        self.sb_fields = {}
        self.proxy_fields = {}

        # Style sheet
        self.setStyleSheet('QGroupBox {border: none;}')

        # Tabs
        account_box = self.get_account_box(sb_field_spec)
        proxy_box = self.get_proxy_box(proxy_field_spec)
        about_box = self.get_about_box(version)
        self.tabs = QtGui.QTabWidget()
        self.tabs.addTab(account_box, 'Accounts')
        self.tabs.addTab(proxy_box, 'Proxy settings')
        self.tabs.addTab(about_box, 'About')

        # Message
        self.message_area = QtGui.QLabel()
        self.message_area.setWordWrap(True)

        # Buttons
        buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok
                                           | QtGui.QDialogButtonBox.Cancel)
        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(self.tabs)
        mainLayout.addWidget(self.message_area)
        mainLayout.addWidget(buttonBox)
        self.setLayout(mainLayout)

    def get_account_box(self, field_spec):
        box = QtGui.QGroupBox()
        box.setFixedHeight(ACCOUNT_BOX_HEIGHT)
        layout = QtGui.QGridLayout()
        for i, spec in enumerate(field_spec):
            field_id = spec['id']
            value = spec.get('value')
            if field_id == 'update_password':
                if spec.get('display'):
                    field = QtGui.QCheckBox(spec['label'])
                    # Set listener to enable / disable password field
                    field.stateChanged.connect(self.enable_password)
                    layout.addWidget(field, i + 1, 1)
                    self.sb_fields[field_id] = field
            else:
                label = QtGui.QLabel(spec['label'])
                field = QtGui.QLineEdit()
                if value is not None:
                    field.setText(str(value))
                if spec.get('secret', False):
                    field.setEchoMode(QtGui.QLineEdit.Password)
                enabled = spec.get('enabled', True)
                field.setEnabled(enabled)
                field.textChanged.connect(self.clear_message)
                if field_id != 'initialized':
                    layout.addWidget(label, i + 1, 0)
                    layout.addWidget(field, i + 1, 1)
                self.sb_fields[field_id] = field
        box.setLayout(layout)
{'fraction_non_alphanumeric': 0.09552366673805954, 'fraction_numerical': 0.005675733561790533, 'mean_word_length': 2.4448542973072667, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7577940', 'n_tokens_mistral': 2866, 'n_tokens_neox': 2757, 'n_words': 594}