Пример #1
0
    def run(self):
        '''
        Setup the dialog and return the results to the invoker.
        '''

        msg = _('\nChoose how to report the bug(s)')

        if self._invalid_login:
            msg += _(
                '<b><i>Invalid credentials, please try again.</i></b>\n\n')

        self.set_markup(msg)

        #
        #    Anon
        #
        anon_button = gtk.RadioButton(None, "Anonymously")
        anon_button.set_active(True)
        self.vbox.pack_start(anon_button, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        #
        #    Email
        #
        email_button = gtk.RadioButton(anon_button, "Use email address")
        self.vbox.pack_start(email_button, True, True, 0)

        # Create the text input field
        self.email_entry = EmailEntry(self._email_entry_changed)
        self.email_entry.connect(
            "activate", lambda x: self.response(gtk.RESPONSE_OK))

        # Create a horizontal box to pack the entry and a label
        email_hbox = gtk.HBox()
        email_hbox.pack_start(gtk.Label("Email address:"), False, 5, 5)
        email_hbox.pack_end(self.email_entry)
        email_hbox.set_sensitive(False)
        self.vbox.pack_start(email_hbox, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        #
        #    Github credentials
        #
        gh_button = gtk.RadioButton(email_button, "GitHub credentials:")
        self.vbox.pack_start(gh_button, True, True, 0)

        gh_vbox = gtk.VBox()

        # Create the text input field
        user_entry = gtk.Entry()
        user_entry.connect(
            "activate", lambda x: self.response(gtk.RESPONSE_OK))

        user_hbox = gtk.HBox()
        user_hbox.pack_start(gtk.Label("Username:  "******"activate", lambda x: self.response(gtk.RESPONSE_OK))

        passwd_hbox = gtk.HBox()
        passwd_hbox.pack_start(gtk.Label("Password:  "******"\nYour credentials won't be stored in your computer,\n"
                    "  and will only be sent over HTTPS connections.")
        warning_label.set_text(warning)
        gh_vbox.pack_start(warning_label, True, True, 0)
        gh_vbox.set_sensitive(False)
        self.vbox.pack_start(gh_vbox, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        # Handling of sensitiviness between the radio contents
        anon_button.connect("toggled", self._radio_callback_anon, [
        ], [email_hbox, gh_vbox])
        email_button.connect("toggled", self._radio_callback_email,
                             [email_hbox, ], [gh_vbox, ])
        gh_button.connect(
            "toggled", self._radio_callback_gh, [gh_vbox, ], [email_hbox, ])

        # Go go go!
        self.show_all()
        gtk_response = super(dlg_ask_credentials, self).run()

        # The user closed the dialog with the X
        if gtk_response == gtk.RESPONSE_DELETE_EVENT:
            return True, None, None

        #
        # Get the results, generate the result tuple and return
        #
        active_label = [r.get_label(
        ) for r in anon_button.get_group() if r.get_active()]
        active_label = active_label[0].lower()

        if 'email' in active_label:
            method = self.METHOD_EMAIL
            email = self.email_entry.get_text()
            params = (email,)
        elif 'sourceforge' in active_label:
            method = self.METHOD_GH
            user = user_entry.get_text()
            passwd = passwd_entry.get_text()
            params = (user, passwd)
        else:
            method = self.METHOD_ANON
            params = ()

        # I'm done!
        self.destroy()

        return (False, method, params)
Пример #2
0
    def run(self):
        '''
        Setup the dialog and return the results to the invoker.
        '''

        msg = _('\nChoose how to report the bug(s)')

        if self._invalid_login:
            msg += _(
                '<b><i>Invalid credentials, please try again.</i></b>\n\n')

        self.set_markup(msg)

        #
        #    Anon
        #
        anon_button = gtk.RadioButton(None, "Anonymously")
        anon_button.set_active(True)
        self.vbox.pack_start(anon_button, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        #
        #    Email
        #
        email_button = gtk.RadioButton(anon_button, "Use email address")
        self.vbox.pack_start(email_button, True, True, 0)

        # Create the text input field
        self.email_entry = EmailEntry(self._email_entry_changed)
        self.email_entry.connect("activate",
                                 lambda x: self.response(gtk.RESPONSE_OK))

        # Create a horizontal box to pack the entry and a label
        email_hbox = gtk.HBox()
        email_hbox.pack_start(gtk.Label("Email address:"), False, 5, 5)
        email_hbox.pack_end(self.email_entry)
        email_hbox.set_sensitive(False)
        self.vbox.pack_start(email_hbox, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        #
        #    Github credentials
        #
        gh_button = gtk.RadioButton(email_button, "GitHub credentials:")
        self.vbox.pack_start(gh_button, True, True, 0)

        gh_vbox = gtk.VBox()

        # Create the text input field
        user_entry = gtk.Entry()
        user_entry.connect("activate",
                           lambda x: self.response(gtk.RESPONSE_OK))

        user_hbox = gtk.HBox()
        user_hbox.pack_start(gtk.Label("Username:  "******"activate",
                             lambda x: self.response(gtk.RESPONSE_OK))

        passwd_hbox = gtk.HBox()
        passwd_hbox.pack_start(gtk.Label("Password:  "******"\nYour credentials won't be stored in your computer,\n"
                    "  and will only be sent over HTTPS connections.")
        warning_label.set_text(warning)
        gh_vbox.pack_start(warning_label, True, True, 0)
        gh_vbox.set_sensitive(False)
        self.vbox.pack_start(gh_vbox, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        # Handling of sensitiviness between the radio contents
        anon_button.connect("toggled", self._radio_callback_anon, [],
                            [email_hbox, gh_vbox])
        email_button.connect("toggled", self._radio_callback_email, [
            email_hbox,
        ], [
            gh_vbox,
        ])
        gh_button.connect("toggled", self._radio_callback_gh, [
            gh_vbox,
        ], [
            email_hbox,
        ])

        # Go go go!
        self.show_all()
        gtk_response = super(dlg_ask_credentials, self).run()

        # The user closed the dialog with the X
        if gtk_response == gtk.RESPONSE_DELETE_EVENT:
            return True, None, None

        #
        # Get the results, generate the result tuple and return
        #
        active_label = [
            r.get_label() for r in anon_button.get_group() if r.get_active()
        ]
        active_label = active_label[0].lower()

        if 'email' in active_label:
            method = self.METHOD_EMAIL
            email = self.email_entry.get_text()
            params = (email, )
        elif 'sourceforge' in active_label:
            method = self.METHOD_GH
            user = user_entry.get_text()
            passwd = passwd_entry.get_text()
            params = (user, passwd)
        else:
            method = self.METHOD_ANON
            params = ()

        # I'm done!
        self.destroy()

        return (False, method, params)
Пример #3
0
class dlg_ask_credentials(gtk.MessageDialog):
    '''
    A dialog that allows any exception handler to ask the user for his credentials
    before sending any bug report information to the network. The supported types
    of credentials are:

        * Anonymous
        * Email
        * Sourceforge user (soon to be deprecated, nobody uses it).

    '''

    METHOD_ANON = 1
    METHOD_EMAIL = 2
    METHOD_GH = 3

    def __init__(self, invalid_login=False):
        '''
        :return: A tuple with the following information:
                    (user_exit, method, params)

                Where method is one of METHOD_ANON, METHOD_EMAIL, METHOD_GH and,
                params is the email or the sourceforge username and password,
                in the anon case, the params are empty.
        '''
        gtk.MessageDialog.__init__(self,
                                   None,
                                   gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                                   gtk.MESSAGE_QUESTION,
                                   gtk.BUTTONS_OK,
                                   None)

        self._invalid_login = invalid_login

        self.set_icon_from_file(W3AF_ICON)
        self.set_title('Bug report method - Step 1/2')

    def run(self):
        '''
        Setup the dialog and return the results to the invoker.
        '''

        msg = _('\nChoose how to report the bug(s)')

        if self._invalid_login:
            msg += _(
                '<b><i>Invalid credentials, please try again.</i></b>\n\n')

        self.set_markup(msg)

        #
        #    Anon
        #
        anon_button = gtk.RadioButton(None, "Anonymously")
        anon_button.set_active(True)
        self.vbox.pack_start(anon_button, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        #
        #    Email
        #
        email_button = gtk.RadioButton(anon_button, "Use email address")
        self.vbox.pack_start(email_button, True, True, 0)

        # Create the text input field
        self.email_entry = EmailEntry(self._email_entry_changed)
        self.email_entry.connect(
            "activate", lambda x: self.response(gtk.RESPONSE_OK))

        # Create a horizontal box to pack the entry and a label
        email_hbox = gtk.HBox()
        email_hbox.pack_start(gtk.Label("Email address:"), False, 5, 5)
        email_hbox.pack_end(self.email_entry)
        email_hbox.set_sensitive(False)
        self.vbox.pack_start(email_hbox, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        #
        #    Github credentials
        #
        gh_button = gtk.RadioButton(email_button, "GitHub credentials:")
        self.vbox.pack_start(gh_button, True, True, 0)

        gh_vbox = gtk.VBox()

        # Create the text input field
        user_entry = gtk.Entry()
        user_entry.connect(
            "activate", lambda x: self.response(gtk.RESPONSE_OK))

        user_hbox = gtk.HBox()
        user_hbox.pack_start(gtk.Label("Username:  "******"activate", lambda x: self.response(gtk.RESPONSE_OK))

        passwd_hbox = gtk.HBox()
        passwd_hbox.pack_start(gtk.Label("Password:  "******"\nYour credentials won't be stored in your computer,\n"
                    "  and will only be sent over HTTPS connections.")
        warning_label.set_text(warning)
        gh_vbox.pack_start(warning_label, True, True, 0)
        gh_vbox.set_sensitive(False)
        self.vbox.pack_start(gh_vbox, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        # Handling of sensitiviness between the radio contents
        anon_button.connect("toggled", self._radio_callback_anon, [
        ], [email_hbox, gh_vbox])
        email_button.connect("toggled", self._radio_callback_email,
                             [email_hbox, ], [gh_vbox, ])
        gh_button.connect(
            "toggled", self._radio_callback_gh, [gh_vbox, ], [email_hbox, ])

        # Go go go!
        self.show_all()
        gtk_response = super(dlg_ask_credentials, self).run()

        # The user closed the dialog with the X
        if gtk_response == gtk.RESPONSE_DELETE_EVENT:
            return True, None, None

        #
        # Get the results, generate the result tuple and return
        #
        active_label = [r.get_label(
        ) for r in anon_button.get_group() if r.get_active()]
        active_label = active_label[0].lower()

        if 'email' in active_label:
            method = self.METHOD_EMAIL
            email = self.email_entry.get_text()
            params = (email,)
        elif 'sourceforge' in active_label:
            method = self.METHOD_GH
            user = user_entry.get_text()
            passwd = passwd_entry.get_text()
            params = (user, passwd)
        else:
            method = self.METHOD_ANON
            params = ()

        # I'm done!
        self.destroy()

        return (False, method, params)

    def _email_entry_changed(self, x, y):
        '''
        Disable the OK button if the email is invalid
        '''
        ok_button = self.get_widget_for_response(gtk.RESPONSE_OK)

        if self.email_entry.is_valid():
            # Activate OK button
            ok_button.set_sensitive(True)
        else:
            # Disable OK button
            ok_button.set_sensitive(False)

    def _radio_callback_anon(self, event, enable, disable):
        self._radio_callback(event, enable, disable)
        # re-enable the button in case it was disabled by an invalid email address entry
        ok_button = self.get_widget_for_response(gtk.RESPONSE_OK)
        ok_button.set_sensitive(True)

    def _radio_callback_email(self, event, enable, disable):
        self._radio_callback(event, enable, disable)
        self._email_entry_changed(True, True)

    def _radio_callback_gh(self, event, enable, disable):
        self._radio_callback(event, enable, disable)
        # re-enable the button in case it was disabled by an invalid email address entry
        ok_button = self.get_widget_for_response(gtk.RESPONSE_OK)
        ok_button.set_sensitive(True)

    def _radio_callback(self, event, enable, disable):
        '''
        Handle the clicks on the different radio buttons.
        '''
        for section in enable:
            section.set_sensitive(True)

        for section in disable:
            section.set_sensitive(False)
Пример #4
0
class dlg_ask_credentials(gtk.MessageDialog):
    '''
    A dialog that allows any exception handler to ask the user for his credentials
    before sending any bug report information to the network. The supported types
    of credentials are:

        * Anonymous
        * Email
        * Sourceforge user (soon to be deprecated, nobody uses it).

    '''

    METHOD_ANON = 1
    METHOD_EMAIL = 2
    METHOD_GH = 3

    def __init__(self, invalid_login=False):
        '''
        :return: A tuple with the following information:
                    (user_exit, method, params)

                Where method is one of METHOD_ANON, METHOD_EMAIL, METHOD_GH and,
                params is the email or the sourceforge username and password,
                in the anon case, the params are empty.
        '''
        gtk.MessageDialog.__init__(
            self, None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
            gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK, None)

        self._invalid_login = invalid_login

        self.set_icon_from_file(W3AF_ICON)
        self.set_title('Bug report method - Step 1/2')

    def run(self):
        '''
        Setup the dialog and return the results to the invoker.
        '''

        msg = _('\nChoose how to report the bug(s)')

        if self._invalid_login:
            msg += _(
                '<b><i>Invalid credentials, please try again.</i></b>\n\n')

        self.set_markup(msg)

        #
        #    Anon
        #
        anon_button = gtk.RadioButton(None, "Anonymously")
        anon_button.set_active(True)
        self.vbox.pack_start(anon_button, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        #
        #    Email
        #
        email_button = gtk.RadioButton(anon_button, "Use email address")
        self.vbox.pack_start(email_button, True, True, 0)

        # Create the text input field
        self.email_entry = EmailEntry(self._email_entry_changed)
        self.email_entry.connect("activate",
                                 lambda x: self.response(gtk.RESPONSE_OK))

        # Create a horizontal box to pack the entry and a label
        email_hbox = gtk.HBox()
        email_hbox.pack_start(gtk.Label("Email address:"), False, 5, 5)
        email_hbox.pack_end(self.email_entry)
        email_hbox.set_sensitive(False)
        self.vbox.pack_start(email_hbox, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        #
        #    Github credentials
        #
        gh_button = gtk.RadioButton(email_button, "GitHub credentials:")
        self.vbox.pack_start(gh_button, True, True, 0)

        gh_vbox = gtk.VBox()

        # Create the text input field
        user_entry = gtk.Entry()
        user_entry.connect("activate",
                           lambda x: self.response(gtk.RESPONSE_OK))

        user_hbox = gtk.HBox()
        user_hbox.pack_start(gtk.Label("Username:  "******"activate",
                             lambda x: self.response(gtk.RESPONSE_OK))

        passwd_hbox = gtk.HBox()
        passwd_hbox.pack_start(gtk.Label("Password:  "******"\nYour credentials won't be stored in your computer,\n"
                    "  and will only be sent over HTTPS connections.")
        warning_label.set_text(warning)
        gh_vbox.pack_start(warning_label, True, True, 0)
        gh_vbox.set_sensitive(False)
        self.vbox.pack_start(gh_vbox, True, True, 0)

        separator = gtk.HSeparator()
        self.vbox.pack_start(separator, True, True, 0)

        # Handling of sensitiviness between the radio contents
        anon_button.connect("toggled", self._radio_callback_anon, [],
                            [email_hbox, gh_vbox])
        email_button.connect("toggled", self._radio_callback_email, [
            email_hbox,
        ], [
            gh_vbox,
        ])
        gh_button.connect("toggled", self._radio_callback_gh, [
            gh_vbox,
        ], [
            email_hbox,
        ])

        # Go go go!
        self.show_all()
        gtk_response = super(dlg_ask_credentials, self).run()

        # The user closed the dialog with the X
        if gtk_response == gtk.RESPONSE_DELETE_EVENT:
            return True, None, None

        #
        # Get the results, generate the result tuple and return
        #
        active_label = [
            r.get_label() for r in anon_button.get_group() if r.get_active()
        ]
        active_label = active_label[0].lower()

        if 'email' in active_label:
            method = self.METHOD_EMAIL
            email = self.email_entry.get_text()
            params = (email, )
        elif 'sourceforge' in active_label:
            method = self.METHOD_GH
            user = user_entry.get_text()
            passwd = passwd_entry.get_text()
            params = (user, passwd)
        else:
            method = self.METHOD_ANON
            params = ()

        # I'm done!
        self.destroy()

        return (False, method, params)

    def _email_entry_changed(self, x, y):
        '''
        Disable the OK button if the email is invalid
        '''
        ok_button = self.get_widget_for_response(gtk.RESPONSE_OK)

        if self.email_entry.is_valid():
            # Activate OK button
            ok_button.set_sensitive(True)
        else:
            # Disable OK button
            ok_button.set_sensitive(False)

    def _radio_callback_anon(self, event, enable, disable):
        self._radio_callback(event, enable, disable)
        # re-enable the button in case it was disabled by an invalid email address entry
        ok_button = self.get_widget_for_response(gtk.RESPONSE_OK)
        ok_button.set_sensitive(True)

    def _radio_callback_email(self, event, enable, disable):
        self._radio_callback(event, enable, disable)
        self._email_entry_changed(True, True)

    def _radio_callback_gh(self, event, enable, disable):
        self._radio_callback(event, enable, disable)
        # re-enable the button in case it was disabled by an invalid email address entry
        ok_button = self.get_widget_for_response(gtk.RESPONSE_OK)
        ok_button.set_sensitive(True)

    def _radio_callback(self, event, enable, disable):
        '''
        Handle the clicks on the different radio buttons.
        '''
        for section in enable:
            section.set_sensitive(True)

        for section in disable:
            section.set_sensitive(False)