Add support of new message "_nicklist_diff"
This commit is contained in:
parent
be3c1edaf1
commit
2a0b6adc57
2 changed files with 77 additions and 26 deletions
|
@ -147,7 +147,7 @@ class Buffer(QtCore.QObject):
|
||||||
def __init__(self, data={}):
|
def __init__(self, data={}):
|
||||||
QtCore.QObject.__init__(self)
|
QtCore.QObject.__init__(self)
|
||||||
self.data = data
|
self.data = data
|
||||||
self.nicklist = []
|
self.nicklist = {}
|
||||||
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist', 0))
|
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist', 0))
|
||||||
self.update_title()
|
self.update_title()
|
||||||
self.update_prompt()
|
self.update_prompt()
|
||||||
|
@ -176,23 +176,51 @@ class Buffer(QtCore.QObject):
|
||||||
if self.data:
|
if self.data:
|
||||||
self.bufferInput.emit(self.data['full_name'], text)
|
self.bufferInput.emit(self.data['full_name'], text)
|
||||||
|
|
||||||
def add_nick(self, prefix, nick):
|
def nicklist_add_item(self, parent, group, prefix, name, visible):
|
||||||
"""Add a nick to nicklist."""
|
"""Add a group/nick in nicklist."""
|
||||||
prefix_color = { '': '', ' ': '', '+': 'yellow' }
|
if group:
|
||||||
self.nicklist.append((prefix, nick))
|
self.nicklist[name] = { 'visible': visible,
|
||||||
color = prefix_color.get(prefix, 'green')
|
'nicks': [] }
|
||||||
if color:
|
|
||||||
icon = QtGui.QIcon('data/icons/bullet_%s_8x8.png' % color)
|
|
||||||
else:
|
else:
|
||||||
pixmap = QtGui.QPixmap(8, 8)
|
self.nicklist[parent]['nicks'].append({ 'prefix': prefix,
|
||||||
pixmap.fill()
|
'name': name,
|
||||||
icon = QtGui.QIcon(pixmap)
|
'visible': visible })
|
||||||
item = QtGui.QListWidgetItem(icon, nick)
|
|
||||||
#item.setFont('monospace')
|
|
||||||
self.widget.nicklist.addItem(item)
|
|
||||||
self.widget.nicklist.setVisible(True)
|
|
||||||
|
|
||||||
def remove_all_nicks(self):
|
def nicklist_remove_item(self, parent, group, name):
|
||||||
"""Remove all nicks from nicklist."""
|
"""Remove a group/nick from nicklist."""
|
||||||
self.nicklist = []
|
if group:
|
||||||
|
if name in self.nicklist:
|
||||||
|
del self.nicklist[name]
|
||||||
|
else:
|
||||||
|
if parent in self.nicklist:
|
||||||
|
self.nicklist[parent]['nicks'] = [nick for nick in self.nicklist[parent]['nicks'] if nick['name'] != name]
|
||||||
|
|
||||||
|
def nicklist_update_item(self, parent, group, prefix, name, visible):
|
||||||
|
"""Update a group/nick in nicklist."""
|
||||||
|
if group:
|
||||||
|
if name in self.nicklist:
|
||||||
|
self.nicklist[name]['visible'] = visible
|
||||||
|
else:
|
||||||
|
if parent in self.nicklist:
|
||||||
|
for nick in self.nicklist[parent]['nicks']:
|
||||||
|
if nick['name'] == name:
|
||||||
|
nick['prefix'] = prefix
|
||||||
|
nick['visible'] = visible
|
||||||
|
break
|
||||||
|
|
||||||
|
def nicklist_refresh(self):
|
||||||
|
"""Refresh nicklist."""
|
||||||
self.widget.nicklist.clear()
|
self.widget.nicklist.clear()
|
||||||
|
for group in sorted(self.nicklist):
|
||||||
|
for nick in sorted(self.nicklist[group]['nicks'], key=lambda n:n['name']):
|
||||||
|
prefix_color = { '': '', ' ': '', '+': 'yellow' }
|
||||||
|
color = prefix_color.get(nick['prefix'], 'green')
|
||||||
|
if color:
|
||||||
|
icon = QtGui.QIcon('data/icons/bullet_%s_8x8.png' % color)
|
||||||
|
else:
|
||||||
|
pixmap = QtGui.QPixmap(8, 8)
|
||||||
|
pixmap.fill()
|
||||||
|
icon = QtGui.QIcon(pixmap)
|
||||||
|
item = QtGui.QListWidgetItem(icon, nick['name'])
|
||||||
|
self.widget.nicklist.addItem(item)
|
||||||
|
self.widget.nicklist.setVisible(True)
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
# start dev
|
# start dev
|
||||||
#
|
#
|
||||||
|
|
||||||
import sys, struct
|
import sys, struct, traceback
|
||||||
import qt_compat
|
import qt_compat
|
||||||
QtCore = qt_compat.import_module('QtCore')
|
QtCore = qt_compat.import_module('QtCore')
|
||||||
QtGui = qt_compat.import_module('QtGui')
|
QtGui = qt_compat.import_module('QtGui')
|
||||||
|
@ -254,7 +254,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
self.debug_display(0, '', 'Message: %s' % message)
|
self.debug_display(0, '', 'Message: %s' % message)
|
||||||
self.parse_message(message)
|
self.parse_message(message)
|
||||||
except:
|
except:
|
||||||
print('Error while decoding message from WeeChat')
|
print('Error while decoding message from WeeChat:\n%s' % traceback.format_exc())
|
||||||
self.network.disconnect_weechat()
|
self.network.disconnect_weechat()
|
||||||
|
|
||||||
def parse_message(self, message):
|
def parse_message(self, message):
|
||||||
|
@ -288,17 +288,40 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
item['prefix'],
|
item['prefix'],
|
||||||
item['message'])
|
item['message'])
|
||||||
elif message.msgid in ('_nicklist', 'nicklist'):
|
elif message.msgid in ('_nicklist', 'nicklist'):
|
||||||
buffer_nicklist = {}
|
buffer_refresh = {}
|
||||||
for obj in message.objects:
|
for obj in message.objects:
|
||||||
if obj.objtype == 'hda' and obj.value['path'][-1] == 'nicklist_item':
|
if obj.objtype == 'hda' and obj.value['path'][-1] == 'nicklist_item':
|
||||||
|
group = '__root'
|
||||||
for item in obj.value['items']:
|
for item in obj.value['items']:
|
||||||
index = [i for i, b in enumerate(self.buffers) if b.pointer() == item['__path'][0]]
|
index = [i for i, b in enumerate(self.buffers) if b.pointer() == item['__path'][0]]
|
||||||
if index:
|
if index:
|
||||||
if not item['__path'][0] in buffer_nicklist:
|
if not index[0] in buffer_refresh:
|
||||||
self.buffers[index[0]].remove_all_nicks()
|
self.buffers[index[0]].nicklist = {}
|
||||||
buffer_nicklist[item['__path'][0]] = True
|
buffer_refresh[index[0]] = True
|
||||||
if not item['group'] and item['visible']:
|
if item['group']:
|
||||||
self.buffers[index[0]].add_nick(item['prefix'], item['name'])
|
group = item['name']
|
||||||
|
self.buffers[index[0]].nicklist_add_item(group, item['group'], item['prefix'], item['name'], item['visible'])
|
||||||
|
for index in buffer_refresh:
|
||||||
|
self.buffers[index].nicklist_refresh()
|
||||||
|
elif message.msgid == '_nicklist_diff':
|
||||||
|
buffer_refresh = {}
|
||||||
|
for obj in message.objects:
|
||||||
|
if obj.objtype == 'hda' and obj.value['path'][-1] == 'nicklist_item':
|
||||||
|
group = '__root'
|
||||||
|
for item in obj.value['items']:
|
||||||
|
index = [i for i, b in enumerate(self.buffers) if b.pointer() == item['__path'][0]]
|
||||||
|
if index:
|
||||||
|
buffer_refresh[index[0]] = True
|
||||||
|
if item['_diff'] == ord('^'):
|
||||||
|
group = item['name']
|
||||||
|
elif item['_diff'] == ord('+'):
|
||||||
|
self.buffers[index[0]].nicklist_add_item(group, item['group'], item['prefix'], item['name'], item['visible'])
|
||||||
|
elif item['_diff'] == ord('-'):
|
||||||
|
self.buffers[index[0]].nicklist_remove_item(group, item['group'], item['name'])
|
||||||
|
elif item['_diff'] == ord('*'):
|
||||||
|
self.buffers[index[0]].nicklist_update_item(group, item['group'], item['prefix'], item['name'], item['visible'])
|
||||||
|
for index in buffer_refresh:
|
||||||
|
self.buffers[index].nicklist_refresh()
|
||||||
elif message.msgid == '_buffer_opened':
|
elif message.msgid == '_buffer_opened':
|
||||||
for obj in message.objects:
|
for obj in message.objects:
|
||||||
if obj.objtype == 'hda' and obj.value['path'][-1] == 'buffer':
|
if obj.objtype == 'hda' and obj.value['path'][-1] == 'buffer':
|
||||||
|
|
Loading…
Reference in a new issue