21 |
21 |
22 class IrcNetworkEditDialog(QDialog, Ui_IrcNetworkEditDialog): |
22 class IrcNetworkEditDialog(QDialog, Ui_IrcNetworkEditDialog): |
23 """ |
23 """ |
24 Class implementing a dialog for editing IRC network definitions. |
24 Class implementing a dialog for editing IRC network definitions. |
25 """ |
25 """ |
|
26 |
26 def __init__(self, manager, networkName, parent=None): |
27 def __init__(self, manager, networkName, parent=None): |
27 """ |
28 """ |
28 Constructor |
29 Constructor |
29 |
30 |
30 @param manager reference to the IRC network manager object |
31 @param manager reference to the IRC network manager object |
31 (IrcNetworkManager) |
32 (IrcNetworkManager) |
32 @param networkName name of the network to work on (string) |
33 @param networkName name of the network to work on (string) |
33 @param parent reference to the parent widget (QWidget) |
34 @param parent reference to the parent widget (QWidget) |
34 """ |
35 """ |
35 super().__init__(parent) |
36 super().__init__(parent) |
36 self.setupUi(self) |
37 self.setupUi(self) |
37 |
38 |
38 self.__manager = manager |
39 self.__manager = manager |
39 |
40 |
40 self.editIdentitiesButton.setIcon( |
41 self.editIdentitiesButton.setIcon(UI.PixmapCache.getIcon("ircConfigure")) |
41 UI.PixmapCache.getIcon("ircConfigure")) |
42 self.editServerButton.setIcon(UI.PixmapCache.getIcon("ircConfigure")) |
42 self.editServerButton.setIcon( |
43 self.editChannelButton.setIcon(UI.PixmapCache.getIcon("ircConfigure")) |
43 UI.PixmapCache.getIcon("ircConfigure")) |
|
44 self.editChannelButton.setIcon( |
|
45 UI.PixmapCache.getIcon("ircConfigure")) |
|
46 self.addChannelButton.setIcon(UI.PixmapCache.getIcon("plus")) |
44 self.addChannelButton.setIcon(UI.PixmapCache.getIcon("plus")) |
47 self.deleteChannelButton.setIcon(UI.PixmapCache.getIcon("minus")) |
45 self.deleteChannelButton.setIcon(UI.PixmapCache.getIcon("minus")) |
48 |
46 |
49 self.__okButton = self.buttonBox.button( |
47 self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok) |
50 QDialogButtonBox.StandardButton.Ok) |
48 |
51 |
|
52 if networkName: |
49 if networkName: |
53 self.__network = copy.deepcopy( |
50 self.__network = copy.deepcopy(self.__manager.getNetwork(networkName)) |
54 self.__manager.getNetwork(networkName)) |
|
55 else: |
51 else: |
56 from .IrcNetworkManager import IrcNetwork |
52 from .IrcNetworkManager import IrcNetwork |
|
53 |
57 self.__network = IrcNetwork("") |
54 self.__network = IrcNetwork("") |
58 |
55 |
59 # network name |
56 # network name |
60 self.networkEdit.setText(networkName) |
57 self.networkEdit.setText(networkName) |
61 |
58 |
62 # identities |
59 # identities |
63 self.__refreshIdentityCombo(self.__network.getIdentityName()) |
60 self.__refreshIdentityCombo(self.__network.getIdentityName()) |
64 |
61 |
65 # server |
62 # server |
66 self.serverEdit.setText(self.__network.getServerName()) |
63 self.serverEdit.setText(self.__network.getServerName()) |
67 |
64 |
68 # channels |
65 # channels |
69 for channelName in sorted(self.__network.getChannelNames()): |
66 for channelName in sorted(self.__network.getChannelNames()): |
70 channel = self.__network.getChannel(channelName) |
67 channel = self.__network.getChannel(channelName) |
71 autoJoin = self.tr("Yes") if channel.autoJoin() else self.tr("No") |
68 autoJoin = self.tr("Yes") if channel.autoJoin() else self.tr("No") |
72 QTreeWidgetItem(self.channelList, [channelName, autoJoin]) |
69 QTreeWidgetItem(self.channelList, [channelName, autoJoin]) |
73 |
70 |
74 self.__updateOkButton() |
71 self.__updateOkButton() |
75 self.on_channelList_itemSelectionChanged() |
72 self.on_channelList_itemSelectionChanged() |
76 |
73 |
77 def __updateOkButton(self): |
74 def __updateOkButton(self): |
78 """ |
75 """ |
79 Private method to update the OK button state. |
76 Private method to update the OK button state. |
80 """ |
77 """ |
81 enable = True |
78 enable = True |
82 enable &= self.networkEdit.text() != "" |
79 enable &= self.networkEdit.text() != "" |
83 enable &= self.serverEdit.text() != "" |
80 enable &= self.serverEdit.text() != "" |
84 |
81 |
85 self.__okButton.setEnabled(enable) |
82 self.__okButton.setEnabled(enable) |
86 |
83 |
87 @pyqtSlot(str) |
84 @pyqtSlot(str) |
88 def on_networkEdit_textChanged(self, txt): |
85 def on_networkEdit_textChanged(self, txt): |
89 """ |
86 """ |
90 Private slot to handle changes of the network name. |
87 Private slot to handle changes of the network name. |
91 |
88 |
92 @param txt text entered into the network name edit (string) |
89 @param txt text entered into the network name edit (string) |
93 """ |
90 """ |
94 self.__updateOkButton() |
91 self.__updateOkButton() |
95 |
92 |
96 def __refreshIdentityCombo(self, currentIdentity): |
93 def __refreshIdentityCombo(self, currentIdentity): |
97 """ |
94 """ |
98 Private method to refresh the identity combo. |
95 Private method to refresh the identity combo. |
99 |
96 |
100 @param currentIdentity name of the identity to select (string) |
97 @param currentIdentity name of the identity to select (string) |
101 """ |
98 """ |
102 self.identityCombo.clear() |
99 self.identityCombo.clear() |
103 |
100 |
104 from .IrcNetworkManager import IrcIdentity |
101 from .IrcNetworkManager import IrcIdentity |
|
102 |
105 identities = sorted(self.__manager.getIdentityNames()) |
103 identities = sorted(self.__manager.getIdentityNames()) |
106 identities[identities.index(IrcIdentity.DefaultIdentityName)] = ( |
104 identities[ |
107 IrcIdentity.DefaultIdentityDisplay |
105 identities.index(IrcIdentity.DefaultIdentityName) |
108 ) |
106 ] = IrcIdentity.DefaultIdentityDisplay |
109 self.identityCombo.addItems(identities) |
107 self.identityCombo.addItems(identities) |
110 if currentIdentity == IrcIdentity.DefaultIdentityName: |
108 if currentIdentity == IrcIdentity.DefaultIdentityName: |
111 currentIdentity = IrcIdentity.DefaultIdentityDisplay |
109 currentIdentity = IrcIdentity.DefaultIdentityDisplay |
112 index = self.identityCombo.findText(currentIdentity) |
110 index = self.identityCombo.findText(currentIdentity) |
113 if index == -1: |
111 if index == -1: |
114 index = 0 |
112 index = 0 |
115 self.identityCombo.setCurrentIndex(index) |
113 self.identityCombo.setCurrentIndex(index) |
116 |
114 |
117 @pyqtSlot(str) |
115 @pyqtSlot(str) |
118 def on_identityCombo_currentTextChanged(self, identity): |
116 def on_identityCombo_currentTextChanged(self, identity): |
119 """ |
117 """ |
120 Private slot to handle the selection of an identity. |
118 Private slot to handle the selection of an identity. |
121 |
119 |
122 @param identity selected identity |
120 @param identity selected identity |
123 @type str |
121 @type str |
124 """ |
122 """ |
125 from .IrcNetworkManager import IrcIdentity |
123 from .IrcNetworkManager import IrcIdentity |
126 |
124 |
127 if identity == IrcIdentity.DefaultIdentityDisplay: |
125 if identity == IrcIdentity.DefaultIdentityDisplay: |
128 identity = IrcIdentity.DefaultIdentityName |
126 identity = IrcIdentity.DefaultIdentityName |
129 self.__network.setIdentityName(identity) |
127 self.__network.setIdentityName(identity) |
130 |
128 |
131 @pyqtSlot() |
129 @pyqtSlot() |
132 def on_editIdentitiesButton_clicked(self): |
130 def on_editIdentitiesButton_clicked(self): |
133 """ |
131 """ |
134 Private slot to edit the identities. |
132 Private slot to edit the identities. |
135 """ |
133 """ |
136 from .IrcIdentitiesEditDialog import IrcIdentitiesEditDialog |
134 from .IrcIdentitiesEditDialog import IrcIdentitiesEditDialog |
|
135 |
137 currentIdentity = self.identityCombo.currentText() |
136 currentIdentity = self.identityCombo.currentText() |
138 dlg = IrcIdentitiesEditDialog(self.__manager, currentIdentity, self) |
137 dlg = IrcIdentitiesEditDialog(self.__manager, currentIdentity, self) |
139 dlg.exec() |
138 dlg.exec() |
140 self.__refreshIdentityCombo(currentIdentity) |
139 self.__refreshIdentityCombo(currentIdentity) |
141 |
140 |
142 @pyqtSlot(str) |
141 @pyqtSlot(str) |
143 def on_serverEdit_textChanged(self, txt): |
142 def on_serverEdit_textChanged(self, txt): |
144 """ |
143 """ |
145 Private slot to handle changes of the server name. |
144 Private slot to handle changes of the server name. |
146 |
145 |
147 @param txt text entered into the server name edit (string) |
146 @param txt text entered into the server name edit (string) |
148 """ |
147 """ |
149 self.__updateOkButton() |
148 self.__updateOkButton() |
150 |
149 |
151 @pyqtSlot() |
150 @pyqtSlot() |
152 def on_editServerButton_clicked(self): |
151 def on_editServerButton_clicked(self): |
153 """ |
152 """ |
154 Private slot to edit the server configuration. |
153 Private slot to edit the server configuration. |
155 """ |
154 """ |
156 from .IrcServerEditDialog import IrcServerEditDialog |
155 from .IrcServerEditDialog import IrcServerEditDialog |
|
156 |
157 dlg = IrcServerEditDialog(self.__network.getServer()) |
157 dlg = IrcServerEditDialog(self.__network.getServer()) |
158 if dlg.exec() == QDialog.DialogCode.Accepted: |
158 if dlg.exec() == QDialog.DialogCode.Accepted: |
159 self.__network.setServer(dlg.getServer()) |
159 self.__network.setServer(dlg.getServer()) |
160 self.serverEdit.setText(self.__network.getServerName()) |
160 self.serverEdit.setText(self.__network.getServerName()) |
161 |
161 |
162 @pyqtSlot() |
162 @pyqtSlot() |
163 def on_addChannelButton_clicked(self): |
163 def on_addChannelButton_clicked(self): |
164 """ |
164 """ |
165 Private slot to add a channel. |
165 Private slot to add a channel. |
166 """ |
166 """ |
167 self.__editChannel(None) |
167 self.__editChannel(None) |
168 |
168 |
169 @pyqtSlot() |
169 @pyqtSlot() |
170 def on_editChannelButton_clicked(self): |
170 def on_editChannelButton_clicked(self): |
171 """ |
171 """ |
172 Private slot to edit the selected channel. |
172 Private slot to edit the selected channel. |
173 """ |
173 """ |
174 itm = self.channelList.selectedItems()[0] |
174 itm = self.channelList.selectedItems()[0] |
175 if itm: |
175 if itm: |
176 self.__editChannel(itm) |
176 self.__editChannel(itm) |
177 |
177 |
178 @pyqtSlot() |
178 @pyqtSlot() |
179 def on_deleteChannelButton_clicked(self): |
179 def on_deleteChannelButton_clicked(self): |
180 """ |
180 """ |
181 Private slot to delete the selected channel. |
181 Private slot to delete the selected channel. |
182 """ |
182 """ |
183 itm = self.channelList.selectedItems()[0] |
183 itm = self.channelList.selectedItems()[0] |
184 if itm: |
184 if itm: |
185 res = EricMessageBox.yesNo( |
185 res = EricMessageBox.yesNo( |
186 self, |
186 self, |
187 self.tr("Delete Channel"), |
187 self.tr("Delete Channel"), |
188 self.tr( |
188 self.tr("""Do you really want to delete channel <b>{0}</b>?""").format( |
189 """Do you really want to delete channel <b>{0}</b>?""") |
189 itm.text(0) |
190 .format(itm.text(0))) |
190 ), |
|
191 ) |
191 if res: |
192 if res: |
192 self.__network.deleteChannel(itm.text(0)) |
193 self.__network.deleteChannel(itm.text(0)) |
193 |
194 |
194 index = self.channelList.indexOfTopLevelItem(itm) |
195 index = self.channelList.indexOfTopLevelItem(itm) |
195 self.channelList.takeTopLevelItem(index) |
196 self.channelList.takeTopLevelItem(index) |
196 del itm |
197 del itm |
197 |
198 |
198 @pyqtSlot(QTreeWidgetItem, int) |
199 @pyqtSlot(QTreeWidgetItem, int) |
199 def on_channelList_itemActivated(self, item, column): |
200 def on_channelList_itemActivated(self, item, column): |
200 """ |
201 """ |
201 Private slot to handle the activation of a channel entry. |
202 Private slot to handle the activation of a channel entry. |
202 |
203 |
203 @param item reference to the activated item (QTreeWidgetItem) |
204 @param item reference to the activated item (QTreeWidgetItem) |
204 @param column column the activation occurred in (integer) |
205 @param column column the activation occurred in (integer) |
205 """ |
206 """ |
206 self.__editChannel(item) |
207 self.__editChannel(item) |
207 |
208 |
208 @pyqtSlot() |
209 @pyqtSlot() |
209 def on_channelList_itemSelectionChanged(self): |
210 def on_channelList_itemSelectionChanged(self): |
210 """ |
211 """ |
211 Private slot to handle changes of the selection of channels. |
212 Private slot to handle changes of the selection of channels. |
212 """ |
213 """ |
213 selectedItems = self.channelList.selectedItems() |
214 selectedItems = self.channelList.selectedItems() |
214 enable = bool(selectedItems) |
215 enable = bool(selectedItems) |
215 self.editChannelButton.setEnabled(enable) |
216 self.editChannelButton.setEnabled(enable) |
216 self.deleteChannelButton.setEnabled(enable) |
217 self.deleteChannelButton.setEnabled(enable) |
217 |
218 |
218 def __editChannel(self, itm): |
219 def __editChannel(self, itm): |
219 """ |
220 """ |
220 Private method to edit a channel. |
221 Private method to edit a channel. |
221 |
222 |
222 @param itm reference to the item to be edited (QTreeWidgetItem) |
223 @param itm reference to the item to be edited (QTreeWidgetItem) |
223 """ |
224 """ |
224 if itm: |
225 if itm: |
225 channel = self.__network.getChannel(itm.text(0)) |
226 channel = self.__network.getChannel(itm.text(0)) |
226 name = channel.getName() |
227 name = channel.getName() |