summaryrefslogtreecommitdiff
path: root/python_client.py
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2014-01-24 20:28:25 +0100
committerTreeki <treeki@gmail.com>2014-01-24 20:28:25 +0100
commit33371638a8985df53f86ed9297b9e57c9f46c015 (patch)
tree5733f9264f0e1572cb6afc1f43697f7898613872 /python_client.py
parent22b35add6baa191b6c82347686e2599d848f2cb7 (diff)
downloadbounce4-33371638a8985df53f86ed9297b9e57c9f46c015.tar.gz
bounce4-33371638a8985df53f86ed9297b9e57c9f46c015.zip
show nick prefixes in client nicklist, sync modes correctly
Diffstat (limited to '')
-rw-r--r--python_client.py66
1 files changed, 45 insertions, 21 deletions
diff --git a/python_client.py b/python_client.py
index 39411c5..11c4a50 100644
--- a/python_client.py
+++ b/python_client.py
@@ -162,10 +162,25 @@ class WindowTab(QtWidgets.QWidget):
self.output.setTextCursor(cursor)
class ChannelTab(WindowTab):
+ class UserEntry:
+ def __init__(self, nick, prefix, modes, listwidget):
+ self.nick = nick
+ self.prefix = prefix
+ self.modes = modes
+ self.item = QtWidgets.QListWidgetItem('', listwidget)
+ self.syncItemText()
+
+ def syncItemText(self):
+ if self.prefix == 0:
+ self.item.setText(self.nick)
+ else:
+ self.item.setText(chr(self.prefix) + self.nick)
+
def __init__(self, parent=None):
WindowTab.__init__(self, parent)
self.userList = QtWidgets.QListWidget(self)
+ self.users = {}
def makeLayout(self):
sublayout = QtWidgets.QVBoxLayout()
@@ -180,7 +195,7 @@ class ChannelTab(WindowTab):
userCount = u32.unpack_from(pdata, pos)[0]
pos += 4
- users = []
+ users = {}
for i in range(userCount):
#prefix = pdata[pos]
#pos += 1
@@ -190,9 +205,10 @@ class ChannelTab(WindowTab):
pos += nicklen
modes = u32.unpack_from(pdata, pos)[0]
pos += 4
- users.append(nick)
- #self.userList.addItem(chr(prefix)+nick)
- self.userList.addItem(nick)
+ prefix = pdata[pos]
+ pos += 1
+
+ users[nick] = self.UserEntry(nick, prefix, modes, self.userList)
self.users = users
@@ -214,14 +230,16 @@ class ChannelTab(WindowTab):
pos += nicklen
modes = u32.unpack_from(pdata, pos)[0]
pos += 4
- self.users.append(nick)
- self.userList.addItem(nick)
+ prefix = pdata[pos]
+ pos += 1
+
+ self.users[nick] = self.UserEntry(nick, prefix, modes, self.userList)
def removeUsers(self, pdata):
userCount = u32.unpack_from(pdata, 4)[0]
pos = 8
if userCount == 0:
- self.users = []
+ self.users = {}
self.userList.clear()
else:
for i in range(userCount):
@@ -231,9 +249,10 @@ class ChannelTab(WindowTab):
pos += nicklen
print('Removing [%s]' % repr(nick))
- self.users.remove(nick)
- items = self.userList.findItems(nick, QtCore.Qt.MatchExactly)
- self.userList.takeItem(self.userList.row(items[0]))
+ uo = self.users[nick]
+ self.userList.takeItem(self.userList.row(uo.item))
+
+ del self.users[nick]
def renameUser(self, pdata):
pos = 4
@@ -245,20 +264,25 @@ class ChannelTab(WindowTab):
pos += 4
tonick = pdata[pos:pos+nicklen].decode('utf-8', 'replace')
- try:
- idx = self.users.index(fromnick)
- except ValueError:
- self.pushMessage('Crap, [%s] was not found in the users list!' % fromnick)
- return
-
- self.users[idx] = tonick
+ uo = self.users[fromnick]
+ del self.users[fromnick]
+ self.users[tonick] = uo
- items = self.userList.findItems(fromnick, QtCore.Qt.MatchExactly)
- items[0].setText(tonick)
+ uo.nick = tonick
+ uo.syncItemText()
def changeUserMode(self, pdata):
- # boop
- pass
+ pos = 4
+ nicklen = u32.unpack_from(pdata, pos)[0]
+ pos += 4
+ nick = pdata[pos:pos+nicklen].decode('utf-8', 'replace')
+ pos += nicklen
+ modes, prefix = struct.unpack_from('<IB', pdata, pos)
+
+ uo = self.users[nick]
+ uo.modes = modes
+ uo.prefix = prefix
+ uo.syncItemText()
class MainWindow(QtWidgets.QMainWindow):