70 UI.PixmapCache.getIcon("clearLeft.png")) |
70 UI.PixmapCache.getIcon("clearLeft.png")) |
71 |
71 |
72 self.__client = CooperationClient(self) |
72 self.__client = CooperationClient(self) |
73 self.__myNickName = self.__client.nickName() |
73 self.__myNickName = self.__client.nickName() |
74 |
74 |
|
75 self.__initChatMenu() |
|
76 self.__initUsersMenu() |
|
77 |
|
78 self.messageEdit.returnPressed.connect(self.__handleMessage) |
|
79 self.sendButton.clicked.connect(self.__handleMessage) |
|
80 self.__client.newMessage.connect(self.appendMessage) |
|
81 self.__client.newParticipant.connect(self.__newParticipant) |
|
82 self.__client.participantLeft.connect(self.__participantLeft) |
|
83 self.__client.connectionError.connect(self.__showErrorMessage) |
|
84 self.__client.cannotConnect.connect(self.__initialConnectionRefused) |
|
85 self.__client.editorCommand.connect(self.__editorCommandMessage) |
|
86 |
|
87 self.serverButton.setText(self.trUtf8("Start Server")) |
|
88 self.serverLed.setColor(QColor(Qt.red)) |
|
89 if port == -1: |
|
90 port = Preferences.getCooperation("ServerPort") |
|
91 |
|
92 self.serverPortSpin.setValue(port) |
|
93 |
|
94 self.__setConnected(False) |
|
95 |
|
96 if Preferences.getCooperation("AutoStartServer"): |
|
97 self.on_serverButton_clicked() |
|
98 |
|
99 self.recent = [] |
|
100 self.__loadHostsHistory() |
|
101 |
|
102 def __loadHostsHistory(self): |
|
103 """ |
|
104 Private method to load the recently connected hosts. |
|
105 """ |
|
106 self.__recent = [] |
|
107 Preferences.Prefs.rsettings.sync() |
|
108 rh = Preferences.Prefs.rsettings.value(recentNameHosts) |
|
109 if rh is not None: |
|
110 self.__recent = rh[:20] |
|
111 self.hostEdit.clear() |
|
112 self.hostEdit.addItems(self.__recent) |
|
113 self.hostEdit.clearEditText() |
|
114 |
|
115 def __saveHostsHistory(self): |
|
116 """ |
|
117 Private method to save the list of recently connected hosts. |
|
118 """ |
|
119 Preferences.Prefs.rsettings.setValue(recentNameHosts, self.__recent) |
|
120 Preferences.Prefs.rsettings.sync() |
|
121 |
|
122 def __setHostsHistory(self, host): |
|
123 """ |
|
124 Private method to remember the given host as the most recent entry. |
|
125 |
|
126 @param host host entry to remember (string) |
|
127 """ |
|
128 if host in self.__recent: |
|
129 self.__recent.remove(host) |
|
130 self.__recent.insert(0, host) |
|
131 self.__saveHostsHistory() |
|
132 self.hostEdit.clear() |
|
133 self.hostEdit.addItems(self.__recent) |
|
134 |
|
135 def __clearHostsHistory(self): |
|
136 """ |
|
137 Private slot to clear the hosts history. |
|
138 """ |
|
139 self.__recent = [] |
|
140 self.__saveHostsHistory() |
|
141 self.hostEdit.clear() |
|
142 self.hostEdit.addItems(self.__recent) |
|
143 |
|
144 def __handleMessage(self): |
|
145 """ |
|
146 Private slot handling the Return key pressed in the message edit. |
|
147 """ |
|
148 text = self.messageEdit.text() |
|
149 if text == "": |
|
150 return |
|
151 |
|
152 if text.startswith("/"): |
|
153 self.__showErrorMessage( |
|
154 self.trUtf8("! Unknown command: {0}\n").format(text.split()[0])) |
|
155 else: |
|
156 self.__client.sendMessage(text) |
|
157 self.appendMessage(self.__myNickName, text) |
|
158 |
|
159 self.messageEdit.clear() |
|
160 |
|
161 def __newParticipant(self, nick): |
|
162 """ |
|
163 Private slot handling a new participant joining. |
|
164 |
|
165 @param nick nick name of the new participant (string) |
|
166 """ |
|
167 if nick == "": |
|
168 return |
|
169 |
|
170 color = self.chatEdit.textColor() |
|
171 self.chatEdit.setTextColor(Qt.gray) |
|
172 self.chatEdit.append( |
|
173 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") |
|
174 self.chatEdit.append(self.trUtf8("* {0} has joined.\n").format(nick)) |
|
175 self.chatEdit.setTextColor(color) |
|
176 |
|
177 QListWidgetItem( |
|
178 UI.PixmapCache.getIcon( |
|
179 "chatUser{0}.png".format(1 + self.usersList.count() % 6)), |
|
180 nick, self.usersList) |
|
181 |
|
182 if not self.__connected: |
|
183 self.__setConnected(True) |
|
184 |
|
185 def __participantLeft(self, nick): |
|
186 """ |
|
187 Private slot handling a participant leaving the session. |
|
188 |
|
189 @param nick nick name of the participant (string) |
|
190 """ |
|
191 if nick == "": |
|
192 return |
|
193 |
|
194 items = self.usersList.findItems(nick, Qt.MatchExactly) |
|
195 for item in items: |
|
196 self.usersList.takeItem(self.usersList.row(item)) |
|
197 del item |
|
198 |
|
199 color = self.chatEdit.textColor() |
|
200 self.chatEdit.setTextColor(Qt.gray) |
|
201 self.chatEdit.append( |
|
202 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") |
|
203 self.chatEdit.append(self.trUtf8("* {0} has left.\n").format(nick)) |
|
204 self.chatEdit.setTextColor(color) |
|
205 |
|
206 if not self.__client.hasConnections(): |
|
207 self.__setConnected(False) |
|
208 |
|
209 def appendMessage(self, from_, message): |
|
210 """ |
|
211 Public slot to append a message to the display. |
|
212 |
|
213 @param from_ originator of the message (string) |
|
214 @param message message to be appended (string) |
|
215 """ |
|
216 if from_ == "" or message == "": |
|
217 return |
|
218 |
|
219 self.chatEdit.append( |
|
220 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + \ |
|
221 " <" + from_ + ">:") |
|
222 self.chatEdit.append(message + "\n") |
|
223 bar = self.chatEdit.verticalScrollBar() |
|
224 bar.setValue(bar.maximum()) |
|
225 |
|
226 @pyqtSlot(str) |
|
227 def on_hostEdit_editTextChanged(self, host): |
|
228 """ |
|
229 Private slot handling the entry of a host to connect to. |
|
230 |
|
231 @param host host to connect to (string) |
|
232 """ |
|
233 if not self.__connected: |
|
234 self.connectButton.setEnabled(host != "") |
|
235 |
|
236 def __getConnectionParameters(self): |
|
237 """ |
|
238 Private method to determine the connection parameters. |
|
239 |
|
240 @return tuple with hostname and port (string, integer) |
|
241 """ |
|
242 hostEntry = self.hostEdit.currentText() |
|
243 if ":" in hostEntry: |
|
244 host, port = hostEntry.split(":") |
|
245 try: |
|
246 port = int(port) |
|
247 except ValueError: |
|
248 port = Preferences.getCooperation("ServerPort") |
|
249 self.hostEdit.setEditText("{0}:{1}".format(host, port)) |
|
250 else: |
|
251 host = hostEntry |
|
252 port = Preferences.getCooperation("ServerPort") |
|
253 self.hostEdit.setEditText("{0}:{1}".format(host, port)) |
|
254 return host, port |
|
255 |
|
256 @pyqtSlot() |
|
257 def on_connectButton_clicked(self): |
|
258 """ |
|
259 Private slot initiating the connection. |
|
260 """ |
|
261 if not self.__connected: |
|
262 host, port = self.__getConnectionParameters() |
|
263 self.__setHostsHistory(self.hostEdit.currentText()) |
|
264 if not self.__client.server().isListening(): |
|
265 self.on_serverButton_clicked() |
|
266 if self.__client.server().isListening(): |
|
267 self.__client.connectToHost(host, port) |
|
268 self.__setConnected(True) |
|
269 else: |
|
270 self.__client.disconnectConnections() |
|
271 self.__setConnected(False) |
|
272 |
|
273 @pyqtSlot() |
|
274 def on_clearHostsButton_clicked(self): |
|
275 """ |
|
276 Private slot to clear the hosts list. |
|
277 """ |
|
278 self.__clearHostsHistory() |
|
279 |
|
280 @pyqtSlot() |
|
281 def on_serverButton_clicked(self): |
|
282 """ |
|
283 Private slot to start the server. |
|
284 """ |
|
285 if self.__client.server().isListening(): |
|
286 self.__client.server().close() |
|
287 self.serverButton.setText(self.trUtf8("Start Server")) |
|
288 self.serverPortSpin.setEnabled(True) |
|
289 if self.serverPortSpin.value() != Preferences.getCooperation("ServerPort"): |
|
290 self.serverPortSpin.setValue(Preferences.getCooperation("ServerPort")) |
|
291 self.serverLed.setColor(QColor(Qt.red)) |
|
292 else: |
|
293 res, port = self.__client.server().startListening(self.serverPortSpin.value()) |
|
294 if res: |
|
295 self.serverButton.setText(self.trUtf8("Stop Server")) |
|
296 self.serverPortSpin.setValue(port) |
|
297 self.serverPortSpin.setEnabled(False) |
|
298 self.serverLed.setColor(QColor(Qt.green)) |
|
299 else: |
|
300 self.__showErrorMessage( |
|
301 self.trUtf8("! Server Error: {0}\n").format( |
|
302 self.__client.server().errorString()) |
|
303 ) |
|
304 |
|
305 def __setConnected(self, connected): |
|
306 """ |
|
307 Private slot to set the connected state. |
|
308 |
|
309 @param connected new connected state (boolean) |
|
310 """ |
|
311 if connected: |
|
312 self.connectButton.setText(self.trUtf8("Disconnect")) |
|
313 self.connectButton.setEnabled(True) |
|
314 self.connectionLed.setColor(QColor(Qt.green)) |
|
315 else: |
|
316 self.connectButton.setText(self.trUtf8("Connect")) |
|
317 self.connectButton.setEnabled(self.hostEdit.currentText() != "") |
|
318 self.connectionLed.setColor(QColor(Qt.red)) |
|
319 self.on_cancelEditButton_clicked() |
|
320 self.shareButton.setChecked(False) |
|
321 self.on_shareButton_clicked(False) |
|
322 self.__connected = connected |
|
323 self.hostEdit.setEnabled(not connected) |
|
324 self.serverButton.setEnabled(not connected) |
|
325 self.sharingGroup.setEnabled(connected) |
|
326 |
|
327 if connected: |
|
328 vm = e5App().getObject("ViewManager") |
|
329 aw = vm.activeWindow() |
|
330 if aw: |
|
331 self.checkEditorActions(aw) |
|
332 |
|
333 def __showErrorMessage(self, message): |
|
334 """ |
|
335 Private slot to show an error message. |
|
336 |
|
337 @param message error message to show (string) |
|
338 """ |
|
339 color = self.chatEdit.textColor() |
|
340 self.chatEdit.setTextColor(Qt.red) |
|
341 self.chatEdit.append( |
|
342 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") |
|
343 self.chatEdit.append(message + "\n") |
|
344 self.chatEdit.setTextColor(color) |
|
345 |
|
346 def __initialConnectionRefused(self): |
|
347 """ |
|
348 Private slot to handle the refusal of the initial connection. |
|
349 """ |
|
350 self.__setConnected(False) |
|
351 |
|
352 def preferencesChanged(self): |
|
353 """ |
|
354 Public slot to handle a change of preferences. |
|
355 """ |
|
356 if not self.__client.server().isListening(): |
|
357 self.serverPortSpin.setValue(Preferences.getCooperation("ServerPort")) |
|
358 if Preferences.getCooperation("AutoStartServer"): |
|
359 self.on_serverButton_clicked() |
|
360 |
|
361 def getClient(self): |
|
362 """ |
|
363 Public method to get a reference to the cooperation client. |
|
364 """ |
|
365 return self.__client |
|
366 |
|
367 def __editorCommandMessage(self, hash, fileName, message): |
|
368 """ |
|
369 Private slot to handle editor command messages from the client. |
|
370 |
|
371 @param hash hash of the project (string) |
|
372 @param fileName project relative file name of the editor (string) |
|
373 @param message command message (string) |
|
374 """ |
|
375 self.editorCommand.emit(hash, fileName, message) |
|
376 |
|
377 if message.startswith(Editor.StartEditToken + Editor.Separator) or \ |
|
378 message.startswith(Editor.EndEditToken + Editor.Separator): |
|
379 vm = e5App().getObject("ViewManager") |
|
380 aw = vm.activeWindow() |
|
381 if aw: |
|
382 self.checkEditorActions(aw) |
|
383 |
|
384 @pyqtSlot(bool) |
|
385 def on_shareButton_clicked(self, checked): |
|
386 """ |
|
387 Private slot to share the current editor. |
|
388 |
|
389 @param checked flag indicating the button state (boolean) |
|
390 """ |
|
391 if checked: |
|
392 self.shareButton.setIcon( |
|
393 UI.PixmapCache.getIcon("sharedEditConnected.png")) |
|
394 else: |
|
395 self.shareButton.setIcon( |
|
396 UI.PixmapCache.getIcon("sharedEditDisconnected.png")) |
|
397 self.startEditButton.setEnabled(checked) |
|
398 |
|
399 self.shareEditor.emit(checked) |
|
400 |
|
401 @pyqtSlot(bool) |
|
402 def on_startEditButton_clicked(self, checked): |
|
403 """ |
|
404 Private slot to start a shared edit session. |
|
405 |
|
406 @param checked flag indicating the button state (boolean) |
|
407 """ |
|
408 if checked: |
|
409 self.sendEditButton.setEnabled(True) |
|
410 self.cancelEditButton.setEnabled(True) |
|
411 self.shareButton.setEnabled(False) |
|
412 self.startEditButton.setEnabled(False) |
|
413 |
|
414 self.startEdit.emit() |
|
415 |
|
416 @pyqtSlot() |
|
417 def on_sendEditButton_clicked(self): |
|
418 """ |
|
419 Private slot to end a shared edit session and send the changes. |
|
420 """ |
|
421 self.sendEditButton.setEnabled(False) |
|
422 self.cancelEditButton.setEnabled(False) |
|
423 self.shareButton.setEnabled(True) |
|
424 self.startEditButton.setEnabled(True) |
|
425 self.startEditButton.setChecked(False) |
|
426 |
|
427 self.sendEdit.emit() |
|
428 |
|
429 @pyqtSlot() |
|
430 def on_cancelEditButton_clicked(self): |
|
431 """ |
|
432 Private slot to cancel a shared edit session. |
|
433 """ |
|
434 self.sendEditButton.setEnabled(False) |
|
435 self.cancelEditButton.setEnabled(False) |
|
436 self.shareButton.setEnabled(True) |
|
437 self.startEditButton.setEnabled(True) |
|
438 self.startEditButton.setChecked(False) |
|
439 |
|
440 self.cancelEdit.emit() |
|
441 |
|
442 def checkEditorActions(self, editor): |
|
443 """ |
|
444 Public slot to set action according to an editor's state. |
|
445 |
|
446 @param editor reference to the editor (Editor) |
|
447 """ |
|
448 shareable, sharing, editing, remoteEditing = editor.getSharingStatus() |
|
449 |
|
450 self.shareButton.setChecked(sharing) |
|
451 if sharing: |
|
452 self.shareButton.setIcon( |
|
453 UI.PixmapCache.getIcon("sharedEditConnected.png")) |
|
454 else: |
|
455 self.shareButton.setIcon( |
|
456 UI.PixmapCache.getIcon("sharedEditDisconnected.png")) |
|
457 self.startEditButton.setChecked(editing) |
|
458 |
|
459 self.shareButton.setEnabled(shareable and not editing) |
|
460 self.startEditButton.setEnabled(sharing and not editing and not remoteEditing) |
|
461 self.sendEditButton.setEnabled(editing) |
|
462 self.cancelEditButton.setEnabled(editing) |
|
463 |
|
464 def __initChatMenu(self): |
|
465 """ |
|
466 Private slot to initialize the chat edit context menu. |
|
467 """ |
75 self.__chatMenu = QMenu(self) |
468 self.__chatMenu = QMenu(self) |
76 self.__cutChatAct = \ |
469 self.__cutChatAct = \ |
77 self.__chatMenu.addAction( |
470 self.__chatMenu.addAction( |
78 UI.PixmapCache.getIcon("editCut.png"), |
471 UI.PixmapCache.getIcon("editCut.png"), |
79 self.trUtf8("Cut"), self.__cutChat) |
472 self.trUtf8("Cut"), self.__cutChat) |
98 self.__chatMenu.addSeparator() |
491 self.__chatMenu.addSeparator() |
99 self.__saveChatAct = \ |
492 self.__saveChatAct = \ |
100 self.__chatMenu.addAction( |
493 self.__chatMenu.addAction( |
101 UI.PixmapCache.getIcon("fileSave.png"), |
494 UI.PixmapCache.getIcon("fileSave.png"), |
102 self.trUtf8("Save"), self.__saveChat) |
495 self.trUtf8("Save"), self.__saveChat) |
103 |
|
104 self.messageEdit.returnPressed.connect(self.__handleMessage) |
|
105 self.sendButton.clicked.connect(self.__handleMessage) |
|
106 self.__client.newMessage.connect(self.appendMessage) |
|
107 self.__client.newParticipant.connect(self.__newParticipant) |
|
108 self.__client.participantLeft.connect(self.__participantLeft) |
|
109 self.__client.connectionError.connect(self.__showErrorMessage) |
|
110 self.__client.cannotConnect.connect(self.__initialConnectionRefused) |
|
111 self.__client.editorCommand.connect(self.__editorCommandMessage) |
|
112 |
|
113 self.serverButton.setText(self.trUtf8("Start Server")) |
|
114 self.serverLed.setColor(QColor(Qt.red)) |
|
115 if port == -1: |
|
116 port = Preferences.getCooperation("ServerPort") |
|
117 |
|
118 self.serverPortSpin.setValue(port) |
|
119 |
|
120 self.__setConnected(False) |
|
121 |
|
122 if Preferences.getCooperation("AutoStartServer"): |
|
123 self.on_serverButton_clicked() |
|
124 |
|
125 self.recent = [] |
|
126 self.__loadHostsHistory() |
|
127 |
|
128 def __loadHostsHistory(self): |
|
129 """ |
|
130 Private method to load the recently connected hosts. |
|
131 """ |
|
132 self.__recent = [] |
|
133 Preferences.Prefs.rsettings.sync() |
|
134 rh = Preferences.Prefs.rsettings.value(recentNameHosts) |
|
135 if rh is not None: |
|
136 self.__recent = rh[:20] |
|
137 self.hostEdit.clear() |
|
138 self.hostEdit.addItems(self.__recent) |
|
139 self.hostEdit.clearEditText() |
|
140 |
|
141 def __saveHostsHistory(self): |
|
142 """ |
|
143 Private method to save the list of recently connected hosts. |
|
144 """ |
|
145 Preferences.Prefs.rsettings.setValue(recentNameHosts, self.__recent) |
|
146 Preferences.Prefs.rsettings.sync() |
|
147 |
|
148 def __setHostsHistory(self, host): |
|
149 """ |
|
150 Private method to remember the given host as the most recent entry. |
|
151 |
|
152 @param host host entry to remember (string) |
|
153 """ |
|
154 if host in self.__recent: |
|
155 self.__recent.remove(host) |
|
156 self.__recent.insert(0, host) |
|
157 self.__saveHostsHistory() |
|
158 self.hostEdit.clear() |
|
159 self.hostEdit.addItems(self.__recent) |
|
160 |
|
161 def __clearHostsHistory(self): |
|
162 """ |
|
163 Private slot to clear the hosts history. |
|
164 """ |
|
165 self.__recent = [] |
|
166 self.__saveHostsHistory() |
|
167 self.hostEdit.clear() |
|
168 self.hostEdit.addItems(self.__recent) |
|
169 |
|
170 def __handleMessage(self): |
|
171 """ |
|
172 Private slot handling the Return key pressed in the message edit. |
|
173 """ |
|
174 text = self.messageEdit.text() |
|
175 if text == "": |
|
176 return |
|
177 |
|
178 if text.startswith("/"): |
|
179 self.__showErrorMessage( |
|
180 self.trUtf8("! Unknown command: {0}\n").format(text.split()[0])) |
|
181 else: |
|
182 self.__client.sendMessage(text) |
|
183 self.appendMessage(self.__myNickName, text) |
|
184 |
|
185 self.messageEdit.clear() |
|
186 |
|
187 def __newParticipant(self, nick): |
|
188 """ |
|
189 Private slot handling a new participant joining. |
|
190 |
|
191 @param nick nick name of the new participant (string) |
|
192 """ |
|
193 if nick == "": |
|
194 return |
|
195 |
|
196 color = self.chatEdit.textColor() |
|
197 self.chatEdit.setTextColor(Qt.gray) |
|
198 self.chatEdit.append( |
|
199 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") |
|
200 self.chatEdit.append(self.trUtf8("* {0} has joined.\n").format(nick)) |
|
201 self.chatEdit.setTextColor(color) |
|
202 |
|
203 QListWidgetItem( |
|
204 UI.PixmapCache.getIcon( |
|
205 "chatUser{0}.png".format(1 + self.usersList.count() % 6)), |
|
206 nick, self.usersList) |
|
207 |
|
208 if not self.__connected: |
|
209 self.__setConnected(True) |
|
210 |
|
211 def __participantLeft(self, nick): |
|
212 """ |
|
213 Private slot handling a participant leaving the session. |
|
214 |
|
215 @param nick nick name of the participant (string) |
|
216 """ |
|
217 if nick == "": |
|
218 return |
|
219 |
|
220 items = self.usersList.findItems(nick, Qt.MatchExactly) |
|
221 for item in items: |
|
222 self.usersList.takeItem(self.usersList.row(item)) |
|
223 del item |
|
224 |
|
225 color = self.chatEdit.textColor() |
|
226 self.chatEdit.setTextColor(Qt.gray) |
|
227 self.chatEdit.append( |
|
228 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") |
|
229 self.chatEdit.append(self.trUtf8("* {0} has left.\n").format(nick)) |
|
230 self.chatEdit.setTextColor(color) |
|
231 |
|
232 if not self.__client.hasConnections(): |
|
233 self.__setConnected(False) |
|
234 |
|
235 def appendMessage(self, from_, message): |
|
236 """ |
|
237 Public slot to append a message to the display. |
|
238 |
|
239 @param from_ originator of the message (string) |
|
240 @param message message to be appended (string) |
|
241 """ |
|
242 if from_ == "" or message == "": |
|
243 return |
|
244 |
|
245 self.chatEdit.append( |
|
246 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + \ |
|
247 " <" + from_ + ">:") |
|
248 self.chatEdit.append(message + "\n") |
|
249 bar = self.chatEdit.verticalScrollBar() |
|
250 bar.setValue(bar.maximum()) |
|
251 |
|
252 @pyqtSlot(str) |
|
253 def on_hostEdit_editTextChanged(self, host): |
|
254 """ |
|
255 Private slot handling the entry of a host to connect to. |
|
256 |
|
257 @param host host to connect to (string) |
|
258 """ |
|
259 if not self.__connected: |
|
260 self.connectButton.setEnabled(host != "") |
|
261 |
|
262 def __getConnectionParameters(self): |
|
263 """ |
|
264 Private method to determine the connection parameters. |
|
265 |
|
266 @return tuple with hostname and port (string, integer) |
|
267 """ |
|
268 hostEntry = self.hostEdit.currentText() |
|
269 if ":" in hostEntry: |
|
270 host, port = hostEntry.split(":") |
|
271 try: |
|
272 port = int(port) |
|
273 except ValueError: |
|
274 port = Preferences.getCooperation("ServerPort") |
|
275 self.hostEdit.setEditText("{0}:{1}".format(host, port)) |
|
276 else: |
|
277 host = hostEntry |
|
278 port = Preferences.getCooperation("ServerPort") |
|
279 self.hostEdit.setEditText("{0}:{1}".format(host, port)) |
|
280 return host, port |
|
281 |
|
282 @pyqtSlot() |
|
283 def on_connectButton_clicked(self): |
|
284 """ |
|
285 Private slot initiating the connection. |
|
286 """ |
|
287 if not self.__connected: |
|
288 host, port = self.__getConnectionParameters() |
|
289 self.__setHostsHistory(self.hostEdit.currentText()) |
|
290 if not self.__client.server().isListening(): |
|
291 self.on_serverButton_clicked() |
|
292 if self.__client.server().isListening(): |
|
293 self.__client.connectToHost(host, port) |
|
294 self.__setConnected(True) |
|
295 else: |
|
296 self.__client.disconnectConnections() |
|
297 self.__setConnected(False) |
|
298 |
|
299 @pyqtSlot() |
|
300 def on_clearHostsButton_clicked(self): |
|
301 """ |
|
302 Private slot to clear the hosts list. |
|
303 """ |
|
304 self.__clearHostsHistory() |
|
305 |
|
306 @pyqtSlot() |
|
307 def on_serverButton_clicked(self): |
|
308 """ |
|
309 Private slot to start the server. |
|
310 """ |
|
311 if self.__client.server().isListening(): |
|
312 self.__client.server().close() |
|
313 self.serverButton.setText(self.trUtf8("Start Server")) |
|
314 self.serverPortSpin.setEnabled(True) |
|
315 if self.serverPortSpin.value() != Preferences.getCooperation("ServerPort"): |
|
316 self.serverPortSpin.setValue(Preferences.getCooperation("ServerPort")) |
|
317 self.serverLed.setColor(QColor(Qt.red)) |
|
318 else: |
|
319 res, port = self.__client.server().startListening(self.serverPortSpin.value()) |
|
320 if res: |
|
321 self.serverButton.setText(self.trUtf8("Stop Server")) |
|
322 self.serverPortSpin.setValue(port) |
|
323 self.serverPortSpin.setEnabled(False) |
|
324 self.serverLed.setColor(QColor(Qt.green)) |
|
325 else: |
|
326 self.__showErrorMessage( |
|
327 self.trUtf8("! Server Error: {0}\n").format( |
|
328 self.__client.server().errorString()) |
|
329 ) |
|
330 |
|
331 def __setConnected(self, connected): |
|
332 """ |
|
333 Private slot to set the connected state. |
|
334 |
|
335 @param connected new connected state (boolean) |
|
336 """ |
|
337 if connected: |
|
338 self.connectButton.setText(self.trUtf8("Disconnect")) |
|
339 self.connectButton.setEnabled(True) |
|
340 self.connectionLed.setColor(QColor(Qt.green)) |
|
341 else: |
|
342 self.connectButton.setText(self.trUtf8("Connect")) |
|
343 self.connectButton.setEnabled(self.hostEdit.currentText() != "") |
|
344 self.connectionLed.setColor(QColor(Qt.red)) |
|
345 self.on_cancelEditButton_clicked() |
|
346 self.shareButton.setChecked(False) |
|
347 self.on_shareButton_clicked(False) |
|
348 self.__connected = connected |
|
349 self.hostEdit.setEnabled(not connected) |
|
350 self.serverButton.setEnabled(not connected) |
|
351 self.sharingGroup.setEnabled(connected) |
|
352 |
|
353 if connected: |
|
354 vm = e5App().getObject("ViewManager") |
|
355 aw = vm.activeWindow() |
|
356 if aw: |
|
357 self.checkEditorActions(aw) |
|
358 |
|
359 def __showErrorMessage(self, message): |
|
360 """ |
|
361 Private slot to show an error message. |
|
362 |
|
363 @param message error message to show (string) |
|
364 """ |
|
365 color = self.chatEdit.textColor() |
|
366 self.chatEdit.setTextColor(Qt.red) |
|
367 self.chatEdit.append( |
|
368 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") |
|
369 self.chatEdit.append(message) |
|
370 self.chatEdit.setTextColor(color) |
|
371 |
|
372 def __initialConnectionRefused(self): |
|
373 """ |
|
374 Private slot to handle the refusal of the initial connection. |
|
375 """ |
|
376 self.__setConnected(False) |
|
377 |
|
378 def preferencesChanged(self): |
|
379 """ |
|
380 Public slot to handle a change of preferences. |
|
381 """ |
|
382 if not self.__client.server().isListening(): |
|
383 self.serverPortSpin.setValue(Preferences.getCooperation("ServerPort")) |
|
384 if Preferences.getCooperation("AutoStartServer"): |
|
385 self.on_serverButton_clicked() |
|
386 |
|
387 def getClient(self): |
|
388 """ |
|
389 Public method to get a reference to the cooperation client. |
|
390 """ |
|
391 return self.__client |
|
392 |
|
393 def __editorCommandMessage(self, hash, fileName, message): |
|
394 """ |
|
395 Private slot to handle editor command messages from the client. |
|
396 |
|
397 @param hash hash of the project (string) |
|
398 @param fileName project relative file name of the editor (string) |
|
399 @param message command message (string) |
|
400 """ |
|
401 self.editorCommand.emit(hash, fileName, message) |
|
402 |
|
403 if message.startswith(Editor.StartEditToken + Editor.Separator) or \ |
|
404 message.startswith(Editor.EndEditToken + Editor.Separator): |
|
405 vm = e5App().getObject("ViewManager") |
|
406 aw = vm.activeWindow() |
|
407 if aw: |
|
408 self.checkEditorActions(aw) |
|
409 |
|
410 @pyqtSlot(bool) |
|
411 def on_shareButton_clicked(self, checked): |
|
412 """ |
|
413 Private slot to share the current editor. |
|
414 |
|
415 @param checked flag indicating the button state (boolean) |
|
416 """ |
|
417 if checked: |
|
418 self.shareButton.setIcon( |
|
419 UI.PixmapCache.getIcon("sharedEditConnected.png")) |
|
420 else: |
|
421 self.shareButton.setIcon( |
|
422 UI.PixmapCache.getIcon("sharedEditDisconnected.png")) |
|
423 self.startEditButton.setEnabled(checked) |
|
424 |
|
425 self.shareEditor.emit(checked) |
|
426 |
|
427 @pyqtSlot(bool) |
|
428 def on_startEditButton_clicked(self, checked): |
|
429 """ |
|
430 Private slot to start a shared edit session. |
|
431 |
|
432 @param checked flag indicating the button state (boolean) |
|
433 """ |
|
434 if checked: |
|
435 self.sendEditButton.setEnabled(True) |
|
436 self.cancelEditButton.setEnabled(True) |
|
437 self.shareButton.setEnabled(False) |
|
438 self.startEditButton.setEnabled(False) |
|
439 |
|
440 self.startEdit.emit() |
|
441 |
|
442 @pyqtSlot() |
|
443 def on_sendEditButton_clicked(self): |
|
444 """ |
|
445 Private slot to end a shared edit session and send the changes. |
|
446 """ |
|
447 self.sendEditButton.setEnabled(False) |
|
448 self.cancelEditButton.setEnabled(False) |
|
449 self.shareButton.setEnabled(True) |
|
450 self.startEditButton.setEnabled(True) |
|
451 self.startEditButton.setChecked(False) |
|
452 |
|
453 self.sendEdit.emit() |
|
454 |
|
455 @pyqtSlot() |
|
456 def on_cancelEditButton_clicked(self): |
|
457 """ |
|
458 Private slot to cancel a shared edit session. |
|
459 """ |
|
460 self.sendEditButton.setEnabled(False) |
|
461 self.cancelEditButton.setEnabled(False) |
|
462 self.shareButton.setEnabled(True) |
|
463 self.startEditButton.setEnabled(True) |
|
464 self.startEditButton.setChecked(False) |
|
465 |
|
466 self.cancelEdit.emit() |
|
467 |
|
468 def checkEditorActions(self, editor): |
|
469 """ |
|
470 Public slot to set action according to an editor's state. |
|
471 |
|
472 @param editor reference to the editor (Editor) |
|
473 """ |
|
474 shareable, sharing, editing, remoteEditing = editor.getSharingStatus() |
|
475 |
|
476 self.shareButton.setChecked(sharing) |
|
477 if sharing: |
|
478 self.shareButton.setIcon( |
|
479 UI.PixmapCache.getIcon("sharedEditConnected.png")) |
|
480 else: |
|
481 self.shareButton.setIcon( |
|
482 UI.PixmapCache.getIcon("sharedEditDisconnected.png")) |
|
483 self.startEditButton.setChecked(editing) |
|
484 |
|
485 self.shareButton.setEnabled(shareable and not editing) |
|
486 self.startEditButton.setEnabled(sharing and not editing and not remoteEditing) |
|
487 self.sendEditButton.setEnabled(editing) |
|
488 self.cancelEditButton.setEnabled(editing) |
|
489 |
496 |
490 @pyqtSlot(bool) |
497 @pyqtSlot(bool) |
491 def on_chatEdit_copyAvailable(self, yes): |
498 def on_chatEdit_copyAvailable(self, yes): |
492 """ |
499 """ |
493 Private slot to react to text selection/deselection of the chat edit. |
500 Private slot to react to text selection/deselection of the chat edit. |
587 txt = self.chatEdit.toPlainText() |
594 txt = self.chatEdit.toPlainText() |
588 if txt: |
595 if txt: |
589 cb = QApplication.clipboard() |
596 cb = QApplication.clipboard() |
590 cb.setText(txt) |
597 cb.setText(txt) |
591 self.chatEdit.clear() |
598 self.chatEdit.clear() |
|
599 |
|
600 def __initUsersMenu(self): |
|
601 """ |
|
602 Private slot to initialize the users list context menu. |
|
603 """ |
|
604 self.__usersMenu = QMenu(self) |
|
605 self.__kickUserAct = \ |
|
606 self.__usersMenu.addAction( |
|
607 UI.PixmapCache.getIcon("chatKickUser.png"), |
|
608 self.trUtf8("Kick User"), self.__kickUser) |
|
609 self.__banUserAct = \ |
|
610 self.__usersMenu.addAction( |
|
611 UI.PixmapCache.getIcon("chatBanUser.png"), |
|
612 self.trUtf8("Ban User"), self.__banUser) |
|
613 self.__banKickUserAct = \ |
|
614 self.__usersMenu.addAction( |
|
615 UI.PixmapCache.getIcon("chatBanKickUser.png"), |
|
616 self.trUtf8("Ban and Kick User"), self.__banKickUser) |
|
617 |
|
618 @pyqtSlot(QPoint) |
|
619 def on_usersList_customContextMenuRequested(self, pos): |
|
620 """ |
|
621 Private slot to show the context menu for the users list. |
|
622 |
|
623 @param pos the position of the mouse pointer (QPoint) |
|
624 """ |
|
625 itm = self.usersList.itemAt(pos) |
|
626 self.__kickUserAct.setEnabled(itm is not None) |
|
627 self.__banUserAct.setEnabled(itm is not None) |
|
628 self.__banKickUserAct.setEnabled(itm is not None) |
|
629 self.__usersMenu.popup(self.usersList.mapToGlobal(pos)) |
|
630 |
|
631 def __kickUser(self): |
|
632 """ |
|
633 Private slot to disconnect a user. |
|
634 """ |
|
635 itm = self.usersList.currentItem() |
|
636 self.__client.kickUser(itm.text()) |
|
637 |
|
638 color = self.chatEdit.textColor() |
|
639 self.chatEdit.setTextColor(Qt.darkYellow) |
|
640 self.chatEdit.append( |
|
641 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") |
|
642 self.chatEdit.append(self.trUtf8("* {0} has been kicked.\n").format( |
|
643 itm.text().split(":")[0])) |
|
644 self.chatEdit.setTextColor(color) |
|
645 |
|
646 def __banUser(self): |
|
647 """ |
|
648 Private slot to ban a user. |
|
649 """ |
|
650 itm = self.usersList.currentItem() |
|
651 self.__client.banUser(itm.text()) |
|
652 |
|
653 color = self.chatEdit.textColor() |
|
654 self.chatEdit.setTextColor(Qt.darkYellow) |
|
655 self.chatEdit.append( |
|
656 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") |
|
657 self.chatEdit.append(self.trUtf8("* {0} has been banned.\n").format( |
|
658 itm.text().split(":")[0])) |
|
659 self.chatEdit.setTextColor(color) |
|
660 |
|
661 def __banKickUser(self): |
|
662 """ |
|
663 Private slot to ban and kick a user. |
|
664 """ |
|
665 itm = self.usersList.currentItem() |
|
666 self.__client.banKickUser(itm.text()) |
|
667 |
|
668 color = self.chatEdit.textColor() |
|
669 self.chatEdit.setTextColor(Qt.darkYellow) |
|
670 self.chatEdit.append( |
|
671 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") |
|
672 self.chatEdit.append(self.trUtf8("* {0} has been banned and kicked.\n").format( |
|
673 itm.text().split(":")[0])) |
|
674 self.chatEdit.setTextColor(color) |