36 Ping = 1 |
36 Ping = 1 |
37 Pong = 2 |
37 Pong = 2 |
38 Greeting = 3 |
38 Greeting = 3 |
39 GetParticipants = 4 |
39 GetParticipants = 4 |
40 Participants = 5 |
40 Participants = 5 |
|
41 Editor = 6 |
41 Undefined = 99 |
42 Undefined = 99 |
42 |
43 |
43 ProtocolMessage = "MESSAGE" |
44 ProtocolMessage = "MESSAGE" |
44 ProtocolPing = "PING" |
45 ProtocolPing = "PING" |
45 ProtocolPong = "PONG" |
46 ProtocolPong = "PONG" |
46 ProtocolGreeting = "GREETING" |
47 ProtocolGreeting = "GREETING" |
47 ProtocolGetParticipants = "GET_PARTICIPANTS" |
48 ProtocolGetParticipants = "GET_PARTICIPANTS" |
48 ProtocolParticipants = "PARTICIPANTS" |
49 ProtocolParticipants = "PARTICIPANTS" |
|
50 ProtocolEditor = "EDITOR" |
49 |
51 |
50 readyForUse = pyqtSignal() |
52 readyForUse = pyqtSignal() |
51 newMessage = pyqtSignal(str, str) |
53 newMessage = pyqtSignal(str, str) |
52 getParticipants = pyqtSignal() |
54 getParticipants = pyqtSignal() |
53 participants = pyqtSignal(list) |
55 participants = pyqtSignal(list) |
|
56 editorCommand = pyqtSignal(str, str, str) |
54 |
57 |
55 def __init__(self, parent = None): |
58 def __init__(self, parent = None): |
56 """ |
59 """ |
57 Constructor |
60 Constructor |
58 |
61 |
265 self.__currentDataType = Connection.Greeting |
268 self.__currentDataType = Connection.Greeting |
266 elif self.__buffer == Connection.ProtocolGetParticipants: |
269 elif self.__buffer == Connection.ProtocolGetParticipants: |
267 self.__currentDataType = Connection.GetParticipants |
270 self.__currentDataType = Connection.GetParticipants |
268 elif self.__buffer == Connection.ProtocolParticipants: |
271 elif self.__buffer == Connection.ProtocolParticipants: |
269 self.__currentDataType = Connection.Participants |
272 self.__currentDataType = Connection.Participants |
|
273 elif self.__buffer == Connection.ProtocolEditor: |
|
274 self.__currentDataType = Connection.Editor |
270 else: |
275 else: |
271 self.__currentDataType = Connection.Undefined |
276 self.__currentDataType = Connection.Undefined |
272 self.abort() |
277 self.abort() |
273 return False |
278 return False |
274 |
279 |
318 if msg == "<empty>": |
323 if msg == "<empty>": |
319 participantsList = [] |
324 participantsList = [] |
320 else: |
325 else: |
321 participantsList = msg.split(SeparatorToken) |
326 participantsList = msg.split(SeparatorToken) |
322 self.participants.emit(participantsList[:]) |
327 self.participants.emit(participantsList[:]) |
|
328 elif self.__currentDataType == Connection.Editor: |
|
329 hash, fn, msg = str(self.__buffer, encoding = "utf-8").split(SeparatorToken) |
|
330 self.editorCommand.emit(hash, fn, msg) |
323 |
331 |
324 self.__currentDataType = Connection.Undefined |
332 self.__currentDataType = Connection.Undefined |
325 self.__numBytesForCurrentDataType = 0 |
333 self.__numBytesForCurrentDataType = 0 |
326 self.__buffer.clear() |
334 self.__buffer.clear() |
327 |
335 |
345 message = "<empty>" |
353 message = "<empty>" |
346 msg = QByteArray(message.encode("utf-8")) |
354 msg = QByteArray(message.encode("utf-8")) |
347 data = QByteArray("{0}{1}{2}{1}".format( |
355 data = QByteArray("{0}{1}{2}{1}".format( |
348 Connection.ProtocolParticipants, SeparatorToken, msg.size())) + msg |
356 Connection.ProtocolParticipants, SeparatorToken, msg.size())) + msg |
349 self.write(data) |
357 self.write(data) |
|
358 |
|
359 def sendEditorCommand(self, projectHash, filename, message): |
|
360 """ |
|
361 Public method to send an editor command. |
|
362 |
|
363 @param projectHash hash of the project (string) |
|
364 @param filename project relative universal file name of |
|
365 the sending editor (string) |
|
366 @param message editor command to be sent (string) |
|
367 """ |
|
368 msg = QByteArray("{0}{1}{2}{1}{3}".format( |
|
369 projectHash, SeparatorToken, filename, message).encode("utf-8")) |
|
370 data = QByteArray("{0}{1}{2}{1}".format( |
|
371 Connection.ProtocolEditor, SeparatorToken, msg.size())) + msg |
|
372 self.write(data) |