diff -r b395b006d2a8 -r 3302a726fd1e Preferences/ConfigurationPages/CooperationPage.py --- a/Preferences/ConfigurationPages/CooperationPage.py Wed Mar 31 12:52:59 2010 +0000 +++ b/Preferences/ConfigurationPages/CooperationPage.py Wed Mar 31 17:11:28 2010 +0000 @@ -7,6 +7,9 @@ Module implementing the Cooperation configuration page. """ +from PyQt4.QtCore import pyqtSlot, QRegExp +from PyQt4.QtGui import QRegExpValidator, QValidator + from .ConfigurationPageBase import ConfigurationPageBase from .Ui_CooperationPage import Ui_CooperationPage @@ -24,6 +27,13 @@ self.setupUi(self) self.setObjectName("CooperationPage") + self.__bannedUserValidator = QRegExpValidator( + QRegExp("[a-zA-Z0-9.-]+@" + "(?:(?:2(?:[0-4][0-9]|5[0-5])|[01]?[0-9]{1,2})\.){3}" + "(?:2(?:[0-4][0-9]|5[0-5])|[01]?[0-9]{1,2})"), + self.bannedUserEdit) + self.bannedUserEdit.setValidator(self.__bannedUserValidator) + # set initial values self.autostartCheckBox.setChecked( Preferences.getCooperation("AutoStartServer")) @@ -35,6 +45,9 @@ Preferences.getCooperation("MaxPortsToTry")) self.autoAcceptCheckBox.setChecked( Preferences.getCooperation("AutoAcceptConnections")) + + self.bannedUsersList.addItems(list(sorted( + Preferences.getCooperation("BannedUsers")))) def save(self): """ @@ -50,6 +63,49 @@ self.serverPortSpin.value()) Preferences.setCooperation("MaxPortsToTry", self.portToTrySpin.value()) + + bannedUsers = [] + for row in range(self.bannedUsersList.count()): + bannedUsers.append(self.bannedUsersList.item(row).text()) + Preferences.setCooperation("BannedUsers", bannedUsers) + + @pyqtSlot() + def on_bannedUsersList_itemSelectionChanged(self): + """ + Private slot to react on changes of selected banned users. + """ + self.deleteBannedUsersButton.setEnabled( + len(self.bannedUsersList.selectedItems()) > 0) + + @pyqtSlot(str) + def on_bannedUserEdit_textChanged(self, txt): + """ + Private slot to handle the user entering a banned user. + + @param txt text entered by the user (string) + """ + self.addBannedUserButton.setEnabled( + self.__bannedUserValidator.validate(txt, len(txt))[0] == \ + QValidator.Acceptable) + + @pyqtSlot() + def on_deleteBannedUsersButton_clicked(self): + """ + Private slot to remove the selected users from the list of + banned users. + """ + for itm in self.bannedUsersList.selectedItems(): + row = self.bannedUsersList.row(itm) + itm = self.bannedUsersList.takeItem(row) + del itm + + @pyqtSlot() + def on_addBannedUserButton_clicked(self): + """ + Private slot to add a user to the list of banned users. + """ + self.bannedUsersList.addItem(self.bannedUserEdit.text()) + self.bannedUserEdit.clear() def create(dlg): """