|
|
|
@ -27,7 +27,8 @@ import secrets
|
|
|
|
|
import struct
|
|
|
|
|
|
|
|
|
|
from qtpy import QtCore, QtNetwork
|
|
|
|
|
from qtoy.QtCore import pyqtSignal as Signal
|
|
|
|
|
# from PyQt5.QtCore import pyqtSignal as Signal
|
|
|
|
|
from qtpy.QtCore import Signal
|
|
|
|
|
|
|
|
|
|
from qweechat import config
|
|
|
|
|
from qweechat.debug import DebugDialog
|
|
|
|
@ -231,7 +232,19 @@ class Network(QtCore.QObject):
|
|
|
|
|
|
|
|
|
|
def is_connected(self):
|
|
|
|
|
"""Return True if the socket is connected, False otherwise."""
|
|
|
|
|
return self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState
|
|
|
|
|
return is_state(self, at='ConnectedState')
|
|
|
|
|
|
|
|
|
|
def is_state(self, at='ConnectedState'):
|
|
|
|
|
"""Return True if the socket is connected, False otherwise."""
|
|
|
|
|
if hasattr(QtNetwork.QAbstractSocket, 'ConnectedState'):
|
|
|
|
|
if self._socket.state() == getattr(QtNetwork.QAbstractSocket, at):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
if hasattr(QtNetwork.QAbstractSocket, 'SocketState'):
|
|
|
|
|
if self._socket.state() == getattr(QtNetwork.QAbstractSocket.SocketState, at):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def is_ssl(self):
|
|
|
|
|
"""Return True if SSL is used, False otherwise."""
|
|
|
|
@ -251,9 +264,10 @@ class Network(QtCore.QObject):
|
|
|
|
|
self._lines = int(lines)
|
|
|
|
|
except ValueError:
|
|
|
|
|
self._lines = config.CONFIG_DEFAULT_RELAY_LINES
|
|
|
|
|
if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState:
|
|
|
|
|
# AttributeError: type object 'QAbstractSocket' has no attribute 'ConnectedState'
|
|
|
|
|
if self.is_connected():
|
|
|
|
|
return
|
|
|
|
|
if self._socket.state() != QtNetwork.QAbstractSocket.UnconnectedState:
|
|
|
|
|
if not self.is_state('UnconnectedState'):
|
|
|
|
|
self._socket.abort()
|
|
|
|
|
if self._ssl:
|
|
|
|
|
self._socket.ignoreSslErrors()
|
|
|
|
@ -264,10 +278,10 @@ class Network(QtCore.QObject):
|
|
|
|
|
|
|
|
|
|
def disconnect_weechat(self):
|
|
|
|
|
"""Disconnect from WeeChat."""
|
|
|
|
|
if self._socket.state() == QtNetwork.QAbstractSocket.UnconnectedState:
|
|
|
|
|
if self.is_state('UnconnectedState'):
|
|
|
|
|
self.set_status(STATUS_DISCONNECTED)
|
|
|
|
|
return
|
|
|
|
|
if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState:
|
|
|
|
|
if self.is_state('ConnectedState'):
|
|
|
|
|
self.send_to_weechat('quit\n')
|
|
|
|
|
self._socket.waitForBytesWritten(1000)
|
|
|
|
|
else:
|
|
|
|
|