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={}):
|
||||
QtCore.QObject.__init__(self)
|
||||
self.data = data
|
||||
self.nicklist = []
|
||||
self.nicklist = {}
|
||||
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist', 0))
|
||||
self.update_title()
|
||||
self.update_prompt()
|
||||
|
@ -176,23 +176,51 @@ class Buffer(QtCore.QObject):
|
|||
if self.data:
|
||||
self.bufferInput.emit(self.data['full_name'], text)
|
||||
|
||||
def add_nick(self, prefix, nick):
|
||||
"""Add a nick to nicklist."""
|
||||
def nicklist_add_item(self, parent, group, prefix, name, visible):
|
||||
"""Add a group/nick in nicklist."""
|
||||
if group:
|
||||
self.nicklist[name] = { 'visible': visible,
|
||||
'nicks': [] }
|
||||
else:
|
||||
self.nicklist[parent]['nicks'].append({ 'prefix': prefix,
|
||||
'name': name,
|
||||
'visible': visible })
|
||||
|
||||
def nicklist_remove_item(self, parent, group, name):
|
||||
"""Remove a group/nick from 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()
|
||||
for group in sorted(self.nicklist):
|
||||
for nick in sorted(self.nicklist[group]['nicks'], key=lambda n:n['name']):
|
||||
prefix_color = { '': '', ' ': '', '+': 'yellow' }
|
||||
self.nicklist.append((prefix, nick))
|
||||
color = prefix_color.get(prefix, 'green')
|
||||
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)
|
||||
#item.setFont('monospace')
|
||||
item = QtGui.QListWidgetItem(icon, nick['name'])
|
||||
self.widget.nicklist.addItem(item)
|
||||
self.widget.nicklist.setVisible(True)
|
||||
|
||||
def remove_all_nicks(self):
|
||||
"""Remove all nicks from nicklist."""
|
||||
self.nicklist = []
|
||||
self.widget.nicklist.clear()
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
# start dev
|
||||
#
|
||||
|
||||
import sys, struct
|
||||
import sys, struct, traceback
|
||||
import qt_compat
|
||||
QtCore = qt_compat.import_module('QtCore')
|
||||
QtGui = qt_compat.import_module('QtGui')
|
||||
|
@ -254,7 +254,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||
self.debug_display(0, '', 'Message: %s' % message)
|
||||
self.parse_message(message)
|
||||
except:
|
||||
print('Error while decoding message from WeeChat')
|
||||
print('Error while decoding message from WeeChat:\n%s' % traceback.format_exc())
|
||||
self.network.disconnect_weechat()
|
||||
|
||||
def parse_message(self, message):
|
||||
|
@ -288,17 +288,40 @@ class MainWindow(QtGui.QMainWindow):
|
|||
item['prefix'],
|
||||
item['message'])
|
||||
elif message.msgid in ('_nicklist', 'nicklist'):
|
||||
buffer_nicklist = {}
|
||||
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:
|
||||
if not item['__path'][0] in buffer_nicklist:
|
||||
self.buffers[index[0]].remove_all_nicks()
|
||||
buffer_nicklist[item['__path'][0]] = True
|
||||
if not item['group'] and item['visible']:
|
||||
self.buffers[index[0]].add_nick(item['prefix'], item['name'])
|
||||
if not index[0] in buffer_refresh:
|
||||
self.buffers[index[0]].nicklist = {}
|
||||
buffer_refresh[index[0]] = True
|
||||
if item['group']:
|
||||
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':
|
||||
for obj in message.objects:
|
||||
if obj.objtype == 'hda' and obj.value['path'][-1] == 'buffer':
|
||||
|
|
Loading…
Reference in a new issue