62 UI.PixmapCache.getIcon("sharedEditStart.png")) |
62 UI.PixmapCache.getIcon("sharedEditStart.png")) |
63 self.sendEditButton.setIcon( |
63 self.sendEditButton.setIcon( |
64 UI.PixmapCache.getIcon("sharedEditSend.png")) |
64 UI.PixmapCache.getIcon("sharedEditSend.png")) |
65 self.cancelEditButton.setIcon( |
65 self.cancelEditButton.setIcon( |
66 UI.PixmapCache.getIcon("sharedEditCancel.png")) |
66 UI.PixmapCache.getIcon("sharedEditCancel.png")) |
67 |
67 self.clearMessageButton.setIcon( |
68 self.__client = CooperationClient() |
68 UI.PixmapCache.getIcon("clearLeft.png")) |
|
69 self.clearHostButton.setIcon( |
|
70 UI.PixmapCache.getIcon("clearLeft.png")) |
|
71 |
|
72 self.__client = CooperationClient(self) |
69 self.__myNickName = self.__client.nickName() |
73 self.__myNickName = self.__client.nickName() |
70 |
74 |
71 self.__chatMenu = QMenu(self) |
75 self.__chatMenu = QMenu(self) |
|
76 self.__cutChatAct = \ |
|
77 self.__chatMenu.addAction( |
|
78 UI.PixmapCache.getIcon("editCut.png"), |
|
79 self.trUtf8("Cut"), self.__cutChat) |
|
80 self.__copyChatAct = \ |
|
81 self.__chatMenu.addAction( |
|
82 UI.PixmapCache.getIcon("editCopy.png"), |
|
83 self.trUtf8("Copy"), self.__copyChat) |
|
84 self.__chatMenu.addSeparator() |
|
85 self.__cutAllChatAct = \ |
|
86 self.__chatMenu.addAction( |
|
87 UI.PixmapCache.getIcon("editCut.png"), |
|
88 self.trUtf8("Cut all"), self.__cutAllChat) |
|
89 self.__copyAllChatAct = \ |
|
90 self.__chatMenu.addAction( |
|
91 UI.PixmapCache.getIcon("editCopy.png"), |
|
92 self.trUtf8("Copy all"), self.__copyAllChat) |
|
93 self.__chatMenu.addSeparator() |
72 self.__clearChatAct = \ |
94 self.__clearChatAct = \ |
73 self.__chatMenu.addAction(self.trUtf8("Clear"), self.__clearChat) |
95 self.__chatMenu.addAction( |
|
96 UI.PixmapCache.getIcon("editDelete.png"), |
|
97 self.trUtf8("Clear"), self.__clearChat) |
|
98 self.__chatMenu.addSeparator() |
74 self.__saveChatAct = \ |
99 self.__saveChatAct = \ |
75 self.__chatMenu.addAction(self.trUtf8("Save"), self.__saveChat) |
100 self.__chatMenu.addAction( |
76 self.__copyChatAct = \ |
101 UI.PixmapCache.getIcon("fileSave.png"), |
77 self.__chatMenu.addAction(self.trUtf8("Copy"), self.__copyChat) |
102 self.trUtf8("Save"), self.__saveChat) |
78 |
103 |
79 self.messageEdit.returnPressed.connect(self.__handleMessage) |
104 self.messageEdit.returnPressed.connect(self.__handleMessage) |
80 self.sendButton.clicked.connect(self.__handleMessage) |
105 self.sendButton.clicked.connect(self.__handleMessage) |
81 self.__client.newMessage.connect(self.appendMessage) |
106 self.__client.newMessage.connect(self.appendMessage) |
82 self.__client.newParticipant.connect(self.__newParticipant) |
107 self.__client.newParticipant.connect(self.__newParticipant) |
88 self.serverButton.setText(self.trUtf8("Start Server")) |
113 self.serverButton.setText(self.trUtf8("Start Server")) |
89 self.serverLed.setColor(QColor(Qt.red)) |
114 self.serverLed.setColor(QColor(Qt.red)) |
90 if port == -1: |
115 if port == -1: |
91 port = Preferences.getCooperation("ServerPort") |
116 port = Preferences.getCooperation("ServerPort") |
92 |
117 |
93 self.portSpin.setValue(port) |
118 ## self.portSpin.setValue(port) |
94 self.serverPortSpin.setValue(port) |
119 self.serverPortSpin.setValue(port) |
95 |
120 |
96 self.__setConnected(False) |
121 self.__setConnected(False) |
97 |
122 |
98 if Preferences.getCooperation("AutoStartServer"): |
123 if Preferences.getCooperation("AutoStartServer"): |
99 self.on_serverButton_clicked() |
124 self.on_serverButton_clicked() |
100 |
125 |
101 self.recent = [] |
126 self.recent = [] |
102 self.__loadRecent() |
127 self.__loadHostsHistory() |
103 |
128 |
104 def __loadRecent(self): |
129 def __loadHostsHistory(self): |
105 """ |
130 """ |
106 Private method to load the recently connected hosts. |
131 Private method to load the recently connected hosts. |
107 """ |
132 """ |
108 self.recent = [] |
133 self.__recent = [] |
109 Preferences.Prefs.rsettings.sync() |
134 Preferences.Prefs.rsettings.sync() |
110 rh = Preferences.Prefs.rsettings.value(recentNameHosts) |
135 rh = Preferences.Prefs.rsettings.value(recentNameHosts) |
111 if rh is not None: |
136 if rh is not None: |
112 self.recent = rh[:20] |
137 self.__recent = rh[:20] |
113 self.hostEdit.clear() |
138 self.hostEdit.clear() |
114 self.hostEdit.addItem("", -1) |
139 self.hostEdit.addItems(self.__recent) |
115 for entry in self.recent: |
140 self.hostEdit.clearEditText() |
116 host, port = entry.split(":") |
141 |
117 port = int(port) |
142 def __saveHostsHistory(self): |
118 hostStr = "{0} ({1})".format(host, port) |
|
119 self.hostEdit.addItem(hostStr, port) |
|
120 |
|
121 def __saveRecent(self): |
|
122 """ |
143 """ |
123 Private method to save the list of recently connected hosts. |
144 Private method to save the list of recently connected hosts. |
124 """ |
145 """ |
125 Preferences.Prefs.rsettings.setValue(recentNameHosts, self.recent) |
146 Preferences.Prefs.rsettings.setValue(recentNameHosts, self.__recent) |
126 Preferences.Prefs.rsettings.sync() |
147 Preferences.Prefs.rsettings.sync() |
127 |
148 |
128 def __setHostsHistory(self, host, port): |
149 def __setHostsHistory(self, host): |
129 """ |
150 """ |
130 Private method to set the given host and port. |
151 Private method to remember the given host as the most recent entry. |
131 |
152 |
132 @param host host name to remember (string) |
153 @param host host entry to remember (string) |
133 @param port port number to remember (integer) |
154 """ |
134 """ |
155 if host in self.__recent: |
135 hostStr = "{0}:{1}".format(host, port) |
156 self.__recent.remove(host) |
136 if hostStr in self.recent: |
157 self.__recent.insert(0, host) |
137 self.recent.remove(hostStr) |
158 self.__saveHostsHistory() |
138 self.recent.insert(0, hostStr) |
159 |
139 |
160 def __clearHostsHistory(self): |
140 hostStr = "{0} ({1})".format(host, port) |
161 """ |
141 index = self.hostEdit.findText(hostStr) |
162 Private slot to clear the hosts history. |
142 if index != -1: |
163 """ |
143 self.hostEdit.removeItem(index) |
164 self.__recent = [] |
144 if self.hostEdit.itemText(0) == host: |
165 self.__saveHostsHistory() |
145 self.hostEdit.removeItem(0) |
|
146 self.hostEdit.setEditText(hostStr) |
|
147 self.hostEdit.insertItem(0, hostStr, port) |
|
148 self.hostEdit.setCurrentIndex(0) |
|
149 |
166 |
150 def __handleMessage(self): |
167 def __handleMessage(self): |
151 """ |
168 """ |
152 Private slot handling the Return key pressed in the message edit. |
169 Private slot handling the Return key pressed in the message edit. |
153 """ |
170 """ |
237 @param host host to connect to (string) |
254 @param host host to connect to (string) |
238 """ |
255 """ |
239 if not self.__connected: |
256 if not self.__connected: |
240 self.connectButton.setEnabled(host != "") |
257 self.connectButton.setEnabled(host != "") |
241 |
258 |
242 @pyqtSlot(int) |
259 ## @pyqtSlot(int) |
243 def on_hostEdit_currentIndexChanged(self, index): |
260 ## def on_hostEdit_currentIndexChanged(self, index): |
244 """ |
261 ## """ |
245 Private slot to handle the selection of a host. |
262 ## Private slot to handle the selection of a host. |
246 |
263 ## |
247 @param index index of the selected entry (integer) |
264 ## @param index index of the selected entry (integer) |
248 """ |
265 ## """ |
249 port = self.hostEdit.itemData(index) |
266 ## port = self.hostEdit.itemData(index) |
250 if port is not None: |
267 ## if port is not None: |
251 if port == -1: |
268 ## if port == -1: |
252 self.portSpin.setValue(Preferences.getCooperation("ServerPort")) |
269 ## self.portSpin.setValue(Preferences.getCooperation("ServerPort")) |
253 else: |
270 ## else: |
254 self.portSpin.setValue(port) |
271 ## self.portSpin.setValue(port) |
|
272 def __getConnectionParameters(self): |
|
273 """ |
|
274 Private method to determine the connection parameters. |
|
275 |
|
276 @return tuple with hostname and port (string, integer) |
|
277 """ |
|
278 hostEntry = self.hostEdit.currentText() |
|
279 if ":" in hostEntry: |
|
280 host, port = hostEntry.split(":") |
|
281 try: |
|
282 port = int(port) |
|
283 except ValueError: |
|
284 port = Preferences.getCooperation("ServerPort") |
|
285 self.hostEdit.setEditText("{0}:{1}".format(host, port)) |
|
286 else: |
|
287 host = hostEntry |
|
288 port = Preferences.getCooperation("ServerPort") |
|
289 self.hostEdit.setEditText("{0}:{1}".format(host, port)) |
|
290 return host, port |
255 |
291 |
256 @pyqtSlot() |
292 @pyqtSlot() |
257 def on_connectButton_clicked(self): |
293 def on_connectButton_clicked(self): |
258 """ |
294 """ |
259 Private slot initiating the connection. |
295 Private slot initiating the connection. |
260 """ |
296 """ |
261 if not self.__connected: |
297 if not self.__connected: |
262 self.__setHostsHistory(self.hostEdit.currentText().split()[0], |
298 self.__setHostsHistory(self.hostEdit.currentText()) |
263 self.portSpin.value()) |
|
264 self.__saveRecent() |
|
265 if not self.__client.server().isListening(): |
299 if not self.__client.server().isListening(): |
266 self.on_serverButton_clicked() |
300 self.on_serverButton_clicked() |
267 if self.__client.server().isListening(): |
301 if self.__client.server().isListening(): |
268 self.__client.connectToHost(self.hostEdit.currentText().split()[0], |
302 self.__client.connectToHost(*self.__getConnectionParameters()) |
269 self.portSpin.value()) |
|
270 self.__setConnected(True) |
303 self.__setConnected(True) |
271 else: |
304 else: |
272 self.__client.disconnectConnections() |
305 self.__client.disconnectConnections() |
273 self.__setConnected(False) |
306 self.__setConnected(False) |
274 |
307 |
313 self.connectionLed.setColor(QColor(Qt.red)) |
346 self.connectionLed.setColor(QColor(Qt.red)) |
314 self.cancelEditButton.click() |
347 self.cancelEditButton.click() |
315 self.shareButton.click() |
348 self.shareButton.click() |
316 self.__connected = connected |
349 self.__connected = connected |
317 self.hostEdit.setEnabled(not connected) |
350 self.hostEdit.setEnabled(not connected) |
318 self.portSpin.setEnabled(not connected) |
351 ## self.portSpin.setEnabled(not connected) |
319 self.serverButton.setEnabled(not connected) |
352 self.serverButton.setEnabled(not connected) |
320 self.sharingGroup.setEnabled(connected) |
353 self.sharingGroup.setEnabled(connected) |
321 |
354 |
322 if connected: |
355 if connected: |
323 vm = e5App().getObject("ViewManager") |
356 vm = e5App().getObject("ViewManager") |
454 self.shareButton.setEnabled(shareable and not editing) |
487 self.shareButton.setEnabled(shareable and not editing) |
455 self.startEditButton.setEnabled(sharing and not editing and not remoteEditing) |
488 self.startEditButton.setEnabled(sharing and not editing and not remoteEditing) |
456 self.sendEditButton.setEnabled(editing) |
489 self.sendEditButton.setEnabled(editing) |
457 self.cancelEditButton.setEnabled(editing) |
490 self.cancelEditButton.setEnabled(editing) |
458 |
491 |
|
492 @pyqtSlot(bool) |
|
493 def on_chatEdit_copyAvailable(self, yes): |
|
494 """ |
|
495 Private slot to react to text selection/deselection of the chat edit. |
|
496 |
|
497 @param yes flag signaling the availability of selected text (boolean) |
|
498 """ |
|
499 self.__copyChatAct.setEnabled(yes) |
|
500 self.__cutChatAct.setEnabled(yes) |
|
501 |
459 @pyqtSlot(QPoint) |
502 @pyqtSlot(QPoint) |
460 def on_chatEdit_customContextMenuRequested(self, pos): |
503 def on_chatEdit_customContextMenuRequested(self, pos): |
461 """ |
504 """ |
462 Private slot to show the context menu for the chat. |
505 Private slot to show the context menu for the chat. |
463 |
506 |
464 @param pos the position of the mouse pointer (QPoint) |
507 @param pos the position of the mouse pointer (QPoint) |
465 """ |
508 """ |
466 self.__saveChatAct.setEnabled(self.chatEdit.toPlainText() != "") |
509 enable = self.chatEdit.toPlainText() != "" |
467 self.__copyChatAct.setEnabled(self.chatEdit.toPlainText() != "") |
510 self.__saveChatAct.setEnabled(enable) |
|
511 self.__copyAllChatAct.setEnabled(enable) |
|
512 self.__cutAllChatAct.setEnabled(enable) |
468 self.__chatMenu.popup(self.chatEdit.mapToGlobal(pos)) |
513 self.__chatMenu.popup(self.chatEdit.mapToGlobal(pos)) |
469 |
514 |
470 def __clearChat(self): |
515 def __clearChat(self): |
471 """ |
516 """ |
472 Private slot to clear the contents of the chat display. |
517 Private slot to clear the contents of the chat display. |