eric6/Network/IRC/IrcChannelWidget.py

changeset 7255
d595f6f9cbf8
parent 7229
53054eb5b15a
child 7360
9190402e4505
equal deleted inserted replaced
7254:f00d825fbdb3 7255:d595f6f9cbf8
10 10
11 from itertools import zip_longest 11 from itertools import zip_longest
12 12
13 import re 13 import re
14 14
15 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QDateTime, QPoint, QFileInfo, \ 15 from PyQt5.QtCore import (
16 QTimer, QUrl, QCoreApplication 16 pyqtSlot, pyqtSignal, QDateTime, QPoint, QFileInfo, QTimer, QUrl,
17 QCoreApplication
18 )
17 from PyQt5.QtGui import QIcon, QPainter, QTextCursor, QDesktopServices 19 from PyQt5.QtGui import QIcon, QPainter, QTextCursor, QDesktopServices
18 from PyQt5.QtWidgets import QWidget, QListWidgetItem, QMenu, QApplication, \ 20 from PyQt5.QtWidgets import (
19 QInputDialog, QLineEdit 21 QWidget, QListWidgetItem, QMenu, QApplication, QInputDialog, QLineEdit
22 )
20 23
21 from E5Gui import E5MessageBox, E5FileDialog 24 from E5Gui import E5MessageBox, E5FileDialog
22 from E5Gui.E5Application import e5App 25 from E5Gui.E5Application import e5App
23 26
24 from .Ui_IrcChannelWidget import Ui_IrcChannelWidget 27 from .Ui_IrcChannelWidget import Ui_IrcChannelWidget
426 msgList = msg.split() 429 msgList = msg.split()
427 cmd = msgList[0][1:].upper() 430 cmd = msgList[0][1:].upper()
428 if cmd in ["MSG", "QUERY"]: 431 if cmd in ["MSG", "QUERY"]:
429 cmd = "PRIVMSG" 432 cmd = "PRIVMSG"
430 if len(msgList) > 1: 433 if len(msgList) > 1:
431 if msgList[1].strip().lower() in \ 434 if (
432 self.__serviceNamesLower: 435 msgList[1].strip().lower() in
433 msg = "PRIVMSG " + \ 436 self.__serviceNamesLower
434 msgList[1].strip().lower() + \ 437 ):
438 msg = (
439 "PRIVMSG " +
440 msgList[1].strip().lower() +
435 " :" + " ".join(msgList[2:]) 441 " :" + " ".join(msgList[2:])
442 )
436 else: 443 else:
437 msg = "PRIVMSG {0} :{1}".format( 444 msg = "PRIVMSG {0} :{1}".format(
438 msgList[1], " ".join(msgList[2:])) 445 msgList[1], " ".join(msgList[2:]))
439 else: 446 else:
440 msgList[0] = cmd 447 msgList[0] = cmd
679 if Preferences.getIrc("ShowNotifications"): 686 if Preferences.getIrc("ShowNotifications"):
680 if Preferences.getIrc("NotifyMessage"): 687 if Preferences.getIrc("NotifyMessage"):
681 self.__ui.showNotification( 688 self.__ui.showNotification(
682 UI.PixmapCache.getPixmap("irc48.png"), 689 UI.PixmapCache.getPixmap("irc48.png"),
683 self.tr("Channel Message"), msg) 690 self.tr("Channel Message"), msg)
684 elif Preferences.getIrc("NotifyNick") and \ 691 elif (
685 self.__userName.lower() in msg.lower(): 692 Preferences.getIrc("NotifyNick") and
693 self.__userName.lower() in msg.lower()
694 ):
686 self.__ui.showNotification( 695 self.__ui.showNotification(
687 UI.PixmapCache.getPixmap("irc48.png"), 696 UI.PixmapCache.getPixmap("irc48.png"),
688 self.tr("Nick mentioned"), msg) 697 self.tr("Nick mentioned"), msg)
689 698
690 def addUsers(self, users): 699 def addUsers(self, users):
717 msg = self.tr( 726 msg = self.tr(
718 "You have joined the channel {0} ({1}).").format( 727 "You have joined the channel {0} ({1}).").format(
719 self.__name, match.group(2)) 728 self.__name, match.group(2))
720 self.__addManagementMessage( 729 self.__addManagementMessage(
721 IrcChannelWidget.JoinIndicator, msg) 730 IrcChannelWidget.JoinIndicator, msg)
722 if Preferences.getIrc("ShowNotifications") and \ 731 if (
723 Preferences.getIrc("NotifyJoinPart"): 732 Preferences.getIrc("ShowNotifications") and
733 Preferences.getIrc("NotifyJoinPart")
734 ):
724 self.__ui.showNotification( 735 self.__ui.showNotification(
725 UI.PixmapCache.getPixmap("irc48.png"), 736 UI.PixmapCache.getPixmap("irc48.png"),
726 self.tr("Join Channel"), msg) 737 self.tr("Join Channel"), msg)
727 return True 738 return True
728 739
750 match.group(1), self.__name, ircFilter(match.group(3))) 761 match.group(1), self.__name, ircFilter(match.group(3)))
751 nmsg = self.tr("{0} has left {1}: {2}.").format( 762 nmsg = self.tr("{0} has left {1}: {2}.").format(
752 match.group(1), self.__name, match.group(3)) 763 match.group(1), self.__name, match.group(3))
753 self.__addManagementMessage( 764 self.__addManagementMessage(
754 IrcChannelWidget.LeaveIndicator, msg) 765 IrcChannelWidget.LeaveIndicator, msg)
755 if Preferences.getIrc("ShowNotifications") and \ 766 if (
756 Preferences.getIrc("NotifyJoinPart"): 767 Preferences.getIrc("ShowNotifications") and
768 Preferences.getIrc("NotifyJoinPart")
769 ):
757 self.__ui.showNotification( 770 self.__ui.showNotification(
758 UI.PixmapCache.getPixmap("irc48.png"), 771 UI.PixmapCache.getPixmap("irc48.png"),
759 self.tr("Leave Channel"), nmsg) 772 self.tr("Leave Channel"), nmsg)
760 return True 773 return True
761 774
780 else: 793 else:
781 msg = self.tr("{0} has quit {1}: {2}.").format( 794 msg = self.tr("{0} has quit {1}: {2}.").format(
782 match.group(1), self.__name, ircFilter(match.group(2))) 795 match.group(1), self.__name, ircFilter(match.group(2)))
783 self.__addManagementMessage( 796 self.__addManagementMessage(
784 IrcChannelWidget.MessageIndicator, msg) 797 IrcChannelWidget.MessageIndicator, msg)
785 if Preferences.getIrc("ShowNotifications") and \ 798 if (
786 Preferences.getIrc("NotifyJoinPart"): 799 Preferences.getIrc("ShowNotifications") and
800 Preferences.getIrc("NotifyJoinPart")
801 ):
787 self.__ui.showNotification( 802 self.__ui.showNotification(
788 UI.PixmapCache.getPixmap("irc48.png"), 803 UI.PixmapCache.getPixmap("irc48.png"),
789 self.tr("Quit"), msg) 804 self.tr("Quit"), msg)
790 805
791 # always return False for other channels and server to process 806 # always return False for other channels and server to process
981 isPlus = False 996 isPlus = False
982 continue 997 continue
983 elif mode == "a": 998 elif mode == "a":
984 if isPlus: 999 if isPlus:
985 message = self.tr( 1000 message = self.tr(
986 "{0} sets the channel mode to 'anonymous'.")\ 1001 "{0} sets the channel mode to 'anonymous'."
987 .format(nick) 1002 ).format(nick)
988 else: 1003 else:
989 message = self.tr( 1004 message = self.tr(
990 "{0} removes the 'anonymous' mode from the" 1005 "{0} removes the 'anonymous' mode from the"
991 " channel.").format(nick) 1006 " channel.").format(nick)
992 elif mode == "b": 1007 elif mode == "b":
1017 "{0} removes the ban exception on {1}.").format( 1032 "{0} removes the ban exception on {1}.").format(
1018 nick, modesParameters.pop(0)) 1033 nick, modesParameters.pop(0))
1019 elif mode == "i": 1034 elif mode == "i":
1020 if isPlus: 1035 if isPlus:
1021 message = self.tr( 1036 message = self.tr(
1022 "{0} sets the channel mode to 'invite only'.")\ 1037 "{0} sets the channel mode to 'invite only'."
1023 .format(nick) 1038 ).format(nick)
1024 else: 1039 else:
1025 message = self.tr( 1040 message = self.tr(
1026 "{0} removes the 'invite only' mode from the" 1041 "{0} removes the 'invite only' mode from the"
1027 " channel.").format(nick) 1042 " channel.").format(nick)
1028 elif mode == "k": 1043 elif mode == "k":
1042 message = self.tr( 1057 message = self.tr(
1043 "{0} removes the channel limit.").format(nick) 1058 "{0} removes the channel limit.").format(nick)
1044 elif mode == "m": 1059 elif mode == "m":
1045 if isPlus: 1060 if isPlus:
1046 message = self.tr( 1061 message = self.tr(
1047 "{0} sets the channel mode to 'moderated'.")\ 1062 "{0} sets the channel mode to 'moderated'."
1048 .format(nick) 1063 ).format(nick)
1049 else: 1064 else:
1050 message = self.tr( 1065 message = self.tr(
1051 "{0} sets the channel mode to 'unmoderated'.")\ 1066 "{0} sets the channel mode to 'unmoderated'."
1052 .format(nick) 1067 ).format(nick)
1053 elif mode == "n": 1068 elif mode == "n":
1054 if isPlus: 1069 if isPlus:
1055 message = self.tr( 1070 message = self.tr(
1056 "{0} sets the channel mode to 'no messages from" 1071 "{0} sets the channel mode to 'no messages from"
1057 " outside'.").format(nick) 1072 " outside'.").format(nick)
1060 "{0} sets the channel mode to 'allow messages" 1075 "{0} sets the channel mode to 'allow messages"
1061 " from outside'.").format(nick) 1076 " from outside'.").format(nick)
1062 elif mode == "p": 1077 elif mode == "p":
1063 if isPlus: 1078 if isPlus:
1064 message = self.tr( 1079 message = self.tr(
1065 "{0} sets the channel mode to 'private'.")\ 1080 "{0} sets the channel mode to 'private'."
1066 .format(nick) 1081 ).format(nick)
1067 else: 1082 else:
1068 message = self.tr( 1083 message = self.tr(
1069 "{0} sets the channel mode to 'public'.")\ 1084 "{0} sets the channel mode to 'public'."
1070 .format(nick) 1085 ).format(nick)
1071 elif mode == "q": 1086 elif mode == "q":
1072 if isPlus: 1087 if isPlus:
1073 message = self.tr( 1088 message = self.tr(
1074 "{0} sets the channel mode to 'quiet'.")\ 1089 "{0} sets the channel mode to 'quiet'."
1075 .format(nick) 1090 ).format(nick)
1076 else: 1091 else:
1077 message = self.tr( 1092 message = self.tr(
1078 "{0} removes the 'quiet' mode from the channel.")\ 1093 "{0} removes the 'quiet' mode from the channel."
1079 .format(nick) 1094 ).format(nick)
1080 elif mode == "r": 1095 elif mode == "r":
1081 continue 1096 continue
1082 elif mode == "s": 1097 elif mode == "s":
1083 if isPlus: 1098 if isPlus:
1084 message = self.tr( 1099 message = self.tr(
1085 "{0} sets the channel mode to 'secret'.")\ 1100 "{0} sets the channel mode to 'secret'."
1086 .format(nick) 1101 ).format(nick)
1087 else: 1102 else:
1088 message = self.tr( 1103 message = self.tr(
1089 "{0} sets the channel mode to 'visible'.")\ 1104 "{0} sets the channel mode to 'visible'."
1090 .format(nick) 1105 ).format(nick)
1091 elif mode == "t": 1106 elif mode == "t":
1092 if isPlus: 1107 if isPlus:
1093 message = self.tr( 1108 message = self.tr(
1094 "{0} switches on 'topic protection'.").format(nick) 1109 "{0} switches on 'topic protection'.").format(nick)
1095 else: 1110 else:
1096 message = self.tr( 1111 message = self.tr(
1097 "{0} switches off 'topic protection'.")\ 1112 "{0} switches off 'topic protection'."
1098 .format(nick) 1113 ).format(nick)
1099 elif mode == "I": 1114 elif mode == "I":
1100 if isPlus: 1115 if isPlus:
1101 message = self.tr( 1116 message = self.tr(
1102 "{0} sets invitation mask {1}.").format( 1117 "{0} sets invitation mask {1}.").format(
1103 nick, modesParameters.pop(0)) 1118 nick, modesParameters.pop(0))
1269 """ 1284 """
1270 Private slot to append a message. 1285 Private slot to append a message.
1271 1286
1272 @param message message to be appended (string) 1287 @param message message to be appended (string)
1273 """ 1288 """
1274 if self.__hidden and \ 1289 if (
1275 self.__markerLine == "" and \ 1290 self.__hidden and
1276 Preferences.getIrc("MarkPositionWhenHidden"): 1291 self.__markerLine == "" and
1292 Preferences.getIrc("MarkPositionWhenHidden")
1293 ):
1277 self.setMarkerLine() 1294 self.setMarkerLine()
1278 self.messages.append(message) 1295 self.messages.append(message)
1279 1296
1280 def setMarkerLine(self): 1297 def setMarkerLine(self):
1281 """ 1298 """
1282 Public method to draw a line to mark the current position. 1299 Public method to draw a line to mark the current position.
1283 """ 1300 """
1284 self.unsetMarkerLine() 1301 self.unsetMarkerLine()
1285 self.__markerLine = \ 1302 self.__markerLine = (
1286 '<span style=" color:{0}; background-color:{1};">{2}</span>'\ 1303 '<span style=" color:{0}; background-color:{1};">{2}</span>'
1287 .format(Preferences.getIrc("MarkerLineForegroundColour"), 1304 .format(Preferences.getIrc("MarkerLineForegroundColour"),
1288 Preferences.getIrc("MarkerLineBackgroundColour"), 1305 Preferences.getIrc("MarkerLineBackgroundColour"),
1289 self.tr('--- New From Here ---')) 1306 self.tr('--- New From Here ---'))
1307 )
1290 self.messages.append(self.__markerLine) 1308 self.messages.append(self.__markerLine)
1291 1309
1292 def unsetMarkerLine(self): 1310 def unsetMarkerLine(self):
1293 """ 1311 """
1294 Public method to remove the marker line. 1312 Public method to remove the marker line.
1396 def __initMessagesMenu(self): 1414 def __initMessagesMenu(self):
1397 """ 1415 """
1398 Private slot to initialize the context menu of the messages pane. 1416 Private slot to initialize the context menu of the messages pane.
1399 """ 1417 """
1400 self.__messagesMenu = QMenu(self) 1418 self.__messagesMenu = QMenu(self)
1401 self.__copyMessagesAct = \ 1419 self.__copyMessagesAct = self.__messagesMenu.addAction(
1402 self.__messagesMenu.addAction( 1420 UI.PixmapCache.getIcon("editCopy.png"),
1403 UI.PixmapCache.getIcon("editCopy.png"), 1421 self.tr("Copy"), self.__copyMessages)
1404 self.tr("Copy"), self.__copyMessages)
1405 self.__messagesMenu.addSeparator() 1422 self.__messagesMenu.addSeparator()
1406 self.__cutAllMessagesAct = \ 1423 self.__cutAllMessagesAct = self.__messagesMenu.addAction(
1407 self.__messagesMenu.addAction( 1424 UI.PixmapCache.getIcon("editCut.png"),
1408 UI.PixmapCache.getIcon("editCut.png"), 1425 self.tr("Cut all"), self.__cutAllMessages)
1409 self.tr("Cut all"), self.__cutAllMessages) 1426 self.__copyAllMessagesAct = self.__messagesMenu.addAction(
1410 self.__copyAllMessagesAct = \ 1427 UI.PixmapCache.getIcon("editCopy.png"),
1411 self.__messagesMenu.addAction( 1428 self.tr("Copy all"), self.__copyAllMessages)
1412 UI.PixmapCache.getIcon("editCopy.png"),
1413 self.tr("Copy all"), self.__copyAllMessages)
1414 self.__messagesMenu.addSeparator() 1429 self.__messagesMenu.addSeparator()
1415 self.__clearMessagesAct = \ 1430 self.__clearMessagesAct = self.__messagesMenu.addAction(
1416 self.__messagesMenu.addAction( 1431 UI.PixmapCache.getIcon("editDelete.png"),
1417 UI.PixmapCache.getIcon("editDelete.png"), 1432 self.tr("Clear"), self.__clearMessages)
1418 self.tr("Clear"), self.__clearMessages)
1419 self.__messagesMenu.addSeparator() 1433 self.__messagesMenu.addSeparator()
1420 self.__saveMessagesAct = \ 1434 self.__saveMessagesAct = self.__messagesMenu.addAction(
1421 self.__messagesMenu.addAction( 1435 UI.PixmapCache.getIcon("fileSave.png"),
1422 UI.PixmapCache.getIcon("fileSave.png"), 1436 self.tr("Save"), self.__saveMessages)
1423 self.tr("Save"), self.__saveMessages)
1424 self.__messagesMenu.addSeparator() 1437 self.__messagesMenu.addSeparator()
1425 self.__setMarkerMessagesAct = self.__messagesMenu.addAction( 1438 self.__setMarkerMessagesAct = self.__messagesMenu.addAction(
1426 self.tr("Mark Current Position"), self.setMarkerLine) 1439 self.tr("Mark Current Position"), self.setMarkerLine)
1427 self.__unsetMarkerMessagesAct = self.__messagesMenu.addAction( 1440 self.__unsetMarkerMessagesAct = self.__messagesMenu.addAction(
1428 self.tr("Remove Position Marker"), 1441 self.tr("Remove Position Marker"),
1655 # group(3) host 1668 # group(3) host
1656 # group(4) nick 1669 # group(4) nick
1657 # group(5) user flags 1670 # group(5) user flags
1658 # group(6) real name 1671 # group(6) real name
1659 if match.group(1).lower() == self.__name.lower(): 1672 if match.group(1).lower() == self.__name.lower():
1660 away = self.tr(" (Away)") if match.group(5).startswith("G") \ 1673 away = (
1661 else "" 1674 self.tr(" (Away)")
1675 if match.group(5).startswith("G") else ""
1676 )
1662 self.__addManagementMessage( 1677 self.__addManagementMessage(
1663 self.tr("Who"), 1678 self.tr("Who"),
1664 self.tr("{0} is {1}@{2} ({3}){4}").format( 1679 self.tr("{0} is {1}@{2} ({3}){4}").format(
1665 match.group(4), match.group(2), match.group(3), 1680 match.group(4), match.group(2), match.group(3),
1666 match.group(6), away)) 1681 match.group(6), away))
1709 # generate the list of channels the user is in 1724 # generate the list of channels the user is in
1710 channelList = match.group(2).split() 1725 channelList = match.group(2).split()
1711 for channel in channelList: 1726 for channel in channelList:
1712 if channel.startswith(("*", "&")): 1727 if channel.startswith(("*", "&")):
1713 adminChannels.append(channel[1:]) 1728 adminChannels.append(channel[1:])
1714 elif channel.startswith(("!", "~")) and \ 1729 elif (
1715 self.__ircWidget.isChannelName(channel[1:]): 1730 channel.startswith(("!", "~")) and
1731 self.__ircWidget.isChannelName(channel[1:])
1732 ):
1716 ownerChannels.append(channel[1:]) 1733 ownerChannels.append(channel[1:])
1717 elif channel.startswith("@+"): 1734 elif channel.startswith("@+"):
1718 opChannels.append(channel[2:]) 1735 opChannels.append(channel[2:])
1719 elif channel.startswith("@"): 1736 elif channel.startswith("@"):
1720 opChannels.append(channel[1:]) 1737 opChannels.append(channel[1:])

eric ide

mercurial