def readServers(self): ''' Read the server config file @return: Server config parser ''' servers = [] for server_listing in constants.SERVER_LISTING_LOCATIONS: try: file, headers = urllib.urlretrieve(server_listing) retrieve_fail=False except: pass #self.error(util.ErrorMessage(_("Could not read server listing. Please try another time."))) #return None parser = ConfigParser.ConfigParser() parser.read(file) for server in parser.sections(): servers.append( (server, parser.get(server, "g_port"), parser.get(server, "w_port"), parser.get(server, "location")) ) servers.extend( util.getAdditionalHosts() ) return servers
def setHost(self, button, host, gport, wport, location, dialog, view): ''' Set host info @param button: @param host: @param gport: @param wport: @param location: @param dialog: @param view ''' try: int(gport.get_text()) int(gport.get_text()) except: self.error(util.ErrorMessage(_('Port must be a number'))) return dialog.destroy() o = manager.OptionManager(section=HOSTS_SECTION) data = o.get_default_option(OPTION_HOSTS, '') data = '%s%s:%s:%s:%s/' % (data, host.get_text(), gport.get_text(), wport.get_text(), location.get_text()) o.set_option(OPTION_HOSTS, data) model = view.get_model() model.clear() for host, gport, wport, location in util.getAdditionalHosts(): model.append((host, location))
def setHost(self, button, host, gport, wport, location, dialog, view): ''' Set host info @param button: @param host: @param gport: @param wport: @param location: @param dialog: @param view ''' try: int(gport.get_text()) int(gport.get_text()) except: self.error(util.ErrorMessage(_('Port must be a number'))) return dialog.destroy() o = manager.OptionManager(section=HOSTS_SECTION) data = o.get_default_option(OPTION_HOSTS, '') data = '%s%s:%s:%s:%s/' % (data, host.get_text(), gport.get_text(), wport.get_text(), location.get_text()) o.set_option(OPTION_HOSTS, data) model = view.get_model() model.clear() for host,gport,wport,location in util.getAdditionalHosts(): model.append( (host,location) )
def getAdditionalHosts(self): ''' Return additional hosts frame for the connection prefs ''' hostbox = gtk.VBox(False, 3) frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_OUT) optionsList = gtk.ListStore(str, str) optionsView = gtk.TreeView(optionsList) optionsView.set_headers_visible(False) col1 = gtk.TreeViewColumn(_('Name')) cell1 = gtk.CellRendererText() col1.pack_start(cell1, True) col1.add_attribute(cell1, 'text', 0) optionsView.append_column(col1) col2 = gtk.TreeViewColumn(_('Location')) cell2 = gtk.CellRendererText() col2.pack_start(cell2, True) col2.add_attribute(cell2, 'text', 1) optionsView.append_column(col2) for host, gport, wport, location in util.getAdditionalHosts(): optionsList.append((host, location)) frame.add(optionsView) hostbuttonbox = gtk.HButtonBox() button = gtk.Button(_('Add')) button.connect("clicked", self.addHost_cb, optionsList, optionsView) hostbuttonbox.add(button) button = gtk.Button(_('Remove')) button.connect("clicked", self.deleteHost_cb, optionsView) hostbuttonbox.add(button) hostbox.pack_start( gtkutil.createLeftJustifiedLabel(_('Additional Hosts')), False, False, 0) hostbox.pack_start(frame, False, False, 0) hostbox.pack_start(hostbuttonbox, False, False, 0) return hostbox
def getAdditionalHosts(self): ''' Return additional hosts frame for the connection prefs ''' hostbox = gtk.VBox(False, 3) frame = gtk.Frame() frame.set_shadow_type( gtk.SHADOW_OUT ) optionsList = gtk.ListStore(str,str) optionsView = gtk.TreeView( optionsList ) optionsView.set_headers_visible( False ) col1 = gtk.TreeViewColumn(_('Name')) cell1 = gtk.CellRendererText() col1.pack_start(cell1, True) col1.add_attribute(cell1, 'text', 0) optionsView.append_column( col1 ) col2 = gtk.TreeViewColumn(_('Location')) cell2 = gtk.CellRendererText() col2.pack_start(cell2, True) col2.add_attribute(cell2, 'text', 1) optionsView.append_column( col2 ) for host,gport,wport,location in util.getAdditionalHosts(): optionsList.append( (host,location) ) frame.add( optionsView ) hostbuttonbox = gtk.HButtonBox() button = gtk.Button( _('Add') ) button.connect("clicked", self.addHost_cb, optionsList, optionsView) hostbuttonbox.add( button ) button = gtk.Button( _('Remove') ) button.connect("clicked", self.deleteHost_cb, optionsView) hostbuttonbox.add( button ) hostbox.pack_start( gtkutil.createLeftJustifiedLabel(_('Additional Hosts')), False, False, 0) hostbox.pack_start(frame, False, False, 0) hostbox.pack_start(hostbuttonbox, False, False, 0) return hostbox