Network/IRC/IrcWidget.py

changeset 2264
d8176c78c6a6
parent 2258
9ca42fd3ecc0
child 2265
72e6f479987b
equal deleted inserted replaced
2263:7876e6ebc0c1 2264:d8176c78c6a6
27 from .IrcChannelWidget import IrcChannelWidget 27 from .IrcChannelWidget import IrcChannelWidget
28 from .IrcNetworkListDialog import IrcNetworkListDialog 28 from .IrcNetworkListDialog import IrcNetworkListDialog
29 29
30 import Preferences 30 import Preferences
31 import UI.PixmapCache 31 import UI.PixmapCache
32
33 from UI.Info import Version, Copyright
32 34
33 35
34 class IrcWidget(QWidget, Ui_IrcWidget): 36 class IrcWidget(QWidget, Ui_IrcWidget):
35 """ 37 """
36 Class implementing the IRC window. 38 Class implementing the IRC window.
253 channel.setPartMessage(identity.getPartMessage()) 255 channel.setPartMessage(identity.getPartMessage())
254 channel.setUserPrivilegePrefix(self.__userPrefix) 256 channel.setUserPrivilegePrefix(self.__userPrefix)
255 channel.initAutoWho() 257 channel.initAutoWho()
256 258
257 channel.sendData.connect(self.__send) 259 channel.sendData.connect(self.__send)
260 channel.sendCtcpReply.connect(self.__sendCtcpReply)
258 channel.channelClosed.connect(self.__closeChannel) 261 channel.channelClosed.connect(self.__closeChannel)
259 channel.openPrivateChat.connect(self.__openPrivate) 262 channel.openPrivateChat.connect(self.__openPrivate)
260 263
261 self.channelsWidget.addTab(channel, name) 264 self.channelsWidget.addTab(channel, name)
262 self.__channelList.append(channel) 265 self.__channelList.append(channel)
283 """ 286 """
284 # group(1) sender user name 287 # group(1) sender user name
285 # group(2) sender user@host 288 # group(2) sender user@host
286 # group(3) target nick 289 # group(3) target nick
287 # group(4) message 290 # group(4) message
291 if match.group(4).startswith("\x01"):
292 return self.__handleCtcp(match)
293
288 self.__openPrivate(match.group(1)) 294 self.__openPrivate(match.group(1))
289 # the above call sets the new channel as the current widget 295 # the above call sets the new channel as the current widget
290 channel = self.channelsWidget.currentWidget() 296 channel = self.channelsWidget.currentWidget()
291 channel.addMessage(match.group(1), match.group(4)) 297 channel.addMessage(match.group(1), match.group(4))
292 channel.setPrivateInfo("{0} - {1}".format(match.group(1), match.group(2))) 298 channel.setPrivateInfo("{0} - {1}".format(match.group(1), match.group(2)))
308 channel.setUserPrivilegePrefix(self.__userPrefix) 314 channel.setUserPrivilegePrefix(self.__userPrefix)
309 channel.setPrivate(True, name) 315 channel.setPrivate(True, name)
310 channel.addUsers([name, self.__nickName]) 316 channel.addUsers([name, self.__nickName])
311 317
312 channel.sendData.connect(self.__send) 318 channel.sendData.connect(self.__send)
319 channel.sendCtcpReply.connect(self.__sendCtcpReply)
313 channel.channelClosed.connect(self.__closeChannel) 320 channel.channelClosed.connect(self.__closeChannel)
314 321
315 self.channelsWidget.addTab(channel, name) 322 self.channelsWidget.addTab(channel, name)
316 self.__channelList.append(channel) 323 self.__channelList.append(channel)
317 self.channelsWidget.setCurrentWidget(channel) 324 self.channelsWidget.setCurrentWidget(channel)
358 365
359 @param data data to be sent (string) 366 @param data data to be sent (string)
360 """ 367 """
361 if self.__socket: 368 if self.__socket:
362 self.__socket.write(QByteArray("{0}\r\n".format(data).encode("utf-8"))) 369 self.__socket.write(QByteArray("{0}\r\n".format(data).encode("utf-8")))
370
371 def __sendCtcpReply(self, receiver, text):
372 """
373 Private slot to send a CTCP reply.
374
375 @param receiver nick name of the receiver (string)
376 @param text text to be sent (string)
377 """
378 self.__send("NOTICE {0} :\x01{1}\x01".format(receiver, text))
363 379
364 def __hostFound(self): 380 def __hostFound(self):
365 """ 381 """
366 Private slot to indicate the host was found. 382 Private slot to indicate the host was found.
367 """ 383 """
734 @return flag indicating, if the message was handled (boolean) 750 @return flag indicating, if the message was handled (boolean)
735 """ 751 """
736 self.__send("PONG " + match.group(1)) 752 self.__send("PONG " + match.group(1))
737 return True 753 return True
738 754
755 def __handleCtcp(self, match):
756 """
757 Private method to handle a CTCP command.
758
759 @param reference to the match object
760 @return flag indicating, if the message was handled (boolean)
761 """
762 # group(1) sender user name
763 # group(2) sender user@host
764 # group(3) target nick
765 # group(4) message
766 if match.group(4).startswith("\x01"):
767 ctcpCommand = match.group(4)[1:].split("\x01", 1)[0]
768 if " " in ctcpCommand:
769 ctcpRequest, ctcpArg = ctcpCommand.split(" ", 1)
770 else:
771 ctcpRequest, ctcpArg = ctcpCommand, ""
772 ctcpRequest = ctcpRequest.lower()
773 if ctcpRequest == "version":
774 msg = "Eric IRC client {0}, {1}".format(Version, Copyright)
775 self.networkWidget.addServerMessage(self.trUtf8("CTCP"),
776 self.trUtf8("Received Version request from {0}.").format(
777 match.group(1)))
778 self.__sendCtcpReply(match.group(1), "VERSION " + msg)
779 elif ctcpRequest == "ping":
780 self.networkWidget.addServerMessage(self.trUtf8("CTCP"),
781 self.trUtf8("Received CTCP-PING request from {0},"
782 " sending answer.").format(match.group(1)))
783 self.__sendCtcpReply(match.group(1), "PING {0}".format(ctcpArg))
784 elif ctcpRequest == "clientinfo":
785 self.networkWidget.addServerMessage(self.trUtf8("CTCP"),
786 self.trUtf8("Received CTCP-CLIENTINFO request from {0},"
787 " sending answer.").format(match.group(1)))
788 self.__sendCtcpReply(match.group(1),
789 "CLIENTINFO CLIENTINFO PING VERSION")
790 else:
791 self.networkWidget.addServerMessage(self.trUtf8("CTCP"),
792 self.trUtf8("Received unknown CTCP-{0} request from {1}.").format(
793 ctcpRequest, match.group(1)))
794 return True
795
796 return False
797
739 def __updateUsersCount(self): 798 def __updateUsersCount(self):
740 """ 799 """
741 Private method to update the users count on the channel tabs. 800 Private method to update the users count on the channel tabs.
742 """ 801 """
743 for channel in self.__channelList: 802 for channel in self.__channelList:

eric ide

mercurial