Extract a few methods to make some code a tiny bit easier to understand and read.
This commit is contained in:
parent
b0b555c630
commit
a8e3dc771e
|
@ -4440,21 +4440,12 @@ class RosterWindow:
|
||||||
"""
|
"""
|
||||||
When a row is added, set properties for icon renderer
|
When a row is added, set properties for icon renderer
|
||||||
"""
|
"""
|
||||||
theme = gajim.config.get('roster_theme')
|
|
||||||
type_ = model[titer][C_TYPE]
|
type_ = model[titer][C_TYPE]
|
||||||
if type_ == 'account':
|
if type_ == 'account':
|
||||||
color = gajim.config.get_per('themes', theme, 'accountbgcolor')
|
self._set_account_row_background_color(renderer)
|
||||||
if color:
|
|
||||||
renderer.set_property('cell-background', color)
|
|
||||||
else:
|
|
||||||
self.set_renderer_color(renderer, gtk.STATE_ACTIVE)
|
|
||||||
renderer.set_property('xalign', 0)
|
renderer.set_property('xalign', 0)
|
||||||
elif type_ == 'group':
|
elif type_ == 'group':
|
||||||
color = gajim.config.get_per('themes', theme, 'groupbgcolor')
|
self._set_group_row_background_color(renderer)
|
||||||
if color:
|
|
||||||
renderer.set_property('cell-background', color)
|
|
||||||
else:
|
|
||||||
self.set_renderer_color(renderer, gtk.STATE_PRELIGHT)
|
|
||||||
renderer.set_property('xalign', 0.2)
|
renderer.set_property('xalign', 0.2)
|
||||||
elif type_: # prevent type_ = None, see http://trac.gajim.org/ticket/2534
|
elif type_: # prevent type_ = None, see http://trac.gajim.org/ticket/2534
|
||||||
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
|
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
|
||||||
|
@ -4462,18 +4453,7 @@ class RosterWindow:
|
||||||
return
|
return
|
||||||
jid = model[titer][C_JID].decode('utf-8')
|
jid = model[titer][C_JID].decode('utf-8')
|
||||||
account = model[titer][C_ACCOUNT].decode('utf-8')
|
account = model[titer][C_ACCOUNT].decode('utf-8')
|
||||||
if jid in gajim.newly_added[account]:
|
self._set_contact_row_background_color(renderer, jid, account)
|
||||||
renderer.set_property('cell-background', gajim.config.get(
|
|
||||||
'just_connected_bg_color'))
|
|
||||||
elif jid in gajim.to_be_removed[account]:
|
|
||||||
renderer.set_property('cell-background', gajim.config.get(
|
|
||||||
'just_disconnected_bg_color'))
|
|
||||||
else:
|
|
||||||
color = gajim.config.get_per('themes', theme, 'contactbgcolor')
|
|
||||||
if color:
|
|
||||||
renderer.set_property('cell-background', color)
|
|
||||||
else:
|
|
||||||
renderer.set_property('cell-background', None)
|
|
||||||
parent_iter = model.iter_parent(titer)
|
parent_iter = model.iter_parent(titer)
|
||||||
if model[parent_iter][C_TYPE] == 'contact':
|
if model[parent_iter][C_TYPE] == 'contact':
|
||||||
renderer.set_property('xalign', 1)
|
renderer.set_property('xalign', 1)
|
||||||
|
@ -4493,29 +4473,21 @@ class RosterWindow:
|
||||||
renderer.set_property('foreground', color)
|
renderer.set_property('foreground', color)
|
||||||
else:
|
else:
|
||||||
self.set_renderer_color(renderer, gtk.STATE_ACTIVE, False)
|
self.set_renderer_color(renderer, gtk.STATE_ACTIVE, False)
|
||||||
color = gajim.config.get_per('themes', theme, 'accountbgcolor')
|
|
||||||
if color:
|
|
||||||
renderer.set_property('cell-background', color)
|
|
||||||
else:
|
|
||||||
self.set_renderer_color(renderer, gtk.STATE_ACTIVE)
|
|
||||||
renderer.set_property('font',
|
renderer.set_property('font',
|
||||||
gtkgui_helpers.get_theme_font_for_option(theme, 'accountfont'))
|
gtkgui_helpers.get_theme_font_for_option(theme, 'accountfont'))
|
||||||
renderer.set_property('xpad', 0)
|
renderer.set_property('xpad', 0)
|
||||||
renderer.set_property('width', 3)
|
renderer.set_property('width', 3)
|
||||||
|
self._set_account_row_background_color(renderer)
|
||||||
elif type_ == 'group':
|
elif type_ == 'group':
|
||||||
color = gajim.config.get_per('themes', theme, 'grouptextcolor')
|
color = gajim.config.get_per('themes', theme, 'grouptextcolor')
|
||||||
if color:
|
if color:
|
||||||
renderer.set_property('foreground', color)
|
renderer.set_property('foreground', color)
|
||||||
else:
|
else:
|
||||||
self.set_renderer_color(renderer, gtk.STATE_PRELIGHT, False)
|
self.set_renderer_color(renderer, gtk.STATE_PRELIGHT, False)
|
||||||
color = gajim.config.get_per('themes', theme, 'groupbgcolor')
|
|
||||||
if color:
|
|
||||||
renderer.set_property('cell-background', color)
|
|
||||||
else:
|
|
||||||
self.set_renderer_color(renderer, gtk.STATE_PRELIGHT)
|
|
||||||
renderer.set_property('font',
|
renderer.set_property('font',
|
||||||
gtkgui_helpers.get_theme_font_for_option(theme, 'groupfont'))
|
gtkgui_helpers.get_theme_font_for_option(theme, 'groupfont'))
|
||||||
renderer.set_property('xpad', 4)
|
renderer.set_property('xpad', 4)
|
||||||
|
self._set_group_row_background_color(renderer)
|
||||||
elif type_: # prevent type_ = None, see http://trac.gajim.org/ticket/2534
|
elif type_: # prevent type_ = None, see http://trac.gajim.org/ticket/2534
|
||||||
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
|
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
|
||||||
# This can append when at the moment we add the row
|
# This can append when at the moment we add the row
|
||||||
|
@ -4535,18 +4507,7 @@ class RosterWindow:
|
||||||
renderer.set_property('foreground', color)
|
renderer.set_property('foreground', color)
|
||||||
else:
|
else:
|
||||||
renderer.set_property('foreground', None)
|
renderer.set_property('foreground', None)
|
||||||
if jid in gajim.newly_added[account]:
|
self._set_contact_row_background_color(renderer, jid, account)
|
||||||
renderer.set_property('cell-background', gajim.config.get(
|
|
||||||
'just_connected_bg_color'))
|
|
||||||
elif jid in gajim.to_be_removed[account]:
|
|
||||||
renderer.set_property('cell-background', gajim.config.get(
|
|
||||||
'just_disconnected_bg_color'))
|
|
||||||
else:
|
|
||||||
color = gajim.config.get_per('themes', theme, 'contactbgcolor')
|
|
||||||
if color:
|
|
||||||
renderer.set_property('cell-background', color)
|
|
||||||
else:
|
|
||||||
renderer.set_property('cell-background', None)
|
|
||||||
renderer.set_property('font',
|
renderer.set_property('font',
|
||||||
gtkgui_helpers.get_theme_font_for_option(theme, 'contactfont'))
|
gtkgui_helpers.get_theme_font_for_option(theme, 'contactfont'))
|
||||||
parent_iter = model.iter_parent(titer)
|
parent_iter = model.iter_parent(titer)
|
||||||
|
@ -4555,7 +4516,6 @@ class RosterWindow:
|
||||||
else:
|
else:
|
||||||
renderer.set_property('xpad', 8)
|
renderer.set_property('xpad', 8)
|
||||||
|
|
||||||
|
|
||||||
def _fill_pep_pixbuf_renderer(self, column, renderer, model, titer,
|
def _fill_pep_pixbuf_renderer(self, column, renderer, model, titer,
|
||||||
data=None):
|
data=None):
|
||||||
"""
|
"""
|
||||||
|
@ -4563,48 +4523,29 @@ class RosterWindow:
|
||||||
"""
|
"""
|
||||||
theme = gajim.config.get('roster_theme')
|
theme = gajim.config.get('roster_theme')
|
||||||
type_ = model[titer][C_TYPE]
|
type_ = model[titer][C_TYPE]
|
||||||
if type_ == 'group':
|
|
||||||
renderer.set_property('visible', False)
|
|
||||||
return
|
|
||||||
|
|
||||||
# allocate space for the icon only if needed
|
# allocate space for the icon only if needed
|
||||||
if model[titer][data]:
|
if not model[titer][data]:
|
||||||
renderer.set_property('visible', True)
|
|
||||||
else:
|
|
||||||
renderer.set_property('visible', False)
|
renderer.set_property('visible', False)
|
||||||
if type_ == 'account':
|
else:
|
||||||
color = gajim.config.get_per('themes', theme, 'accountbgcolor')
|
renderer.set_property('visible', True)
|
||||||
if color:
|
|
||||||
renderer.set_property('cell-background', color)
|
if type_ == 'account':
|
||||||
else:
|
|
||||||
self.set_renderer_color(renderer, gtk.STATE_ACTIVE)
|
self.set_renderer_color(renderer, gtk.STATE_ACTIVE)
|
||||||
# align pixbuf to the right)
|
renderer.set_property('xalign', 1)
|
||||||
renderer.set_property('xalign', 1)
|
elif type_:
|
||||||
# prevent type_ = None, see http://trac.gajim.org/ticket/2534
|
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
|
||||||
elif type_:
|
# This can append at the moment we add the row
|
||||||
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
|
return
|
||||||
# This can append at the moment we add the row
|
jid = model[titer][C_JID].decode('utf-8')
|
||||||
return
|
account = model[titer][C_ACCOUNT].decode('utf-8')
|
||||||
jid = model[titer][C_JID].decode('utf-8')
|
self._set_contact_row_background_color(renderer, jid, account)
|
||||||
account = model[titer][C_ACCOUNT].decode('utf-8')
|
|
||||||
if jid in gajim.newly_added[account]:
|
|
||||||
renderer.set_property('cell-background', gajim.config.get(
|
|
||||||
'just_connected_bg_color'))
|
|
||||||
elif jid in gajim.to_be_removed[account]:
|
|
||||||
renderer.set_property('cell-background', gajim.config.get(
|
|
||||||
'just_disconnected_bg_color'))
|
|
||||||
else:
|
|
||||||
color = gajim.config.get_per('themes', theme, 'contactbgcolor')
|
|
||||||
renderer.set_property('cell-background', color if color else None)
|
|
||||||
# align pixbuf to the right
|
|
||||||
renderer.set_property('xalign', 1)
|
|
||||||
|
|
||||||
def _fill_avatar_pixbuf_renderer(self, column, renderer, model, titer, data
|
def _fill_avatar_pixbuf_renderer(self, column, renderer, model, titer, data
|
||||||
= None):
|
= None):
|
||||||
"""
|
"""
|
||||||
When a row is added, set properties for avatar renderer
|
When a row is added, set properties for avatar renderer
|
||||||
"""
|
"""
|
||||||
theme = gajim.config.get('roster_theme')
|
|
||||||
type_ = model[titer][C_TYPE]
|
type_ = model[titer][C_TYPE]
|
||||||
if type_ in ('group', 'account'):
|
if type_ in ('group', 'account'):
|
||||||
renderer.set_property('visible', False)
|
renderer.set_property('visible', False)
|
||||||
|
@ -4614,51 +4555,63 @@ class RosterWindow:
|
||||||
if model[titer][C_AVATAR_PIXBUF] or \
|
if model[titer][C_AVATAR_PIXBUF] or \
|
||||||
gajim.config.get('avatar_position_in_roster') == 'left':
|
gajim.config.get('avatar_position_in_roster') == 'left':
|
||||||
renderer.set_property('visible', True)
|
renderer.set_property('visible', True)
|
||||||
|
if type_: # prevent type_ = None, see http://trac.gajim.org/ticket/2534
|
||||||
|
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
|
||||||
|
# This can append at the moment we add the row
|
||||||
|
return
|
||||||
|
jid = model[titer][C_JID].decode('utf-8')
|
||||||
|
account = model[titer][C_ACCOUNT].decode('utf-8')
|
||||||
|
self._set_contact_row_background_color(renderer, jid, account)
|
||||||
else:
|
else:
|
||||||
renderer.set_property('visible', False)
|
renderer.set_property('visible', False)
|
||||||
if type_: # prevent type_ = None, see http://trac.gajim.org/ticket/2534
|
|
||||||
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
|
|
||||||
# This can append at the moment we add the row
|
|
||||||
return
|
|
||||||
jid = model[titer][C_JID].decode('utf-8')
|
|
||||||
account = model[titer][C_ACCOUNT].decode('utf-8')
|
|
||||||
if jid in gajim.newly_added[account]:
|
|
||||||
renderer.set_property('cell-background', gajim.config.get(
|
|
||||||
'just_connected_bg_color'))
|
|
||||||
elif jid in gajim.to_be_removed[account]:
|
|
||||||
renderer.set_property('cell-background', gajim.config.get(
|
|
||||||
'just_disconnected_bg_color'))
|
|
||||||
else:
|
|
||||||
color = gajim.config.get_per('themes', theme, 'contactbgcolor')
|
|
||||||
if color:
|
|
||||||
renderer.set_property('cell-background', color)
|
|
||||||
else:
|
|
||||||
renderer.set_property('cell-background', None)
|
|
||||||
if gajim.config.get('avatar_position_in_roster') == 'left':
|
if gajim.config.get('avatar_position_in_roster') == 'left':
|
||||||
renderer.set_property('width', gajim.config.get('roster_avatar_width'))
|
renderer.set_property('width', gajim.config.get('roster_avatar_width'))
|
||||||
renderer.set_property('xalign', 0.5)
|
renderer.set_property('xalign', 0.5)
|
||||||
else:
|
else:
|
||||||
renderer.set_property('xalign', 1) # align pixbuf to the right
|
renderer.set_property('xalign', 1) # align pixbuf to the right
|
||||||
|
|
||||||
def _fill_padlock_pixbuf_renderer(self, column, renderer, model, titer, data
|
def _fill_padlock_pixbuf_renderer(self, column, renderer, model, titer, data=None):
|
||||||
= None):
|
|
||||||
"""
|
"""
|
||||||
When a row is added, set properties for padlock renderer
|
When a row is added, set properties for padlock renderer
|
||||||
"""
|
"""
|
||||||
theme = gajim.config.get('roster_theme')
|
|
||||||
type_ = model[titer][C_TYPE]
|
type_ = model[titer][C_TYPE]
|
||||||
# allocate space for the icon only if needed
|
# allocate space for the icon only if needed
|
||||||
if type_ == 'account' and model[titer][C_PADLOCK_PIXBUF]:
|
if type_ == 'account' and model[titer][C_PADLOCK_PIXBUF]:
|
||||||
renderer.set_property('visible', True)
|
renderer.set_property('visible', True)
|
||||||
color = gajim.config.get_per('themes', theme, 'accountbgcolor')
|
self._set_account_row_background_color(renderer)
|
||||||
if color:
|
|
||||||
renderer.set_property('cell-background', color)
|
|
||||||
else:
|
|
||||||
self.set_renderer_color(renderer, gtk.STATE_ACTIVE)
|
|
||||||
renderer.set_property('xalign', 1) # align pixbuf to the right
|
renderer.set_property('xalign', 1) # align pixbuf to the right
|
||||||
else:
|
else:
|
||||||
renderer.set_property('visible', False)
|
renderer.set_property('visible', False)
|
||||||
|
|
||||||
|
def _set_account_row_background_color(self, renderer):
|
||||||
|
theme = gajim.config.get('roster_theme')
|
||||||
|
color = gajim.config.get_per('themes', theme, 'accountbgcolor')
|
||||||
|
if color:
|
||||||
|
renderer.set_property('cell-background', color)
|
||||||
|
else:
|
||||||
|
self.set_renderer_color(renderer, gtk.STATE_ACTIVE)
|
||||||
|
|
||||||
|
def _set_contact_row_background_color(self, renderer, jid, account):
|
||||||
|
theme = gajim.config.get('roster_theme')
|
||||||
|
if jid in gajim.newly_added[account]:
|
||||||
|
renderer.set_property('cell-background', gajim.config.get(
|
||||||
|
'just_connected_bg_color'))
|
||||||
|
elif jid in gajim.to_be_removed[account]:
|
||||||
|
renderer.set_property('cell-background', gajim.config.get(
|
||||||
|
'just_disconnected_bg_color'))
|
||||||
|
else:
|
||||||
|
color = gajim.config.get_per('themes', theme, 'contactbgcolor')
|
||||||
|
renderer.set_property('cell-background', color if color else None)
|
||||||
|
|
||||||
|
def _set_group_row_background_color(self, renderer):
|
||||||
|
theme = gajim.config.get('roster_theme')
|
||||||
|
color = gajim.config.get_per('themes', theme, 'groupbgcolor')
|
||||||
|
if color:
|
||||||
|
renderer.set_property('cell-background', color)
|
||||||
|
else:
|
||||||
|
self.set_renderer_color(renderer, gtk.STATE_PRELIGHT)
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
### Everything about building menus
|
### Everything about building menus
|
||||||
### FIXME: We really need to make it simpler! 1465 lines are a few to much....
|
### FIXME: We really need to make it simpler! 1465 lines are a few to much....
|
||||||
|
@ -5891,8 +5844,7 @@ class RosterWindow:
|
||||||
def add_avatar_renderer():
|
def add_avatar_renderer():
|
||||||
render_pixbuf = gtk.CellRendererPixbuf() # avatar img
|
render_pixbuf = gtk.CellRendererPixbuf() # avatar img
|
||||||
col.pack_start(render_pixbuf, expand=False)
|
col.pack_start(render_pixbuf, expand=False)
|
||||||
col.add_attribute(render_pixbuf, 'pixbuf',
|
col.add_attribute(render_pixbuf, 'pixbuf', C_AVATAR_PIXBUF)
|
||||||
C_AVATAR_PIXBUF)
|
|
||||||
col.set_cell_data_func(render_pixbuf,
|
col.set_cell_data_func(render_pixbuf,
|
||||||
self._fill_avatar_pixbuf_renderer, None)
|
self._fill_avatar_pixbuf_renderer, None)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue