Network/IRC/IrcNetworkEditDialog.py

changeset 2235
266800cbe7cc
parent 2234
1e33501a0d33
child 2236
e30d5f978919
equal deleted inserted replaced
2234:1e33501a0d33 2235:266800cbe7cc
5 5
6 """ 6 """
7 Module implementing a dialog for editing IRC network definitions. 7 Module implementing a dialog for editing IRC network definitions.
8 """ 8 """
9 9
10 import copy
11
10 from PyQt4.QtCore import pyqtSlot 12 from PyQt4.QtCore import pyqtSlot
11 from PyQt4.QtGui import QDialog, QDialogButtonBox, QTreeWidgetItem 13 from PyQt4.QtGui import QDialog, QDialogButtonBox, QTreeWidgetItem
12 14
13 from .Ui_IrcNetworkEditDialog import Ui_IrcNetworkEditDialog 15 from .Ui_IrcNetworkEditDialog import Ui_IrcNetworkEditDialog
14 16
15 from .IrcNetworkManager import IrcIdentity 17 from .IrcNetworkManager import IrcIdentity, IrcChannel
18 from .IrcChannelEditDialog import IrcChannelEditDialog
16 19
17 import UI.PixmapCache 20 import UI.PixmapCache
18 21
19 22
20 class IrcNetworkEditDialog(QDialog, Ui_IrcNetworkEditDialog): 23 class IrcNetworkEditDialog(QDialog, Ui_IrcNetworkEditDialog):
40 self.addChannelButton.setIcon(UI.PixmapCache.getIcon("plus.png")) 43 self.addChannelButton.setIcon(UI.PixmapCache.getIcon("plus.png"))
41 self.deleteChannelButton.setIcon(UI.PixmapCache.getIcon("minus.png")) 44 self.deleteChannelButton.setIcon(UI.PixmapCache.getIcon("minus.png"))
42 45
43 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) 46 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
44 47
45 self.__network = self.__manager.getNetwork(networkName) 48 # TODO: add the ADD mode
49 self.__network = copy.deepcopy(self.__manager.getNetwork(networkName))
46 50
47 # network name 51 # network name
48 self.networkEdit.setText(networkName) 52 self.networkEdit.setText(networkName)
49 53
50 # identities 54 # identities
67 if index == -1: 71 if index == -1:
68 index = 0 72 index = 0
69 self.serverCombo.setCurrentIndex(index) 73 self.serverCombo.setCurrentIndex(index)
70 74
71 # channels 75 # channels
72 # TODO: change this to use channel objects
73 for channelName in sorted(self.__network.getChannelNames()): 76 for channelName in sorted(self.__network.getChannelNames()):
74 channel = self.__network.getChannel(channelName) 77 channel = self.__network.getChannel(channelName)
75 if channel.autoJoin(): 78 if channel.autoJoin():
76 autoJoin = self.trUtf8("Yes") 79 autoJoin = self.trUtf8("Yes")
77 else: 80 else:
138 """ 141 """
139 Private slot to edit the selected channel. 142 Private slot to edit the selected channel.
140 """ 143 """
141 itm = self.channelList.selectedItems()[0] 144 itm = self.channelList.selectedItems()[0]
142 if itm: 145 if itm:
143 self.__editChannel(itm.text(0)) 146 self.__editChannel(itm)
144 147
145 @pyqtSlot() 148 @pyqtSlot()
146 def on_deleteChannelButton_clicked(self): 149 def on_deleteChannelButton_clicked(self):
147 """ 150 """
148 Slot documentation goes here. 151 Slot documentation goes here.
156 Private slot to handle the activation of a channel entry. 159 Private slot to handle the activation of a channel entry.
157 160
158 @param item reference to the activated item (QTreeWidgetItem) 161 @param item reference to the activated item (QTreeWidgetItem)
159 @param column column the activation occurred in (integer) 162 @param column column the activation occurred in (integer)
160 """ 163 """
161 self.__editChannel(item.text(0)) 164 self.__editChannel(item)
162 165
163 @pyqtSlot() 166 @pyqtSlot()
164 def on_channelList_itemSelectionChanged(self): 167 def on_channelList_itemSelectionChanged(self):
165 """ 168 """
166 Private slot to handle changes of the selection of channels. 169 Private slot to handle changes of the selection of channels.
171 else: 174 else:
172 enable = True 175 enable = True
173 self.editChannelButton.setEnabled(enable) 176 self.editChannelButton.setEnabled(enable)
174 self.deleteChannelButton.setEnabled(enable) 177 self.deleteChannelButton.setEnabled(enable)
175 178
176 def __editChannel(self, name): 179 def __editChannel(self, itm):
177 """ 180 """
178 Private method to edit a channel. 181 Private method to edit a channel.
179 182
180 @param name name of the channel (string) 183 @param itm reference to the item to be edited (QTreeWidgetItem)
181 """ 184 """
182 # TODO: not implemented yet 185 if itm:
183 raise NotImplementedError 186 channel = self.__network.getChannel(itm.text(0))
187 name = channel.getName()
188 key = channel.getKey()
189 autoJoin = channel.autoJoin()
190 else:
191 # add a new channel
192 name = ""
193 key = ""
194 autoJoin = False
195
196 dlg = IrcChannelEditDialog(name, key, autoJoin, itm is not None, self)
197 if dlg.exec_() == QDialog.Accepted:
198 name, key, autoJoin = dlg.getData()
199 channel = IrcChannel(name)
200 channel.setKey(key)
201 channel.setAutoJoin(autoJoin)
202 if itm:
203 if autoJoin:
204 itm.setText(1, self.trUtf8("Yes"))
205 else:
206 itm.setText(1, self.trUtf8("No"))
207 self.__network.setChannel(channel)
208 else:
209 if autoJoin:
210 autoJoinTxt = self.trUtf8("Yes")
211 else:
212 autoJoinTxt = self.trUtf8("No")
213 QTreeWidgetItem(self.channelList, [name, autoJoinTxt])
214 self.__network.addChannel(channel)
215
216 def getData(self):
217 """
218 Public method to get the network data.
219
220 @return edited network object (IrcNetwork)
221 """
222 return self.__network

eric ide

mercurial