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_FILENAME = '%s/qweechat.conf' % CONFIG_DIR | ||||
| 
 | ||||
| CONFIG_DEFAULT_RELAY_LINES = 50 | ||||
| 
 | ||||
| CONFIG_DEFAULT_SECTIONS = ('relay', 'look', 'color') | ||||
| CONFIG_DEFAULT_OPTIONS = (('relay.server', ''), | ||||
|                           ('relay.port', ''), | ||||
|                           ('relay.ssl', 'off'), | ||||
|                           ('relay.password', ''), | ||||
|                           ('relay.autoconnect', 'off'), | ||||
|                           ('relay.lines', str(CONFIG_DEFAULT_RELAY_LINES)), | ||||
|                           ('look.debug', 'off'), | ||||
|                           ('look.statusbar', 'off')) | ||||
| 
 | ||||
|  |  | |||
|  | @ -26,7 +26,7 @@ QtGui = qt_compat.import_module('QtGui') | |||
| 
 | ||||
| 
 | ||||
| class ConnectionDialog(QtGui.QDialog): | ||||
|     """Connection window with server/port/password fields.""" | ||||
|     """Connection window.""" | ||||
| 
 | ||||
|     def __init__(self, values, *args): | ||||
|         QtGui.QDialog.__init__(*(self,) + args) | ||||
|  | @ -37,12 +37,16 @@ class ConnectionDialog(QtGui.QDialog): | |||
|         grid.setSpacing(10) | ||||
| 
 | ||||
|         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) | ||||
|             lineEdit = QtGui.QLineEdit() | ||||
|             lineEdit.setFixedWidth(200) | ||||
|             if field == '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]) | ||||
|             grid.addWidget(lineEdit, y, 1) | ||||
|             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.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.show() | ||||
|  |  | |||
|  | @ -25,10 +25,11 @@ import struct | |||
| import qt_compat | ||||
| QtCore = qt_compat.import_module('QtCore') | ||||
| QtNetwork = qt_compat.import_module('QtNetwork') | ||||
| import config | ||||
| 
 | ||||
| _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', | ||||
|                     '(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', | ||||
|                     'sync', | ||||
|                     ''] | ||||
|  | @ -49,6 +50,7 @@ class Network(QtCore.QObject): | |||
|         self._port = None | ||||
|         self._ssl = None | ||||
|         self._password = None | ||||
|         self._lines = config.CONFIG_DEFAULT_RELAY_LINES | ||||
|         self._buffer = QtCore.QByteArray() | ||||
|         self._socket = QtNetwork.QSslSocket() | ||||
|         self._socket.connected.connect(self._socket_connected) | ||||
|  | @ -60,7 +62,9 @@ class Network(QtCore.QObject): | |||
|         """Slot: socket connected.""" | ||||
|         self.statusChanged.emit(self.status_connected, None) | ||||
|         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): | ||||
|         """Slot: socket error.""" | ||||
|  | @ -102,7 +106,7 @@ class Network(QtCore.QObject): | |||
|     def is_ssl(self): | ||||
|         return self._ssl | ||||
| 
 | ||||
|     def connect_weechat(self, server, port, ssl, password): | ||||
|     def connect_weechat(self, server, port, ssl, password, lines): | ||||
|         self._server = server | ||||
|         try: | ||||
|             self._port = int(port) | ||||
|  | @ -110,6 +114,10 @@ class Network(QtCore.QObject): | |||
|             self._port = 0 | ||||
|         self._ssl = ssl | ||||
|         self._password = password | ||||
|         try: | ||||
|             self._lines = int(lines) | ||||
|         except: | ||||
|             self._lines = config.CONFIG_DEFAULT_RELAY_LINES | ||||
|         if self._socket.state() == QtNetwork.QAbstractSocket.ConnectedState: | ||||
|             return | ||||
|         if self._socket.state() != QtNetwork.QAbstractSocket.UnconnectedState: | ||||
|  | @ -148,4 +156,5 @@ class Network(QtCore.QObject): | |||
|         return {'server': self._server, | ||||
|                 'port': self._port, | ||||
|                 '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.config.get('relay', 'port'), | ||||
|                                          self.config.getboolean('relay', 'ssl'), | ||||
|                                          self.config.get('relay', 'password')) | ||||
|                                          self.config.get('relay', 'password'), | ||||
|                                          self.config.get('relay', 'lines')) | ||||
| 
 | ||||
|         self.show() | ||||
| 
 | ||||
|  | @ -206,7 +207,7 @@ class MainWindow(QtGui.QMainWindow): | |||
| 
 | ||||
|     def open_connection_dialog(self): | ||||
|         values = {} | ||||
|         for option in ('server', 'port', 'ssl', 'password'): | ||||
|         for option in ('server', 'port', 'ssl', 'password', 'lines'): | ||||
|             values[option] = self.config.get('relay', option) | ||||
|         self.connection_dialog = ConnectionDialog(values, self) | ||||
|         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.connection_dialog.fields['port'].text(), | ||||
|                                      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() | ||||
| 
 | ||||
|     def network_status_changed(self, status, extra): | ||||
|  | @ -283,6 +285,7 @@ class MainWindow(QtGui.QMainWindow): | |||
|                     self.buffers[0].widget.input.setFocus() | ||||
|         elif message.msgid in ('listlines', '_buffer_line_added'): | ||||
|             for obj in message.objects: | ||||
|                 lines = [] | ||||
|                 if obj.objtype == 'hda' and obj.value['path'][-1] == 'line_data': | ||||
|                     for item in obj.value['items']: | ||||
|                         if message.msgid == 'listlines': | ||||
|  | @ -291,9 +294,11 @@ class MainWindow(QtGui.QMainWindow): | |||
|                             ptrbuf = item['buffer'] | ||||
|                         index = [i for i, b in enumerate(self.buffers) if b.pointer() == ptrbuf] | ||||
|                         if index: | ||||
|                             self.buffers[index[0]].widget.chat.display(item['date'], | ||||
|                                                                        item['prefix'], | ||||
|                                                                        item['message']) | ||||
|                             lines.append((item['date'], item['prefix'], item['message'])) | ||||
|                 if message.msgid == 'listlines': | ||||
|                     lines.reverse() | ||||
|                 for line in lines: | ||||
|                     self.buffers[index[0]].widget.chat.display(*line) | ||||
|         elif message.msgid in ('_nicklist', 'nicklist'): | ||||
|             buffer_refresh = {} | ||||
|             for obj in message.objects: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sebastien Helleu
						Sebastien Helleu