coding standards

This commit is contained in:
Yann Leboulanger 2008-06-02 10:04:27 +00:00
parent 8f9c097343
commit b3d57ed5b1
1 changed files with 289 additions and 268 deletions

View File

@ -261,20 +261,21 @@ class RosterWindow:
if self.regroup:
# Merged accounts view
show = helpers.get_global_show()
self.model.append(None, [gajim.interface.jabber_state_images['16'][show],
_('Merged accounts'), 'account', '', 'all', None, None])
self.model.append(None, [gajim.interface.jabber_state_images['16'][
show], _('Merged accounts'), 'account', '', 'all', None, None])
else:
show = gajim.SHOW_LIST[gajim.connections[account].connected]
our_jid = gajim.get_jid_from_account(account)
tls_pixbuf = None
if gajim.account_is_securely_connected(account):
tls_pixbuf = self.window.render_icon(gtk.STOCK_DIALOG_AUTHENTICATION,
gtk.ICON_SIZE_MENU) # the only way to create a pixbuf from stock
# the only way to create a pixbuf from stock
tls_pixbuf = self.window.render_icon(
gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_MENU)
self.model.append(None, [gajim.interface.jabber_state_images['16'][show],
gobject.markup_escape_text(account),
'account', our_jid, account, None, tls_pixbuf])
self.model.append(None, [gajim.interface.jabber_state_images['16'][
show], gobject.markup_escape_text(account), 'account', our_jid,
account, None, tls_pixbuf])
self.draw_account(account)
@ -340,7 +341,7 @@ class RosterWindow:
parent_iters = self._get_contact_iter(big_brother_contact.jid,
big_brother_account, big_brother_contact, self.model)
assert len(parent_iters) > 0,\
"Big brother is not yet in roster!"
'Big brother is not yet in roster!'
# Do not confuse get_contact_iter
# Sync groups of family members
@ -359,7 +360,7 @@ class RosterWindow:
if not groups:
groups = [_('General')]
for group in groups:
child_iterG = self._get_group_iter(group, account, model = self.model)
child_iterG = self._get_group_iter(group, account, model=self.model)
if not child_iterG:
# Group is not yet in roster, add it!
child_iterA = self._get_account_iter(account, self.model)
@ -392,10 +393,9 @@ class RosterWindow:
if group not in gajim.groups[account]:
gajim.groups[account][group] = {'expand': is_expanded}
assert len(added_iters), "%s has not been added to roster!" % contact.jid
assert len(added_iters), '%s has not been added to roster!' % contact.jid
return added_iters
def _remove_entity(self, contact, account, groups = None):
'''Remove the given contact from roster data model.
@ -410,7 +410,7 @@ class RosterWindow:
'''
iters = self._get_contact_iter(contact.jid, account, contact, self.model)
assert iters, "%s shall be removed but is not in roster" % contact.jid
assert iters, '%s shall be removed but is not in roster' % contact.jid
parent_iter = self.model.iter_parent(iters[0])
parent_type = self.model[parent_iter][C_TYPE]
@ -418,7 +418,8 @@ class RosterWindow:
if groups:
# Only remove from specified groups
all_iters = iters[:]
group_iters = [self._get_group_iter(group, account) for group in groups]
group_iters = [self._get_group_iter(group, account) for group in \
groups]
iters = [titer for titer in all_iters
if self.model.iter_parent(titer) in group_iters]
@ -441,7 +442,6 @@ class RosterWindow:
self.model.remove(i)
return True
def _add_metacontact_family(self, family, account):
'''Add the give Metacontact family to roster data model.
@ -461,7 +461,8 @@ class RosterWindow:
nearby_family = [data for data in family
if account == data['account']]
big_brother_data = gajim.contacts.get_metacontacts_big_brother(nearby_family)
big_brother_data = gajim.contacts.get_metacontacts_big_brother(
nearby_family)
big_brother_jid = big_brother_data['jid']
big_brother_account = big_brother_data['account']
big_brother_contact = gajim.contacts.get_first_contact_from_jid(
@ -469,7 +470,8 @@ class RosterWindow:
assert len(self._get_contact_iter(big_brother_jid, big_brother_account,
big_brother_contact, self.model)) == 0,\
"Big brother %s already in roster \n Family: %s" % (big_brother_jid, family)
'Big brother %s already in roster \n Family: %s' % (big_brother_jid,
family)
self._add_entity(big_brother_contact, big_brother_account)
brothers = []
@ -488,14 +490,13 @@ class RosterWindow:
assert len(self._get_contact_iter(_jid, _account, _contact, self.model)
) == 0, "%s already in roster. \n Family: " % (_jid, nearby_family)
self._add_entity(_contact, _account, big_brother_contact = big_brother_contact,
big_brother_account = big_brother_account)
self._add_entity(_contact, _account, big_brother_contact = \
big_brother_contact, big_brother_account=big_brother_account)
brothers.append((_contact, _account))
brothers.insert(0, (big_brother_contact, big_brother_account))
return brothers
def _remove_metacontact_family(self, family, account):
'''Remove the given Metacontact family from roster data model.
@ -522,8 +523,8 @@ class RosterWindow:
# Family might not be up to date.
# Only try to remove what is actually in the roster
continue
assert iters, "%s shall be removed but is not in roster \
\n Family: %s" % (_jid, family)
assert iters, '%s shall be removed but is not in roster \
\n Family: %s' % (_jid, family)
family_in_roster = True
@ -538,28 +539,28 @@ class RosterWindow:
continue
ok = self._remove_entity(_contact, _account)
assert ok, "%s was not removed" % _jid
assert len(self._get_contact_iter(_jid, _account, _contact, self.model)) == 0,\
"%s is removed but still in roster" % _jid
assert ok, '%s was not removed' % _jid
assert len(self._get_contact_iter(_jid, _account, _contact,
self.model)) == 0, '%s is removed but still in roster' % _jid
if not family_in_roster:
return False
iters = self._get_contact_iter(old_big_jid, old_big_account, old_big_contact,
self.model)
assert len(iters) > 0, "Old Big Brother %s is not in roster anymore" % old_big_jid
assert not self.model.iter_children(iters[0]),\
"Old Big Brother %s still has children" % old_big_jid
iters = self._get_contact_iter(old_big_jid, old_big_account,
old_big_contact, self.model)
assert len(iters) > 0, 'Old Big Brother %s is not in roster anymore' % \
old_big_jid
assert not self.model.iter_children(iters[0]),
'Old Big Brother %s still has children' % old_big_jid
ok = self._remove_entity(old_big_contact, old_big_account)
assert ok, "Old Big Brother %s not removed" % old_big_jid
assert len(self._get_contact_iter(old_big_jid, old_big_account, old_big_contact,
self.model)) == 0,\
"Old Big Brother %s is removed but still in roster" % old_big_jid
assert len(self._get_contact_iter(old_big_jid, old_big_account,
old_big_contact, self.model)) == 0,
'Old Big Brother %s is removed but still in roster' % old_big_jid
return True
def _add_self_contact(self, account):
'''Add account's SelfContact to roster and draw it and the account.
@ -568,8 +569,8 @@ class RosterWindow:
jid = gajim.get_jid_from_account(account)
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
assert len(self._get_contact_iter(jid, account, contact, self.model)) == 0,\
"Self contact %s already in roster" % jid
assert len(self._get_contact_iter(jid, account, contact, self.model)) == \
0, 'Self contact %s already in roster' % jid
child_iterA = self._get_account_iter(account, self.model)
self.model.append(child_iterA, (None, gajim.nicks[account],
@ -649,7 +650,8 @@ class RosterWindow:
def remove_contact(self, jid, account, force = False, backend = False):
'''Remove contact from roster.
Remove contact from all its group. Remove empty groups or redraw otherwise.
Remove contact from all its group. Remove empty groups or redraw
otherwise.
Draw the account.
If it's a Metacontact, remove the whole family.
Do nothing if the contact is not in roster.
@ -739,7 +741,6 @@ class RosterWindow:
self.add_contact(jid, account)
return contact
def remove_transport(self, jid, account):
'''Remove transport from roster and redraw account and group.'''
contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
@ -759,7 +760,8 @@ class RosterWindow:
# Close chat window
msg_win = gajim.interface.msg_win_mgr.get_window(contact.jid,
account)
for ctrl in gajim.interface.msg_win_mgr.get_chat_controls(contact.jid, account):
for ctrl in gajim.interface.msg_win_mgr.get_chat_controls(
contact.jid, account):
msg_win.remove_tab(ctrl, msg_win.CLOSE_CLOSE_BUTTON)
else:
need_readd = True
@ -1034,7 +1036,8 @@ class RosterWindow:
nearby_family = [data for data in family
if account == data['account']]
big_brother_data = gajim.contacts.get_metacontacts_big_brother(nearby_family)
big_brother_data = gajim.contacts.get_metacontacts_big_brother(
nearby_family)
big_brother_jid = big_brother_data['jid']
big_brother_account = big_brother_data['account']
@ -1315,7 +1318,7 @@ class RosterWindow:
self.filtering = False
def contact_has_pending_roster_events(self, contact, account):
''' Return True if the contact or one if it resources has pending events'''
'''Return True if the contact or one if it resources has pending events'''
# jid has pending events
if gajim.events.get_nb_roster_events(account, contact.jid) > 0:
return True
@ -1578,7 +1581,8 @@ class RosterWindow:
# If we already have chat windows opened, update them with new contact
# instance
for chat_control in gajim.interface.msg_win_mgr.get_chat_controls(ji, account):
for chat_control in gajim.interface.msg_win_mgr.get_chat_controls(ji,
account):
chat_control.contact = contact1
def _change_awn_icon_status(self, status):
@ -1666,7 +1670,8 @@ class RosterWindow:
Only performed if removal was requested before but the contact
still had pending events
'''
contact_list = ((event.jid.split('/')[0], event.account) for event in event_list)
contact_list = ((event.jid.split('/')[0], event.account) for event in \
event_list)
for jid, account in contact_list:
self.draw_contact(jid, account)
@ -1800,15 +1805,16 @@ class RosterWindow:
text = _('Enter your password for account %s') % account
if passwords.USER_HAS_GNOMEKEYRING and \
not passwords.USER_USES_GNOMEKEYRING:
text += '\n' + _('Gnome Keyring is installed but not correctly started\
(environment variable probably not correctly set)')
text += '\n' + _('Gnome Keyring is installed but not \
correctly started (environment variable probably not \
correctly set)')
w = dialogs.PassphraseDialog(_('Password Required'), text,
_('Save password'))
passphrase, save = w.run()
if passphrase == -1:
if child_iterA:
self.model[child_iterA][0] = gajim.interface.jabber_state_images[
'16']['offline']
self.model[child_iterA][0] = \
gajim.interface.jabber_state_images['16']['offline']
if gajim.interface.systray_enabled:
gajim.interface.systray.change_status('offline')
self.update_status_combobox()
@ -1838,9 +1844,9 @@ class RosterWindow:
while ctx is not None:
if ctx.msgstate == gajim.otr_module.OTRL_MSGSTATE_ENCRYPTED:
disconnected = True
gajim.otr_module.otrl_message_disconnect(gajim.connections[account].otr_userstates,
(gajim.otr_ui_ops,
{'account':account,'urgent':True}), ctx.accountname,
gajim.otr_module.otrl_message_disconnect(gajim.connections[
account].otr_userstates, (gajim.otr_ui_ops,
{'account': account,'urgent': True}), ctx.accountname,
ctx.protocol, ctx.username)
ctx = ctx.next
if to:
@ -1893,7 +1899,8 @@ class RosterWindow:
win.redraw_tab(ctrl)
gajim.contacts.remove_contact(account, contact)
elif contact.jid == gajim.get_jid_from_account(account) and show == 'offline':
elif contact.jid == gajim.get_jid_from_account(account) and \
show == 'offline':
# Our SelfContact went offline. Remove him
self.remove_contact(contact.jid, account)
@ -2663,7 +2670,8 @@ class RosterWindow:
keyID = keyID[0]
keys[contact.jid] = keyID
for ctrl in gajim.interface.msg_win_mgr.get_chat_controls(contact.jid, account):
for ctrl in gajim.interface.msg_win_mgr.get_chat_controls(contact.jid,
account):
ctrl.update_ui()
keys_str = ''
for jid in keys:
@ -2803,7 +2811,8 @@ class RosterWindow:
def on_groupchat_maximized(self, widget, jid, account):
'''When a groupchat is maximised'''
ctrl = gajim.interface.minimized_controls[account][jid]
mw = gajim.interface.msg_win_mgr.get_window(ctrl.contact.jid, ctrl.account)
mw = gajim.interface.msg_win_mgr.get_window(ctrl.contact.jid,
ctrl.account)
if not mw:
mw = gajim.interface.msg_win_mgr.create_window(ctrl.contact,
ctrl.account, ctrl.type_id)
@ -3094,7 +3103,8 @@ class RosterWindow:
return
status = model[active][2].decode('utf-8')
statuses_unified = helpers.statuses_unified() # status "desync'ed" or not
if (active == 7 and statuses_unified) or (active == 9 and not statuses_unified):
if (active == 7 and statuses_unified) or (active == 9 and \
not statuses_unified):
# 'Change status message' selected:
# do not change show, just show change status dialog
status = model[self.previous_status_combobox_active][2].decode('utf-8')
@ -3663,14 +3673,15 @@ class RosterWindow:
dlg.checkbutton.set_active(True)
def on_drop_in_group(self, widget, account, c_source, grp_dest, is_big_brother,
context, etime, grp_source = None):
def on_drop_in_group(self, widget, account, c_source, grp_dest,
is_big_brother, context, etime, grp_source = None):
if is_big_brother:
# add whole metacontact to new group
self.add_contact_to_groups(c_source.jid, account, [grp_dest,])
# remove afterwards so the contact is not moved to General in the meantime
# remove afterwards so the contact is not moved to General in the
# meantime
if grp_dest != grp_source:
self.remove_contact_from_groups(c_source.jid, account, [grp_source,])
self.remove_contact_from_groups(c_source.jid, account, [grp_source])
else:
# Normal contact or little brother
family = gajim.contacts.get_metacontacts_family(account,
@ -3695,9 +3706,11 @@ class RosterWindow:
else:
# Normal contact
self.add_contact_to_groups(c_source.jid, account, [grp_dest,])
# remove afterwards so the contact is not moved to General in the meantime
# remove afterwards so the contact is not moved to General in the
# meantime
if grp_dest != grp_source:
self.remove_contact_from_groups(c_source.jid, account, [grp_source,])
self.remove_contact_from_groups(c_source.jid, account,
[grp_source])
if context.action in (gtk.gdk.ACTION_MOVE, gtk.gdk.ACTION_COPY):
context.finish(True, True, etime)
@ -3752,7 +3765,8 @@ class RosterWindow:
uri = data.strip()
uri_splitted = uri.split() # we may have more than one file dropped
try:
uri_splitted.remove('\0') # This is always the last element in windows
# This is always the last element in windows
uri_splitted.remove('\0')
except ValueError:
pass
nb_uri = len(uri_splitted)
@ -3823,7 +3837,8 @@ class RosterWindow:
if grp_source in helpers.special_groups and \
grp_source not in ('Not in Roster', 'Observers'):
# a transport or a minimized groupchat was dragged
# we can add it to other accounts but not move it to another group, see below
# we can add it to other accounts but not move it to another group,
# see below
return
jid_source = data.decode('utf-8')
c_source = gajim.contacts.get_contact_with_highest_priority(
@ -3901,7 +3916,6 @@ class RosterWindow:
return self.transports_state_images[size][transport]
return gajim.interface.jabber_state_images[size]
def make_transport_state_images(self, transport):
'''initialise opened and closed 'transport' iconset dict'''
if gajim.config.get('use_transports_iconsets'):
@ -3909,15 +3923,15 @@ class RosterWindow:
'16x16')
pixo, pixc = gtkgui_helpers.load_icons_meta()
self.transports_state_images['opened'][transport] = \
gtkgui_helpers.load_iconset(folder, pixo, transport = True)
gtkgui_helpers.load_iconset(folder, pixo, transport=True)
self.transports_state_images['closed'][transport] = \
gtkgui_helpers.load_iconset(folder, pixc, transport = True)
gtkgui_helpers.load_iconset(folder, pixc, transport=True)
folder = os.path.join(helpers.get_transport_path(transport), '32x32')
self.transports_state_images['32'][transport] = gtkgui_helpers.load_iconset(
folder, transport = True)
self.transports_state_images['32'][transport] = \
gtkgui_helpers.load_iconset(folder, transport=True)
folder = os.path.join(helpers.get_transport_path(transport), '16x16')
self.transports_state_images['16'][transport] = gtkgui_helpers.load_iconset(
folder, transport = True)
self.transports_state_images['16'][transport] = \
gtkgui_helpers.load_iconset(folder, transport=True)
def update_jabber_state_images(self):
# Update the roster
@ -3929,7 +3943,8 @@ class RosterWindow:
if model[titer][2] != '':
# If it's not change status message iter
# eg. if it has show parameter not ''
model[titer][1] = gajim.interface.jabber_state_images['16'][model[titer][2]]
model[titer][1] = gajim.interface.jabber_state_images['16'][model[
titer][2]]
titer = model.iter_next(titer)
# Update the systray
if gajim.interface.systray_enabled:
@ -3951,7 +3966,8 @@ class RosterWindow:
show = gajim.SHOW_LIST[status]
else: # accounts merged
show = helpers.get_global_show()
self.model[child_iterA][C_IMG] = gajim.interface.jabber_state_images['16'][show]
self.model[child_iterA][C_IMG] = gajim.interface.jabber_state_images[
'16'][show]
################################################################################
### Style and theme related methods
@ -4205,7 +4221,8 @@ class RosterWindow:
if not force and not self.actions_menu_needs_rebuild:
return
new_chat_menuitem = self.xml.get_widget('new_chat_menuitem')
single_message_menuitem = self.xml.get_widget('send_single_message_menuitem')
single_message_menuitem = self.xml.get_widget(
'send_single_message_menuitem')
join_gc_menuitem = self.xml.get_widget('join_gc_menuitem')
muc_icon = gtkgui_helpers.load_icon('muc_active')
if muc_icon:
@ -4562,8 +4579,8 @@ class RosterWindow:
else:
pep_config.set_sensitive(False)
pep_submenu.append(pep_config)
pep_config.connect('activate', self.on_pep_services_menuitem_activate,
account)
pep_config.connect('activate',
self.on_pep_services_menuitem_activate, account)
img = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES,
gtk.ICON_SIZE_MENU)
pep_config.set_image(img)
@ -4731,7 +4748,8 @@ class RosterWindow:
group_message_to_all_item = gtk.MenuItem(_('To all users'))
send_group_message_submenu.append(group_message_to_all_item)
group_message_to_all_online_item = gtk.MenuItem(_('To all online users'))
group_message_to_all_online_item = gtk.MenuItem(
_('To all online users'))
send_group_message_submenu.append(group_message_to_all_online_item)
group_message_to_all_online_item.connect('activate',
@ -4749,10 +4767,12 @@ class RosterWindow:
menu.append(invite_menuitem)
# Send Custom Status
send_custom_status_menuitem = gtk.ImageMenuItem(_('Send Cus_tom Status'))
send_custom_status_menuitem = gtk.ImageMenuItem(
_('Send Cus_tom Status'))
# add a special img for this menuitem
if group in gajim.connections[account].blocked_groups:
send_custom_status_menuitem.set_image(gtkgui_helpers.load_icon('offline'))
send_custom_status_menuitem.set_image(gtkgui_helpers.load_icon(
'offline'))
send_custom_status_menuitem.set_sensitive(False)
else:
icon = gtk.image_new_from_stock(gtk.STOCK_NETWORK,
@ -4766,8 +4786,8 @@ class RosterWindow:
# icon MUST be different instance for every item
state_images = gtkgui_helpers.load_iconset(path)
status_menuitem = gtk.ImageMenuItem(helpers.get_uf_show(s))
status_menuitem.connect('activate', self.on_send_custom_status, list_,
s, group)
status_menuitem.connect('activate', self.on_send_custom_status,
list_, s, group)
icon = state_images[s]
status_menuitem.set_image(icon)
status_menuitems.append(status_menuitem)
@ -5294,7 +5314,8 @@ class RosterWindow:
send_custom_status_menuitem = gtk.ImageMenuItem(_('Send Cus_tom Status'))
# add a special img for this menuitem
if blocked:
send_custom_status_menuitem.set_image(gtkgui_helpers.load_icon('offline'))
send_custom_status_menuitem.set_image(gtkgui_helpers.load_icon(
'offline'))
send_custom_status_menuitem.set_sensitive(False)
else:
if gajim.interface.status_sent_to_users.has_key(account) and \
@ -5808,8 +5829,8 @@ class RosterWindow:
for show in ('online', 'chat', 'away', 'xa', 'dnd', 'invisible'):
uf_show = helpers.get_uf_show(show)
liststore.append([uf_show, gajim.interface.jabber_state_images['16'][show],
show, True])
liststore.append([uf_show, gajim.interface.jabber_state_images['16'][
show], show, True])
# Add a Separator (self._iter_is_separator() checks on string SEPARATOR)
liststore.append(['SEPARATOR', None, '', True])
@ -5823,8 +5844,8 @@ class RosterWindow:
liststore.append(['SEPARATOR', None, '', True])
uf_show = helpers.get_uf_show('offline')
liststore.append([uf_show, gajim.interface.jabber_state_images['16']['offline'],
'offline', True])
liststore.append([uf_show, gajim.interface.jabber_state_images['16'][
'offline'], 'offline', True])
status_combobox_items = ['online', 'chat', 'away', 'xa', 'dnd',
'invisible', 'separator1', 'change_status_msg', 'separator2',
@ -5901,8 +5922,8 @@ class RosterWindow:
# signals
self.TARGET_TYPE_URI_LIST = 80
TARGETS = [('MY_TREE_MODEL_ROW', gtk.TARGET_SAME_APP | gtk.TARGET_SAME_WIDGET,
0)]
TARGETS = [('MY_TREE_MODEL_ROW',
gtk.TARGET_SAME_APP | gtk.TARGET_SAME_WIDGET, 0)]
TARGETS2 = [('MY_TREE_MODEL_ROW', gtk.TARGET_SAME_WIDGET, 0),
('text/uri-list', 0, self.TARGET_TYPE_URI_LIST)]
self.tree.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, TARGETS,