100 } |
100 } |
101 self.__serviceInterfaces = {} |
101 self.__serviceInterfaces = {} |
102 # no specific service interfaces have been created yet |
102 # no specific service interfaces have been created yet |
103 |
103 |
104 self.__connection = None |
104 self.__connection = None |
|
105 self.__clientId = b"" # prepended to each messge for validity checking |
105 self.__callbacks = {} # callback references indexed by UUID |
106 self.__callbacks = {} # callback references indexed by UUID |
106 self.__messageQueue = collections.deque() |
107 self.__messageQueue = collections.deque() |
107 self.__connected = False |
108 self.__connected = False |
108 |
109 |
109 self.connectionStateChanged.connect(self.__connectionStateChanged) |
110 self.connectionStateChanged.connect(self.__connectionStateChanged) |
168 |
169 |
169 ####################################################################### |
170 ####################################################################### |
170 ## Methods for handling the server connection. |
171 ## Methods for handling the server connection. |
171 ####################################################################### |
172 ####################################################################### |
172 |
173 |
173 def connectToServer(self, host, port=None, timeout=None): |
174 def connectToServer(self, host, port=None, timeout=None, clientId=""): |
174 """ |
175 """ |
175 Public method to connect to the given host and port. |
176 Public method to connect to the given host and port. |
176 |
177 |
177 @param host host name or IP address of the eric remote server |
178 @param host host name or IP address of the eric remote server |
178 @type str |
179 @type str |
179 @param port port number to connect to (defaults to None) |
180 @param port port number to connect to (defaults to None) |
180 @type int (optional) |
181 @type int (optional) |
181 @param timeout timeout im seconds for the connection attempt |
182 @param timeout timeout im seconds for the connection attempt |
182 (defaults to None) |
183 (defaults to None) |
183 @type int (optional) |
184 @type int (optional) |
|
185 @param clientId string prepended to each message for validity checking |
|
186 (defaults to "") |
|
187 @type str (optional) |
184 @return flag indicating success |
188 @return flag indicating success |
185 @rtype bool |
189 @rtype bool |
186 """ |
190 """ |
187 if not bool(port): # None or 0 |
191 if not bool(port): # None or 0 |
188 # use default port |
192 # use default port |
241 |
247 |
242 self.connectionStateChanged.emit(False) |
248 self.connectionStateChanged.emit(False) |
243 self.__connection = None |
249 self.__connection = None |
244 self.__callbacks.clear() |
250 self.__callbacks.clear() |
245 |
251 |
|
252 self.__clientId = b"" |
|
253 |
246 def isServerConnected(self): |
254 def isServerConnected(self): |
247 """ |
255 """ |
248 Public method to check, if a connection to an eric-ide server has been |
256 Public method to check, if a connection to an eric-ide server has been |
249 established. |
257 established. |
250 |
258 |
265 self.__connection.close() |
273 self.__connection.close() |
266 |
274 |
267 self.connectionStateChanged.emit(False) |
275 self.connectionStateChanged.emit(False) |
268 self.__connection = None |
276 self.__connection = None |
269 self.__callbacks.clear() |
277 self.__callbacks.clear() |
|
278 self.__clientId = b"" |
270 |
279 |
271 def getHost(self): |
280 def getHost(self): |
272 """ |
281 """ |
273 Public method to get the connected host as "host name:port". |
282 Public method to get the connected host as "host name:port". |
274 |
283 |
455 # - this is for debugging only |
464 # - this is for debugging only |
456 |
465 |
457 if self.__connection is not None: |
466 if self.__connection is not None: |
458 data = jsonString.encode("utf8", "backslashreplace") |
467 data = jsonString.encode("utf8", "backslashreplace") |
459 header = struct.pack(b"!II", len(data), zlib.adler32(data) & 0xFFFFFFFF) |
468 header = struct.pack(b"!II", len(data), zlib.adler32(data) & 0xFFFFFFFF) |
|
469 if self.__clientId: |
|
470 self.__connection.write(self.__clientId) |
460 self.__connection.write(header) |
471 self.__connection.write(header) |
461 self.__connection.write(data) |
472 self.__connection.write(data) |
462 if flush: |
473 if flush: |
463 self.__connection.flush() |
474 self.__connection.flush() |
464 |
475 |
670 |
681 |
671 self.disconnectServerAct.setEnabled(False) |
682 self.disconnectServerAct.setEnabled(False) |
672 self.stopServerAct.setEnabled(False) |
683 self.stopServerAct.setEnabled(False) |
673 self.serverVersionsAct.setEnabled(False) |
684 self.serverVersionsAct.setEnabled(False) |
674 |
685 |
675 def initMenu(self): |
686 def initMenus(self): |
676 """ |
687 """ |
677 Public slot to initialize the eric-ide server menu. |
688 Public slot to initialize the eric-ide server menus. |
678 |
689 |
679 @return the menu generated |
690 @return reference to the main eric-ide server menu |
680 @rtype QMenu |
691 @rtype QMenu |
681 """ |
692 """ |
682 self.__serverProfilesMenu = QMenu(self.tr("Connect to")) |
693 self.__serverProfilesMenu = QMenu(self.tr("Connect to")) |
683 self.__serverProfilesMenu.aboutToShow.connect(self.__showServerProfilesMenu) |
694 self.__serverProfilesMenu.aboutToShow.connect(self.__showServerProfilesMenu) |
684 self.__serverProfilesMenu.triggered.connect(self.__serverProfileTriggered) |
695 self.__serverProfilesMenu.triggered.connect(self.__serverProfileTriggered) |
755 @pyqtSlot() |
766 @pyqtSlot() |
756 def __showServerProfilesMenu(self): |
767 def __showServerProfilesMenu(self): |
757 """ |
768 """ |
758 Private slot to prepare the eric server profiles menu. |
769 Private slot to prepare the eric server profiles menu. |
759 """ |
770 """ |
760 profiles = Preferences.getEricServer("ConnectionProfiles") |
771 serverProfiles = Preferences.getEricServer("ConnectionProfiles") |
761 |
772 |
762 self.__serverProfilesMenu.clear() |
773 self.__serverProfilesMenu.clear() |
763 |
774 |
764 if not self.isServerConnected(): |
775 if not self.isServerConnected(): |
765 for profile in sorted(profiles): |
776 for serverProfile in sorted(serverProfiles): |
766 act = self.__serverProfilesMenu.addAction(profile) |
777 act = self.__serverProfilesMenu.addAction(serverProfile) |
767 act.setData(profiles[profile]) |
778 data = serverProfiles[serverProfile] |
|
779 if len(data) == 3: |
|
780 # profile generated before eric-ide 24.12 |
|
781 data.append("") |
|
782 act.setData(data) |
768 self.__serverProfilesMenu.addSeparator() |
783 self.__serverProfilesMenu.addSeparator() |
769 |
784 |
770 self.__serverProfilesMenu.addAction( |
785 self.__serverProfilesMenu.addAction( |
771 self.tr("Manage Server Connections"), self.__manageServerProfiles |
786 self.tr("Manage Server Connections"), self.__manageServerProfiles |
772 ) |
787 ) |
816 """ |
831 """ |
817 from .EricServerConnectionDialog import EricServerConnectionDialog |
832 from .EricServerConnectionDialog import EricServerConnectionDialog |
818 |
833 |
819 dlg = EricServerConnectionDialog(parent=self.__ui) |
834 dlg = EricServerConnectionDialog(parent=self.__ui) |
820 if dlg.exec() == QDialog.DialogCode.Accepted: |
835 if dlg.exec() == QDialog.DialogCode.Accepted: |
821 hostname, port, timeout = dlg.getData() |
836 hostname, port, timeout, clientId = dlg.getData() |
822 self.connectToServer(hostname, port=port, timeout=timeout) |
837 self.connectToServer( |
|
838 hostname, port=port, timeout=timeout, clientId=clientId |
|
839 ) |
823 |
840 |
824 @pyqtSlot() |
841 @pyqtSlot() |
825 def __shutdownServer(self): |
842 def __shutdownServer(self): |
826 """ |
843 """ |
827 Private slot to shut down the currently connected eric-ide server. |
844 Private slot to shut down the currently connected eric-ide server. |
847 @type QAction |
864 @type QAction |
848 """ |
865 """ |
849 data = act.data() |
866 data = act.data() |
850 if data is not None: |
867 if data is not None: |
851 # handle the connection |
868 # handle the connection |
852 hostname, port, timeout = data |
869 hostname, port, timeout, clientId = data |
853 self.connectToServer(hostname, port=port, timeout=timeout) |
870 self.connectToServer( |
|
871 hostname, port=port, timeout=timeout, clientId=clientId |
|
872 ) |
854 |
873 |
855 @pyqtSlot() |
874 @pyqtSlot() |
856 def __manageServerProfiles(self): |
875 def __manageServerProfiles(self): |
857 """ |
876 """ |
858 Private slot to show a dialog to manage the eric-ide server connection |
877 Private slot to show a dialog to manage the eric-ide server connection |