26 |
26 |
27 |
27 |
28 class IrcNetworkWidget(QWidget, Ui_IrcNetworkWidget): |
28 class IrcNetworkWidget(QWidget, Ui_IrcNetworkWidget): |
29 """ |
29 """ |
30 Class implementing the network part of the IRC widget. |
30 Class implementing the network part of the IRC widget. |
31 |
31 |
32 @signal connectNetwork(str,bool,bool) emitted to connect or disconnect from |
32 @signal connectNetwork(str,bool,bool) emitted to connect or disconnect from |
33 a network |
33 a network |
34 @signal editNetwork(str) emitted to edit a network configuration |
34 @signal editNetwork(str) emitted to edit a network configuration |
35 @signal joinChannel(str) emitted to join a channel |
35 @signal joinChannel(str) emitted to join a channel |
36 @signal nickChanged(str) emitted to change the nick name |
36 @signal nickChanged(str) emitted to change the nick name |
37 @signal sendData(str) emitted to send a message to the channel |
37 @signal sendData(str) emitted to send a message to the channel |
38 @signal away(bool) emitted to indicate the away status |
38 @signal away(bool) emitted to indicate the away status |
39 @signal autoConnected() emitted after an automatic connection was initiated |
39 @signal autoConnected() emitted after an automatic connection was initiated |
40 """ |
40 """ |
|
41 |
41 connectNetwork = pyqtSignal(str, bool, bool) |
42 connectNetwork = pyqtSignal(str, bool, bool) |
42 editNetwork = pyqtSignal(str) |
43 editNetwork = pyqtSignal(str) |
43 joinChannel = pyqtSignal(str) |
44 joinChannel = pyqtSignal(str) |
44 nickChanged = pyqtSignal(str) |
45 nickChanged = pyqtSignal(str) |
45 sendData = pyqtSignal(str) |
46 sendData = pyqtSignal(str) |
46 away = pyqtSignal(bool) |
47 away = pyqtSignal(bool) |
47 autoConnected = pyqtSignal() |
48 autoConnected = pyqtSignal() |
48 |
49 |
49 def __init__(self, parent=None): |
50 def __init__(self, parent=None): |
50 """ |
51 """ |
51 Constructor |
52 Constructor |
52 |
53 |
53 @param parent reference to the parent widget (QWidget) |
54 @param parent reference to the parent widget (QWidget) |
54 """ |
55 """ |
55 super().__init__(parent) |
56 super().__init__(parent) |
56 self.setupUi(self) |
57 self.setupUi(self) |
57 |
58 |
58 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect")) |
59 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect")) |
59 self.editButton.setIcon(UI.PixmapCache.getIcon("ircConfigure")) |
60 self.editButton.setIcon(UI.PixmapCache.getIcon("ircConfigure")) |
60 self.joinButton.setIcon(UI.PixmapCache.getIcon("ircJoinChannel")) |
61 self.joinButton.setIcon(UI.PixmapCache.getIcon("ircJoinChannel")) |
61 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent")) |
62 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent")) |
62 |
63 |
63 self.joinButton.setEnabled(False) |
64 self.joinButton.setEnabled(False) |
64 self.nickCombo.setEnabled(False) |
65 self.nickCombo.setEnabled(False) |
65 self.awayButton.setEnabled(False) |
66 self.awayButton.setEnabled(False) |
66 |
67 |
67 self.channelCombo.lineEdit().returnPressed.connect( |
68 self.channelCombo.lineEdit().returnPressed.connect(self.on_joinButton_clicked) |
68 self.on_joinButton_clicked) |
|
69 self.nickCombo.lineEdit().returnPressed.connect( |
69 self.nickCombo.lineEdit().returnPressed.connect( |
70 self.on_nickCombo_currentIndexChanged) |
70 self.on_nickCombo_currentIndexChanged |
71 |
71 ) |
|
72 |
72 self.setConnected(False) |
73 self.setConnected(False) |
73 |
74 |
74 self.__initMessagesMenu() |
75 self.__initMessagesMenu() |
75 |
76 |
76 self.__manager = None |
77 self.__manager = None |
77 self.__connected = False |
78 self.__connected = False |
78 self.__registered = False |
79 self.__registered = False |
79 self.__away = False |
80 self.__away = False |
80 |
81 |
81 def initialize(self, manager): |
82 def initialize(self, manager): |
82 """ |
83 """ |
83 Public method to initialize the widget. |
84 Public method to initialize the widget. |
84 |
85 |
85 @param manager reference to the network manager (IrcNetworkManager) |
86 @param manager reference to the network manager (IrcNetworkManager) |
86 """ |
87 """ |
87 self.__manager = manager |
88 self.__manager = manager |
88 |
89 |
89 self.networkCombo.addItems(self.__manager.getNetworkNames()) |
90 self.networkCombo.addItems(self.__manager.getNetworkNames()) |
90 |
91 |
91 self.__manager.networksChanged.connect(self.__refreshNetworks) |
92 self.__manager.networksChanged.connect(self.__refreshNetworks) |
92 self.__manager.identitiesChanged.connect(self.__refreshNetworks) |
93 self.__manager.identitiesChanged.connect(self.__refreshNetworks) |
93 |
94 |
94 def autoConnect(self): |
95 def autoConnect(self): |
95 """ |
96 """ |
96 Public method to perform the IRC auto connection. |
97 Public method to perform the IRC auto connection. |
97 """ |
98 """ |
98 userInterface = ericApp().getObject("UserInterface") |
99 userInterface = ericApp().getObject("UserInterface") |
99 online = userInterface.isOnline() |
100 online = userInterface.isOnline() |
100 self.connectButton.setEnabled(online) |
101 self.connectButton.setEnabled(online) |
101 userInterface.onlineStateChanged.connect(self.__onlineStateChanged) |
102 userInterface.onlineStateChanged.connect(self.__onlineStateChanged) |
102 if online: |
103 if online: |
103 self.__autoConnect() |
104 self.__autoConnect() |
104 |
105 |
105 def __autoConnect(self): |
106 def __autoConnect(self): |
106 """ |
107 """ |
107 Private method to perform the IRC auto connection. |
108 Private method to perform the IRC auto connection. |
108 """ |
109 """ |
109 for networkName in self.__manager.getNetworkNames(): |
110 for networkName in self.__manager.getNetworkNames(): |
150 blocked = self.nickCombo.blockSignals(True) |
151 blocked = self.nickCombo.blockSignals(True) |
151 self.networkCombo.setCurrentIndex(row) |
152 self.networkCombo.setCurrentIndex(row) |
152 self.nickCombo.setEditText(currentNick) |
153 self.nickCombo.setEditText(currentNick) |
153 self.nickCombo.blockSignals(blocked) |
154 self.nickCombo.blockSignals(blocked) |
154 self.channelCombo.setEditText(currentChannel) |
155 self.channelCombo.setEditText(currentChannel) |
155 |
156 |
156 @pyqtSlot() |
157 @pyqtSlot() |
157 def on_connectButton_clicked(self): |
158 def on_connectButton_clicked(self): |
158 """ |
159 """ |
159 Private slot to connect to a network. |
160 Private slot to connect to a network. |
160 """ |
161 """ |
161 network = self.networkCombo.currentText() |
162 network = self.networkCombo.currentText() |
162 self.connectNetwork.emit(network, not self.__connected, False) |
163 self.connectNetwork.emit(network, not self.__connected, False) |
163 |
164 |
164 @pyqtSlot() |
165 @pyqtSlot() |
165 def on_awayButton_clicked(self): |
166 def on_awayButton_clicked(self): |
166 """ |
167 """ |
167 Private slot to toggle the away status. |
168 Private slot to toggle the away status. |
168 """ |
169 """ |
169 if self.__away: |
170 if self.__away: |
170 self.handleAwayCommand("") |
171 self.handleAwayCommand("") |
171 else: |
172 else: |
172 networkName = self.networkCombo.currentText() |
173 networkName = self.networkCombo.currentText() |
173 identityName = ( |
174 identityName = self.__manager.getNetwork(networkName).getIdentityName() |
174 self.__manager.getNetwork(networkName).getIdentityName() |
|
175 ) |
|
176 identity = self.__manager.getIdentity(identityName) |
175 identity = self.__manager.getIdentity(identityName) |
177 if identity: |
176 if identity: |
178 awayMessage = identity.getAwayMessage() |
177 awayMessage = identity.getAwayMessage() |
179 else: |
178 else: |
180 awayMessage = "" |
179 awayMessage = "" |
181 self.handleAwayCommand(awayMessage) |
180 self.handleAwayCommand(awayMessage) |
182 |
181 |
183 @pyqtSlot(str) |
182 @pyqtSlot(str) |
184 def handleAwayCommand(self, awayMessage): |
183 def handleAwayCommand(self, awayMessage): |
185 """ |
184 """ |
186 Public slot to process an away command. |
185 Public slot to process an away command. |
187 |
186 |
188 @param awayMessage message to be set for being away |
187 @param awayMessage message to be set for being away |
189 @type str |
188 @type str |
190 """ |
189 """ |
191 if awayMessage and not self.__away: |
190 if awayMessage and not self.__away: |
192 # set being away |
191 # set being away |
196 self.__away = True |
195 self.__away = True |
197 self.away.emit(self.__away) |
196 self.away.emit(self.__away) |
198 elif not awayMessage and self.__away: |
197 elif not awayMessage and self.__away: |
199 # cancel being away |
198 # cancel being away |
200 self.sendData.emit("AWAY") |
199 self.sendData.emit("AWAY") |
201 self.awayButton.setIcon( |
200 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent")) |
202 UI.PixmapCache.getIcon("ircUserPresent")) |
|
203 self.__away = False |
201 self.__away = False |
204 self.away.emit(self.__away) |
202 self.away.emit(self.__away) |
205 |
203 |
206 @pyqtSlot() |
204 @pyqtSlot() |
207 def on_editButton_clicked(self): |
205 def on_editButton_clicked(self): |
208 """ |
206 """ |
209 Private slot to edit a network. |
207 Private slot to edit a network. |
210 """ |
208 """ |
211 network = self.networkCombo.currentText() |
209 network = self.networkCombo.currentText() |
212 self.editNetwork.emit(network) |
210 self.editNetwork.emit(network) |
213 |
211 |
214 @pyqtSlot(str) |
212 @pyqtSlot(str) |
215 def on_channelCombo_editTextChanged(self, txt): |
213 def on_channelCombo_editTextChanged(self, txt): |
216 """ |
214 """ |
217 Private slot to react upon changes of the channel. |
215 Private slot to react upon changes of the channel. |
218 |
216 |
219 @param txt current text of the channel combo (string) |
217 @param txt current text of the channel combo (string) |
220 """ |
218 """ |
221 on = bool(txt) and self.__registered |
219 on = bool(txt) and self.__registered |
222 self.joinButton.setEnabled(on) |
220 self.joinButton.setEnabled(on) |
223 |
221 |
224 @pyqtSlot() |
222 @pyqtSlot() |
225 def on_joinButton_clicked(self): |
223 def on_joinButton_clicked(self): |
226 """ |
224 """ |
227 Private slot to join a channel. |
225 Private slot to join a channel. |
228 """ |
226 """ |
229 channel = self.channelCombo.currentText() |
227 channel = self.channelCombo.currentText() |
230 self.joinChannel.emit(channel) |
228 self.joinChannel.emit(channel) |
231 |
229 |
232 @pyqtSlot(int) |
230 @pyqtSlot(int) |
233 def on_networkCombo_currentIndexChanged(self, index): |
231 def on_networkCombo_currentIndexChanged(self, index): |
234 """ |
232 """ |
235 Private slot to handle selections of a network. |
233 Private slot to handle selections of a network. |
236 |
234 |
237 @param index index of the selected entry |
235 @param index index of the selected entry |
238 @type int |
236 @type int |
239 """ |
237 """ |
240 networkName = self.networkCombo.itemText(index) |
238 networkName = self.networkCombo.itemText(index) |
241 network = self.__manager.getNetwork(networkName) |
239 network = self.__manager.getNetwork(networkName) |
243 self.channelCombo.clear() |
241 self.channelCombo.clear() |
244 if network: |
242 if network: |
245 channels = network.getChannelNames() |
243 channels = network.getChannelNames() |
246 self.channelCombo.addItems(channels) |
244 self.channelCombo.addItems(channels) |
247 self.channelCombo.setEnabled(True) |
245 self.channelCombo.setEnabled(True) |
248 identity = self.__manager.getIdentity( |
246 identity = self.__manager.getIdentity(network.getIdentityName()) |
249 network.getIdentityName()) |
|
250 if identity: |
247 if identity: |
251 self.nickCombo.addItems(identity.getNickNames()) |
248 self.nickCombo.addItems(identity.getNickNames()) |
252 else: |
249 else: |
253 self.channelCombo.setEnabled(False) |
250 self.channelCombo.setEnabled(False) |
254 |
251 |
255 def getNetworkChannels(self): |
252 def getNetworkChannels(self): |
256 """ |
253 """ |
257 Public method to get the list of channels associated with the |
254 Public method to get the list of channels associated with the |
258 selected network. |
255 selected network. |
259 |
256 |
260 @return associated channels (list of IrcChannel) |
257 @return associated channels (list of IrcChannel) |
261 """ |
258 """ |
262 networkName = self.networkCombo.currentText() |
259 networkName = self.networkCombo.currentText() |
263 network = self.__manager.getNetwork(networkName) |
260 network = self.__manager.getNetwork(networkName) |
264 return network.getChannels() |
261 return network.getChannels() |
265 |
262 |
266 @pyqtSlot(int) |
263 @pyqtSlot(int) |
267 @pyqtSlot() |
264 @pyqtSlot() |
268 def on_nickCombo_currentIndexChanged(self, nick=0): |
265 def on_nickCombo_currentIndexChanged(self, nick=0): |
269 """ |
266 """ |
270 Private slot to use another nick name. |
267 Private slot to use another nick name. |
271 |
268 |
272 @param nick index of the selected nick name (unused) |
269 @param nick index of the selected nick name (unused) |
273 """ |
270 """ |
274 if self.__connected: |
271 if self.__connected: |
275 self.nickChanged.emit(self.nickCombo.currentText()) |
272 self.nickChanged.emit(self.nickCombo.currentText()) |
276 |
273 |
277 def getNickname(self): |
274 def getNickname(self): |
278 """ |
275 """ |
279 Public method to get the currently selected nick name. |
276 Public method to get the currently selected nick name. |
280 |
277 |
281 @return selected nick name (string) |
278 @return selected nick name (string) |
282 """ |
279 """ |
283 return self.nickCombo.currentText() |
280 return self.nickCombo.currentText() |
284 |
281 |
285 def setNickName(self, nick): |
282 def setNickName(self, nick): |
286 """ |
283 """ |
287 Public slot to set the nick name in use. |
284 Public slot to set the nick name in use. |
288 |
285 |
289 @param nick nick name in use (string) |
286 @param nick nick name in use (string) |
290 """ |
287 """ |
291 self.nickCombo.blockSignals(True) |
288 self.nickCombo.blockSignals(True) |
292 self.nickCombo.setEditText(nick) |
289 self.nickCombo.setEditText(nick) |
293 self.nickCombo.blockSignals(False) |
290 self.nickCombo.blockSignals(False) |
294 |
291 |
295 def addMessage(self, msg): |
292 def addMessage(self, msg): |
296 """ |
293 """ |
297 Public method to add a message. |
294 Public method to add a message. |
298 |
295 |
299 @param msg message to be added (string) |
296 @param msg message to be added (string) |
300 """ |
297 """ |
301 s = '<font color="{0}">{1} {2}</font>'.format( |
298 s = '<font color="{0}">{1} {2}</font>'.format( |
302 Preferences.getIrc("NetworkMessageColour"), |
299 Preferences.getIrc("NetworkMessageColour"), ircTimestamp(), msg |
303 ircTimestamp(), |
|
304 msg |
|
305 ) |
300 ) |
306 self.messages.append(s) |
301 self.messages.append(s) |
307 |
302 |
308 def addServerMessage(self, msgType, msg, filterMsg=True): |
303 def addServerMessage(self, msgType, msg, filterMsg=True): |
309 """ |
304 """ |
310 Public method to add a server message. |
305 Public method to add a server message. |
311 |
306 |
312 @param msgType txpe of the message (string) |
307 @param msgType txpe of the message (string) |
313 @param msg message to be added (string) |
308 @param msg message to be added (string) |
314 @param filterMsg flag indicating to filter the message (boolean) |
309 @param filterMsg flag indicating to filter the message (boolean) |
315 """ |
310 """ |
316 if filterMsg: |
311 if filterMsg: |
317 msg = ircFilter(msg) |
312 msg = ircFilter(msg) |
318 s = '<font color="{0}">{1} <b>[</b>{2}<b>]</b> {3}</font>'.format( |
313 s = '<font color="{0}">{1} <b>[</b>{2}<b>]</b> {3}</font>'.format( |
319 Preferences.getIrc("ServerMessageColour"), |
314 Preferences.getIrc("ServerMessageColour"), ircTimestamp(), msgType, msg |
320 ircTimestamp(), |
|
321 msgType, |
|
322 msg |
|
323 ) |
315 ) |
324 self.messages.append(s) |
316 self.messages.append(s) |
325 |
317 |
326 def addErrorMessage(self, msgType, msg): |
318 def addErrorMessage(self, msgType, msg): |
327 """ |
319 """ |
328 Public method to add an error message. |
320 Public method to add an error message. |
329 |
321 |
330 @param msgType txpe of the message (string) |
322 @param msgType txpe of the message (string) |
331 @param msg message to be added (string) |
323 @param msg message to be added (string) |
332 """ |
324 """ |
333 s = '<font color="{0}">{1} <b>[</b>{2}<b>]</b> {3}</font>'.format( |
325 s = '<font color="{0}">{1} <b>[</b>{2}<b>]</b> {3}</font>'.format( |
334 Preferences.getIrc("ErrorMessageColour"), |
326 Preferences.getIrc("ErrorMessageColour"), ircTimestamp(), msgType, msg |
335 ircTimestamp(), |
|
336 msgType, |
|
337 msg |
|
338 ) |
327 ) |
339 self.messages.append(s) |
328 self.messages.append(s) |
340 |
329 |
341 def setConnected(self, connected): |
330 def setConnected(self, connected): |
342 """ |
331 """ |
343 Public slot to set the connection state. |
332 Public slot to set the connection state. |
344 |
333 |
345 @param connected flag indicating the connection state (boolean) |
334 @param connected flag indicating the connection state (boolean) |
346 """ |
335 """ |
347 self.__connected = connected |
336 self.__connected = connected |
348 if self.__connected: |
337 if self.__connected: |
349 self.connectButton.setIcon( |
338 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircDisconnect")) |
350 UI.PixmapCache.getIcon("ircDisconnect")) |
|
351 self.connectButton.setToolTip( |
339 self.connectButton.setToolTip( |
352 self.tr("Press to disconnect from the network")) |
340 self.tr("Press to disconnect from the network") |
|
341 ) |
353 else: |
342 else: |
354 self.connectButton.setIcon( |
343 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect")) |
355 UI.PixmapCache.getIcon("ircConnect")) |
|
356 self.connectButton.setToolTip( |
344 self.connectButton.setToolTip( |
357 self.tr("Press to connect to the selected network")) |
345 self.tr("Press to connect to the selected network") |
358 |
346 ) |
|
347 |
359 def isConnected(self): |
348 def isConnected(self): |
360 """ |
349 """ |
361 Public method to check, if the network is connected. |
350 Public method to check, if the network is connected. |
362 |
351 |
363 @return flag indicating a connected network (boolean) |
352 @return flag indicating a connected network (boolean) |
364 """ |
353 """ |
365 return self.__connected |
354 return self.__connected |
366 |
355 |
367 def setRegistered(self, registered): |
356 def setRegistered(self, registered): |
368 """ |
357 """ |
369 Public slot to set the registered state. |
358 Public slot to set the registered state. |
370 |
359 |
371 @param registered flag indicating the registration state (boolean) |
360 @param registered flag indicating the registration state (boolean) |
372 """ |
361 """ |
373 self.__registered = registered |
362 self.__registered = registered |
374 on = bool(self.channelCombo.currentText()) and self.__registered |
363 on = bool(self.channelCombo.currentText()) and self.__registered |
375 self.joinButton.setEnabled(on) |
364 self.joinButton.setEnabled(on) |
376 self.nickCombo.setEnabled(registered) |
365 self.nickCombo.setEnabled(registered) |
377 self.awayButton.setEnabled(registered) |
366 self.awayButton.setEnabled(registered) |
378 if registered: |
367 if registered: |
379 self.awayButton.setIcon( |
368 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent")) |
380 UI.PixmapCache.getIcon("ircUserPresent")) |
|
381 self.__away = False |
369 self.__away = False |
382 |
370 |
383 def __clearMessages(self): |
371 def __clearMessages(self): |
384 """ |
372 """ |
385 Private slot to clear the contents of the messages display. |
373 Private slot to clear the contents of the messages display. |
386 """ |
374 """ |
387 self.messages.clear() |
375 self.messages.clear() |
388 |
376 |
389 def __copyMessages(self): |
377 def __copyMessages(self): |
390 """ |
378 """ |
391 Private slot to copy the selection of the messages display to |
379 Private slot to copy the selection of the messages display to |
392 the clipboard. |
380 the clipboard. |
393 """ |
381 """ |
394 self.messages.copy() |
382 self.messages.copy() |
395 |
383 |
396 def __copyAllMessages(self): |
384 def __copyAllMessages(self): |
397 """ |
385 """ |
398 Private slot to copy the contents of the messages display to |
386 Private slot to copy the contents of the messages display to |
399 the clipboard. |
387 the clipboard. |
400 """ |
388 """ |
401 txt = self.messages.toPlainText() |
389 txt = self.messages.toPlainText() |
402 if txt: |
390 if txt: |
403 cb = QApplication.clipboard() |
391 cb = QApplication.clipboard() |
404 cb.setText(txt) |
392 cb.setText(txt) |
405 |
393 |
406 def __cutAllMessages(self): |
394 def __cutAllMessages(self): |
407 """ |
395 """ |
408 Private slot to cut the contents of the messages display to |
396 Private slot to cut the contents of the messages display to |
409 the clipboard. |
397 the clipboard. |
410 """ |
398 """ |
411 txt = self.messages.toPlainText() |
399 txt = self.messages.toPlainText() |
412 if txt: |
400 if txt: |
413 cb = QApplication.clipboard() |
401 cb = QApplication.clipboard() |
414 cb.setText(txt) |
402 cb.setText(txt) |
415 self.messages.clear() |
403 self.messages.clear() |
416 |
404 |
417 def __saveMessages(self): |
405 def __saveMessages(self): |
418 """ |
406 """ |
419 Private slot to save the contents of the messages display. |
407 Private slot to save the contents of the messages display. |
420 """ |
408 """ |
421 hasText = not self.messages.document().isEmpty() |
409 hasText = not self.messages.document().isEmpty() |
426 htmlExtension = "html" |
414 htmlExtension = "html" |
427 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
415 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
428 self, |
416 self, |
429 self.tr("Save Messages"), |
417 self.tr("Save Messages"), |
430 "", |
418 "", |
431 self.tr( |
419 self.tr("HTML Files (*.{0});;Text Files (*.txt);;All Files (*)").format( |
432 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)") |
420 htmlExtension |
433 .format(htmlExtension), |
421 ), |
434 None, |
422 None, |
435 EricFileDialog.DontConfirmOverwrite) |
423 EricFileDialog.DontConfirmOverwrite, |
|
424 ) |
436 if fname: |
425 if fname: |
437 fpath = pathlib.Path(fname) |
426 fpath = pathlib.Path(fname) |
438 if not fpath.suffix: |
427 if not fpath.suffix: |
439 ex = selectedFilter.split("(*")[1].split(")")[0] |
428 ex = selectedFilter.split("(*")[1].split(")")[0] |
440 if ex: |
429 if ex: |
441 fpath = fpath.with_suffix(ex) |
430 fpath = fpath.with_suffix(ex) |
442 if fpath.exists(): |
431 if fpath.exists(): |
443 res = EricMessageBox.yesNo( |
432 res = EricMessageBox.yesNo( |
444 self, |
433 self, |
445 self.tr("Save Messages"), |
434 self.tr("Save Messages"), |
446 self.tr("<p>The file <b>{0}</b> already exists." |
435 self.tr( |
447 " Overwrite it?</p>").format(fpath), |
436 "<p>The file <b>{0}</b> already exists." |
448 icon=EricMessageBox.Warning) |
437 " Overwrite it?</p>" |
|
438 ).format(fpath), |
|
439 icon=EricMessageBox.Warning, |
|
440 ) |
449 if not res: |
441 if not res: |
450 return |
442 return |
451 |
443 |
452 try: |
444 try: |
453 txt = ( |
445 txt = ( |
454 self.messages.toHtml() |
446 self.messages.toHtml() |
455 if fpath.suffix.lower() in [".htm", ".html"] else |
447 if fpath.suffix.lower() in [".htm", ".html"] |
456 self.messages.toPlainText() |
448 else self.messages.toPlainText() |
457 ) |
449 ) |
458 with fpath.open("w", encoding="utf-8") as f: |
450 with fpath.open("w", encoding="utf-8") as f: |
459 f.write(txt) |
451 f.write(txt) |
460 except OSError as err: |
452 except OSError as err: |
461 EricMessageBox.critical( |
453 EricMessageBox.critical( |
462 self, |
454 self, |
463 self.tr("Error saving Messages"), |
455 self.tr("Error saving Messages"), |
464 self.tr( |
456 self.tr( |
465 """<p>The messages contents could not be written""" |
457 """<p>The messages contents could not be written""" |
466 """ to <b>{0}</b></p><p>Reason: {1}</p>""") |
458 """ to <b>{0}</b></p><p>Reason: {1}</p>""" |
467 .format(fpath, str(err))) |
459 ).format(fpath, str(err)), |
468 |
460 ) |
|
461 |
469 def __initMessagesMenu(self): |
462 def __initMessagesMenu(self): |
470 """ |
463 """ |
471 Private slot to initialize the context menu of the messages pane. |
464 Private slot to initialize the context menu of the messages pane. |
472 """ |
465 """ |
473 self.__messagesMenu = QMenu(self) |
466 self.__messagesMenu = QMenu(self) |
474 self.__copyMessagesAct = self.__messagesMenu.addAction( |
467 self.__copyMessagesAct = self.__messagesMenu.addAction( |
475 UI.PixmapCache.getIcon("editCopy"), |
468 UI.PixmapCache.getIcon("editCopy"), self.tr("Copy"), self.__copyMessages |
476 self.tr("Copy"), self.__copyMessages) |
469 ) |
477 self.__messagesMenu.addSeparator() |
470 self.__messagesMenu.addSeparator() |
478 self.__cutAllMessagesAct = self.__messagesMenu.addAction( |
471 self.__cutAllMessagesAct = self.__messagesMenu.addAction( |
479 UI.PixmapCache.getIcon("editCut"), |
472 UI.PixmapCache.getIcon("editCut"), self.tr("Cut all"), self.__cutAllMessages |
480 self.tr("Cut all"), self.__cutAllMessages) |
473 ) |
481 self.__copyAllMessagesAct = self.__messagesMenu.addAction( |
474 self.__copyAllMessagesAct = self.__messagesMenu.addAction( |
482 UI.PixmapCache.getIcon("editCopy"), |
475 UI.PixmapCache.getIcon("editCopy"), |
483 self.tr("Copy all"), self.__copyAllMessages) |
476 self.tr("Copy all"), |
|
477 self.__copyAllMessages, |
|
478 ) |
484 self.__messagesMenu.addSeparator() |
479 self.__messagesMenu.addSeparator() |
485 self.__clearMessagesAct = self.__messagesMenu.addAction( |
480 self.__clearMessagesAct = self.__messagesMenu.addAction( |
486 UI.PixmapCache.getIcon("editDelete"), |
481 UI.PixmapCache.getIcon("editDelete"), self.tr("Clear"), self.__clearMessages |
487 self.tr("Clear"), self.__clearMessages) |
482 ) |
488 self.__messagesMenu.addSeparator() |
483 self.__messagesMenu.addSeparator() |
489 self.__saveMessagesAct = self.__messagesMenu.addAction( |
484 self.__saveMessagesAct = self.__messagesMenu.addAction( |
490 UI.PixmapCache.getIcon("fileSave"), |
485 UI.PixmapCache.getIcon("fileSave"), self.tr("Save"), self.__saveMessages |
491 self.tr("Save"), self.__saveMessages) |
486 ) |
492 |
487 |
493 self.on_messages_copyAvailable(False) |
488 self.on_messages_copyAvailable(False) |
494 |
489 |
495 @pyqtSlot(bool) |
490 @pyqtSlot(bool) |
496 def on_messages_copyAvailable(self, yes): |
491 def on_messages_copyAvailable(self, yes): |
497 """ |
492 """ |
498 Private slot to react to text selection/deselection of the |
493 Private slot to react to text selection/deselection of the |
499 messages edit. |
494 messages edit. |
500 |
495 |
501 @param yes flag signaling the availability of selected text (boolean) |
496 @param yes flag signaling the availability of selected text (boolean) |
502 """ |
497 """ |
503 self.__copyMessagesAct.setEnabled(yes) |
498 self.__copyMessagesAct.setEnabled(yes) |
504 |
499 |
505 @pyqtSlot(QPoint) |
500 @pyqtSlot(QPoint) |
506 def on_messages_customContextMenuRequested(self, pos): |
501 def on_messages_customContextMenuRequested(self, pos): |
507 """ |
502 """ |
508 Private slot to show the context menu of the messages pane. |
503 Private slot to show the context menu of the messages pane. |
509 |
504 |
510 @param pos position the menu should be opened at (QPoint) |
505 @param pos position the menu should be opened at (QPoint) |
511 """ |
506 """ |
512 enable = not self.messages.document().isEmpty() |
507 enable = not self.messages.document().isEmpty() |
513 self.__cutAllMessagesAct.setEnabled(enable) |
508 self.__cutAllMessagesAct.setEnabled(enable) |
514 self.__copyAllMessagesAct.setEnabled(enable) |
509 self.__copyAllMessagesAct.setEnabled(enable) |
515 self.__saveMessagesAct.setEnabled(enable) |
510 self.__saveMessagesAct.setEnabled(enable) |
516 self.__messagesMenu.popup(self.messages.mapToGlobal(pos)) |
511 self.__messagesMenu.popup(self.messages.mapToGlobal(pos)) |
517 |
512 |
518 @pyqtSlot(QUrl) |
513 @pyqtSlot(QUrl) |
519 def on_messages_anchorClicked(self, url): |
514 def on_messages_anchorClicked(self, url): |
520 """ |
515 """ |
521 Private slot to open links in the default browser. |
516 Private slot to open links in the default browser. |
522 |
517 |
523 @param url URL to be opened (QUrl) |
518 @param url URL to be opened (QUrl) |
524 """ |
519 """ |
525 QDesktopServices.openUrl(url) |
520 QDesktopServices.openUrl(url) |