mirror of
https://github.com/Syncplay/syncplay
synced 2025-03-05 03:07:45 +00:00
Improve chat/GUI handling of < and > characters
This commit is contained in:
parent
665956b84c
commit
ddae114694
@ -153,7 +153,8 @@ STYLE_READY_PUSHBUTTON = "QPushButton { text-align: left; padding: 10px 5px 10px
|
|||||||
STYLE_AUTO_PLAY_PUSHBUTTON = "QPushButton { text-align: left; padding: 5px 5px 5px 5px; }"
|
STYLE_AUTO_PLAY_PUSHBUTTON = "QPushButton { text-align: left; padding: 5px 5px 5px 5px; }"
|
||||||
STYLE_NOTIFICATIONBOX = "Username { color: #367AA9; font-weight:bold; }"
|
STYLE_NOTIFICATIONBOX = "Username { color: #367AA9; font-weight:bold; }"
|
||||||
STYLE_CONTACT_INFO = u"<span style=\"color: grey\"><strong><small>{}</span><br /><br />" # Contact info message
|
STYLE_CONTACT_INFO = u"<span style=\"color: grey\"><strong><small>{}</span><br /><br />" # Contact info message
|
||||||
STYLE_USERNAME = "color: #367AA9; font-weight:bold;"
|
STYLE_USER_MESSAGE = u"<span style=\"{}\"><{}></span> {}"
|
||||||
|
STYLE_USERNAME = u"color: #367AA9; font-weight:bold;"
|
||||||
STYLE_ERRORNOTIFICATION = "color: red;"
|
STYLE_ERRORNOTIFICATION = "color: red;"
|
||||||
STYLE_DIFFERENTITEM_COLOR = 'red'
|
STYLE_DIFFERENTITEM_COLOR = 'red'
|
||||||
STYLE_NOFILEITEM_COLOR = 'blue'
|
STYLE_NOFILEITEM_COLOR = 'blue'
|
||||||
@ -180,6 +181,7 @@ UI_COMMAND_REGEX = r"^(?P<command>[^\ ]+)(?:\ (?P<parameter>.+))?"
|
|||||||
UI_OFFSET_REGEX = r"^(?:o|offset)\ ?(?P<sign>[/+-])?(?P<time>\d{1,9}(?:[^\d\.](?:\d{1,9})){0,2}(?:\.(?:\d{1,3}))?)$"
|
UI_OFFSET_REGEX = r"^(?:o|offset)\ ?(?P<sign>[/+-])?(?P<time>\d{1,9}(?:[^\d\.](?:\d{1,9})){0,2}(?:\.(?:\d{1,3}))?)$"
|
||||||
UI_SEEK_REGEX = r"^(?:s|seek)?\ ?(?P<sign>[+-])?(?P<time>\d{1,4}(?:[^\d\.](?:\d{1,6})){0,2}(?:\.(?:\d{1,3}))?)$"
|
UI_SEEK_REGEX = r"^(?:s|seek)?\ ?(?P<sign>[+-])?(?P<time>\d{1,4}(?:[^\d\.](?:\d{1,6})){0,2}(?:\.(?:\d{1,3}))?)$"
|
||||||
PARSE_TIME_REGEX = r'(:?(?:(?P<hours>\d+?)[^\d\.])?(?:(?P<minutes>\d+?))?[^\d\.])?(?P<seconds>\d+?)(?:\.(?P<miliseconds>\d+?))?$'
|
PARSE_TIME_REGEX = r'(:?(?:(?P<hours>\d+?)[^\d\.])?(?:(?P<minutes>\d+?))?[^\d\.])?(?P<seconds>\d+?)(?:\.(?P<miliseconds>\d+?))?$'
|
||||||
|
MESSAGE_WITH_USERNAME_REGEX = "^(<(?P<username>[^<>]+)>)(?P<message>.*)"
|
||||||
SERVER_MAX_TEMPLATE_LENGTH = 10000
|
SERVER_MAX_TEMPLATE_LENGTH = 10000
|
||||||
PRIVACY_SENDRAW_MODE = "SendRaw"
|
PRIVACY_SENDRAW_MODE = "SendRaw"
|
||||||
PRIVACY_SENDHASHED_MODE = "SendHashed"
|
PRIVACY_SENDHASHED_MODE = "SendHashed"
|
||||||
|
@ -249,10 +249,9 @@ class SyncClientProtocol(JSONCommandProtocol):
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
def handleChat(self,message):
|
def handleChat(self,message):
|
||||||
userMessage = message['message'].replace(u"<",u"<<").replace(u">",u">>")
|
userMessage = message['message']
|
||||||
messageString = u"<{}> {}".format(message['username'], userMessage)
|
messageString = u"<{}> {}".format(message['username'], userMessage)
|
||||||
self._client.ui.showMessage(messageString)
|
self._client.ui.showMessage(messageString)
|
||||||
#TODO
|
|
||||||
|
|
||||||
def setReady(self, isReady, manuallyInitiated=True):
|
def setReady(self, isReady, manuallyInitiated=True):
|
||||||
self.sendSet({
|
self.sendSet({
|
||||||
|
@ -337,13 +337,14 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
|
|
||||||
def showMessage(self, message, noTimestamp=False):
|
def showMessage(self, message, noTimestamp=False):
|
||||||
message = unicode(message)
|
message = unicode(message)
|
||||||
message = message.replace(u"&", u"&").replace(u'"', u""").replace(u"<", u"<").replace(">", u">")
|
username = None
|
||||||
message = message.replace(u"<<", u"<LT>")
|
messageWithUsername = re.match(constants.MESSAGE_WITH_USERNAME_REGEX, message, re.UNICODE)
|
||||||
message = message.replace(u">>", u"<GT>")
|
if messageWithUsername:
|
||||||
message = message.replace(u"<", u"<span style=\"{}\"><".format(constants.STYLE_USERNAME))
|
username = messageWithUsername.group("username")
|
||||||
message = message.replace(u">", u"></span>")
|
message = messageWithUsername.group("message")
|
||||||
message = message.replace(u"<LT>;", u"<")
|
message = message.replace(u"&", u"&").replace(u'"', u""").replace(u"<", u"<").replace(u">", u">")
|
||||||
message = message.replace(u"<GT>", u">")
|
if username:
|
||||||
|
message = constants.STYLE_USER_MESSAGE.format(constants.STYLE_USERNAME, username, message)
|
||||||
message = message.replace(u"\n", u"<br />")
|
message = message.replace(u"\n", u"<br />")
|
||||||
if noTimestamp:
|
if noTimestamp:
|
||||||
self.newMessage(u"{}<br />".format(message))
|
self.newMessage(u"{}<br />".format(message))
|
||||||
|
Loading…
Reference in New Issue
Block a user