10 from PyQt4.QtCore import Qt, pyqtSlot, pyqtSignal, QDateTime, QPoint, QFileInfo |
10 from PyQt4.QtCore import Qt, pyqtSlot, pyqtSignal, QDateTime, QPoint, QFileInfo |
11 from PyQt4.QtGui import QWidget, QColor, QListWidgetItem, QMenu, QFileDialog, \ |
11 from PyQt4.QtGui import QWidget, QColor, QListWidgetItem, QMenu, QFileDialog, \ |
12 QMessageBox, QApplication |
12 QMessageBox, QApplication |
13 |
13 |
14 from E5Gui.E5Application import e5App |
14 from E5Gui.E5Application import e5App |
|
15 |
|
16 from Globals import recentNameHosts |
15 |
17 |
16 from QScintilla.Editor import Editor |
18 from QScintilla.Editor import Editor |
17 |
19 |
18 from .CooperationClient import CooperationClient |
20 from .CooperationClient import CooperationClient |
19 |
21 |
93 |
95 |
94 self.__setConnected(False) |
96 self.__setConnected(False) |
95 |
97 |
96 if Preferences.getCooperation("AutoStartServer"): |
98 if Preferences.getCooperation("AutoStartServer"): |
97 self.on_serverButton_clicked() |
99 self.on_serverButton_clicked() |
|
100 |
|
101 self.recent = [] |
|
102 self.__loadRecent() |
|
103 |
|
104 def __loadRecent(self): |
|
105 """ |
|
106 Private method to load the recently connected hosts. |
|
107 """ |
|
108 self.recent = [] |
|
109 Preferences.Prefs.rsettings.sync() |
|
110 rh = Preferences.Prefs.rsettings.value(recentNameHosts) |
|
111 if rh is not None: |
|
112 self.recent = rh[:20] |
|
113 self.hostEdit.clear() |
|
114 self.hostEdit.addItem("", -1) |
|
115 for entry in self.recent: |
|
116 host, port = entry.split(":") |
|
117 port = int(port) |
|
118 hostStr = "{0} ({1})".format(host, port) |
|
119 self.hostEdit.addItem(hostStr, port) |
|
120 |
|
121 def __saveRecent(self): |
|
122 """ |
|
123 Private method to save the list of recently connected hosts. |
|
124 """ |
|
125 Preferences.Prefs.rsettings.setValue(recentNameHosts, self.recent) |
|
126 Preferences.Prefs.rsettings.sync() |
|
127 |
|
128 def __setHostsHistory(self, host, port): |
|
129 """ |
|
130 Private method to set the given host and port. |
|
131 |
|
132 @param host host name to remember (string) |
|
133 @param port port number to remember (integer) |
|
134 """ |
|
135 hostStr = "{0}:{1}".format(host, port) |
|
136 if hostStr in self.recent: |
|
137 self.recent.remove(hostStr) |
|
138 self.recent.insert(0, hostStr) |
|
139 |
|
140 hostStr = "{0} ({1})".format(host, port) |
|
141 index = self.hostEdit.findText(hostStr) |
|
142 if index != -1: |
|
143 self.hostEdit.removeItem(index) |
|
144 if self.hostEdit.itemText(0) == host: |
|
145 self.hostEdit.removeItem(0) |
|
146 self.hostEdit.setEditText(hostStr) |
|
147 self.hostEdit.insertItem(0, hostStr, port) |
|
148 self.hostEdit.setCurrentIndex(0) |
98 |
149 |
99 def __handleMessage(self): |
150 def __handleMessage(self): |
100 """ |
151 """ |
101 Private slot handling the Return key pressed in the message edit. |
152 Private slot handling the Return key pressed in the message edit. |
102 """ |
153 """ |
177 self.chatEdit.append(message + "\n") |
228 self.chatEdit.append(message + "\n") |
178 bar = self.chatEdit.verticalScrollBar() |
229 bar = self.chatEdit.verticalScrollBar() |
179 bar.setValue(bar.maximum()) |
230 bar.setValue(bar.maximum()) |
180 |
231 |
181 @pyqtSlot(str) |
232 @pyqtSlot(str) |
182 def on_hostEdit_textChanged(self, host): |
233 def on_hostEdit_editTextChanged(self, host): |
183 """ |
234 """ |
184 Private slot handling the entry of a host to connect to. |
235 Private slot handling the entry of a host to connect to. |
185 |
236 |
186 @param host host to connect to (string) |
237 @param host host to connect to (string) |
187 """ |
238 """ |
188 if not self.__connected: |
239 if not self.__connected: |
189 self.connectButton.setEnabled(host != "") |
240 self.connectButton.setEnabled(host != "") |
190 |
241 |
|
242 @pyqtSlot(int) |
|
243 def on_hostEdit_currentIndexChanged(self, index): |
|
244 """ |
|
245 Private slot to handle the selection of a host. |
|
246 |
|
247 @param index index of the selected entry (integer) |
|
248 """ |
|
249 port = self.hostEdit.itemData(index) |
|
250 if port is not None: |
|
251 if port == -1: |
|
252 self.portSpin.setValue(Preferences.getCooperation("ServerPort")) |
|
253 else: |
|
254 self.portSpin.setValue(port) |
|
255 |
191 @pyqtSlot() |
256 @pyqtSlot() |
192 def on_connectButton_clicked(self): |
257 def on_connectButton_clicked(self): |
193 """ |
258 """ |
194 Private slot initiating the connection. |
259 Private slot initiating the connection. |
195 """ |
260 """ |
196 if not self.__connected: |
261 if not self.__connected: |
|
262 self.__setHostsHistory(self.hostEdit.currentText().split()[0], |
|
263 self.portSpin.value()) |
|
264 self.__saveRecent() |
197 if not self.__client.server().isListening(): |
265 if not self.__client.server().isListening(): |
198 self.on_serverButton_clicked() |
266 self.on_serverButton_clicked() |
199 if self.__client.server().isListening(): |
267 if self.__client.server().isListening(): |
200 self.__client.connectToHost(self.hostEdit.text(), self.portSpin.value()) |
268 self.__client.connectToHost(self.hostEdit.currentText().split()[0], |
|
269 self.portSpin.value()) |
201 self.__setConnected(True) |
270 self.__setConnected(True) |
202 else: |
271 else: |
203 self.__client.disconnectConnections() |
272 self.__client.disconnectConnections() |
204 self.__setConnected(False) |
273 self.__setConnected(False) |
205 |
274 |
238 self.connectButton.setText(self.trUtf8("Disconnect")) |
307 self.connectButton.setText(self.trUtf8("Disconnect")) |
239 self.connectButton.setEnabled(True) |
308 self.connectButton.setEnabled(True) |
240 self.connectionLed.setColor(QColor(Qt.green)) |
309 self.connectionLed.setColor(QColor(Qt.green)) |
241 else: |
310 else: |
242 self.connectButton.setText(self.trUtf8("Connect")) |
311 self.connectButton.setText(self.trUtf8("Connect")) |
243 self.connectButton.setEnabled(self.hostEdit.text() != "") |
312 self.connectButton.setEnabled(self.hostEdit.currentText() != "") |
244 self.connectionLed.setColor(QColor(Qt.red)) |
313 self.connectionLed.setColor(QColor(Qt.red)) |
245 self.cancelEditButton.click() |
314 self.cancelEditButton.click() |
246 self.shareButton.click() |
315 self.shareButton.click() |
247 self.__connected = connected |
316 self.__connected = connected |
248 self.hostEdit.setEnabled(not connected) |
317 self.hostEdit.setEnabled(not connected) |