Example #1
0
    def run(self):
        #
        #    Main text
        #
        text = 'Thank you for reporting your bugs, it helps us improve our'
        text += ' scanning engine. If you want to get involved with the project'
        text += ' please send an email to our <a href="mailto:%s">mailing list</a>.'
        text = text % ('*****@*****.**')
        # All these lines are here to add a label instead of the easy "set_markup"
        # in order to avoid a bug where the label text appears selected
        msg_area = self.get_message_area()
        [msg_area.remove(c) for c in msg_area.get_children()]
        label = gtk.Label()
        label.set_markup( text )
        label.set_line_wrap(True)
        label.select_region(0, 0)
        msg_area.pack_start(label)
        

        self.worker = bug_report_worker(self.bug_report_function, self.bugs_to_report)
        self.worker.start()        
        gobject.timeout_add(200, self.add_result_from_worker)
        
        self.status_hbox = gtk.HBox()
        
        #
        #    Empty markup for the ticket ids
        #
        self.link_label = gtk.Label( '' )
        self.link_label.set_line_wrap(True)
        self.link_label.set_use_markup( True )
        self.status_hbox.pack_end(self.link_label)
        
        #
        #    Throbber, only show while still running.
        #
        
        self.throbber = Throbber()
        self.throbber.running(True)
        self.status_hbox.pack_end(self.throbber)
        
        #
        #    Check, hidden at the beginning 
        #    http://www.pygtk.org/docs/pygtk/gtk-stock-items.html
        #
        self.done_icon = gtk.Image()
        self.done_icon.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_BUTTON)
        self.status_hbox.pack_end(self.done_icon)
        
        self.vbox.pack_start(self.status_hbox, True, True)

        self.add(self.vbox)
        self.show_all()
        self.done_icon.hide()
        
        super(report_bug_show_result, self).run()
        self.destroy()
        
        return self.reported_ids
Example #2
0
class report_bug_show_result(gtk.MessageDialog):
    '''
    A class that shows the result of one or more bug reports to the user. The
    window shows a "Thanks" message and links to the bugs that were generated.
    
    Unlike previous versions, this window actually sends the bugs to the network
    since we want to show the ticket IDs "in real time" to the user instead of
    reporting them all and then showing a long list of items.
    '''
    
    def __init__(self, bug_report_function, bugs_to_report):
        '''
        @param bug_report_function: The function that's used to report bugs.
                                    apply(bug_report_function, bug_to_report)
                                    
        @param bugs_to_report: An iterable with the bugs to report. These are
                               going to be the parameters for the bug_report_function.
        '''
        gtk.MessageDialog.__init__(self,
                                   None,
                                   gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                                   gtk.MESSAGE_INFO,
                                   gtk.BUTTONS_OK,
                                   None)
        
        self.bug_report_function = bug_report_function
        self.bugs_to_report = bugs_to_report
        self.ticket_ids_in_markup = 0
        self.reported_ids = []
        
        self.set_title('Bug report results')
        self.set_icon_from_file(W3AF_ICON)

        # Disable OK button until the worker finishes the bug reporting process
        ok_button = self.get_widget_for_response(gtk.RESPONSE_OK)
        ok_button.set_sensitive(False)
        
        
    def run(self):
        #
        #    Main text
        #
        text = 'Thank you for reporting your bugs, it helps us improve our'
        text += ' scanning engine. If you want to get involved with the project'
        text += ' please send an email to our <a href="mailto:%s">mailing list</a>.'
        text = text % ('*****@*****.**')
        # All these lines are here to add a label instead of the easy "set_markup"
        # in order to avoid a bug where the label text appears selected
        msg_area = self.get_message_area()
        [msg_area.remove(c) for c in msg_area.get_children()]
        label = gtk.Label()
        label.set_markup( text )
        label.set_line_wrap(True)
        label.select_region(0, 0)
        msg_area.pack_start(label)
        

        self.worker = bug_report_worker(self.bug_report_function, self.bugs_to_report)
        self.worker.start()        
        gobject.timeout_add(200, self.add_result_from_worker)
        
        self.status_hbox = gtk.HBox()
        
        #
        #    Empty markup for the ticket ids
        #
        self.link_label = gtk.Label( '' )
        self.link_label.set_line_wrap(True)
        self.link_label.set_use_markup( True )
        self.status_hbox.pack_end(self.link_label)
        
        #
        #    Throbber, only show while still running.
        #
        
        self.throbber = Throbber()
        self.throbber.running(True)
        self.status_hbox.pack_end(self.throbber)
        
        #
        #    Check, hidden at the beginning 
        #    http://www.pygtk.org/docs/pygtk/gtk-stock-items.html
        #
        self.done_icon = gtk.Image()
        self.done_icon.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_BUTTON)
        self.status_hbox.pack_end(self.done_icon)
        
        self.vbox.pack_start(self.status_hbox, True, True)

        self.add(self.vbox)
        self.show_all()
        self.done_icon.hide()
        
        super(report_bug_show_result, self).run()
        self.destroy()
        
        return self.reported_ids
        
      
    def add_result_from_worker(self):
        '''
        Adds the results from the worker to the text that's shown in the window
        '''
        # The links to the reported tickets
        try:
            bug_report_result = self.worker.output.get(block=False)
        except Queue.Empty:
            # The worker is reporting stuff to the network and doesn't
            # have any results at this moment. Call me in some seconds.
            return True
        
        if bug_report_result == self.worker.FINISHED:
            self.throbber.running(False)
            self.throbber.hide()
            self.done_icon.show()
            ok_button = self.get_widget_for_response(gtk.RESPONSE_OK)
            ok_button.set_sensitive(True)
            # don't call me anymore !
            return False
        else:
            # Add the data to the label and ask to be called again
            ticket_id, ticket_url = bug_report_result
            self.add_link(ticket_id, ticket_url)
            return True

    def add_link(self, ticket_id, ticket_url):
        self.reported_ids.append(ticket_id)
        
        new_link = '<a href="%s">%s</a>'
        new_link = new_link % (ticket_url, ticket_id)
        
        current_markup = self.link_label.get_label()

        needs_new_line = False
        if self.ticket_ids_in_markup == 4:
            needs_new_line = True
            self.ticket_ids_in_markup = 0
        else:
            self.ticket_ids_in_markup += 1

        needs_delim = True
        if len(current_markup) == 0 or needs_new_line:
            needs_delim = False
                    
        current_markup += ('\n' if needs_new_line else '') + (', ' if needs_delim else '')
        current_markup += new_link
        
        self.link_label.set_markup(current_markup)