Network/IRC/IrcChannelWidget.py

changeset 3036
30c81c9e88b8
parent 3034
7ce719013078
child 3060
5883ce99ee12
child 3160
209a07d7e401
equal deleted inserted replaced
3035:36e9f388958b 3036:30c81c9e88b8
347 msg = self.messageEdit.text() 347 msg = self.messageEdit.text()
348 if msg: 348 if msg:
349 self.messages.append( 349 self.messages.append(
350 '<font color="{0}">{2} <b>&lt;</b><font color="{1}">{3}</font>' 350 '<font color="{0}">{2} <b>&lt;</b><font color="{1}">{3}</font>'
351 '<b>&gt;</b> {4}</font>'.format( 351 '<b>&gt;</b> {4}</font>'.format(
352 Preferences.getIrc("ChannelMessageColour"), 352 Preferences.getIrc("ChannelMessageColour"),
353 Preferences.getIrc("OwnNickColour"), 353 Preferences.getIrc("OwnNickColour"),
354 ircTimestamp(), self.__userName, Utilities.html_encode(msg))) 354 ircTimestamp(), self.__userName,
355 Utilities.html_encode(msg)))
355 if msg.startswith("/"): 356 if msg.startswith("/"):
356 if self.__private: 357 if self.__private:
357 E5MessageBox.information( 358 E5MessageBox.information(
358 self, 359 self,
359 self.trUtf8("Send Message"), 360 self.trUtf8("Send Message"),
384 ok = E5MessageBox.yesNo( 385 ok = E5MessageBox.yesNo(
385 self, 386 self,
386 self.trUtf8("Leave IRC channel"), 387 self.trUtf8("Leave IRC channel"),
387 self.trUtf8( 388 self.trUtf8(
388 """Do you really want to leave the IRC channel <b>{0}</b>?""") 389 """Do you really want to leave the IRC channel <b>{0}</b>?""")
389 .format(self.__name)) 390 .format(self.__name))
390 if ok: 391 if ok:
391 if not self.__private: 392 if not self.__private:
392 self.sendData.emit( 393 self.sendData.emit(
393 "PART " + self.__name + " :" + self.__partMessage) 394 "PART " + self.__name + " :" + self.__partMessage)
394 self.channelClosed.emit(self.__name) 395 self.channelClosed.emit(self.__name)
515 @param msg message received from sender (string) 516 @param msg message received from sender (string)
516 """ 517 """
517 self.__appendMessage( 518 self.__appendMessage(
518 '<font color="{0}">{2} <b>&lt;</b><font color="{1}">{3}</font>' 519 '<font color="{0}">{2} <b>&lt;</b><font color="{1}">{3}</font>'
519 '<b>&gt;</b> {4}</font>'.format( 520 '<b>&gt;</b> {4}</font>'.format(
520 Preferences.getIrc("ChannelMessageColour"), 521 Preferences.getIrc("ChannelMessageColour"),
521 Preferences.getIrc("NickColour"), 522 Preferences.getIrc("NickColour"),
522 ircTimestamp(), sender, ircFilter(msg))) 523 ircTimestamp(), sender, ircFilter(msg)))
523 if Preferences.getIrc("ShowNotifications"): 524 if Preferences.getIrc("ShowNotifications"):
524 if Preferences.getIrc("NotifyMessage"): 525 if Preferences.getIrc("NotifyMessage"):
525 self.__ui.showNotification( 526 self.__ui.showNotification(
526 UI.PixmapCache.getPixmap("irc48.png"), 527 UI.PixmapCache.getPixmap("irc48.png"),
527 self.trUtf8("Channel Message"), msg) 528 self.trUtf8("Channel Message"), msg)
528 elif Preferences.getIrc("NotifyNick") and \ 529 elif Preferences.getIrc("NotifyNick") and \
529 self.__userName.lower() in msg.lower(): 530 self.__userName.lower() in msg.lower():
530 self.__ui.showNotification( 531 self.__ui.showNotification(
531 UI.PixmapCache.getPixmap("irc48.png"), 532 UI.PixmapCache.getPixmap("irc48.png"),
532 self.trUtf8("Nick mentioned"), msg) 533 self.trUtf8("Nick mentioned"), msg)
533 534
534 def addUsers(self, users): 535 def addUsers(self, users):
552 if match.group(3).lower() == self.__name.lower(): 553 if match.group(3).lower() == self.__name.lower():
553 if self.__userName != match.group(1): 554 if self.__userName != match.group(1):
554 IrcUserItem(match.group(1), self.usersList) 555 IrcUserItem(match.group(1), self.usersList)
555 msg = self.trUtf8( 556 msg = self.trUtf8(
556 "{0} has joined the channel {1} ({2}).").format( 557 "{0} has joined the channel {1} ({2}).").format(
557 match.group(1), self.__name, match.group(2)) 558 match.group(1), self.__name, match.group(2))
558 self.__addManagementMessage( 559 self.__addManagementMessage(
559 IrcChannelWidget.JoinIndicator, msg) 560 IrcChannelWidget.JoinIndicator, msg)
560 else: 561 else:
561 msg = self.trUtf8( 562 msg = self.trUtf8(
562 "You have joined the channel {0} ({1}).").format( 563 "You have joined the channel {0} ({1}).").format(
563 self.__name, match.group(2)) 564 self.__name, match.group(2))
564 self.__addManagementMessage( 565 self.__addManagementMessage(
565 IrcChannelWidget.JoinIndicator, msg) 566 IrcChannelWidget.JoinIndicator, msg)
566 if Preferences.getIrc("ShowNotifications") and \ 567 if Preferences.getIrc("ShowNotifications") and \
567 Preferences.getIrc("NotifyJoinPart"): 568 Preferences.getIrc("NotifyJoinPart"):
568 self.__ui.showNotification( 569 self.__ui.showNotification(
725 if match.group(1).lower() == self.__name.lower(): 726 if match.group(1).lower() == self.__name.lower():
726 self.__addManagementMessage( 727 self.__addManagementMessage(
727 IrcChannelWidget.MessageIndicator, 728 IrcChannelWidget.MessageIndicator,
728 self.trUtf8("The topic was set by {0} on {1}.").format( 729 self.trUtf8("The topic was set by {0} on {1}.").format(
729 match.group(2), QDateTime.fromTime_t(int(match.group(3))) 730 match.group(2), QDateTime.fromTime_t(int(match.group(3)))
730 .toString("yyyy-MM-dd hh:mm"))) 731 .toString("yyyy-MM-dd hh:mm")))
731 return True 732 return True
732 733
733 return False 734 return False
734 735
735 def __channelUrl(self, match): 736 def __channelUrl(self, match):
794 if match.group(1).lower() == self.__name.lower(): 795 if match.group(1).lower() == self.__name.lower():
795 self.__addManagementMessage( 796 self.__addManagementMessage(
796 IrcChannelWidget.MessageIndicator, 797 IrcChannelWidget.MessageIndicator,
797 self.trUtf8("This channel was created on {0}.").format( 798 self.trUtf8("This channel was created on {0}.").format(
798 QDateTime.fromTime_t(int(match.group(2))) 799 QDateTime.fromTime_t(int(match.group(2)))
799 .toString("yyyy-MM-dd hh:mm"))) 800 .toString("yyyy-MM-dd hh:mm")))
800 return True 801 return True
801 802
802 return False 803 return False
803 804
804 def __updateChannelModes(self, match): 805 def __updateChannelModes(self, match):
1021 if ctcpRequest == "version": 1022 if ctcpRequest == "version":
1022 msg = "Eric IRC client {0}, {1}".format(Version, Copyright) 1023 msg = "Eric IRC client {0}, {1}".format(Version, Copyright)
1023 self.__addManagementMessage( 1024 self.__addManagementMessage(
1024 self.trUtf8("CTCP"), 1025 self.trUtf8("CTCP"),
1025 self.trUtf8("Received Version request from {0}.").format( 1026 self.trUtf8("Received Version request from {0}.").format(
1026 match.group(1))) 1027 match.group(1)))
1027 self.sendCtcpReply.emit(match.group(1), "VERSION " + msg) 1028 self.sendCtcpReply.emit(match.group(1), "VERSION " + msg)
1028 elif ctcpRequest == "ping": 1029 elif ctcpRequest == "ping":
1029 self.__addManagementMessage( 1030 self.__addManagementMessage(
1030 self.trUtf8("CTCP"), 1031 self.trUtf8("CTCP"),
1031 self.trUtf8( 1032 self.trUtf8(
1105 color = Preferences.getIrc("LeaveChannelColour") 1106 color = Preferences.getIrc("LeaveChannelColour")
1106 else: 1107 else:
1107 color = Preferences.getIrc("ChannelInfoColour") 1108 color = Preferences.getIrc("ChannelInfoColour")
1108 self.__appendMessage( 1109 self.__appendMessage(
1109 '<font color="{0}">{1} <b>[</b>{2}<b>]</b> {3}</font>'.format( 1110 '<font color="{0}">{1} <b>[</b>{2}<b>]</b> {3}</font>'.format(
1110 color, ircTimestamp(), indicator, message)) 1111 color, ircTimestamp(), indicator, message))
1111 1112
1112 def __appendMessage(self, message): 1113 def __appendMessage(self, message):
1113 """ 1114 """
1114 Private slot to append a message. 1115 Private slot to append a message.
1115 1116
1197 self, 1198 self,
1198 self.trUtf8("Save Messages"), 1199 self.trUtf8("Save Messages"),
1199 "", 1200 "",
1200 self.trUtf8( 1201 self.trUtf8(
1201 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)") 1202 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)")
1202 .format(htmlExtension), 1203 .format(htmlExtension),
1203 None, 1204 None,
1204 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) 1205 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
1205 if fname: 1206 if fname:
1206 ext = QFileInfo(fname).suffix() 1207 ext = QFileInfo(fname).suffix()
1207 if not ext: 1208 if not ext:
1233 self, 1234 self,
1234 self.trUtf8("Error saving Messages"), 1235 self.trUtf8("Error saving Messages"),
1235 self.trUtf8( 1236 self.trUtf8(
1236 """<p>The messages contents could not be written""" 1237 """<p>The messages contents could not be written"""
1237 """ to <b>{0}</b></p><p>Reason: {1}</p>""") 1238 """ to <b>{0}</b></p><p>Reason: {1}</p>""")
1238 .format(fname, str(err))) 1239 .format(fname, str(err)))
1239 1240
1240 def __initMessagesMenu(self): 1241 def __initMessagesMenu(self):
1241 """ 1242 """
1242 Private slot to initialize the context menu of the messages pane. 1243 Private slot to initialize the context menu of the messages pane.
1243 """ 1244 """
1411 self.initAutoWho() 1412 self.initAutoWho()
1412 else: 1413 else:
1413 self.__addManagementMessage( 1414 self.__addManagementMessage(
1414 self.trUtf8("Who"), 1415 self.trUtf8("Who"),
1415 self.trUtf8("End of WHO list for {0}.").format( 1416 self.trUtf8("End of WHO list for {0}.").format(
1416 match.group(1))) 1417 match.group(1)))
1417 return True 1418 return True
1418 1419
1419 return False 1420 return False
1420 1421
1421 def __whoEntry(self, match): 1422 def __whoEntry(self, match):
1486 channelList = match.group(2).split() 1487 channelList = match.group(2).split()
1487 for channel in channelList: 1488 for channel in channelList:
1488 if channel.startswith(("*", "&")): 1489 if channel.startswith(("*", "&")):
1489 adminChannels.append(channel[1:]) 1490 adminChannels.append(channel[1:])
1490 elif channel.startswith(("!", "~")) and \ 1491 elif channel.startswith(("!", "~")) and \
1491 self.__ircWidget.isChannelName(channel[1:]): 1492 self.__ircWidget.isChannelName(channel[1:]):
1492 ownerChannels.append(channel[1:]) 1493 ownerChannels.append(channel[1:])
1493 elif channel.startswith("@+"): 1494 elif channel.startswith("@+"):
1494 opChannels.append(channel[2:]) 1495 opChannels.append(channel[2:])
1495 elif channel.startswith("@"): 1496 elif channel.startswith("@"):
1496 opChannels.append(channel[1:]) 1497 opChannels.append(channel[1:])
1504 # show messages 1505 # show messages
1505 if userChannels: 1506 if userChannels:
1506 self.__addManagementMessage( 1507 self.__addManagementMessage(
1507 self.trUtf8("Whois"), 1508 self.trUtf8("Whois"),
1508 self.trUtf8("{0} is a user on channels: {1}").format( 1509 self.trUtf8("{0} is a user on channels: {1}").format(
1509 match.group(1), " ".join(userChannels))) 1510 match.group(1), " ".join(userChannels)))
1510 if voiceChannels: 1511 if voiceChannels:
1511 self.__addManagementMessage( 1512 self.__addManagementMessage(
1512 self.trUtf8("Whois"), 1513 self.trUtf8("Whois"),
1513 self.trUtf8("{0} has voice on channels: {1}").format( 1514 self.trUtf8("{0} has voice on channels: {1}").format(
1514 match.group(1), " ".join(voiceChannels))) 1515 match.group(1), " ".join(voiceChannels)))
1515 if halfopChannels: 1516 if halfopChannels:
1516 self.__addManagementMessage( 1517 self.__addManagementMessage(
1517 self.trUtf8("Whois"), 1518 self.trUtf8("Whois"),
1518 self.trUtf8("{0} is a halfop on channels: {1}").format( 1519 self.trUtf8("{0} is a halfop on channels: {1}").format(
1519 match.group(1), " ".join(halfopChannels))) 1520 match.group(1), " ".join(halfopChannels)))
1520 if opChannels: 1521 if opChannels:
1521 self.__addManagementMessage( 1522 self.__addManagementMessage(
1522 self.trUtf8("Whois"), 1523 self.trUtf8("Whois"),
1523 self.trUtf8("{0} is an operator on channels: {1}").format( 1524 self.trUtf8("{0} is an operator on channels: {1}").format(
1524 match.group(1), " ".join(opChannels))) 1525 match.group(1), " ".join(opChannels)))
1525 if ownerChannels: 1526 if ownerChannels:
1526 self.__addManagementMessage( 1527 self.__addManagementMessage(
1527 self.trUtf8("Whois"), 1528 self.trUtf8("Whois"),
1528 self.trUtf8("{0} is owner of channels: {1}").format( 1529 self.trUtf8("{0} is owner of channels: {1}").format(
1529 match.group(1), " ".join(ownerChannels))) 1530 match.group(1), " ".join(ownerChannels)))
1530 if adminChannels: 1531 if adminChannels:
1531 self.__addManagementMessage( 1532 self.__addManagementMessage(
1532 self.trUtf8("Whois"), 1533 self.trUtf8("Whois"),
1533 self.trUtf8("{0} is admin on channels: {1}").format( 1534 self.trUtf8("{0} is admin on channels: {1}").format(
1534 match.group(1), " ".join(adminChannels))) 1535 match.group(1), " ".join(adminChannels)))
1535 return True 1536 return True
1536 1537
1537 return False 1538 return False
1538 1539
1539 def __whoIsServer(self, match): 1540 def __whoIsServer(self, match):
1616 hoursString = self.trUtf8("%n hour(s)", "", hours) 1617 hoursString = self.trUtf8("%n hour(s)", "", hours)
1617 minutesString = self.trUtf8("%n minute(s)", "", minutes) 1618 minutesString = self.trUtf8("%n minute(s)", "", minutes)
1618 secondsString = self.trUtf8("%n second(s)", "", seconds) 1619 secondsString = self.trUtf8("%n second(s)", "", seconds)
1619 self.__addManagementMessage( 1620 self.__addManagementMessage(
1620 self.trUtf8("Whois"), 1621 self.trUtf8("Whois"),
1621 self.trUtf8("{0} has been idle for {1}, {2}, and {3}.", 1622 self.trUtf8(
1622 "{0} = name of person, {1} = (x hours), " 1623 "{0} has been idle for {1}, {2}, and {3}.",
1623 "{2} = (x minutes), {3} = (x seconds)").format( 1624 "{0} = name of person, {1} = (x hours), "
1624 match.group(1), hoursString, minutesString, secondsString)) 1625 "{2} = (x minutes), {3} = (x seconds)")
1626 .format(match.group(1), hoursString, minutesString,
1627 secondsString))
1625 elif minutes: 1628 elif minutes:
1626 minutesString = self.trUtf8("%n minute(s)", "", minutes) 1629 minutesString = self.trUtf8("%n minute(s)", "", minutes)
1627 secondsString = self.trUtf8("%n second(s)", "", seconds) 1630 secondsString = self.trUtf8("%n second(s)", "", seconds)
1628 self.__addManagementMessage( 1631 self.__addManagementMessage(
1629 self.trUtf8("Whois"), 1632 self.trUtf8("Whois"),
1630 self.trUtf8("{0} has been idle for {1} and {2}.", 1633 self.trUtf8(
1631 "{0} = name of person, {1} = (x minutes), " 1634 "{0} has been idle for {1} and {2}.",
1632 "{3} = (x seconds)").format( 1635 "{0} = name of person, {1} = (x minutes), "
1633 match.group(1), minutesString, secondsString)) 1636 "{3} = (x seconds)")
1637 .format(match.group(1), minutesString, secondsString))
1634 else: 1638 else:
1635 self.__addManagementMessage( 1639 self.__addManagementMessage(
1636 self.trUtf8("Whois"), 1640 self.trUtf8("Whois"),
1637 self.trUtf8( 1641 self.trUtf8(
1638 "{0} has been idle for %n second(s).", "", 1642 "{0} has been idle for %n second(s).", "",
1640 1644
1641 if not signonTime.isNull(): 1645 if not signonTime.isNull():
1642 self.__addManagementMessage( 1646 self.__addManagementMessage(
1643 self.trUtf8("Whois"), 1647 self.trUtf8("Whois"),
1644 self.trUtf8("{0} has been online since {1}.").format( 1648 self.trUtf8("{0} has been online since {1}.").format(
1645 match.group(1), 1649 match.group(1),
1646 signonTime.toString("yyyy-MM-dd, hh:mm:ss"))) 1650 signonTime.toString("yyyy-MM-dd, hh:mm:ss")))
1647 return True 1651 return True
1648 1652
1649 return False 1653 return False
1650 1654
1651 def __whoIsEnd(self, match): 1655 def __whoIsEnd(self, match):
1770 # group(3) IP 1774 # group(3) IP
1771 if match.group(1) == self.__whoIsNick: 1775 if match.group(1) == self.__whoIsNick:
1772 self.__addManagementMessage( 1776 self.__addManagementMessage(
1773 self.trUtf8("Whois"), 1777 self.trUtf8("Whois"),
1774 self.trUtf8("{0} is connecting from {1} (IP: {2}).").format( 1778 self.trUtf8("{0} is connecting from {1} (IP: {2}).").format(
1775 match.group(1), match.group(2), match.group(3))) 1779 match.group(1), match.group(2), match.group(3)))
1776 return True 1780 return True
1777 1781
1778 return False 1782 return False
1779 1783
1780 def __setEditTopicButton(self): 1784 def __setEditTopicButton(self):

eric ide

mercurial