sort group chats by status if option is checked. Fixes #3823

This commit is contained in:
Yann Leboulanger 2008-09-23 14:39:04 +00:00
parent 10af522af6
commit 941b7cf974
2 changed files with 57 additions and 8 deletions

View File

@ -532,6 +532,13 @@ class PreferencesWindow:
def on_sort_by_show_checkbutton_toggled(self, widget): def on_sort_by_show_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'sort_by_show') self.on_checkbutton_toggled(widget, 'sort_by_show')
gajim.interface.roster.setup_and_draw_roster() gajim.interface.roster.setup_and_draw_roster()
# Redraw connected groupchats
for account in gajim.connections:
if gajim.connections[account].connected:
for gc_control in gajim.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC) + \
gajim.interface.minimized_controls[account].values():
gc_control.draw_roster()
def on_show_avatars_in_roster_checkbutton_toggled(self, widget): def on_show_avatars_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_avatars_in_roster') self.on_checkbutton_toggled(widget, 'show_avatars_in_roster')
@ -540,9 +547,9 @@ class PreferencesWindow:
for account in gajim.connections: for account in gajim.connections:
if gajim.connections[account].connected: if gajim.connections[account].connected:
for gc_control in gajim.interface.msg_win_mgr.get_controls( for gc_control in gajim.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC) + \ message_control.TYPE_GC) + \
gajim.interface.minimized_controls[account].values(): gajim.interface.minimized_controls[account].values():
gc_control.draw_roster() gc_control.draw_roster()
def on_show_status_msgs_in_roster_checkbutton_toggled(self, widget): def on_show_status_msgs_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_status_msgs_in_roster') self.on_checkbutton_toggled(widget, 'show_status_msgs_in_roster')
@ -563,10 +570,6 @@ class PreferencesWindow:
self.on_checkbutton_toggled(widget, 'show_tunes_in_roster') self.on_checkbutton_toggled(widget, 'show_tunes_in_roster')
gajim.interface.roster.setup_and_draw_roster() gajim.interface.roster.setup_and_draw_roster()
def on_sort_by_show_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'sort_by_show')
gajim.interface.roster.setup_and_draw_roster()
def on_emoticons_combobox_changed(self, widget): def on_emoticons_combobox_changed(self, widget):
active = widget.get_active() active = widget.get_active()
model = widget.get_model() model = widget.get_model()

View File

@ -320,7 +320,8 @@ class GroupchatControl(ChatControlBase):
self.handlers[id] = self.list_treeview self.handlers[id] = self.list_treeview
#status_image, shown_nick, type, nickname, avatar #status_image, shown_nick, type, nickname, avatar
store = gtk.TreeStore(gtk.Image, str, str, str, gtk.gdk.Pixbuf) store = gtk.TreeStore(gtk.Image, str, str, str, gtk.gdk.Pixbuf)
store.set_sort_column_id(C_TEXT, gtk.SORT_ASCENDING) store.set_sort_func(C_NICK, self.tree_compare_iters)
store.set_sort_column_id(C_NICK, gtk.SORT_ASCENDING)
self.list_treeview.set_model(store) self.list_treeview.set_model(store)
# columns # columns
@ -374,6 +375,51 @@ class GroupchatControl(ChatControlBase):
self.conv_textview.tv.grab_focus() self.conv_textview.tv.grab_focus()
self.widget.show_all() self.widget.show_all()
def tree_compare_iters(self, model, iter1, iter2):
'''Compare two iters to sort them'''
type1 = model[iter1][C_TYPE]
type2 = model[iter2][C_TYPE]
if not type1 or not type2:
return 0
nick1 = model[iter1][C_NICK]
nick2 = model[iter2][C_NICK]
if not nick1 or not nick2:
return 0
nick1 = nick1.decode('utf-8')
nick2 = nick2.decode('utf-8')
if type1 == 'role':
if nick1 < nick2:
return -1
return 1
if type1 == 'contact':
gc_contact1 = gajim.contacts.get_gc_contact(self.account, self.room_jid,
nick1)
if not gc_contact1:
return 0
if type2 == 'contact':
gc_contact2 = gajim.contacts.get_gc_contact(self.account, self.room_jid,
nick2)
if not gc_contact2:
return 0
if type1 == 'contact' and type2 == 'contact' and \
gajim.config.get('sort_by_show'):
cshow = {'online':0, 'chat': 1, 'away': 2, 'xa': 3, 'dnd': 4,
'invisible': 5, 'offline': 6, 'error': 7}
show1 = cshow[gc_contact1.show]
show2 = cshow[gc_contact2.show]
if show1 < show2:
return -1
elif show1 > show2:
return 1
# We compare names
name1 = gc_contact1.get_shown_name()
name2 = gc_contact2.get_shown_name()
if name1.lower() < name2.lower():
return -1
if name2.lower() < name1.lower():
return 1
return 0
def on_msg_textview_populate_popup(self, textview, menu): def on_msg_textview_populate_popup(self, textview, menu):
'''we override the default context menu and we prepend Clear '''we override the default context menu and we prepend Clear
and the ability to insert a nick''' and the ability to insert a nick'''