eric7/Network/IRC/IrcNetworkEditDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8234
fcb6b4b96274
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog for editing IRC network definitions.
8 """
9
10 import copy
11
12 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem
14
15 from E5Gui import E5MessageBox
16
17 from .Ui_IrcNetworkEditDialog import Ui_IrcNetworkEditDialog
18
19 import UI.PixmapCache
20
21
22 class IrcNetworkEditDialog(QDialog, Ui_IrcNetworkEditDialog):
23 """
24 Class implementing a dialog for editing IRC network definitions.
25 """
26 def __init__(self, manager, networkName, parent=None):
27 """
28 Constructor
29
30 @param manager reference to the IRC network manager object
31 (IrcNetworkManager)
32 @param networkName name of the network to work on (string)
33 @param parent reference to the parent widget (QWidget)
34 """
35 super().__init__(parent)
36 self.setupUi(self)
37
38 self.__manager = manager
39
40 self.editIdentitiesButton.setIcon(
41 UI.PixmapCache.getIcon("ircConfigure"))
42 self.editServerButton.setIcon(
43 UI.PixmapCache.getIcon("ircConfigure"))
44 self.editChannelButton.setIcon(
45 UI.PixmapCache.getIcon("ircConfigure"))
46 self.addChannelButton.setIcon(UI.PixmapCache.getIcon("plus"))
47 self.deleteChannelButton.setIcon(UI.PixmapCache.getIcon("minus"))
48
49 self.__okButton = self.buttonBox.button(
50 QDialogButtonBox.StandardButton.Ok)
51
52 if networkName:
53 self.__network = copy.deepcopy(
54 self.__manager.getNetwork(networkName))
55 else:
56 from .IrcNetworkManager import IrcNetwork
57 self.__network = IrcNetwork("")
58
59 # network name
60 self.networkEdit.setText(networkName)
61
62 # identities
63 self.__refreshIdentityCombo(self.__network.getIdentityName())
64
65 # server
66 self.serverEdit.setText(self.__network.getServerName())
67
68 # channels
69 for channelName in sorted(self.__network.getChannelNames()):
70 channel = self.__network.getChannel(channelName)
71 autoJoin = self.tr("Yes") if channel.autoJoin() else self.tr("No")
72 QTreeWidgetItem(self.channelList, [channelName, autoJoin])
73
74 self.__updateOkButton()
75 self.on_channelList_itemSelectionChanged()
76
77 def __updateOkButton(self):
78 """
79 Private method to update the OK button state.
80 """
81 enable = True
82 enable &= self.networkEdit.text() != ""
83 enable &= self.serverEdit.text() != ""
84
85 self.__okButton.setEnabled(enable)
86
87 @pyqtSlot(str)
88 def on_networkEdit_textChanged(self, txt):
89 """
90 Private slot to handle changes of the network name.
91
92 @param txt text entered into the network name edit (string)
93 """
94 self.__updateOkButton()
95
96 def __refreshIdentityCombo(self, currentIdentity):
97 """
98 Private method to refresh the identity combo.
99
100 @param currentIdentity name of the identity to select (string)
101 """
102 self.identityCombo.clear()
103
104 from .IrcNetworkManager import IrcIdentity
105 identities = list(sorted(self.__manager.getIdentityNames()))
106 identities[identities.index(IrcIdentity.DefaultIdentityName)] = (
107 IrcIdentity.DefaultIdentityDisplay
108 )
109 self.identityCombo.addItems(identities)
110 if currentIdentity == IrcIdentity.DefaultIdentityName:
111 currentIdentity = IrcIdentity.DefaultIdentityDisplay
112 index = self.identityCombo.findText(currentIdentity)
113 if index == -1:
114 index = 0
115 self.identityCombo.setCurrentIndex(index)
116
117 @pyqtSlot(int)
118 def on_identityCombo_currentIndexChanged(self, index):
119 """
120 Private slot to handle the selection of an identity.
121
122 @param index index of the selected entry
123 @type int
124 """
125 from .IrcNetworkManager import IrcIdentity
126
127 identity = self.identitiesCombo.itemText(index)
128 if identity == IrcIdentity.DefaultIdentityDisplay:
129 identity = IrcIdentity.DefaultIdentityName
130 self.__network.setIdentityName(identity)
131
132 @pyqtSlot()
133 def on_editIdentitiesButton_clicked(self):
134 """
135 Private slot to edit the identities.
136 """
137 from .IrcIdentitiesEditDialog import IrcIdentitiesEditDialog
138 currentIdentity = self.identityCombo.currentText()
139 dlg = IrcIdentitiesEditDialog(self.__manager, currentIdentity, self)
140 dlg.exec()
141 self.__refreshIdentityCombo(currentIdentity)
142
143 @pyqtSlot(str)
144 def on_serverEdit_textChanged(self, txt):
145 """
146 Private slot to handle changes of the server name.
147
148 @param txt text entered into the server name edit (string)
149 """
150 self.__updateOkButton()
151
152 @pyqtSlot()
153 def on_editServerButton_clicked(self):
154 """
155 Private slot to edit the server configuration.
156 """
157 from .IrcServerEditDialog import IrcServerEditDialog
158 dlg = IrcServerEditDialog(self.__network.getServer())
159 if dlg.exec() == QDialog.DialogCode.Accepted:
160 self.__network.setServer(dlg.getServer())
161 self.serverEdit.setText(self.__network.getServerName())
162
163 @pyqtSlot()
164 def on_addChannelButton_clicked(self):
165 """
166 Private slot to add a channel.
167 """
168 self.__editChannel(None)
169
170 @pyqtSlot()
171 def on_editChannelButton_clicked(self):
172 """
173 Private slot to edit the selected channel.
174 """
175 itm = self.channelList.selectedItems()[0]
176 if itm:
177 self.__editChannel(itm)
178
179 @pyqtSlot()
180 def on_deleteChannelButton_clicked(self):
181 """
182 Private slot to delete the selected channel.
183 """
184 itm = self.channelList.selectedItems()[0]
185 if itm:
186 res = E5MessageBox.yesNo(
187 self,
188 self.tr("Delete Channel"),
189 self.tr(
190 """Do you really want to delete channel <b>{0}</b>?""")
191 .format(itm.text(0)))
192 if res:
193 self.__network.deleteChannel(itm.text(0))
194
195 index = self.channelList.indexOfTopLevelItem(itm)
196 self.channelList.takeTopLevelItem(index)
197 del itm
198
199 @pyqtSlot(QTreeWidgetItem, int)
200 def on_channelList_itemActivated(self, item, column):
201 """
202 Private slot to handle the activation of a channel entry.
203
204 @param item reference to the activated item (QTreeWidgetItem)
205 @param column column the activation occurred in (integer)
206 """
207 self.__editChannel(item)
208
209 @pyqtSlot()
210 def on_channelList_itemSelectionChanged(self):
211 """
212 Private slot to handle changes of the selection of channels.
213 """
214 selectedItems = self.channelList.selectedItems()
215 enable = bool(selectedItems)
216 self.editChannelButton.setEnabled(enable)
217 self.deleteChannelButton.setEnabled(enable)
218
219 def __editChannel(self, itm):
220 """
221 Private method to edit a channel.
222
223 @param itm reference to the item to be edited (QTreeWidgetItem)
224 """
225 if itm:
226 channel = self.__network.getChannel(itm.text(0))
227 name = channel.getName()
228 key = channel.getKey()
229 autoJoin = channel.autoJoin()
230 else:
231 # add a new channel
232 name = ""
233 key = ""
234 autoJoin = False
235
236 from .IrcChannelEditDialog import IrcChannelEditDialog
237 dlg = IrcChannelEditDialog(name, key, autoJoin, itm is not None, self)
238 if dlg.exec() == QDialog.DialogCode.Accepted:
239 from .IrcNetworkManager import IrcChannel
240 name, key, autoJoin = dlg.getData()
241 channel = IrcChannel(name)
242 channel.setKey(key)
243 channel.setAutoJoin(autoJoin)
244 if itm:
245 if autoJoin:
246 itm.setText(1, self.tr("Yes"))
247 else:
248 itm.setText(1, self.tr("No"))
249 self.__network.setChannel(channel)
250 else:
251 if autoJoin:
252 autoJoinTxt = self.tr("Yes")
253 else:
254 autoJoinTxt = self.tr("No")
255 QTreeWidgetItem(self.channelList, [name, autoJoinTxt])
256 self.__network.addChannel(channel)
257
258 def getNetwork(self):
259 """
260 Public method to get the network object.
261
262 @return edited network object (IrcNetwork)
263 """
264 self.__network.setName(self.networkEdit.text())
265 return self.__network

eric ide

mercurial