23 |
23 |
24 class IrcNetworkWidget(QWidget, Ui_IrcNetworkWidget): |
24 class IrcNetworkWidget(QWidget, Ui_IrcNetworkWidget): |
25 """ |
25 """ |
26 Class implementing the network part of the IRC widget. |
26 Class implementing the network part of the IRC widget. |
27 |
27 |
28 @signal connectNetwork(str,bool) emitted to connect or disconnect from a network |
28 @signal connectNetwork(str,bool) emitted to connect or disconnect from |
|
29 a network |
29 @signal editNetwork(str) emitted to edit a network configuration |
30 @signal editNetwork(str) emitted to edit a network configuration |
30 @signal joinChannel(str) emitted to join a channel |
31 @signal joinChannel(str) emitted to join a channel |
31 @signal nickChanged(str) emitted to change the nick name |
32 @signal nickChanged(str) emitted to change the nick name |
32 @signal sendData(str) emitted to send a message to the channel |
33 @signal sendData(str) emitted to send a message to the channel |
33 @signal away(bool) emitted to indicate the away status |
34 @signal away(bool) emitted to indicate the away status |
57 |
58 |
58 self.joinButton.setEnabled(False) |
59 self.joinButton.setEnabled(False) |
59 self.nickCombo.setEnabled(False) |
60 self.nickCombo.setEnabled(False) |
60 self.awayButton.setEnabled(False) |
61 self.awayButton.setEnabled(False) |
61 |
62 |
62 self.channelCombo.lineEdit().returnPressed.connect(self.on_joinButton_clicked) |
63 self.channelCombo.lineEdit().returnPressed.connect( |
|
64 self.on_joinButton_clicked) |
63 self.nickCombo.lineEdit().returnPressed.connect( |
65 self.nickCombo.lineEdit().returnPressed.connect( |
64 self.on_nickCombo_currentIndexChanged) |
66 self.on_nickCombo_currentIndexChanged) |
65 |
67 |
66 self.setConnected(False) |
68 self.setConnected(False) |
67 |
69 |
131 """ |
133 """ |
132 Private slot to toggle the away status. |
134 Private slot to toggle the away status. |
133 """ |
135 """ |
134 if self.__away: |
136 if self.__away: |
135 self.sendData.emit("AWAY") |
137 self.sendData.emit("AWAY") |
136 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent.png")) |
138 self.awayButton.setIcon( |
|
139 UI.PixmapCache.getIcon("ircUserPresent.png")) |
137 self.__away = False |
140 self.__away = False |
138 else: |
141 else: |
139 networkName = self.networkCombo.currentText() |
142 networkName = self.networkCombo.currentText() |
140 identityName = self.__manager.getNetwork(networkName).getIdentityName() |
143 identityName = self.__manager.getNetwork(networkName)\ |
141 awayMessage = self.__manager.getIdentity(identityName).getAwayMessage() |
144 .getIdentityName() |
|
145 awayMessage = self.__manager.getIdentity(identityName)\ |
|
146 .getAwayMessage() |
142 self.sendData.emit("AWAY :" + awayMessage) |
147 self.sendData.emit("AWAY :" + awayMessage) |
143 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserAway.png")) |
148 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserAway.png")) |
144 self.__away = True |
149 self.__away = True |
145 self.away.emit(self.__away) |
150 self.away.emit(self.__away) |
146 |
151 |
282 |
287 |
283 @param connected flag indicating the connection state (boolean) |
288 @param connected flag indicating the connection state (boolean) |
284 """ |
289 """ |
285 self.__connected = connected |
290 self.__connected = connected |
286 if self.__connected: |
291 if self.__connected: |
287 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircDisconnect.png")) |
292 self.connectButton.setIcon( |
|
293 UI.PixmapCache.getIcon("ircDisconnect.png")) |
288 self.connectButton.setToolTip( |
294 self.connectButton.setToolTip( |
289 self.trUtf8("Press to disconnect from the network")) |
295 self.trUtf8("Press to disconnect from the network")) |
290 else: |
296 else: |
291 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) |
297 self.connectButton.setIcon( |
|
298 UI.PixmapCache.getIcon("ircConnect.png")) |
292 self.connectButton.setToolTip( |
299 self.connectButton.setToolTip( |
293 self.trUtf8("Press to connect to the selected network")) |
300 self.trUtf8("Press to connect to the selected network")) |
294 |
301 |
295 def isConnected(self): |
302 def isConnected(self): |
296 """ |
303 """ |
302 |
309 |
303 def setRegistered(self, registered): |
310 def setRegistered(self, registered): |
304 """ |
311 """ |
305 Public slot to set the registered state. |
312 Public slot to set the registered state. |
306 |
313 |
307 @param connected flag indicating the connection state (boolean) |
314 @param registered flag indicating the registration state (boolean) |
308 """ |
315 """ |
309 self.__registered = registered |
316 self.__registered = registered |
310 on = bool(self.channelCombo.currentText()) and self.__registered |
317 on = bool(self.channelCombo.currentText()) and self.__registered |
311 self.joinButton.setEnabled(on) |
318 self.joinButton.setEnabled(on) |
312 self.nickCombo.setEnabled(registered) |
319 self.nickCombo.setEnabled(registered) |
313 self.awayButton.setEnabled(registered) |
320 self.awayButton.setEnabled(registered) |
314 if registered: |
321 if registered: |
315 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent.png")) |
322 self.awayButton.setIcon( |
|
323 UI.PixmapCache.getIcon("ircUserPresent.png")) |
316 self.__away = False |
324 self.__away = False |
317 |
325 |
318 def __clearMessages(self): |
326 def __clearMessages(self): |
319 """ |
327 """ |
320 Private slot to clear the contents of the messages display. |
328 Private slot to clear the contents of the messages display. |
321 """ |
329 """ |
322 self.messages.clear() |
330 self.messages.clear() |
323 |
331 |
324 def __copyMessages(self): |
332 def __copyMessages(self): |
325 """ |
333 """ |
326 Private slot to copy the selection of the messages display to the clipboard. |
334 Private slot to copy the selection of the messages display to |
|
335 the clipboard. |
327 """ |
336 """ |
328 self.messages.copy() |
337 self.messages.copy() |
329 |
338 |
330 def __copyAllMessages(self): |
339 def __copyAllMessages(self): |
331 """ |
340 """ |
332 Private slot to copy the contents of the messages display to the clipboard. |
341 Private slot to copy the contents of the messages display to |
|
342 the clipboard. |
333 """ |
343 """ |
334 txt = self.messages.toPlainText() |
344 txt = self.messages.toPlainText() |
335 if txt: |
345 if txt: |
336 cb = QApplication.clipboard() |
346 cb = QApplication.clipboard() |
337 cb.setText(txt) |
347 cb.setText(txt) |
338 |
348 |
339 def __cutAllMessages(self): |
349 def __cutAllMessages(self): |
340 """ |
350 """ |
341 Private slot to cut the contents of the messages display to the clipboard. |
351 Private slot to cut the contents of the messages display to |
|
352 the clipboard. |
342 """ |
353 """ |
343 txt = self.messages.toPlainText() |
354 txt = self.messages.toPlainText() |
344 if txt: |
355 if txt: |
345 cb = QApplication.clipboard() |
356 cb = QApplication.clipboard() |
346 cb.setText(txt) |
357 cb.setText(txt) |
359 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
370 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
360 self, |
371 self, |
361 self.trUtf8("Save Messages"), |
372 self.trUtf8("Save Messages"), |
362 "", |
373 "", |
363 self.trUtf8( |
374 self.trUtf8( |
364 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)").format( |
375 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)") |
365 htmlExtension), |
376 .format(htmlExtension), |
366 None, |
377 None, |
367 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
378 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
368 if fname: |
379 if fname: |
369 ext = QFileInfo(fname).suffix() |
380 ext = QFileInfo(fname).suffix() |
370 if not ext: |
381 if not ext: |
391 f.write(txt) |
402 f.write(txt) |
392 f.close() |
403 f.close() |
393 except IOError as err: |
404 except IOError as err: |
394 E5MessageBox.critical(self, |
405 E5MessageBox.critical(self, |
395 self.trUtf8("Error saving Messages"), |
406 self.trUtf8("Error saving Messages"), |
396 self.trUtf8("""<p>The messages contents could not be written""" |
407 self.trUtf8( |
397 """ to <b>{0}</b></p><p>Reason: {1}</p>""")\ |
408 """<p>The messages contents could not be written""" |
|
409 """ to <b>{0}</b></p><p>Reason: {1}</p>""")\ |
398 .format(fname, str(err))) |
410 .format(fname, str(err))) |
399 |
411 |
400 def __initMessagesMenu(self): |
412 def __initMessagesMenu(self): |
401 """ |
413 """ |
402 Private slot to initialize the context menu of the messages pane. |
414 Private slot to initialize the context menu of the messages pane. |
429 self.on_messages_copyAvailable(False) |
441 self.on_messages_copyAvailable(False) |
430 |
442 |
431 @pyqtSlot(bool) |
443 @pyqtSlot(bool) |
432 def on_messages_copyAvailable(self, yes): |
444 def on_messages_copyAvailable(self, yes): |
433 """ |
445 """ |
434 Private slot to react to text selection/deselection of the messages edit. |
446 Private slot to react to text selection/deselection of the |
|
447 messages edit. |
435 |
448 |
436 @param yes flag signaling the availability of selected text (boolean) |
449 @param yes flag signaling the availability of selected text (boolean) |
437 """ |
450 """ |
438 self.__copyMessagesAct.setEnabled(yes) |
451 self.__copyMessagesAct.setEnabled(yes) |
439 |
452 |
440 @pyqtSlot(QPoint) |
453 @pyqtSlot(QPoint) |
441 def on_messages_customContextMenuRequested(self, pos): |
454 def on_messages_customContextMenuRequested(self, pos): |
442 """ |
455 """ |
443 Private slot to show the context menu of the messages pane. |
456 Private slot to show the context menu of the messages pane. |
|
457 |
|
458 @param pos position the menu should be opened at (QPoint) |
444 """ |
459 """ |
445 enable = not self.messages.document().isEmpty() |
460 enable = not self.messages.document().isEmpty() |
446 self.__cutAllMessagesAct.setEnabled(enable) |
461 self.__cutAllMessagesAct.setEnabled(enable) |
447 self.__copyAllMessagesAct.setEnabled(enable) |
462 self.__copyAllMessagesAct.setEnabled(enable) |
448 self.__saveMessagesAct.setEnabled(enable) |
463 self.__saveMessagesAct.setEnabled(enable) |