Skip to content

Commit

Permalink
remember expand/collapse of groups in group view
Browse files Browse the repository at this point in the history
  • Loading branch information
marianoguerra committed Jul 2, 2010
1 parent 2a21523 commit cc86282
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
22 changes: 12 additions & 10 deletions emesene/gui/base/ContactList.py
Expand Up @@ -42,14 +42,20 @@ def __init__(self, session, dialog):
self.session = session
self.dialog = dialog

self.group_state = {}

self.session.config.get_or_set('b_order_by_group', True)
self.session.config.get_or_set('b_show_nick', True)
self.session.config.get_or_set('b_show_empty_groups', False)
self.session.config.get_or_set('b_show_offline', False)
self.session.config.get_or_set('b_show_blocked', False)
self.session.config.get_or_set('b_group_offline', False)
group_state = self.session.config.get_or_set('d_group_state', {})

self.group_state = {}
for (group, state) in group_state.iteritems():
try:
self.group_state[group] = bool(int(state))
except ValueError:
self.group_state[group] = False

self.avatar_size = self.session.config.get_or_set('i_avatar_size', 32)
self.set_avatar_size(self.avatar_size)
Expand Down Expand Up @@ -441,21 +447,17 @@ def set_group_state(self, group, state):
'''expand group id state is True, collapse it if False'''
raise NotImplementedError()

def expand_collapse_groups(self):
'''expand and collapse the groups according to the state of the
group'''
for (group, state) in self.group_state.iteritems():
self.set_group_state(group, state)

def on_group_collapsed(self, group):
'''called when a group is collapsed, update the status of the
groups'''
self.group_state.update({group.name:False})
self.group_state[group.name] = False
self.session.config.d_group_state[group.name] = "0"

def on_group_expanded(self, group):
'''called when a group is expanded, update the status of the
groups'''
self.group_state.update({group.name:True})
self.group_state[group.name] = True
self.session.config.d_group_state[group.name] = "1"

def compare_groups(self, group1, group2, order1=0, order2=0):
'''compare two groups and return 1 if group1 should go first, 0
Expand Down
43 changes: 30 additions & 13 deletions emesene/gui/gtkui/ContactList.py
Expand Up @@ -98,6 +98,16 @@ def __init__(self, session):

self.connect('row-activated', self._on_row_activated)
self.connect('button-release-event' , self._on_button_press_event)
self.connect('row-expanded' , self._on_expand)
self.connect('row-collapsed' , self._on_collapse)

def _on_expand(self, treeview, iter_, path):
group = self.model[path][1]
self.on_group_expanded(group)

def _on_collapse(self, treeview, iter_, path):
group = self.model[path][1]
self.on_group_collapsed(group)

def _get_contact_pixbuf_or_default(self, contact):
'''try to return a pixbuf of the user picture or the default
Expand Down Expand Up @@ -306,7 +316,9 @@ def add_group(self, group, special=False):
log.debug('Trying to add an existing group! ' + obj.name)
return row.iter

return self._model.append(None, group_data)
itr = self._model.append(None, group_data)

return itr

def remove_group(self, group):
'''remove a group from the contact list'''
Expand Down Expand Up @@ -400,7 +412,9 @@ def add_contact(self, contact, group=None):
return return_iter
else:
self.add_group(group)
return self.add_contact(contact, group)
result = self.add_contact(contact, group)
self.update_group(group)
return result

def remove_contact(self, contact, group=None):
'''remove a contact from the specified group, if group is None
Expand Down Expand Up @@ -488,6 +502,9 @@ def update_contact(self, contact):

def update_no_group(self):
'''update the special "No group" group'''
if self.no_group_iter is None:
return

group_data = (None, self.no_group, self.format_group(self.no_group), False, None,
0, True, False)
self._model[self.no_group_iter] = group_data
Expand All @@ -510,21 +527,21 @@ def update_group(self, group):
for row in self._model:
obj = row[1]
if type(obj) == e3.Group and obj.identifier == group.identifier:
if group.name in self.group_state:
state = self.group_state[group.name]
childpath = self._model.get_path(row.iter)
path = self.model.convert_child_path_to_path(childpath)

if path:
if state:
self.expand_row(path, False)
else:
self.collapse_row(path)

group_data = (None, group, self.format_group(group), False, None,
weight, row[6], False)
self._model[row.iter] = group_data

def set_group_state(self, group, state):
'''expand group id state is True, collapse it if False'''
for row in self._model:
obj = row[1]
if type(obj) == e3.Group and obj.name == group.name:
path = self._model.get_path()

if state:
self.expand_row(path, False)
else:
self.collapse_row(path)

def format_nick(self, contact):
'''replace the appearance of the template vars using the values of
Expand Down

0 comments on commit cc86282

Please sign in to comment.