Beispiel #1
0
    def _set_expander(self):
        """Set the expander widget."""
        self.ssl_text = QTextEdit()
        self.ssl_text.setText(self.details)
        scroll_area = QScrollArea()
        scroll_area.setViewport(self.ssl_text)
        scroll_area.setFixedHeight(50)

        self.expander = QExpander(SSL_CERT_DETAILS)
        self.expander.addWidget(scroll_area)
        self.ui.expander_layout.insertWidget(2, self.expander)
Beispiel #2
0
class SSLDialog(QDialog):
    """"Dialog used to show SSL exceptions."""

    def __init__(self, app_name, domain=None, details=None, parent=None):
        """Create a new instance."""
        super(SSLDialog, self).__init__()
        if domain is None:
            logger.debug('Domain passed as None.')
            domain = ''
        self.domain = domain
        if details is None:
            logger.debug('Details passed as None.')
            details = ''
        self.details = details
        self.app_name = app_name
        self.ssl_text = None
        self.expander = None
        self.ui = Ui_SSLDialog()
        self.ui.setupUi(self)
        self.setWindowTitle(SSL_DIALOG_TITLE)
        self._set_expander()
        self._set_labels()
        self._set_buttons()
        self._set_icon()

    def _set_labels(self):
        """Set the labels translations."""
        self.ui.title_label.setText(SSL_HEADER)
        explanation = SSL_EXPLANATION % dict(domain=self.domain)
        intro = REASONS_TEMPLATE % dict(explanation=explanation,
                                        first_reason=SSL_FIRST_REASON,
                                        second_reason=SSL_SECOND_REASON,
                                        third_reason=SSL_THIRD_REASON)
        self.ui.intro_label.setText(intro)
        self.ui.not_sure_label.setText(SSL_NOT_SURE %
                                       {'app_name': self.app_name})
        self.ui.remember_checkbox.setText(SSL_REMEMBER_DECISION)

    def _on_cancel_clicked(self):
        """Cancel was cliked."""
        logger.debug('User canceled the ssl dialog.')
        self.done(USER_CANCELLATION)

    def _on_connect_clicked(self):
        """Connect was clicked."""
        logger.debug('User accepted the ssl certificate.')
        self.done(USER_SUCCESS)

    def _set_buttons(self):
        """Set the labels of the buttons."""
        self.ui.help_button.setText(SSL_HELP_BUTTON)
        self.ui.cancel_button.setText(CANCEL_BUTTON)
        self.ui.cancel_button.clicked.connect(self._on_cancel_clicked)
        self.ui.connect_button.setText(SSL_CONNECT_BUTTON)
        self.ui.connect_button.clicked.connect(self._on_connect_clicked)

    def _set_expander(self):
        """Set the expander widget."""
        self.ssl_text = QTextEdit()
        self.ssl_text.setText(self.details)
        scroll_area = QScrollArea()
        scroll_area.setViewport(self.ssl_text)
        scroll_area.setFixedHeight(50)

        self.expander = QExpander(SSL_CERT_DETAILS)
        self.expander.addWidget(scroll_area)
        self.ui.expander_layout.insertWidget(2, self.expander)

    def _set_icon(self):
        """Set the icon used in the dialog."""
        icon = self.style().standardIcon(QStyle.SP_MessageBoxWarning)
        self.ui.logo_label.setText('')
        self.ui.logo_label.setPixmap(icon.pixmap(48, 48))