Exemple #1
0
    def set_scan_infos(self, scan_info):
        for scan in scan_info:
            exp = gtk.Expander('<b>%s - %s</b>' %
                               (_('Scan Info'), scan['type'].capitalize()))
            exp.set_use_markup(True)
            hbox = HIGHBox()
            table = HIGTable()
            table.set_border_width(5)
            table.set_row_spacings(6)
            table.set_col_spacings(6)

            table.attach(HIGEntryLabel(_('Scan type:')), 0, 1, 0, 1)
            table.attach(HIGEntryLabel(scan['type']), 1, 2, 0, 1)

            table.attach(HIGEntryLabel(_('Protocol:')), 0, 1, 1, 2)
            table.attach(HIGEntryLabel(scan['protocol']), 1, 2, 1, 2)

            table.attach(HIGEntryLabel(_('# scanned ports:')), 0, 1, 2, 3)
            table.attach(HIGEntryLabel(scan['numservices']), 1, 2, 2, 3)

            table.attach(HIGEntryLabel(_('Services:')), 0, 1, 3, 4)
            table.attach(self.get_service_view(scan['services'].split(',')),\
                                               1,2,3,4)

            hbox._pack_noexpand_nofill(hig_box_space_holder())
            hbox._pack_noexpand_nofill(table)

            exp.add(hbox)
            self._pack_noexpand_nofill(exp)
 def set_scan_infos(self, scan_info):
     for scan in scan_info:
         exp = gtk.Expander('<b>%s - %s</b>' % (_('Scan Info'),
                                                scan['type'].capitalize()))
         exp.set_use_markup(True)
         hbox = HIGHBox()
         table = HIGTable()
         table.set_border_width(5)
         table.set_row_spacings(6)
         table.set_col_spacings(6)
         
         table.attach(HIGEntryLabel(_('Scan type:')),0,1,0,1)
         table.attach(HIGEntryLabel(scan['type']),1,2,0,1)
         
         table.attach(HIGEntryLabel(_('Protocol:')),0,1,1,2)
         table.attach(HIGEntryLabel(scan['protocol']),1,2,1,2)
         
         table.attach(HIGEntryLabel(_('# scanned ports:')),0,1,2,3)
         table.attach(HIGEntryLabel(scan['numservices']),1,2,2,3)
         
         table.attach(HIGEntryLabel(_('Services:')),0,1,3,4)
         table.attach(self.get_service_view(scan['services'].split(',')),\
                                            1,2,3,4)
         
         hbox._pack_noexpand_nofill(hig_box_space_holder())
         hbox._pack_noexpand_nofill(table)
         
         exp.add (hbox)
         self._pack_noexpand_nofill(exp)
