Sort contact by show in systray->chat with if sort_by_show is on. Fixes #1539

This commit is contained in:
Jean-Marie Traissard 2006-04-08 14:33:04 +00:00
parent 40f41bf81d
commit 039a74adff
1 changed files with 49 additions and 32 deletions

View File

@ -248,42 +248,59 @@ class Systray:
state_images = gajim.interface.roster.load_iconset(path) state_images = gajim.interface.roster.load_iconset(path)
groups_menu = gtk.Menu() groups_menu = gtk.Menu()
sort_by_show = gajim.config.get('sort_by_show')
groups_list = gajim.groups[account].keys() # store contact infos in a table so we can easily sort by group, status and name
groups_list.sort() # if we sort_by_show : contacts_table = [group, status, name]
for group in groups_list: # else : contacts_table = [group, name, status]
if group == _('Transports'): contacts_table = []
continue
# at least one 'not offline' or 'without errors' in this group
at_least_one = False
item = gtk.MenuItem(group)
contacts_menu = gtk.Menu()
self.popup_menus.append(contacts_menu)
item.set_submenu(contacts_menu)
for jid in gajim.contacts.get_jid_list(account): for jid in gajim.contacts.get_jid_list(account):
contact = gajim.contacts.get_contact_with_highest_priority(account, contact = gajim.contacts.get_contact_with_highest_priority(account,
jid) jid)
if contact.show != 'offline' and contact.show != 'error':
if contact.groups == []: #user has no group, print him in General if contact.groups == []: #user has no group, print him in General
contact_groups = _('General') contact_groups = [_('General')]
else: else:
contact_groups = contact.groups contact_groups = contact.groups
if group in contact_groups and contact.show != 'offline' and \ for group in contact_groups: # the user can be in mutiple groups, see in all of them
contact.show != 'error': if group == _('Transports'):
at_least_one = True continue
s = gtkgui_helpers.escape_underscore(contact.get_shown_name()) if sort_by_show: # see comment about contacts_table above
contacts_table.append ([group, gajim.SHOW_LIST.index(contact.show),
contact.get_shown_name()])
else:
contacts_table.append ([group, contact.get_shown_name(),
gajim.SHOW_LIST.index(contact.show)])
contacts_table.sort() # Sort : first column before, last column in the end
previous_group = ''
for contact_item in contacts_table:
if sort_by_show: # see comment about contacts_table above
contact_name = contact_item[2]
contact_show = gajim.SHOW_LIST[contact_item[1]]
else:
contact_name = contact_item[1]
contact_show = gajim.SHOW_LIST[contact_item[2]]
if contact_item[0] != previous_group: #It's a new group, add the submenu
item = gtk.MenuItem(contact_item[0])
contacts_menu = gtk.Menu()
self.popup_menus.append(contacts_menu)
item.set_submenu(contacts_menu)
groups_menu.append(item)
previous_group = contact_item[0]
# add contact in group submenu
s = gtkgui_helpers.escape_underscore(contact_name)
item_contact = gtk.ImageMenuItem(s) item_contact = gtk.ImageMenuItem(s)
# any given gtk widget can only be used in one place # any given gtk widget can only be used in one place
# (here we use it in status menu too) # (here we use it in status menu too)
# gtk.Image is a widget, it's better we refactor to use gdk.gdk.Pixbuf allover # gtk.Image is a widget, it's better we refactor to use gdk.gdk.Pixbuf allover
img = state_images[contact.show] img = state_images[contact_show]
img_copy = gobject.new(gtk.Image, pixbuf=img.get_pixbuf()) img_copy = gobject.new(gtk.Image, pixbuf=img.get_pixbuf())
item_contact.set_image(img_copy) item_contact.set_image(img_copy)
item_contact.connect('activate', self.start_chat, account, item_contact.connect('activate', self.start_chat, account,
contact.jid) contact.jid)
contacts_menu.append(item_contact) contacts_menu.append(item_contact)
if at_least_one:
groups_menu.append(item)
return groups_menu return groups_menu
def on_left_click(self): def on_left_click(self):