summaryrefslogtreecommitdiff
path: root/src/tabs
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-04-06 00:15:01 +0200
committermathieui <mathieui@mathieui.net>2014-04-06 00:15:01 +0200
commit7b446d9b4d9b41deda280596cb0a01a0c7d01700 (patch)
tree479412b54667532bced8eecd60470e019079fac5 /src/tabs
parent7c7f9b2f4757a1ec4ab4a51d6dfd8d7254d0e705 (diff)
downloadpoezio-7b446d9b4d9b41deda280596cb0a01a0c7d01700.tar.gz
poezio-7b446d9b4d9b41deda280596cb0a01a0c7d01700.tar.bz2
poezio-7b446d9b4d9b41deda280596cb0a01a0c7d01700.tar.xz
poezio-7b446d9b4d9b41deda280596cb0a01a0c7d01700.zip
Improve drastically the performance of the MucListTab
- avoid doing stringprep on every item, avoid at least one full copy - add the number of items to the infowin
Diffstat (limited to 'src/tabs')
-rw-r--r--src/tabs/muclisttab.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/tabs/muclisttab.py b/src/tabs/muclisttab.py
index c5b2a205..cefe0460 100644
--- a/src/tabs/muclisttab.py
+++ b/src/tabs/muclisttab.py
@@ -10,13 +10,18 @@ import logging
log = logging.getLogger(__name__)
import curses
+import collections
+from datetime import datetime
-from . import Tab
+from sleekxmpp.plugins.xep_0030.stanza.items import DiscoItem
import windows
from common import safeJID
from decorators import refresh_wrapper
+from . import Tab
+
+
class MucListTab(Tab):
"""
A tab listing rooms from a specific server, displaying various information,
@@ -29,8 +34,11 @@ class MucListTab(Tab):
Tab.__init__(self)
self.state = 'normal'
self.name = server
- columns = ('node-part', 'name', 'users')
- self.list_header = windows.ColumnHeaderWin(columns)
+ columns = collections.OrderedDict()
+ columns['node-part'] = 0
+ columns['name'] = 2
+ columns['users'] = 3
+ self.list_header = windows.ColumnHeaderWin(list(columns))
self.listview = windows.ListWin(columns)
self.info_header = windows.MucListInfoWin(_('Chatroom list on server %s (Loading)') % self.name)
self.default_help_message = windows.HelpText("ā€œjā€: join room.")
@@ -55,7 +63,7 @@ class MucListTab(Tab):
if self.need_resize:
self.resize()
log.debug(' TAB Refresh: %s', self.__class__.__name__)
- self.info_header.refresh()
+ self.info_header.refresh(window=self.listview)
self.info_win.refresh()
self.refresh_tab_win()
self.list_header.refresh()
@@ -110,18 +118,22 @@ class MucListTab(Tab):
if iq['type'] == 'error':
self.set_error(iq['error']['type'], iq['error']['code'], iq['error']['text'])
return
- items = [{'node-part': safeJID(item[0]).user if safeJID(item[0]).server == self.name else safeJID(item[0]).bare,
- 'jid': item[0],
- 'name': item[2] or '', 'users': ''} for item in iq['disco_items'].get_items()]
- self.listview.add_lines(items)
+ def get_items():
+ substanza = iq['disco_items']
+ for item in substanza['substanzas']:
+ if isinstance(item, DiscoItem):
+ yield (item['jid'], item['node'], item['name'])
+ items = [ (item[0].split('@')[0],
+ item[0],
+ item[2] or '', '') for item in get_items()]
+ self.listview.set_lines(items)
self.info_header.message = _('Chatroom list on server %s') % self.name
if self.core.current_tab() is self:
- self.listview.refresh()
- self.info_header.refresh()
+ self.refresh()
else:
self.state = 'highlight'
self.refresh_tab_win()
- curses.doupdate()
+ self.core.doupdate()
def sort_by(self):
if self.list_header.get_order():
@@ -136,7 +148,7 @@ class MucListTab(Tab):
asc=True)
self.list_header.set_order(True)
self.list_header.refresh()
- curses.doupdate()
+ self.core.doupdate()
def join_selected(self):
row = self.listview.get_selected_row()