class NmapOutputProperties(HIGDialog):
    def __init__(self, nmap_output_view):
        HIGDialog.__init__(self, _("Nmap Output Properties"),
                           buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
        
        self.nmap_highlight = NmapOutputHighlight()

        self.__create_widgets()
        self.__pack_widgets()
        self.highlight_tab()

        self.vbox.show_all()

    def __create_widgets(self):
        self.properties_notebook = HIGNotebook()

    def __pack_widgets(self):
        self.vbox.pack_start(self.properties_notebook)

    def highlight_tab(self):
        # Creating highlight tab main box
        self.highlight_main_vbox = HIGVBox()

        # Creating highlight tab main table
        self.highlight_main_table = HIGTable()
        self.highlight_main_table.set_border_width(6)

        #############
        # Properties:
        self.property_names = {"details": [_("details"), "MAC Address:"],
                               "port_list": [_("port listing title"),
                                             "PORT   STATE   SERVICE"],
                               "open_port": [_("open port"),
                                             "22/tcp   open   ssh"],
                               "closed_port": [_("closed port"),
                                               "70/tcp   closed   gopher"],
                               "filtered_port": [_("filtered port"),
                                                 "80/tcp   filtered   http"],
                               "date": [_("date"),
                                        "2006-05-26 11:14 BRT"],
                               "hostname": [_("hostname"),
                                            "scanme.nmap.org"],
                               "ip": [_("ip"),
                                      "127.0.0.1"]}

        for p in self.property_names:
            settings = self.nmap_highlight.__getattribute__(p)

            self.property_names[p].append(settings[0])
            self.property_names[p].append(settings[1])
            self.property_names[p].append(settings[2])
            self.property_names[p].append(gtk.gdk.Color(*settings[3]))
            self.property_names[p].append(gtk.gdk.Color(*settings[4]))
            self.property_names[p].append(settings[5])
            
        # Creating properties and related widgets and attaching it to main table
        y1 = 0
        y2 = 1
        for p in self.property_names:
            hp = HighlightProperty(p, self.property_names[p])
            self.highlight_main_table.attach(hp.property_name_label,
                                             0, 1, y1, y2)
            self.highlight_main_table.attach(hp.example_label,
                                             1, 2, y1, y2)
            self.highlight_main_table.attach(hp.bold_tg_button,
                                             2, 3, y1, y2)
            self.highlight_main_table.attach(hp.italic_tg_button,
                                             3, 4, y1, y2)
            self.highlight_main_table.attach(hp.underline_tg_button,
                                             4, 5, y1, y2)
            self.highlight_main_table.attach(hp.text_color_button,
                                             5, 6, y1, y2)
            self.highlight_main_table.attach(hp.highlight_color_button,
                                             6, 7, y1, y2)

            # Setting example styles and colors
            hp.update_example()

            self.property_names[p].append(hp)
            
            y1 += 1
            y2 += 1


        # Packing main table into main vbox
        self.highlight_main_vbox.pack_start(self.highlight_main_table)

        # Adding color tab
        self.properties_notebook.append_page(self.highlight_main_vbox,
                                          gtk.Label(_("Highlight definitions")))
Exemple #4
0
class ScanRunDetailsPage(HIGVBox):
    def __init__(self):
        HIGVBox.__init__(self)

        self.__create_widgets()

    def __create_widgets(self):
        na = _('Not available')
        self.command_expander = gtk.Expander("<b>" + _("Command Info") +
                                             "</b>")
        self.general_expander = gtk.Expander("<b>" + _("General Info") +
                                             "</b>")

        # Command info
        self.command_label = HIGEntryLabel(_('Command:'))
        self.info_command_label = HIGEntryLabel(na)

        self.nmap_version_label = HIGEntryLabel(_('Nmap Version:'))
        self.info_nmap_version_label = HIGEntryLabel(na)

        self.verbose_label = HIGEntryLabel(_('Verbosity level:'))
        self.info_verbose_label = HIGEntryLabel(na)

        self.debug_label = HIGEntryLabel(_('Debug level:'))
        self.info_debug_label = HIGEntryLabel(na)

        self.command_table = HIGTable()
        self.command_hbox = HIGHBox()

        # General info:
        self.start_label = HIGEntryLabel(_('Started on:'))
        self.info_start_label = HIGEntryLabel(na)

        self.finished_label = HIGEntryLabel(_('Finished on:'))
        self.info_finished_label = HIGEntryLabel(na)

        self.host_up_label = HIGEntryLabel(_('Hosts up:'))
        self.info_hosts_up_label = HIGEntryLabel(na)

        self.host_down_label = HIGEntryLabel(_('Hosts down:'))
        self.info_hosts_down_label = HIGEntryLabel(na)

        self.host_scanned_label = HIGEntryLabel(_('Hosts scanned:'))
        self.info_hosts_scanned_label = HIGEntryLabel(na)

        self.open_label = HIGEntryLabel(_('Open ports:'))
        self.info_open_label = HIGEntryLabel(na)

        self.filtered_label = HIGEntryLabel(_('Filtered ports:'))
        self.info_filtered_label = HIGEntryLabel(na)

        self.closed_label = HIGEntryLabel(_('Closed ports:'))
        self.info_closed_label = HIGEntryLabel(na)

        self.general_table = HIGTable()
        self.general_hbox = HIGHBox()

    def set_command_info(self, info):
        # Fix aligment!
        self.command_expander.set_use_markup(True)
        self.command_table.set_border_width(5)
        self.command_table.set_row_spacings(6)
        self.command_table.set_col_spacings(6)

        try:
            self.info_command_label.set_text(info['command'])
        except:
            pass

        try:
            self.info_nmap_version_label.set_text(info['version'])
        except:
            pass

        try:
            self.info_verbose_label.set_text(info['verbose'])
        except:
            pass

        try:
            self.info_debug_label.set_text(info['debug'])
        except:
            pass

        self.command_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.command_hbox._pack_noexpand_nofill(self.command_table)

        self.command_table.attach(self.command_label, 0, 1, 0, 1)
        self.command_table.attach(self.info_command_label, 1, 2, 0, 1)

        self.command_table.attach(self.nmap_version_label, 0, 1, 1, 2)
        self.command_table.attach(self.info_nmap_version_label, 1, 2, 1, 2)

        self.command_table.attach(self.verbose_label, 0, 1, 2, 3)
        self.command_table.attach(self.info_verbose_label, 1, 2, 2, 3)

        self.command_table.attach(self.debug_label, 0, 1, 3, 4)
        self.command_table.attach(self.info_debug_label, 1, 2, 3, 4)

        self.command_expander.add(self.command_hbox)
        self._pack_noexpand_nofill(self.command_expander)
        self.command_expander.set_expanded(True)

    def set_general_info(self, info):
        # Fix aligment!
        self.general_expander.set_use_markup(True)
        self.general_table.set_border_width(5)
        self.general_table.set_row_spacings(6)
        self.general_table.set_col_spacings(6)

        try:
            self.info_start_label.set_text(info['start'])
        except:
            pass

        try:
            self.info_finished_label.set_text(info['finish'])
        except:
            pass

        try:
            self.info_hosts_up_label.set_text(info['hosts_up'])
        except:
            pass

        try:
            self.info_hosts_down_label.set_text(info['hosts_down'])
        except:
            pass

        try:
            self.info_hosts_scanned_label.set_text(info['hosts_scanned'])
        except:
            pass

        #try:
        self.info_open_label.set_text(info['open_ports'])
        #except:pass

        #try:
        self.info_filtered_label.set_text(info['filtered_ports'])
        #except:pass

        #try:
        self.info_closed_label.set_text(info['closed_ports'])
        #except:pass

        self.general_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.general_hbox._pack_noexpand_nofill(self.general_table)

        self.general_table.attach(self.start_label, 0, 1, 0, 1)
        self.general_table.attach(self.info_start_label, 1, 2, 0, 1)

        self.general_table.attach(self.finished_label, 0, 1, 1, 2)
        self.general_table.attach(self.info_finished_label, 1, 2, 1, 2)

        self.general_table.attach(self.host_up_label, 0, 1, 2, 3)
        self.general_table.attach(self.info_hosts_up_label, 1, 2, 2, 3)

        self.general_table.attach(self.host_down_label, 0, 1, 3, 4)
        self.general_table.attach(self.info_hosts_down_label, 1, 2, 3, 4)

        self.general_table.attach(self.host_scanned_label, 0, 1, 4, 5)
        self.general_table.attach(self.info_hosts_scanned_label, 1, 2, 4, 5)

        self.general_table.attach(self.open_label, 0, 1, 5, 6)
        self.general_table.attach(self.info_open_label, 1, 2, 5, 6)

        self.general_table.attach(self.filtered_label, 0, 1, 6, 7)
        self.general_table.attach(self.info_filtered_label, 1, 2, 6, 7)

        self.general_table.attach(self.closed_label, 0, 1, 7, 8)
        self.general_table.attach(self.info_closed_label, 1, 2, 7, 8)

        self.general_expander.add(self.general_hbox)
        self._pack_noexpand_nofill(self.general_expander)
        self.general_expander.set_expanded(True)

    def set_scan_infos(self, scan_info):
        for scan in scan_info:
            exp = gtk.Expander('<b>%s - %s</b>' %
                               (_('Scan Info'), scan['type'].capitalize()))
            exp.set_use_markup(True)
            hbox = HIGHBox()
            table = HIGTable()
            table.set_border_width(5)
            table.set_row_spacings(6)
            table.set_col_spacings(6)

            table.attach(HIGEntryLabel(_('Scan type:')), 0, 1, 0, 1)
            table.attach(HIGEntryLabel(scan['type']), 1, 2, 0, 1)

            table.attach(HIGEntryLabel(_('Protocol:')), 0, 1, 1, 2)
            table.attach(HIGEntryLabel(scan['protocol']), 1, 2, 1, 2)

            table.attach(HIGEntryLabel(_('# scanned ports:')), 0, 1, 2, 3)
            table.attach(HIGEntryLabel(scan['numservices']), 1, 2, 2, 3)

            table.attach(HIGEntryLabel(_('Services:')), 0, 1, 3, 4)
            table.attach(self.get_service_view(scan['services'].split(',')),\
                                               1,2,3,4)

            hbox._pack_noexpand_nofill(hig_box_space_holder())
            hbox._pack_noexpand_nofill(table)

            exp.add(hbox)
            self._pack_noexpand_nofill(exp)

    def get_service_view(self, services):
        combo = gtk.combo_box_new_text()

        for i in services:
            combo.append_text(i)

        return combo
Exemple #5
0
class GeneralSettings(TabBox, object):
    """
    General Settings
    - Splash enable/disable
    - Warnings
    - Erros, log, configure bugreport
    - Autosave: clean up, define folder etc
    - Define Nmap Command
    """

    def __init__(self, name):
        TabBox.__init__(self, name)


    def _create_widgets(self):
        """
        Design all
        """
        # Create general widgets
        self._create_widgets_common()
        self._create_widgets_autosave()
        self._create_widgets_error()
        # Packing main section
        self.pack_start(self._box_common, False, False)
        self.pack_start(self._box_error_frame, False, False)
        self.pack_start(self._box_save_frame, False, False)
        self._box_error_frame.set_shadow_type(gtk.SHADOW_NONE)
        self._box_error_frame.set_shadow_type(gtk.SHADOW_NONE)


        # Settings Values

        self.splash = general_settings.splash
        self.warnings_extensions = general_settings.warnings_extensions
        self.silent_root = general_settings.silent_root
        self.crash_report = general_settings.crash_report
        self.log = general_settings.log
        self.log_file = general_settings.log_file
        self.warnings_save = general_settings.warnings_save

        self._connect_events()
    def _create_widgets_common(self):
        """ generally tab """
        self._box_common = HIGVBox() # pack main section
        self.__check_splash = gtk.CheckButton(_('Enable Splash on start'))
        self.__check_silent_root = gtk.CheckButton(\
            _('Silent Warning Non-Root'))
        self.__check_warning_extensions = gtk.CheckButton(\
            _('Set/Check extensions - Windows only'))
        self._box_common.pack_start(self.__check_splash, False, False)
        #self._box_common.pack_start(self.__check_warning_extensions, False, \
        #                            False)
        self._box_common.pack_start(self.__check_silent_root, False, False)
        self.__label_nmap = HIGEntryLabel(_('Nmap Command'))
        self.__entry_nmap = HIGTextEntry()
        # Files usr saved on predefined directory:
        self.__label_path = HIGEntryLabel(_('Nmap Command'))
        self.__entry_path = HIGTextEntry()
        self.__button_path = HIGButton(_('Choose'))
        self.__box_path = HIGHBox()
        self.__box_path.pack_start(self.__label_path, False, False)
        self.__box_path.pack_end(self.__button_path, False, False)

        self._box_common.set_border_width(0)




    def _create_widgets_error(self):

        # Create Widgets
        self._box_error_frame = HIGFrame('Error')

        self._box_error = HIGTable(5, 2)
        self._box_error.set_border_width(10)
        self._box_error_frame.add(self._box_error)
        self.__crash_report = gtk.CheckButton(_('Enable Crash Report'))
        # Radio Button List
        self.__log_no = gtk.RadioButton(None, _('No log'))
        self.__log_terminal = gtk.RadioButton(self.__log_no, _('Enable log in terminal'))
        self.__log_file = gtk.RadioButton(self.__log_terminal,\
                                         _('Enable log file'))

        self.__log_file_label = HIGEntryLabel(_('Log file'))
        self.__log_file_entry = HIGTextEntry()
        self.__log_file_entry.set_editable(False)
        # FIXME: Do default file ~/.umit/umit.log
        self.__log_file_browser = HIGButton(_('Browse file'), \
                                            gtk.STOCK_DIRECTORY)

        tmpbox = HIGHBox()
        tmpbox.pack_start(self.__log_file_entry, False, False)
        tmpbox.pack_start(self.__log_file_browser, False, False)


        # attach table
        self._box_error.attach(self.__crash_report, 0,1,0,1,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_no, 0,1,1,2,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_terminal, 0,1,2,3,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_file, 0,1,3,4,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(self.__log_file_label, 0,1,4,5,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
        self._box_error.attach(tmpbox, 1,2,4,5,\
                               gtk.FILL|gtk.EXPAND| gtk.SHRINK, gtk.FILL)
    def _create_widgets_autosave(self):

        # Create Widgets
        self._box_save_frame = HIGFrame('Auto-save')

        self._box_save = HIGVBox()
        self._box_save_frame.add(self._box_save)
        self._box_save.set_border_width(10)

        self._warnings_save = gtk.CheckButton(
            _('Enable warnings without saving'))
        self._clean_b = HIGButton(_('Delete saved files'), gtk.STOCK_CLEAR)
        self._clean_b_box = HIGHBox()
        self._clean_b_box.pack_start(self._clean_b, False, True)

        # pack

        self._box_save.pack_start(self._warnings_save, False, False)
        self._box_save.pack_start(self._clean_b_box, False, False)
    def _connect_events(self):
        """
        connect call backs
        """

        self.__check_splash.connect('toggled', self.update_splash)
        self.__check_silent_root.connect('toggled', self.update_silent_root)
        self.__crash_report.connect('toggled', self.update_crash_report)


        self.__log_file.connect('toggled', self.update_log)
        self.__log_file.connect('toggled', self.update_log_file)
        self.__log_terminal.connect('toggled', self.update_log)
        self.__log_no.connect('toggled', self.update_log)

        self.__log_file_browser.connect('clicked', self.read_file)
        self.__log_file_entry.connect('changed', self.update_log_file_text)

        self._warnings_save.connect('toggled', self.update_save_warn)
        
        self._clean_b.connect('clicked', self.delete_files)
        
        self.update_log_file(None)
    # Callbacks
    def delete_files(self, widget):
        # NOTE: This method should be adapted in umit.core.UserConf
        # Creating an empty recent_scans file
        
        log.debug('>>> Reset store files:  -  %s' % base_paths['user_dir'])

        reset_user_dir(base_paths['user_dir'])
        
    
    def update_save_warn(self, widget):
        general_settings.warnings_save = self.warnings_save

    def read_file(self, widget):
        dialog = gtk.FileChooserDialog("Open..",
                                       None,
                                       gtk.FILE_CHOOSER_ACTION_SAVE,
                                       (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                        gtk.STOCK_SAVE_AS, gtk.RESPONSE_OK))
        dialog.set_default_response(gtk.RESPONSE_OK)
        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            # Get name of file
            self.__log_file_entry.set_text(dialog.get_filename())
        dialog.destroy()

    def update_crash_report(self, widget):
        general_settings.crash_report = self.crash_report
    def update_splash(self, widget):
        general_settings.splash = self.splash
    def update_silent_root(self, widget):
        general_settings.silent_root = self.silent_root
    def update_log_file_text(self, widget):
        general_settings.log_file = self.log_file
    def update_log_file(self, widget):
        if not self.__log_file.get_active():
            self.__log_file_active(False)
        else:
            self.__log_file_active(True)
    def update_log(self, widget):
        """ Verify if is enable, if it is not enable nothing to do """
        if not widget.get_active():
            return
        # Widget is enable.
        ## But which is enable?

        # Setting kind of log
        if widget == self.__log_no:
            general_settings.log = "None"
        elif widget == self.__log_terminal:
            general_settings.log = "Debug"
        elif widget == self.__log_file:
            general_settings.log = "File"


    # API
    def get_splash(self):
        return self.__check_splash.get_active()
    def set_splash(self, splash):
        self.__check_splash.set_active(splash)

    def set_warnings_extensions(self, extensions):
        self.__check_warning_extensions.set_active(extensions)
    def get_warnings_extensions(self):
        return self.__check_warning_extensions.get_active()
    def set_silent_root(self, root):
        self.__check_silent_root.set_active(root)
    def get_silent_root(self):
        return self.__check_silent_root.get_active()


    def set_crash_report(self, crash):
        self.__crash_report.set_active(crash)
    def get_crash_report(self):
        return self.__crash_report.get_active()

    def get_log(self):
        """
        filter a str with None, Debug or File
        return: int (means 0 - No debug, 1 - debug, 2 - debug file)
        """
        if self.__log_no.get_active():
            return "None"
        elif self.__log_terminal.get_active():
            return "Debug"
        elif self.__log_file.get_active():
            return "File"
        else:
            raise LogException()



    def set_log(self, log):
        if log == "None":
            self.__log_no.set_active(True)
        elif log == "Debug":
            self.__log_terminal.set_active(True)
        elif log == "File":
            self.__log_file.set_active(True)


    def __log_file_active(self, bool):
        self.__log_file_label.set_sensitive(bool)
        self.__log_file_entry.set_sensitive(bool)
        self.__log_file_browser.set_sensitive(bool)

    def set_log_file(self, filename):
        self.__log_file_entry.set_text(filename)
    def get_log_file(self):
        return self.__log_file_entry.get_text()

    def set_warnings_save(self, save):
        self._warnings_save.set_active(save)
    def get_warnings_save(self):
        return self._warnings_save.get_active()

    # Propertys
    splash = property(get_splash, set_splash)
    warnings_extensions = property(get_warnings_extensions, \
                                   set_warnings_extensions)
    silent_root = property(get_silent_root, set_silent_root)
    crash_report = property(get_crash_report, set_crash_report)
    log = property(get_log, set_log)
    log_file = property(get_log_file, set_log_file)
    warnings_save = property(get_warnings_save, set_warnings_save)
class ScanRunDetailsPage(HIGVBox):
    def __init__(self):
        HIGVBox.__init__(self)
        
        self.__create_widgets()
    
    def __create_widgets(self):
        na = _('Not available')
        self.command_expander = gtk.Expander("<b>"+_("Command Info")+"</b>")
        self.general_expander = gtk.Expander("<b>"+_("General Info")+"</b>")
        
        # Command info
        self.command_label = HIGEntryLabel(_('Command:'))
        self.info_command_label = HIGEntryLabel(na)
        
        self.nmap_version_label = HIGEntryLabel(_('Nmap Version:'))
        self.info_nmap_version_label = HIGEntryLabel(na)
        
        self.verbose_label = HIGEntryLabel(_('Verbosity level:'))
        self.info_verbose_label = HIGEntryLabel(na)
        
        self.debug_label = HIGEntryLabel(_('Debug level:'))
        self.info_debug_label = HIGEntryLabel(na)
        
        self.command_table = HIGTable()
        self.command_hbox = HIGHBox()
        
        # General info:
        self.start_label = HIGEntryLabel(_('Started on:'))
        self.info_start_label = HIGEntryLabel(na)
        
        self.finished_label = HIGEntryLabel(_('Finished on:'))
        self.info_finished_label = HIGEntryLabel(na)
        
        self.host_up_label = HIGEntryLabel(_('Hosts up:'))
        self.info_hosts_up_label = HIGEntryLabel(na)
        
        self.host_down_label = HIGEntryLabel(_('Hosts down:'))
        self.info_hosts_down_label = HIGEntryLabel(na)
        
        self.host_scanned_label = HIGEntryLabel(_('Hosts scanned:'))
        self.info_hosts_scanned_label = HIGEntryLabel(na)
        
        self.open_label = HIGEntryLabel(_('Open ports:'))
        self.info_open_label = HIGEntryLabel(na)
        
        self.filtered_label = HIGEntryLabel(_('Filtered ports:'))
        self.info_filtered_label = HIGEntryLabel(na)
        
        self.closed_label = HIGEntryLabel(_('Closed ports:'))
        self.info_closed_label = HIGEntryLabel(na)
        
        self.general_table = HIGTable()
        self.general_hbox = HIGHBox()
    
    def set_command_info(self, info):
        # Fix aligment!
        self.command_expander.set_use_markup(True)
        self.command_table.set_border_width(5)
        self.command_table.set_row_spacings(6)
        self.command_table.set_col_spacings(6)
        
        try:self.info_command_label.set_text(info['command'])
        except:pass
        
        try:self.info_nmap_version_label.set_text(info['version'])
        except:pass
        
        try:self.info_verbose_label.set_text(info['verbose'])
        except:pass
        
        try:self.info_debug_label.set_text(info['debug'])
        except:pass
        
        self.command_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.command_hbox._pack_noexpand_nofill(self.command_table)
        
        self.command_table.attach(self.command_label,0,1,0,1)
        self.command_table.attach(self.info_command_label,1,2,0,1)
        
        self.command_table.attach(self.nmap_version_label,0,1,1,2)
        self.command_table.attach(self.info_nmap_version_label,1,2,1,2)
        
        self.command_table.attach(self.verbose_label,0,1,2,3)
        self.command_table.attach(self.info_verbose_label,1,2,2,3)
        
        self.command_table.attach(self.debug_label,0,1,3,4)
        self.command_table.attach(self.info_debug_label,1,2,3,4)
        
        self.command_expander.add(self.command_hbox)
        self._pack_noexpand_nofill(self.command_expander)
        self.command_expander.set_expanded(True)
    
    def set_general_info(self, info):
        # Fix aligment!
        self.general_expander.set_use_markup(True)
        self.general_table.set_border_width(5)
        self.general_table.set_row_spacings(6)
        self.general_table.set_col_spacings(6)
        
        try:self.info_start_label.set_text(info['start'])
        except:pass
        
        try:self.info_finished_label.set_text(info['finish'])
        except:pass
        
        try:self.info_hosts_up_label.set_text(info['hosts_up'])
        except:pass
        
        try:self.info_hosts_down_label.set_text(info['hosts_down'])
        except:pass
        
        try:self.info_hosts_scanned_label.set_text(info['hosts_scanned'])
        except:pass
        
        #try:
        self.info_open_label.set_text(info['open_ports'])
        #except:pass
        
        #try:
        self.info_filtered_label.set_text(info['filtered_ports'])
        #except:pass
        
        #try:
        self.info_closed_label.set_text(info['closed_ports'])
        #except:pass
        
        self.general_hbox._pack_noexpand_nofill(hig_box_space_holder())
        self.general_hbox._pack_noexpand_nofill(self.general_table)
        
        self.general_table.attach(self.start_label,0,1,0,1)
        self.general_table.attach(self.info_start_label,1,2,0,1)
        
        self.general_table.attach(self.finished_label,0,1,1,2)
        self.general_table.attach(self.info_finished_label,1,2,1,2)
        
        self.general_table.attach(self.host_up_label,0,1,2,3)
        self.general_table.attach(self.info_hosts_up_label,1,2,2,3)
        
        self.general_table.attach(self.host_down_label,0,1,3,4)
        self.general_table.attach(self.info_hosts_down_label,1,2,3,4)
        
        self.general_table.attach(self.host_scanned_label,0,1,4,5)
        self.general_table.attach(self.info_hosts_scanned_label,1,2,4,5)
        
        self.general_table.attach(self.open_label,0,1,5,6)
        self.general_table.attach(self.info_open_label,1,2,5,6)
        
        self.general_table.attach(self.filtered_label,0,1,6,7)
        self.general_table.attach(self.info_filtered_label,1,2,6,7)
        
        self.general_table.attach(self.closed_label,0,1,7,8)
        self.general_table.attach(self.info_closed_label,1,2,7,8)
        
        self.general_expander.add(self.general_hbox)
        self._pack_noexpand_nofill(self.general_expander)
        self.general_expander.set_expanded(True)

    def set_scan_infos(self, scan_info):
        for scan in scan_info:
            exp = gtk.Expander('<b>%s - %s</b>' % (_('Scan Info'),
                                                   scan['type'].capitalize()))
            exp.set_use_markup(True)
            hbox = HIGHBox()
            table = HIGTable()
            table.set_border_width(5)
            table.set_row_spacings(6)
            table.set_col_spacings(6)
            
            table.attach(HIGEntryLabel(_('Scan type:')),0,1,0,1)
            table.attach(HIGEntryLabel(scan['type']),1,2,0,1)
            
            table.attach(HIGEntryLabel(_('Protocol:')),0,1,1,2)
            table.attach(HIGEntryLabel(scan['protocol']),1,2,1,2)
            
            table.attach(HIGEntryLabel(_('# scanned ports:')),0,1,2,3)
            table.attach(HIGEntryLabel(scan['numservices']),1,2,2,3)
            
            table.attach(HIGEntryLabel(_('Services:')),0,1,3,4)
            table.attach(self.get_service_view(scan['services'].split(',')),\
                                               1,2,3,4)
            
            hbox._pack_noexpand_nofill(hig_box_space_holder())
            hbox._pack_noexpand_nofill(table)
            
            exp.add (hbox)
            self._pack_noexpand_nofill(exp)
    
    def get_service_view(self, services):
        combo = gtk.combo_box_new_text()
        
        for i in services:
            combo.append_text(i)
        
        return combo
class BoxEditable(HIGVBox):
    def __init__(self, section_name, profile, listoptions, notebook_parent, new=False):
        """
        A Box Editable contains a options of each tab
        @param section_name: section name <tab>
        @type section_name: str 
        @param profile: A class that view and modify xml file 
        @type profile: ProfileCore
        @param listoptions: The List of Options to update XML (I guess to confirm)
        @type listoptions: ListOptions
        @param notebook_parent: Notebook
        @type notebook_parent: Notebook or Subclass
        @param new: It's a new tab or not 
        @type new: bool
        """

        HIGVBox.__init__(self)
        self._coords = {}
        self._parent = notebook_parent
        self._last = None 
        #Profile Core do a manage at profile_editor.xml file 
        self._profilecore = None 

        self._profile = profile
        self._listoptions = listoptions
        self._table = HIGTable()
        self._section_name = section_name
        if not new :
            self._options = self._profile.get_section(section_name)
        self._table.set_border_width(3)
        c = self.get_colormap()
        color = c.alloc_color(0,0,0)   
        self._table.modify_fg(gtk.STATE_NORMAL,color )
        #self._fill_table()

        box_tmp = HIGVBox()
        box_tmp.pack_start(self._table, False, False)
        self._sw = HIGScrolledWindow()
        #self._sw.set_size_request(400,200)
        vp = gtk.Viewport()
        vp.add(box_tmp)
        vp.set_shadow_type(gtk.SHADOW_NONE)
        self._sw.add(vp)
        self.pack_start(self._sw, True, True)
        self._old_selected = None 
        self._x = 0
        self._y = 0 


        self.connect('button-press-event', self._bp)
    #Private API 
    def _bp(self, widget,event):
        pass

    def _fill_table(self):
        k = 0
        self._old_po = None
        for i in self._options:
            t = SpecialHBox()
            type = i.get_type()
            if type== 'option_check':

                name_option = i.get_option()
                hint = self._listoptions.get_hint(name_option)
                tmp_widget = OptionCheckIcon(i.get_label(),name_option,hint)
                t.pack_start(tmp_widget)
                arg_type = self._listoptions.get_arg_type(name_option)
                if arg_type!= '':
                    additional = type_mapping[arg_type]()
                    t.pack_start(additional)
                po = ProfileOption('option_check', i.get_label(),name_option, 
                                   arg_type,None)
                po.set_section(self.get_name())
                t.set_profileoption(po)


            elif type == 'option_list': 
                eventbox = gtk.EventBox()
                label = HIGEntryLabel(i.get_label())

                eventbox.add(label)
                tmp_widget = OptionList()
                list = []
                for j in i.get_option_list():
                    d = {}
                    d['name'] = j 
                    tmp_widget.append(d)
                    list.append(j)
                po = ProfileOption('option_list', i.get_label(),i.get_label(), 
                                   None,list)
                po.set_section(self.get_name())
                t.set_profileoption(po)
                t.pack_start(eventbox)		
                t.pack_start(tmp_widget)
                #t.drag_source_set(gtk.gdk.BUTTON1_MASK |
                                                    #gtk.gdk.BUTTON3_MASK,
                                                    #target, 
                                                    #gtk.gdk.ACTION_COPY |
                                                    #gtk.gdk.ACTION_MOVE)
                #t.connect('drag_data_get', self.source_drag_data_get)

            #XXX : I think that is very important ( I only comment to get focus)
            if self._old_po!=None:
                self._old_po.set_next_opt(i.get_label())
            self._old_po = po
            t.set_flags( t.flags() |  gtk.CAN_FOCUS)
            t.connect('button-press-event', self._button_press_event)
            t.connect('key-press-event', self._key_press_event)
            t.set_name(i.get_label())
            t.connect('drag_data_received', self.drag_received)
            t.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
                            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)

            self._table.attach(t, 0,2, k,k+1)
            self._coords[t] = [k, k+1]
            self._x = k 
            self._y = k+1
            k =k +1
            self._last = t 


    def delete_on_item(self, widget):
        if not widget.is_voidplace(): 
            # remove widgets like checkbuttons or others and put voidplace
            childs = widget.get_children()
            cmd = CommandAddRemoveOption(widget,childs,
                                         self._profilecore,self, False)
            widget.set_select(False)
            command_manager.add_command(cmd)
            log.debug(' Remove Widgets like CheckButtons or others and put voidplace')

        else:
            # remove voidplace and delete the widget from table/box
            #XXX 
            cmd = CommandAddRemoveVoidplace(self, 
                                            widget, self._coords, False)
            #widget.unload_voidplace()
            command_manager.add_command(cmd)
            log.debug('Remove voidplace and delete the widget from table')


        self._parent.emit('need-save', 'Sent', None)

    def _key_press_event(self, widget, event):
        _keyval = gtk.gdk.keyval_name(event.keyval)
        if _keyval == "Delete" and self._old_selected!=None :
            self.delete_on_item(widget)


        #self._table.remove(widget)
        #childs = self._table.get_children()
        #for i in childs:
            #if i.is_voidplace():
                #i.do_resize_voidplace()
    def _button_press_event(self,widget, event):

        widget.set_select(True) 
        self._parent.select(False)
        if widget == self._old_selected :
            log.debug('Do nothing')
            if widget.is_voidplace():
                widget.do_draw()
            widget.grab_focus()
            return 
        widget.do_draw()
        if self._old_selected != None:
            self._old_selected.set_select(False)
        log.debug('drawing')
        self._old_selected = widget
        widget.grab_focus()
        self._parent.emit('changed', 'Options', self._parent.get_current_page())
    #Public API 
    def set_name(self, name):
        self._section_name = name 
    def get_name(self):
        return self._section_name

    def get_generic_widget(self, widget, num):
        '''
        Get widget - None Vodplace
        '''
        result = None 
        num  = num 
        x1,y1 = self._coords[widget]
        while True : 
            for i in self._coords:
                x,y = self._coords[i]
                if x == (x1-num) and y == (y1-num):
                    result = i
                    break 
            if result!=None and result.is_voidplace():
                num = num +1 
                result = None 
            else: 
                break 
        return result
    def get_next_widget(self, widget):
        '''
        Get the next widget - None Vodplace
        '''
        if widget == self._last:
            return None 
        return self.get_generic_widget(widget, -1)

    def get_prev_widget(self, widget):
        '''
        Get a Previews widget - None Voidplace 
        '''
        x, y = self._coords[widget]
        if x == 0 and y == 1: 
            return None 
        return self.get_generic_widget(widget, 1)



    def can_move_up(self):

        widget = self._old_selected
        x = 0 
        if widget!= None :
            try:
                x,y = self._coords[widget]
            except KeyError:
                return False
        return x != 0
    def can_move_down(self):

        widget = self._old_selected
        y = len(self._coords)
        if widget!= None :
            try:
                x,y = self._coords[widget]
            except KeyError:
                return 
        return y != (len(self._coords))
    def send_signal_save(self):
        self._parent.emit('need-save', 'Sent', None)
    def send_signal(self):
        self._parent.emit('changed', 'Options', self._parent.get_current_page())
    def create_item(self):
        t = SpecialHBox()
        e = gtk.EventBox()
        label = gtk.Label('-')
        label.set_size_request(-1, 23)
        #e.add(label)
        t.pack_start(label)
        t.set_flags( t.flags() |  gtk.CAN_FOCUS)
        t.connect('button-press-event', self._button_press_event)
        t.connect('key-press-event', self._key_press_event)
        t.connect('drag_data_received', self.drag_received)
        t.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
                        gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
        return t 
    def add_voidplace(self, position):
        # Create SpecialHBox with Voidplace
        t = self.create_item()
        cmd = CommandVoidPlaceAttach(self, t, self._coords, True)
        command_manager.add_command(cmd)
        self._parent.emit('need-save', 'Sent', None)

        #if position == -1 : 
            #x, y = self._x,self._y 
            #self._table.attach()
        #else:
            ## Choose the position 
            #pass

    def move_item_down(self):
        '''
        Move selected item to down
        '''
        assert self.can_move_down()

        cmd = CommandMove(self, self._old_selected, self._coords, self._profilecore, False)
        command_manager.add_command(cmd)
        self.send_signal()
        self.send_signal_save()
    def move_item_up(self):
        '''
        Move selected item to up
        '''
        assert self.can_move_up()

        cmd = CommandMove(self, self._old_selected, self._coords, self._profilecore, True)
        command_manager.add_command(cmd)
        self.send_signal()
        self.send_signal_save()


    def search_option(self, name):
        '''
        returns widget 
        '''
        list = self._table.get_children()
        result = None 
        for i in list : 
            if i.get_name() == name : 
                result = i
                break
        return result

    def set_profile_core(self, profile_core):
        self._profilecore = profile_core

    def option_builder(self, option_name, type):
        '''
        construct a widget with the name of the option
        @return: A widget
        @rtype: Widget like OptionCheck or others 
        '''
        result = []
        hint = self._listoptions.get_hint(option_name)
        #label, option_name, hint
        tmp_widget = OptionCheckIcon(option_name,option_name,hint) 
        result.append(tmp_widget)
        arg_type = self._listoptions.get_arg_type(option_name)
        if arg_type!= '':
            additional = type_mapping[arg_type]()
            result.append(additional)
        return result




    def _is_widget(self, name):
        return name[0:4] == '_wid'
    def _create_option_list(self, widget):
        eventbox = gtk.EventBox()
        name = 'New Option List'
        label = HIGEntryLabel(name)

        eventbox.add(label)
        tmp_widget = OptionList()
        list = []
        void = {'name':''}
        j = 'None'
        d = {}
        d['name'] = j 
        tmp_widget.append(void)
        tmp_widget.append(d)
        list.append(j)
        po = ProfileOption('option_list',name ,None, 
                           None,list)
        po.set_section(self.get_name())
        widget.set_profileoption(po)
        widgets = [] 
        widgets.append(eventbox)
        widgets.append(tmp_widget)
        widget.set_name(name)
        return widgets

    def exec_option_list(self, w):
        widgets = self._create_option_list( w)
        cmd = CommandAddRemoveOption(w,widgets, self._profile,self,
                                     True)
        command_manager.add_command(cmd)

    def exec_checkopt(self, name, w):
        option_name = name
        opt = self._listoptions.get_option_class(name)
        profileoption = option_to_profileoption(opt)
        profileoption.set_section(self.get_name())
        arg_type = self._listoptions.get_arg_type(name)
        widgets = self.option_builder(option_name, arg_type)
        w.set_profileoption(profileoption)
        w.set_name(name)
        cmd = CommandAddRemoveOption(w, widgets, self._profilecore, self,True)
        command_manager.add_command(cmd)






    def drag_received(self,w, context, x, y, data, info, time):
        if not w.is_voidplace(): 
            return 
        option_name = data.data
        if self._is_widget(option_name) :
            if option_name == '_widget_option_list':
                self.exec_option_list(w)
                #widgets = self._create_option_list( w)
                #cmd = CommandAddRemoveOption(w,widgets, self._profile,
                                                #True)
                #command_manager.add_command(cmd)

            return
        name = data.data
        self.exec_checkopt(name, w)

        #Remove child 
        #childs = w.get_children()
        #w.remove(childs[0])
        #Add

        #for child in widgets:
            #t = gtk.Label('fsck')
            #tmp_w.pack_start(child)
            #child.show_all()

        #w.unload_voidplace()


    def get_table(self):
        return self._table
    def set_last(self, last):
        self._last = last
    def get_last(self):
        return self._last
    def source_drag_data_get(self, btn, context, selection_data, info, time):
        selection_data.set(selection_data.target, 8, "I'm Data!")    
class BoxEditable(HIGVBox):
    def __init__(self,
                 section_name,
                 profile,
                 listoptions,
                 notebook_parent,
                 new=False):
        """
        A Box Editable contains a options of each tab
        @param section_name: section name <tab>
        @type section_name: str 
        @param profile: A class that view and modify xml file 
        @type profile: ProfileCore
        @param listoptions: The List of Options to update XML (I guess to confirm)
        @type listoptions: ListOptions
        @param notebook_parent: Notebook
        @type notebook_parent: Notebook or Subclass
        @param new: It's a new tab or not 
        @type new: bool
        """

        HIGVBox.__init__(self)
        self._coords = {}
        self._parent = notebook_parent
        self._last = None
        #Profile Core do a manage at profile_editor.xml file
        self._profilecore = None

        self._profile = profile
        self._listoptions = listoptions
        self._table = HIGTable()
        self._section_name = section_name
        if not new:
            self._options = self._profile.get_section(section_name)
        self._table.set_border_width(3)
        c = self.get_colormap()
        color = c.alloc_color(0, 0, 0)
        self._table.modify_fg(gtk.STATE_NORMAL, color)
        #self._fill_table()

        box_tmp = HIGVBox()
        box_tmp.pack_start(self._table, False, False)
        self._sw = HIGScrolledWindow()
        #self._sw.set_size_request(400,200)
        vp = gtk.Viewport()
        vp.add(box_tmp)
        vp.set_shadow_type(gtk.SHADOW_NONE)
        self._sw.add(vp)
        self.pack_start(self._sw, True, True)
        self._old_selected = None
        self._x = 0
        self._y = 0

        self.connect('button-press-event', self._bp)

    #Private API
    def _bp(self, widget, event):
        pass

    def _fill_table(self):
        k = 0
        self._old_po = None
        for i in self._options:
            t = SpecialHBox()
            type = i.get_type()
            if type == 'option_check':

                name_option = i.get_option()
                hint = self._listoptions.get_hint(name_option)
                tmp_widget = OptionCheckIcon(i.get_label(), name_option, hint)
                t.pack_start(tmp_widget)
                arg_type = self._listoptions.get_arg_type(name_option)
                if arg_type != '':
                    additional = type_mapping[arg_type]()
                    t.pack_start(additional)
                po = ProfileOption('option_check', i.get_label(), name_option,
                                   arg_type, None)
                po.set_section(self.get_name())
                t.set_profileoption(po)

            elif type == 'option_list':
                eventbox = gtk.EventBox()
                label = HIGEntryLabel(i.get_label())

                eventbox.add(label)
                tmp_widget = OptionList()
                list = []
                for j in i.get_option_list():
                    d = {}
                    d['name'] = j
                    tmp_widget.append(d)
                    list.append(j)
                po = ProfileOption('option_list', i.get_label(), i.get_label(),
                                   None, list)
                po.set_section(self.get_name())
                t.set_profileoption(po)
                t.pack_start(eventbox)
                t.pack_start(tmp_widget)
                #t.drag_source_set(gtk.gdk.BUTTON1_MASK |
                #gtk.gdk.BUTTON3_MASK,
                #target,
                #gtk.gdk.ACTION_COPY |
                #gtk.gdk.ACTION_MOVE)
                #t.connect('drag_data_get', self.source_drag_data_get)

            #XXX : I think that is very important ( I only comment to get focus)
            if self._old_po != None:
                self._old_po.set_next_opt(i.get_label())
            self._old_po = po
            t.set_flags(t.flags() | gtk.CAN_FOCUS)
            t.connect('button-press-event', self._button_press_event)
            t.connect('key-press-event', self._key_press_event)
            t.set_name(i.get_label())
            t.connect('drag_data_received', self.drag_received)
            t.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
                            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)

            self._table.attach(t, 0, 2, k, k + 1)
            self._coords[t] = [k, k + 1]
            self._x = k
            self._y = k + 1
            k = k + 1
            self._last = t

    def delete_on_item(self, widget):
        if not widget.is_voidplace():
            # remove widgets like checkbuttons or others and put voidplace
            childs = widget.get_children()
            cmd = CommandAddRemoveOption(widget, childs, self._profilecore,
                                         self, False)
            widget.set_select(False)
            command_manager.add_command(cmd)
            log.debug(
                ' Remove Widgets like CheckButtons or others and put voidplace'
            )

        else:
            # remove voidplace and delete the widget from table/box
            #XXX
            cmd = CommandAddRemoveVoidplace(self, widget, self._coords, False)
            #widget.unload_voidplace()
            command_manager.add_command(cmd)
            log.debug('Remove voidplace and delete the widget from table')

        self._parent.emit('need-save', 'Sent', None)

    def _key_press_event(self, widget, event):
        _keyval = gtk.gdk.keyval_name(event.keyval)
        if _keyval == "Delete" and self._old_selected != None:
            self.delete_on_item(widget)

        #self._table.remove(widget)
        #childs = self._table.get_children()
        #for i in childs:
        #if i.is_voidplace():
        #i.do_resize_voidplace()
    def _button_press_event(self, widget, event):

        widget.set_select(True)
        self._parent.select(False)
        if widget == self._old_selected:
            log.debug('Do nothing')
            if widget.is_voidplace():
                widget.do_draw()
            widget.grab_focus()
            return
        widget.do_draw()
        if self._old_selected != None:
            self._old_selected.set_select(False)
        log.debug('drawing')
        self._old_selected = widget
        widget.grab_focus()
        self._parent.emit('changed', 'Options',
                          self._parent.get_current_page())

    #Public API
    def set_name(self, name):
        self._section_name = name

    def get_name(self):
        return self._section_name

    def get_generic_widget(self, widget, num):
        '''
        Get widget - None Vodplace
        '''
        result = None
        num = num
        x1, y1 = self._coords[widget]
        while True:
            for i in self._coords:
                x, y = self._coords[i]
                if x == (x1 - num) and y == (y1 - num):
                    result = i
                    break
            if result != None and result.is_voidplace():
                num = num + 1
                result = None
            else:
                break
        return result

    def get_next_widget(self, widget):
        '''
        Get the next widget - None Vodplace
        '''
        if widget == self._last:
            return None
        return self.get_generic_widget(widget, -1)

    def get_prev_widget(self, widget):
        '''
        Get a Previews widget - None Voidplace 
        '''
        x, y = self._coords[widget]
        if x == 0 and y == 1:
            return None
        return self.get_generic_widget(widget, 1)

    def can_move_up(self):

        widget = self._old_selected
        x = 0
        if widget != None:
            try:
                x, y = self._coords[widget]
            except KeyError:
                return False
        return x != 0

    def can_move_down(self):

        widget = self._old_selected
        y = len(self._coords)
        if widget != None:
            try:
                x, y = self._coords[widget]
            except KeyError:
                return
        return y != (len(self._coords))

    def send_signal_save(self):
        self._parent.emit('need-save', 'Sent', None)

    def send_signal(self):
        self._parent.emit('changed', 'Options',
                          self._parent.get_current_page())

    def create_item(self):
        t = SpecialHBox()
        e = gtk.EventBox()
        label = gtk.Label('-')
        label.set_size_request(-1, 23)
        #e.add(label)
        t.pack_start(label)
        t.set_flags(t.flags() | gtk.CAN_FOCUS)
        t.connect('button-press-event', self._button_press_event)
        t.connect('key-press-event', self._key_press_event)
        t.connect('drag_data_received', self.drag_received)
        t.drag_dest_set(gtk.DEST_DEFAULT_ALL, target[:-1],
                        gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
        return t

    def add_voidplace(self, position):
        # Create SpecialHBox with Voidplace
        t = self.create_item()
        cmd = CommandVoidPlaceAttach(self, t, self._coords, True)
        command_manager.add_command(cmd)
        self._parent.emit('need-save', 'Sent', None)

        #if position == -1 :
        #x, y = self._x,self._y
        #self._table.attach()
        #else:
        ## Choose the position
        #pass

    def move_item_down(self):
        '''
        Move selected item to down
        '''
        assert self.can_move_down()

        cmd = CommandMove(self, self._old_selected, self._coords,
                          self._profilecore, False)
        command_manager.add_command(cmd)
        self.send_signal()
        self.send_signal_save()

    def move_item_up(self):
        '''
        Move selected item to up
        '''
        assert self.can_move_up()

        cmd = CommandMove(self, self._old_selected, self._coords,
                          self._profilecore, True)
        command_manager.add_command(cmd)
        self.send_signal()
        self.send_signal_save()

    def search_option(self, name):
        '''
        returns widget 
        '''
        list = self._table.get_children()
        result = None
        for i in list:
            if i.get_name() == name:
                result = i
                break
        return result

    def set_profile_core(self, profile_core):
        self._profilecore = profile_core

    def option_builder(self, option_name, type):
        '''
        construct a widget with the name of the option
        @return: A widget
        @rtype: Widget like OptionCheck or others 
        '''
        result = []
        hint = self._listoptions.get_hint(option_name)
        #label, option_name, hint
        tmp_widget = OptionCheckIcon(option_name, option_name, hint)
        result.append(tmp_widget)
        arg_type = self._listoptions.get_arg_type(option_name)
        if arg_type != '':
            additional = type_mapping[arg_type]()
            result.append(additional)
        return result

    def _is_widget(self, name):
        return name[0:4] == '_wid'

    def _create_option_list(self, widget):
        eventbox = gtk.EventBox()
        name = 'New Option List'
        label = HIGEntryLabel(name)

        eventbox.add(label)
        tmp_widget = OptionList()
        list = []
        void = {'name': ''}
        j = 'None'
        d = {}
        d['name'] = j
        tmp_widget.append(void)
        tmp_widget.append(d)
        list.append(j)
        po = ProfileOption('option_list', name, None, None, list)
        po.set_section(self.get_name())
        widget.set_profileoption(po)
        widgets = []
        widgets.append(eventbox)
        widgets.append(tmp_widget)
        widget.set_name(name)
        return widgets

    def exec_option_list(self, w):
        widgets = self._create_option_list(w)
        cmd = CommandAddRemoveOption(w, widgets, self._profile, self, True)
        command_manager.add_command(cmd)

    def exec_checkopt(self, name, w):
        option_name = name
        opt = self._listoptions.get_option_class(name)
        profileoption = option_to_profileoption(opt)
        profileoption.set_section(self.get_name())
        arg_type = self._listoptions.get_arg_type(name)
        widgets = self.option_builder(option_name, arg_type)
        w.set_profileoption(profileoption)
        w.set_name(name)
        cmd = CommandAddRemoveOption(w, widgets, self._profilecore, self, True)
        command_manager.add_command(cmd)

    def drag_received(self, w, context, x, y, data, info, time):
        if not w.is_voidplace():
            return
        option_name = data.data
        if self._is_widget(option_name):
            if option_name == '_widget_option_list':
                self.exec_option_list(w)
                #widgets = self._create_option_list( w)
                #cmd = CommandAddRemoveOption(w,widgets, self._profile,
                #True)
                #command_manager.add_command(cmd)

            return
        name = data.data
        self.exec_checkopt(name, w)

        #Remove child
        #childs = w.get_children()
        #w.remove(childs[0])
        #Add

        #for child in widgets:
        #t = gtk.Label('fsck')
        #tmp_w.pack_start(child)
        #child.show_all()

        #w.unload_voidplace()

    def get_table(self):
        return self._table

    def set_last(self, last):
        self._last = last

    def get_last(self):
        return self._last

    def source_drag_data_get(self, btn, context, selection_data, info, time):
        selection_data.set(selection_data.target, 8, "I'm Data!")