Cooperation/ChatWidget.py

changeset 158
6a561f87bc07
parent 155
375e3c884874
child 160
32cc58d56d4d
equal deleted inserted replaced
157:c8d5916b9934 158:6a561f87bc07
5 5
6 """ 6 """
7 Module implementing the chat dialog. 7 Module implementing the chat dialog.
8 """ 8 """
9 9
10 from PyQt4.QtCore import Qt, pyqtSlot, QDateTime 10 from PyQt4.QtCore import Qt, pyqtSlot, pyqtSignal, QDateTime
11 from PyQt4.QtGui import QWidget, QColor, QListWidgetItem 11 from PyQt4.QtGui import QWidget, QColor, QListWidgetItem
12
13 from E5Gui.E5Application import e5App
14
15 from QScintilla.Editor import Editor
12 16
13 from .CooperationClient import CooperationClient 17 from .CooperationClient import CooperationClient
14 18
15 from .Ui_ChatWidget import Ui_ChatWidget 19 from .Ui_ChatWidget import Ui_ChatWidget
16 20
18 import UI.PixmapCache 22 import UI.PixmapCache
19 23
20 class ChatWidget(QWidget, Ui_ChatWidget): 24 class ChatWidget(QWidget, Ui_ChatWidget):
21 """ 25 """
22 Class implementing the chat dialog. 26 Class implementing the chat dialog.
27
28 @signal connected(connected) emitted to signal a change of the connected
29 state (boole)
30 @signal editorCommand(hash, filename, message) emitted when an editor command
31 has been received (string, string, string)
32 @signal shareEditor(share) emitted to signal a share is requested (bool)
33 @signal startEdit() emitted to start a shared edit session
34 @signal sendEdit() emitted to send a shared edit session
35 @signal cancelEdit() emitted to cancel a shared edit session
23 """ 36 """
37 connected = pyqtSignal(bool)
38 editorCommand = pyqtSignal(str, str, str)
39
40 shareEditor = pyqtSignal(bool)
41 startEdit = pyqtSignal()
42 sendEdit = pyqtSignal()
43 cancelEdit = pyqtSignal()
44
24 def __init__(self, port = -1, parent = None): 45 def __init__(self, port = -1, parent = None):
25 """ 46 """
26 Constructor 47 Constructor
27 48
28 @param port port to be used for the cooperation server (integer) 49 @param port port to be used for the cooperation server (integer)
29 @param parent reference to the parent widget (QWidget) 50 @param parent reference to the parent widget (QWidget)
30 """ 51 """
31 QWidget.__init__(self, parent) 52 QWidget.__init__(self, parent)
32 self.setupUi(self) 53 self.setupUi(self)
54
55 self.shareButton.setIcon(
56 UI.PixmapCache.getIcon("sharedEditDisconnected.png"))
57 self.startEditButton.setIcon(
58 UI.PixmapCache.getIcon("sharedEditStart.png"))
59 self.sendEditButton.setIcon(
60 UI.PixmapCache.getIcon("sharedEditSend.png"))
61 self.cancelEditButton.setIcon(
62 UI.PixmapCache.getIcon("sharedEditCancel.png"))
33 63
34 self.__client = CooperationClient() 64 self.__client = CooperationClient()
35 self.__myNickName = self.__client.nickName() 65 self.__myNickName = self.__client.nickName()
36 66
37 self.messageEdit.returnPressed.connect(self.__handleMessage) 67 self.messageEdit.returnPressed.connect(self.__handleMessage)
39 self.__client.newMessage.connect(self.appendMessage) 69 self.__client.newMessage.connect(self.appendMessage)
40 self.__client.newParticipant.connect(self.__newParticipant) 70 self.__client.newParticipant.connect(self.__newParticipant)
41 self.__client.participantLeft.connect(self.__participantLeft) 71 self.__client.participantLeft.connect(self.__participantLeft)
42 self.__client.connectionError.connect(self.__showErrorMessage) 72 self.__client.connectionError.connect(self.__showErrorMessage)
43 self.__client.cannotConnect.connect(self.__initialConnectionRefused) 73 self.__client.cannotConnect.connect(self.__initialConnectionRefused)
74 self.__client.editorCommand.connect(self.__editorCommandMessage)
44 75
45 self.serverButton.setText(self.trUtf8("Start Server")) 76 self.serverButton.setText(self.trUtf8("Start Server"))
46 self.serverLed.setColor(QColor(Qt.red)) 77 self.serverLed.setColor(QColor(Qt.red))
47 if port == -1: 78 if port == -1:
48 port = Preferences.getCooperation("ServerPort") 79 port = Preferences.getCooperation("ServerPort")
192 Private slot to set the connected state. 223 Private slot to set the connected state.
193 224
194 @param connected new connected state (boolean) 225 @param connected new connected state (boolean)
195 """ 226 """
196 if connected: 227 if connected:
197 self.__connected = True
198 self.connectButton.setText(self.trUtf8("Disconnect")) 228 self.connectButton.setText(self.trUtf8("Disconnect"))
199 self.connectButton.setEnabled(True) 229 self.connectButton.setEnabled(True)
200 self.hostEdit.setEnabled(False)
201 self.portSpin.setEnabled(False)
202 self.connectionLed.setColor(QColor(Qt.green)) 230 self.connectionLed.setColor(QColor(Qt.green))
203 self.serverButton.setEnabled(False) 231 else:
204 else:
205 self.__connected = False
206 self.connectButton.setText(self.trUtf8("Connect")) 232 self.connectButton.setText(self.trUtf8("Connect"))
207 self.connectButton.setEnabled(self.hostEdit.text() != "") 233 self.connectButton.setEnabled(self.hostEdit.text() != "")
208 self.hostEdit.setEnabled(True)
209 self.portSpin.setEnabled(True)
210 self.connectionLed.setColor(QColor(Qt.red)) 234 self.connectionLed.setColor(QColor(Qt.red))
211 self.serverButton.setEnabled(True) 235 self.cancelEditButton.click()
236 self.shareButton.click()
237 self.__connected = connected
238 self.hostEdit.setEnabled(not connected)
239 self.portSpin.setEnabled(not connected)
240 self.serverButton.setEnabled(not connected)
241 self.sharingGroup.setEnabled(connected)
242
243 if connected:
244 vm = e5App().getObject("ViewManager")
245 aw = vm.activeWindow()
246 if aw:
247 self.checkEditorActions(aw)
212 248
213 def __showErrorMessage(self, message): 249 def __showErrorMessage(self, message):
214 """ 250 """
215 Private slot to show an error message. 251 Private slot to show an error message.
216 252
241 def getClient(self): 277 def getClient(self):
242 """ 278 """
243 Public method to get a reference to the cooperation client. 279 Public method to get a reference to the cooperation client.
244 """ 280 """
245 return self.__client 281 return self.__client
282
283 def __editorCommandMessage(self, hash, fileName, message):
284 """
285 Private slot to handle editor command messages from the client.
286
287 @param hash hash of the project (string)
288 @param fileName project relative file name of the editor (string)
289 @param message command message (string)
290 """
291 self.editorCommand.emit(hash, fileName, message)
292
293 if message.startswith(Editor.StartEditToken + Editor.Separator) or \
294 message.startswith(Editor.EndEditToken + Editor.Separator):
295 vm = e5App().getObject("ViewManager")
296 aw = vm.activeWindow()
297 if aw:
298 self.checkEditorActions(aw)
299
300 @pyqtSlot(bool)
301 def on_shareButton_clicked(self, checked):
302 """
303 Private slot to share the current editor.
304
305 @param checked flag indicating the button state (boolean)
306 """
307 if checked:
308 self.shareButton.setIcon(
309 UI.PixmapCache.getIcon("sharedEditConnected.png"))
310 else:
311 self.shareButton.setIcon(
312 UI.PixmapCache.getIcon("sharedEditDisconnected.png"))
313 self.startEditButton.setEnabled(checked)
314
315 self.shareEditor.emit(checked)
316
317 @pyqtSlot(bool)
318 def on_startEditButton_clicked(self, checked):
319 """
320 Private slot to start a shared edit session.
321
322 @param checked flag indicating the button state (boolean)
323 """
324 if checked:
325 self.sendEditButton.setEnabled(True)
326 self.cancelEditButton.setEnabled(True)
327 self.shareButton.setEnabled(False)
328 self.startEditButton.setEnabled(False)
329
330 self.startEdit.emit()
331
332 @pyqtSlot()
333 def on_sendEditButton_clicked(self):
334 """
335 Private slot to end a shared edit session and send the changes.
336 """
337 self.sendEditButton.setEnabled(False)
338 self.cancelEditButton.setEnabled(False)
339 self.shareButton.setEnabled(True)
340 self.startEditButton.setEnabled(True)
341 self.startEditButton.setChecked(False)
342
343 self.sendEdit.emit()
344
345 @pyqtSlot()
346 def on_cancelEditButton_clicked(self):
347 """
348 Private slot to cancel a shared edit session.
349 """
350 self.sendEditButton.setEnabled(False)
351 self.cancelEditButton.setEnabled(False)
352 self.shareButton.setEnabled(True)
353 self.startEditButton.setEnabled(True)
354 self.startEditButton.setChecked(False)
355
356 self.cancelEdit.emit()
357
358 def checkEditorActions(self, editor):
359 """
360 Public slot to set action according to an editor's state.
361
362 @param editor reference to the editor (Editor)
363 """
364 shareable, sharing, editing, remoteEditing = editor.getSharingStatus()
365
366 self.shareButton.setChecked(sharing)
367 if sharing:
368 self.shareButton.setIcon(
369 UI.PixmapCache.getIcon("sharedEditConnected.png"))
370 else:
371 self.shareButton.setIcon(
372 UI.PixmapCache.getIcon("sharedEditDisconnected.png"))
373 self.startEditButton.setChecked(editing)
374
375 self.shareButton.setEnabled(shareable and not editing)
376 self.startEditButton.setEnabled(sharing and not editing and not remoteEditing)
377 self.sendEditButton.setEnabled(editing)
378 self.cancelEditButton.setEnabled(editing)

eric ide

mercurial