src/eric7/Network/IRC/IrcWidget.py

branch
eric7
changeset 10428
a071d4065202
parent 10069
435cc5875135
child 10439
21c28b0f9e41
equal deleted inserted replaced
10427:3733e2b23cf7 10428:a071d4065202
51 51
52 def __init__(self, parent=None): 52 def __init__(self, parent=None):
53 """ 53 """
54 Constructor 54 Constructor
55 55
56 @param parent reference to the parent widget (QWidget) 56 @param parent reference to the parent widget
57 @type QWidget
57 """ 58 """
58 super().__init__(parent) 59 super().__init__(parent)
59 self.setupUi(self) 60 self.setupUi(self)
60 61
61 self.__ircNetworkManager = IrcNetworkManager(self) 62 self.__ircNetworkManager = IrcNetworkManager(self)
131 132
132 def shutdown(self): 133 def shutdown(self):
133 """ 134 """
134 Public method to shut down the widget. 135 Public method to shut down the widget.
135 136
136 @return flag indicating successful shutdown (boolean) 137 @return flag indicating successful shutdown
138 @rtype bool
137 """ 139 """
138 if self.__server: 140 if self.__server:
139 if Preferences.getIrc("AskOnShutdown"): 141 if Preferences.getIrc("AskOnShutdown"):
140 ok = EricMessageBox.yesNo( 142 ok = EricMessageBox.yesNo(
141 self, 143 self,
166 168
167 def __connectNetwork(self, name, connect, silent): 169 def __connectNetwork(self, name, connect, silent):
168 """ 170 """
169 Private slot to connect to or disconnect from the given network. 171 Private slot to connect to or disconnect from the given network.
170 172
171 @param name name of the network to connect to (string) 173 @param name name of the network to connect to
172 @param connect flag indicating to connect (boolean) 174 @type str
173 @param silent flag indicating a silent connect/disconnect (boolean) 175 @param connect flag indicating to connect
176 @type bool
177 @param silent flag indicating a silent connect/disconnect
178 @type bool
174 """ 179 """
175 if connect: 180 if connect:
176 network = self.__ircNetworkManager.getNetwork(name) 181 network = self.__ircNetworkManager.getNetwork(name)
177 if network: 182 if network:
178 self.__server = network.getServer() 183 self.__server = network.getServer()
300 305
301 def joinChannel(self, name, key=""): 306 def joinChannel(self, name, key=""):
302 """ 307 """
303 Public slot to join a channel. 308 Public slot to join a channel.
304 309
305 @param name name of the channel (string) 310 @param name name of the channel
306 @param key key of the channel (string) 311 @type str
312 @param key key of the channel
313 @type str
307 """ 314 """
308 from .IrcChannelWidget import IrcChannelWidget 315 from .IrcChannelWidget import IrcChannelWidget
309 316
310 # step 1: check, if this channel is already joined 317 # step 1: check, if this channel is already joined
311 for channel in self.__channelList: 318 for channel in self.__channelList:
349 def __query(self, match): 356 def __query(self, match):
350 """ 357 """
351 Private method to handle a new private connection. 358 Private method to handle a new private connection.
352 359
353 @param match reference to the match object 360 @param match reference to the match object
354 @return flag indicating, if the message was handled (boolean) 361 @type re.Match
362 @return flag indicating, if the message was handled
363 @rtype bool
355 """ 364 """
356 # group(1) sender user name 365 # group(1) sender user name
357 # group(2) sender user@host 366 # group(2) sender user@host
358 # group(3) target nick 367 # group(3) target nick
359 # group(4) message 368 # group(4) message
371 @pyqtSlot(str) 380 @pyqtSlot(str)
372 def __openPrivate(self, name): 381 def __openPrivate(self, name):
373 """ 382 """
374 Private slot to open a private chat with the given user. 383 Private slot to open a private chat with the given user.
375 384
376 @param name name of the user (string) 385 @param name name of the user
386 @type str
377 """ 387 """
378 from .IrcChannelWidget import IrcChannelWidget 388 from .IrcChannelWidget import IrcChannelWidget
379 389
380 channel = IrcChannelWidget(self) 390 channel = IrcChannelWidget(self)
381 channel.setName(self.__nickName) 391 channel.setName(self.__nickName)
447 457
448 def __closeChannel(self, name): 458 def __closeChannel(self, name):
449 """ 459 """
450 Private slot handling the closing of a channel. 460 Private slot handling the closing of a channel.
451 461
452 @param name name of the closed channel (string) 462 @param name name of the closed channel
463 @type str
453 """ 464 """
454 for channel in self.__channelList: 465 for channel in self.__channelList:
455 if channel.name() == name: 466 if channel.name() == name:
456 self.channelsWidget.removeTab(self.channelsWidget.indexOf(channel)) 467 self.channelsWidget.removeTab(self.channelsWidget.indexOf(channel))
457 self.__channelList.remove(channel) 468 self.__channelList.remove(channel)
467 def on_channelsWidget_tabCloseRequested(self, index): 478 def on_channelsWidget_tabCloseRequested(self, index):
468 """ 479 """
469 Private slot to close a channel by pressing the close button of 480 Private slot to close a channel by pressing the close button of
470 the channels widget. 481 the channels widget.
471 482
472 @param index index of the tab to be closed (integer) 483 @param index index of the tab to be closed
484 @type int
473 """ 485 """
474 channel = self.channelsWidget.widget(index) 486 channel = self.channelsWidget.widget(index)
475 channel.requestLeave() 487 channel.requestLeave()
476 488
477 def __send(self, data): 489 def __send(self, data):
478 """ 490 """
479 Private slot to send data to the IRC server. 491 Private slot to send data to the IRC server.
480 492
481 @param data data to be sent (string) 493 @param data data to be sent
494 @type str
482 """ 495 """
483 if self.__socket: 496 if self.__socket:
484 self.__socket.write(QByteArray("{0}\r\n".format(data).encode("utf-8"))) 497 self.__socket.write(QByteArray("{0}\r\n".format(data).encode("utf-8")))
485 498
486 def __sendCtcpRequest(self, receiver, request, arguments): 499 def __sendCtcpRequest(self, receiver, request, arguments):
617 def __handleCtcpReply(self, match): 630 def __handleCtcpReply(self, match):
618 """ 631 """
619 Private method to handle a server message containing a CTCP reply. 632 Private method to handle a server message containing a CTCP reply.
620 633
621 @param match reference to the match object 634 @param match reference to the match object
635 @type re.Match
622 """ 636 """
623 if "!" in match.group(1): 637 if "!" in match.group(1):
624 sender = match.group(1).split("!", 1)[0] 638 sender = match.group(1).split("!", 1)[0]
625 639
626 try: 640 try:
656 def __handleNamedMessage(self, match): 670 def __handleNamedMessage(self, match):
657 """ 671 """
658 Private method to handle a server message containing a message name. 672 Private method to handle a server message containing a message name.
659 673
660 @param match reference to the match object 674 @param match reference to the match object
661 @return flag indicating, if the message was handled (boolean) 675 @type re.Match
676 @return flag indicating, if the message was handled
677 @rtype bool
662 """ 678 """
663 name = match.group(2) 679 name = match.group(2)
664 if name == "NOTICE": 680 if name == "NOTICE":
665 try: 681 try:
666 msg = match.group(3).split(":", 1)[1] 682 msg = match.group(3).split(":", 1)[1]
738 def __handleNumericMessage(self, match): 754 def __handleNumericMessage(self, match):
739 """ 755 """
740 Private method to handle a server message containing a numeric code. 756 Private method to handle a server message containing a numeric code.
741 757
742 @param match reference to the match object 758 @param match reference to the match object
743 @return flag indicating, if the message was handled (boolean) 759 @type re.Match
760 @return flag indicating, if the message was handled
761 @rtype bool
744 """ 762 """
745 code = int(match.group(2)) 763 code = int(match.group(2))
746 if code < 400: 764 if code < 400:
747 return self.__handleServerReply(code, match.group(1), match.group(3)) 765 return self.__handleServerReply(code, match.group(1), match.group(3))
748 else: 766 else:
750 768
751 def __handleServerError(self, code, message): 769 def __handleServerError(self, code, message):
752 """ 770 """
753 Private slot to handle a server error reply. 771 Private slot to handle a server error reply.
754 772
755 @param code numerical code sent by the server (integer) 773 @param code numerical code sent by the server
756 @param message message sent by the server (string) 774 @type int
757 @return flag indicating, if the message was handled (boolean) 775 @param message message sent by the server
776 @type str
777 @return flag indicating, if the message was handled
778 @rtype bool
758 """ 779 """
759 if code == 433: 780 if code == 433:
760 if self.__registering: 781 if self.__registering:
761 self.__handleNickInUseLogin() 782 self.__handleNickInUseLogin()
762 else: 783 else:
768 789
769 def __handleServerReply(self, code, server, message): 790 def __handleServerReply(self, code, server, message):
770 """ 791 """
771 Private slot to handle a server reply. 792 Private slot to handle a server reply.
772 793
773 @param code numerical code sent by the server (integer) 794 @param code numerical code sent by the server
774 @param server name of the server (string) 795 @type int
775 @param message message sent by the server (string) 796 @param server name of the server
776 @return flag indicating, if the message was handled (boolean) 797 @type str
798 @param message message sent by the server
799 @type str
800 @return flag indicating, if the message was handled
801 @rtype bool
777 """ 802 """
778 # determine message type 803 # determine message type
779 if code in [1, 2, 3, 4]: 804 if code in [1, 2, 3, 4]:
780 msgType = self.tr("Welcome") 805 msgType = self.tr("Welcome")
781 elif code == 5: 806 elif code == 5:
867 def __tcpError(self, error): 892 def __tcpError(self, error):
868 """ 893 """
869 Private slot to handle errors reported by the TCP socket. 894 Private slot to handle errors reported by the TCP socket.
870 895
871 @param error error code reported by the socket 896 @param error error code reported by the socket
872 (QAbstractSocket.SocketError) 897 @type QAbstractSocket.SocketError
873 """ 898 """
874 if error == QAbstractSocket.SocketError.RemoteHostClosedError: 899 if error == QAbstractSocket.SocketError.RemoteHostClosedError:
875 # ignore this one, it's a disconnect 900 # ignore this one, it's a disconnect
876 if self.__sslErrorLock: 901 if self.__sslErrorLock:
877 self.networkWidget.addErrorMessage( 902 self.networkWidget.addErrorMessage(
917 942
918 def __sslErrors(self, errors): 943 def __sslErrors(self, errors):
919 """ 944 """
920 Private slot to handle SSL errors. 945 Private slot to handle SSL errors.
921 946
922 @param errors list of SSL errors (list of QSslError) 947 @param errors list of SSL errors
948 @type list of QSslError
923 """ 949 """
924 ignored, defaultChanged = self.__sslErrorHandler.sslErrors( 950 ignored, defaultChanged = self.__sslErrorHandler.sslErrors(
925 errors, self.__server.getName(), self.__server.getPort() 951 errors, self.__server.getName(), self.__server.getPort()
926 ) 952 )
927 if ignored == EricSslErrorState.NOT_IGNORED: 953 if ignored == EricSslErrorState.NOT_IGNORED:
954 980
955 def __setUserPrivilegePrefix(self, prefix1, prefix2): 981 def __setUserPrivilegePrefix(self, prefix1, prefix2):
956 """ 982 """
957 Private method to set the user privilege prefix. 983 Private method to set the user privilege prefix.
958 984
959 @param prefix1 first part of the prefix (string) 985 @param prefix1 first part of the prefix
960 @param prefix2 indictors the first part gets mapped to (string) 986 @type str
987 @param prefix2 indictors the first part gets mapped to
988 @type str
961 """ 989 """
962 # PREFIX=(ov)@+ 990 # PREFIX=(ov)@+
963 # o = @ -> @ircbot , channel operator 991 # o = @ -> @ircbot , channel operator
964 # v = + -> +userName , voice operator 992 # v = + -> +userName , voice operator
965 for i in range(len(prefix1)): 993 for i in range(len(prefix1)):
969 def __ping(self, match): 997 def __ping(self, match):
970 """ 998 """
971 Private method to handle a PING message. 999 Private method to handle a PING message.
972 1000
973 @param match reference to the match object 1001 @param match reference to the match object
974 @return flag indicating, if the message was handled (boolean) 1002 @type re.Match
1003 @return flag indicating, if the message was handled
1004 @rtype bool
975 """ 1005 """
976 self.__send("PONG " + match.group(1)) 1006 self.__send("PONG " + match.group(1))
977 return True 1007 return True
978 1008
979 def __handleCtcp(self, match): 1009 def __handleCtcp(self, match):
980 """ 1010 """
981 Private method to handle a CTCP command. 1011 Private method to handle a CTCP command.
982 1012
983 @param match reference to the match object 1013 @param match reference to the match object
984 @return flag indicating, if the message was handled (boolean) 1014 @type re.Match
1015 @return flag indicating, if the message was handled
1016 @rtype bool
985 """ 1017 """
986 # group(1) sender user name 1018 # group(1) sender user name
987 # group(2) sender user@host 1019 # group(2) sender user@host
988 # group(3) target nick 1020 # group(3) target nick
989 # group(4) message 1021 # group(4) message
1091 1123
1092 def __changeNick(self, nick): 1124 def __changeNick(self, nick):
1093 """ 1125 """
1094 Private slot to use a new nick name. 1126 Private slot to use a new nick name.
1095 1127
1096 @param nick nick name to use (str) 1128 @param nick nick name to use
1129 @type str
1097 """ 1130 """
1098 if nick and nick != self.__nickName: 1131 if nick and nick != self.__nickName:
1099 self.__send("NICK " + nick) 1132 self.__send("NICK " + nick)
1100 1133
1101 def __setChannelTypePrefixes(self, prefixes): 1134 def __setChannelTypePrefixes(self, prefixes):
1102 """ 1135 """
1103 Private method to set the channel type prefixes. 1136 Private method to set the channel type prefixes.
1104 1137
1105 @param prefixes channel prefix characters (string) 1138 @param prefixes channel prefix characters
1139 @type str
1106 """ 1140 """
1107 self.__channelTypePrefixes = prefixes 1141 self.__channelTypePrefixes = prefixes
1108 1142
1109 def isChannelName(self, name): 1143 def isChannelName(self, name):
1110 """ 1144 """
1111 Public method to check, if the given name is a channel name. 1145 Public method to check, if the given name is a channel name.
1112 1146
1113 @param name name to check (string) 1147 @param name name to check
1114 @return flag indicating a channel name (boolean) 1148 @type str
1149 @return flag indicating a channel name
1150 @rtype bool
1115 """ 1151 """
1116 if not name: 1152 if not name:
1117 return False 1153 return False
1118 1154
1119 if self.__channelTypePrefixes: 1155 if self.__channelTypePrefixes:
1123 1159
1124 def __away(self, isAway): 1160 def __away(self, isAway):
1125 """ 1161 """
1126 Private slot handling the change of the away state. 1162 Private slot handling the change of the away state.
1127 1163
1128 @param isAway flag indicating the current away state (boolean) 1164 @param isAway flag indicating the current away state
1165 @type bool
1129 """ 1166 """
1130 if isAway and self.__identityName: 1167 if isAway and self.__identityName:
1131 identity = self.__ircNetworkManager.getIdentity(self.__identityName) 1168 identity = self.__ircNetworkManager.getIdentity(self.__identityName)
1132 if identity and identity.rememberAwayPosition(): 1169 if identity and identity.rememberAwayPosition():
1133 for channel in self.__channelList: 1170 for channel in self.__channelList:

eric ide

mercurial