Add option relay.lines to limit the number of lines received on connection (default: 50)
This commit is contained in:
parent
9738f64af8
commit
46e5dee03a
4 changed files with 34 additions and 13 deletions
|
@ -27,12 +27,15 @@ import weechat.color as color
|
||||||
CONFIG_DIR = '%s/.qweechat' % os.getenv('HOME')
|
CONFIG_DIR = '%s/.qweechat' % os.getenv('HOME')
|
||||||
CONFIG_FILENAME = '%s/qweechat.conf' % CONFIG_DIR
|
CONFIG_FILENAME = '%s/qweechat.conf' % CONFIG_DIR
|
||||||
|
|
||||||
|
CONFIG_DEFAULT_RELAY_LINES = 50
|
||||||
|
|
||||||
CONFIG_DEFAULT_SECTIONS = ('relay', 'look', 'color')
|
CONFIG_DEFAULT_SECTIONS = ('relay', 'look', 'color')
|
||||||
CONFIG_DEFAULT_OPTIONS = (('relay.server', ''),
|
CONFIG_DEFAULT_OPTIONS = (('relay.server', ''),
|
||||||
('relay.port', ''),
|
('relay.port', ''),
|
||||||
('relay.ssl', 'off'),
|
('relay.ssl', 'off'),
|
||||||
('relay.password', ''),
|
('relay.password', ''),
|
||||||
('relay.autoconnect', 'off'),
|
('relay.autoconnect', 'off'),
|
||||||
|
('relay.lines', str(CONFIG_DEFAULT_RELAY_LINES)),
|
||||||
('look.debug', 'off'),
|
('look.debug', 'off'),
|
||||||
('look.statusbar', 'off'))
|
('look.statusbar', 'off'))
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ QtGui = qt_compat.import_module('QtGui')
|
||||||
|
|
||||||
|
|
||||||
class ConnectionDialog(QtGui.QDialog):
|
class ConnectionDialog(QtGui.QDialog):
|
||||||
"""Connection window with server/port/password fields."""
|
"""Connection window."""
|
||||||
|
|
||||||
def __init__(self, values, *args):
|
def __init__(self, values, *args):
|
||||||
QtGui.QDialog.__init__(*(self,) + args)
|
QtGui.QDialog.__init__(*(self,) + args)
|
||||||
|
@ -37,12 +37,16 @@ class ConnectionDialog(QtGui.QDialog):
|
||||||
grid.setSpacing(10)
|
grid.setSpacing(10)
|
||||||
|
|
||||||
self.fields = {}
|
self.fields = {}
|
||||||
for y, field in enumerate(('server', 'port', 'password')):
|
for y, field in enumerate(('server', 'port', 'password', 'lines')):
|
||||||
grid.addWidget(QtGui.QLabel(field.capitalize()), y, 0)
|
grid.addWidget(QtGui.QLabel(field.capitalize()), y, 0)
|
||||||
lineEdit = QtGui.QLineEdit()
|
lineEdit = QtGui.QLineEdit()
|
||||||
lineEdit.setFixedWidth(200)
|
lineEdit.setFixedWidth(200)
|
||||||
if field == 'password':
|
if field == 'password':
|
||||||
lineEdit.setEchoMode(QtGui.QLineEdit.Password)
|
lineEdit.setEchoMode(QtGui.QLineEdit.Password)
|
||||||
|
if field == 'lines':
|
||||||
|
validator = QtGui.QIntValidator(0, 2147483647, self)
|
||||||
|
lineEdit.setValidator(validator)
|
||||||
|
lineEdit.setFixedWidth(80)
|
||||||
lineEdit.insert(self.values[field])
|
lineEdit.insert(self.values[field])
|
||||||
grid.addWidget(lineEdit, y, 1)
|
grid.addWidget(lineEdit, y, 1)
|
||||||
self.fields[field] = lineEdit
|
self.fields[field] = lineEdit
|
||||||
|
@ -56,6 +60,6 @@ class ConnectionDialog(QtGui.QDialog):
|
||||||
self.dialog_buttons.setStandardButtons(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
|
self.dialog_buttons.setStandardButtons(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
|
||||||
self.dialog_buttons.rejected.connect(self.close)
|
self.dialog_buttons.rejected.connect(self.close)
|
||||||
|
|
||||||
grid.addWidget(self.dialog_buttons, 3, 0, 1, 2)
|
grid.addWidget(self.dialog_buttons, 4, 0, 1, 2)
|
||||||
self.setLayout(grid)
|
self.setLayout(grid)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
|
@ -25,10 +25,11 @@ import struct
|
||||||
import qt_compat
|
import qt_compat
|
||||||
QtCore = qt_compat.import_module('QtCore')
|
QtCore = qt_compat.import_module('QtCore')
|
||||||
QtNetwork = qt_compat.import_module('QtNetwork')
|
QtNetwork = qt_compat.import_module('QtNetwork')
|
||||||
|
import config
|
||||||
|
|
||||||
_PROTO_INIT_CMD = ['init password=%(password)s']
|
_PROTO_INIT_CMD = ['init password=%(password)s']
|
||||||
_PROTO_SYNC_CMDS = ['(listbuffers) hdata buffer:gui_buffers(*) number,full_name,short_name,type,nicklist,title,local_variables',
|
_PROTO_SYNC_CMDS = ['(listbuffers) hdata buffer:gui_buffers(*) number,full_name,short_name,type,nicklist,title,local_variables',
|
||||||
'(listlines) hdata buffer:gui_buffers(*)/own_lines/first_line(*)/data date,displayed,prefix,message',
|
'(listlines) hdata buffer:gui_buffers(*)/own_lines/last_line(-%(lines)d)/data date,displayed,prefix,message',
|
||||||
'(nicklist) nicklist',
|
'(nicklist) nicklist',
|
||||||
'sync',
|
'sync',
|
||||||
'']
|
'']
|
||||||
|
@ -49,6 +50,7 @@ class Network(QtCore.QObject):
|
||||||
self._port = None
|
self._port = None
|
||||||
self._ssl = None
|
self._ssl = None
|
||||||
self._password = None
|
self._password = None
|
||||||
|
self._lines = config.CONFIG_DEFAULT_RELAY_LINES
|
||||||
self._buffer = QtCore.QByteArray()
|
self._buffer = QtCore.QByteArray()
|
||||||
self._socket = QtNetwork.QSslSocket()
|
self._socket = QtNetwork.QSslSocket()
|
||||||
self._socket.connected.connect(self._socket_connected)
|
self._socket.connected.connect(self._socket_connected)
|
||||||
|
@ -60,7 +62,9 @@ class Network(QtCore.QObject):
|
||||||
"""Slot: socket connected."""
|
"""Slot: socket connected."""
|
||||||
self.statusChanged.emit(self.status_connected, None)
|
self.statusChanged.emit(self.status_connected, None)
|
||||||
if self._password:
|
if self._password:
|
||||||
self.send_to_weechat('\n'.join(_PROTO_INIT_CMD + _PROTO_SYNC_CMDS) % {'password': str(self._password)})
|
self.send_to_weechat('\n'.join(_PROTO_INIT_CMD + _PROTO_SYNC_CMDS)
|
||||||
|
% {'password': str(self._password),
|
||||||
|
'lines': self._lines})
|
||||||
|
|
||||||
def _socket_error(self, error):
|
def _socket_error(self, error):
|
||||||
"""Slot: socket error."""
|
"""Slot: socket error."""
|
||||||
|
@ -102,7 +106,7 @@ class Network(QtCore.QObject):
|
||||||
def is_ssl(self):
|
def is_ssl(self):
|
||||||
return self._ssl
|
return self._ssl
|
||||||
|
|
||||||
def connect_weechat(self, server, port, ssl, password):
|
def connect_weechat(self, server, port, ssl, password, lines):
|
||||||
self._server = server
|
self._server = server
|
||||||
try:
|
try:
|
||||||
self._port = int(port)
|
self._port = int(port)
|
||||||
|
@ -110,6 +114,10 @@ class Network(QtCore.QObject):
|
||||||
self._port = 0
|
self._port = 0
|
||||||
self._ssl = ssl
|
self._ssl = ssl
|
||||||
self._password = password
|
self._password = password
|
||||||
|
try:
|
||||||
|
self._lines = int(lines)
|
||||||
|
except:
|
||||||
|
self._lines = config.CONFIG_DEFAULT_RELAY_LINES
|
||||||
if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState:
|
if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState:
|
||||||
return
|
return
|
||||||
if self._socket.state() != QtNetwork.QAbstractSocket.UnconnectedState:
|
if self._socket.state() != QtNetwork.QAbstractSocket.UnconnectedState:
|
||||||
|
@ -148,4 +156,5 @@ class Network(QtCore.QObject):
|
||||||
return {'server': self._server,
|
return {'server': self._server,
|
||||||
'port': self._port,
|
'port': self._port,
|
||||||
'ssl': 'on' if self._ssl else 'off',
|
'ssl': 'on' if self._ssl else 'off',
|
||||||
'password': self._password}
|
'password': self._password,
|
||||||
|
'lines': str(self._lines)}
|
||||||
|
|
|
@ -142,7 +142,8 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
self.network.connect_weechat(self.config.get('relay', 'server'),
|
self.network.connect_weechat(self.config.get('relay', 'server'),
|
||||||
self.config.get('relay', 'port'),
|
self.config.get('relay', 'port'),
|
||||||
self.config.getboolean('relay', 'ssl'),
|
self.config.getboolean('relay', 'ssl'),
|
||||||
self.config.get('relay', 'password'))
|
self.config.get('relay', 'password'),
|
||||||
|
self.config.get('relay', 'lines'))
|
||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
@ -206,7 +207,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
|
|
||||||
def open_connection_dialog(self):
|
def open_connection_dialog(self):
|
||||||
values = {}
|
values = {}
|
||||||
for option in ('server', 'port', 'ssl', 'password'):
|
for option in ('server', 'port', 'ssl', 'password', 'lines'):
|
||||||
values[option] = self.config.get('relay', option)
|
values[option] = self.config.get('relay', option)
|
||||||
self.connection_dialog = ConnectionDialog(values, self)
|
self.connection_dialog = ConnectionDialog(values, self)
|
||||||
self.connection_dialog.dialog_buttons.accepted.connect(self.connect_weechat)
|
self.connection_dialog.dialog_buttons.accepted.connect(self.connect_weechat)
|
||||||
|
@ -215,7 +216,8 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
self.network.connect_weechat(self.connection_dialog.fields['server'].text(),
|
self.network.connect_weechat(self.connection_dialog.fields['server'].text(),
|
||||||
self.connection_dialog.fields['port'].text(),
|
self.connection_dialog.fields['port'].text(),
|
||||||
self.connection_dialog.fields['ssl'].isChecked(),
|
self.connection_dialog.fields['ssl'].isChecked(),
|
||||||
self.connection_dialog.fields['password'].text())
|
self.connection_dialog.fields['password'].text(),
|
||||||
|
int(self.connection_dialog.fields['lines'].text()))
|
||||||
self.connection_dialog.close()
|
self.connection_dialog.close()
|
||||||
|
|
||||||
def network_status_changed(self, status, extra):
|
def network_status_changed(self, status, extra):
|
||||||
|
@ -283,6 +285,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
self.buffers[0].widget.input.setFocus()
|
self.buffers[0].widget.input.setFocus()
|
||||||
elif message.msgid in ('listlines', '_buffer_line_added'):
|
elif message.msgid in ('listlines', '_buffer_line_added'):
|
||||||
for obj in message.objects:
|
for obj in message.objects:
|
||||||
|
lines = []
|
||||||
if obj.objtype == 'hda' and obj.value['path'][-1] == 'line_data':
|
if obj.objtype == 'hda' and obj.value['path'][-1] == 'line_data':
|
||||||
for item in obj.value['items']:
|
for item in obj.value['items']:
|
||||||
if message.msgid == 'listlines':
|
if message.msgid == 'listlines':
|
||||||
|
@ -291,9 +294,11 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
ptrbuf = item['buffer']
|
ptrbuf = item['buffer']
|
||||||
index = [i for i, b in enumerate(self.buffers) if b.pointer() == ptrbuf]
|
index = [i for i, b in enumerate(self.buffers) if b.pointer() == ptrbuf]
|
||||||
if index:
|
if index:
|
||||||
self.buffers[index[0]].widget.chat.display(item['date'],
|
lines.append((item['date'], item['prefix'], item['message']))
|
||||||
item['prefix'],
|
if message.msgid == 'listlines':
|
||||||
item['message'])
|
lines.reverse()
|
||||||
|
for line in lines:
|
||||||
|
self.buffers[index[0]].widget.chat.display(*line)
|
||||||
elif message.msgid in ('_nicklist', 'nicklist'):
|
elif message.msgid in ('_nicklist', 'nicklist'):
|
||||||
buffer_refresh = {}
|
buffer_refresh = {}
|
||||||
for obj in message.objects:
|
for obj in message.objects:
|
||||||
|
|
Loading…
Reference in a new issue