23 arrived (string, string) |
23 arrived (string, string) |
24 @signal newParticipant(nickname) emitted after a new participant joined (string) |
24 @signal newParticipant(nickname) emitted after a new participant joined (string) |
25 @signal participantLeft(nickname) emitted after a participant left (string) |
25 @signal participantLeft(nickname) emitted after a participant left (string) |
26 @signal connectionError(message) emitted when a connection error occurs (string) |
26 @signal connectionError(message) emitted when a connection error occurs (string) |
27 @signal cannotConnect() emitted, if the initial connection fails |
27 @signal cannotConnect() emitted, if the initial connection fails |
|
28 @signal editorCommand(hash, filename, message) emitted when an editor command |
|
29 has been received (string, string, string) |
28 """ |
30 """ |
29 newMessage = pyqtSignal(str, str) |
31 newMessage = pyqtSignal(str, str) |
30 newParticipant = pyqtSignal(str) |
32 newParticipant = pyqtSignal(str) |
31 participantLeft = pyqtSignal(str) |
33 participantLeft = pyqtSignal(str) |
32 connectionError = pyqtSignal(str) |
34 connectionError = pyqtSignal(str) |
33 cannotConnect = pyqtSignal() |
35 cannotConnect = pyqtSignal() |
|
36 editorCommand = pyqtSignal(str, str, str) |
34 |
37 |
35 def __init__(self): |
38 def __init__(self): |
36 """ |
39 """ |
37 Constructor |
40 Constructor |
38 """ |
41 """ |
201 if self.hasConnection(connection.peerAddress(), connection.peerPort()): |
204 if self.hasConnection(connection.peerAddress(), connection.peerPort()): |
202 return |
205 return |
203 |
206 |
204 connection.newMessage.connect(self.newMessage) |
207 connection.newMessage.connect(self.newMessage) |
205 connection.getParticipants.connect(self.__getParticipants) |
208 connection.getParticipants.connect(self.__getParticipants) |
|
209 connection.editorCommand.connect(self.editorCommand) |
206 |
210 |
207 self.__peers[connection.peerAddress()].append(connection) |
211 self.__peers[connection.peerAddress()].append(connection) |
208 nick = connection.name() |
212 nick = connection.name() |
209 if nick != "": |
213 if nick != "": |
210 self.newParticipant.emit(nick) |
214 self.newParticipant.emit(nick) |
254 else: |
258 else: |
255 if not self.hasConnection(QHostAddress(host), port): |
259 if not self.hasConnection(QHostAddress(host), port): |
256 connection = Connection(self) |
260 connection = Connection(self) |
257 self.__newConnection(connection) |
261 self.__newConnection(connection) |
258 connection.connectToHost(host, port) |
262 connection.connectToHost(host, port) |
|
263 |
|
264 def sendEditorCommand(self, projectHash, filename, message): |
|
265 """ |
|
266 Public method to send an editor command. |
|
267 |
|
268 @param projectHash hash of the project (string) |
|
269 @param filename project relative universal file name of |
|
270 the sending editor (string) |
|
271 @param message editor command to be sent (string) |
|
272 """ |
|
273 for connectionList in self.__peers.values(): |
|
274 for connection in connectionList: |
|
275 connection.sendEditorCommand(projectHash, filename, message) |