18 |
18 |
19 class CooperationPage(ConfigurationPageBase, Ui_CooperationPage): |
19 class CooperationPage(ConfigurationPageBase, Ui_CooperationPage): |
20 """ |
20 """ |
21 Class implementing the Cooperation configuration page. |
21 Class implementing the Cooperation configuration page. |
22 """ |
22 """ |
|
23 |
23 def __init__(self): |
24 def __init__(self): |
24 """ |
25 """ |
25 Constructor |
26 Constructor |
26 """ |
27 """ |
27 super().__init__() |
28 super().__init__() |
28 self.setupUi(self) |
29 self.setupUi(self) |
29 self.setObjectName("CooperationPage") |
30 self.setObjectName("CooperationPage") |
30 |
31 |
31 self.__bannedUserValidator = QRegularExpressionValidator( |
32 self.__bannedUserValidator = QRegularExpressionValidator( |
32 QRegularExpression( |
33 QRegularExpression( |
33 r"[a-zA-Z0-9.-]+@" |
34 r"[a-zA-Z0-9.-]+@" |
34 r"(?:(?:2(?:[0-4][0-9]|5[0-5])|[01]?[0-9]{1,2})\.){3}" |
35 r"(?:(?:2(?:[0-4][0-9]|5[0-5])|[01]?[0-9]{1,2})\.){3}" |
35 r"(?:2(?:[0-4][0-9]|5[0-5])|[01]?[0-9]{1,2})"), |
36 r"(?:2(?:[0-4][0-9]|5[0-5])|[01]?[0-9]{1,2})" |
36 self.bannedUserEdit) |
37 ), |
|
38 self.bannedUserEdit, |
|
39 ) |
37 self.bannedUserEdit.setValidator(self.__bannedUserValidator) |
40 self.bannedUserEdit.setValidator(self.__bannedUserValidator) |
38 |
41 |
39 # set initial values |
42 # set initial values |
40 self.autostartCheckBox.setChecked( |
43 self.autostartCheckBox.setChecked(Preferences.getCooperation("AutoStartServer")) |
41 Preferences.getCooperation("AutoStartServer")) |
44 self.otherPortsCheckBox.setChecked(Preferences.getCooperation("TryOtherPorts")) |
42 self.otherPortsCheckBox.setChecked( |
45 self.serverPortSpin.setValue(Preferences.getCooperation("ServerPort")) |
43 Preferences.getCooperation("TryOtherPorts")) |
46 self.portToTrySpin.setValue(Preferences.getCooperation("MaxPortsToTry")) |
44 self.serverPortSpin.setValue( |
|
45 Preferences.getCooperation("ServerPort")) |
|
46 self.portToTrySpin.setValue( |
|
47 Preferences.getCooperation("MaxPortsToTry")) |
|
48 self.autoAcceptCheckBox.setChecked( |
47 self.autoAcceptCheckBox.setChecked( |
49 Preferences.getCooperation("AutoAcceptConnections")) |
48 Preferences.getCooperation("AutoAcceptConnections") |
50 |
49 ) |
51 self.bannedUsersList.addItems(sorted( |
50 |
52 Preferences.getCooperation("BannedUsers"))) |
51 self.bannedUsersList.addItems(sorted(Preferences.getCooperation("BannedUsers"))) |
53 |
52 |
54 def save(self): |
53 def save(self): |
55 """ |
54 """ |
56 Public slot to save the Cooperation configuration. |
55 Public slot to save the Cooperation configuration. |
57 """ |
56 """ |
58 Preferences.setCooperation( |
57 Preferences.setCooperation( |
59 "AutoStartServer", |
58 "AutoStartServer", self.autostartCheckBox.isChecked() |
60 self.autostartCheckBox.isChecked()) |
59 ) |
|
60 Preferences.setCooperation("TryOtherPorts", self.otherPortsCheckBox.isChecked()) |
61 Preferences.setCooperation( |
61 Preferences.setCooperation( |
62 "TryOtherPorts", |
62 "AutoAcceptConnections", self.autoAcceptCheckBox.isChecked() |
63 self.otherPortsCheckBox.isChecked()) |
63 ) |
64 Preferences.setCooperation( |
64 Preferences.setCooperation("ServerPort", self.serverPortSpin.value()) |
65 "AutoAcceptConnections", |
65 Preferences.setCooperation("MaxPortsToTry", self.portToTrySpin.value()) |
66 self.autoAcceptCheckBox.isChecked()) |
66 |
67 Preferences.setCooperation( |
|
68 "ServerPort", |
|
69 self.serverPortSpin.value()) |
|
70 Preferences.setCooperation( |
|
71 "MaxPortsToTry", |
|
72 self.portToTrySpin.value()) |
|
73 |
|
74 bannedUsers = [] |
67 bannedUsers = [] |
75 for row in range(self.bannedUsersList.count()): |
68 for row in range(self.bannedUsersList.count()): |
76 bannedUsers.append(self.bannedUsersList.item(row).text()) |
69 bannedUsers.append(self.bannedUsersList.item(row).text()) |
77 Preferences.setCooperation("BannedUsers", bannedUsers) |
70 Preferences.setCooperation("BannedUsers", bannedUsers) |
78 |
71 |
79 @pyqtSlot() |
72 @pyqtSlot() |
80 def on_bannedUsersList_itemSelectionChanged(self): |
73 def on_bannedUsersList_itemSelectionChanged(self): |
81 """ |
74 """ |
82 Private slot to react on changes of selected banned users. |
75 Private slot to react on changes of selected banned users. |
83 """ |
76 """ |
84 self.deleteBannedUsersButton.setEnabled( |
77 self.deleteBannedUsersButton.setEnabled( |
85 len(self.bannedUsersList.selectedItems()) > 0) |
78 len(self.bannedUsersList.selectedItems()) > 0 |
86 |
79 ) |
|
80 |
87 @pyqtSlot(str) |
81 @pyqtSlot(str) |
88 def on_bannedUserEdit_textChanged(self, txt): |
82 def on_bannedUserEdit_textChanged(self, txt): |
89 """ |
83 """ |
90 Private slot to handle the user entering a banned user. |
84 Private slot to handle the user entering a banned user. |
91 |
85 |
92 @param txt text entered by the user (string) |
86 @param txt text entered by the user (string) |
93 """ |
87 """ |
94 self.addBannedUserButton.setEnabled( |
88 self.addBannedUserButton.setEnabled( |
95 self.__bannedUserValidator.validate(txt, len(txt))[0] == |
89 self.__bannedUserValidator.validate(txt, len(txt))[0] |
96 QValidator.State.Acceptable) |
90 == QValidator.State.Acceptable |
97 |
91 ) |
|
92 |
98 @pyqtSlot() |
93 @pyqtSlot() |
99 def on_deleteBannedUsersButton_clicked(self): |
94 def on_deleteBannedUsersButton_clicked(self): |
100 """ |
95 """ |
101 Private slot to remove the selected users from the list of |
96 Private slot to remove the selected users from the list of |
102 banned users. |
97 banned users. |
103 """ |
98 """ |
104 for itm in self.bannedUsersList.selectedItems(): |
99 for itm in self.bannedUsersList.selectedItems(): |
105 row = self.bannedUsersList.row(itm) |
100 row = self.bannedUsersList.row(itm) |
106 itm = self.bannedUsersList.takeItem(row) |
101 itm = self.bannedUsersList.takeItem(row) |
107 del itm |
102 del itm |
108 |
103 |
109 @pyqtSlot() |
104 @pyqtSlot() |
110 def on_addBannedUserButton_clicked(self): |
105 def on_addBannedUserButton_clicked(self): |
111 """ |
106 """ |
112 Private slot to add a user to the list of banned users. |
107 Private slot to add a user to the list of banned users. |
113 """ |
108 """ |
114 self.bannedUsersList.addItem(self.bannedUserEdit.text()) |
109 self.bannedUsersList.addItem(self.bannedUserEdit.text()) |
115 self.bannedUserEdit.clear() |
110 self.bannedUserEdit.clear() |
116 |
111 |
117 |
112 |
118 def create(dlg): |
113 def create(dlg): |
119 """ |
114 """ |
120 Module function to create the configuration page. |
115 Module function to create the configuration page. |
121 |
116 |
122 @param dlg reference to the configuration dialog |
117 @param dlg reference to the configuration dialog |
123 @return reference to the instantiated page (ConfigurationPageBase) |
118 @return reference to the instantiated page (ConfigurationPageBase) |
124 """ |
119 """ |
125 page = CooperationPage() |
120 page = CooperationPage() |
126 return page |
121 return page |