make more helper functions out of accounts code found mainly in roster
This commit is contained in:
parent
5e8ebac923
commit
6bab3917b1
2 changed files with 37 additions and 26 deletions
|
@ -212,6 +212,29 @@ def get_number_of_connected_accounts(accounts_list = None):
|
||||||
connected_accounts = connected_accounts + 1
|
connected_accounts = connected_accounts + 1
|
||||||
return connected_accounts
|
return connected_accounts
|
||||||
|
|
||||||
|
def account_is_connected(account):
|
||||||
|
if connections[account].connected > 1: # 0 is offline, 1 is connecting
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def account_is_disconnected(account):
|
||||||
|
return not account_is_connected(account)
|
||||||
|
|
||||||
|
def get_number_of_securely_connected_accounts():
|
||||||
|
'''returns the number of the accounts that are SSL/TLS connected'''
|
||||||
|
num_of_secured = 0
|
||||||
|
for account in connections:
|
||||||
|
if account_is_securely_connected(account):
|
||||||
|
num_of_secured += 1
|
||||||
|
return num_of_secured
|
||||||
|
|
||||||
|
def account_is_securely_connected(account):
|
||||||
|
if account in con_types and con_types[account] in ('tls', 'ssl'):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def get_transport_name_from_jid(jid, use_config_setting = True):
|
def get_transport_name_from_jid(jid, use_config_setting = True):
|
||||||
'''returns 'aim', 'gg', 'irc' etc
|
'''returns 'aim', 'gg', 'irc' etc
|
||||||
if JID is not from transport returns None'''
|
if JID is not from transport returns None'''
|
||||||
|
@ -260,15 +283,6 @@ def jid_is_transport(jid):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def account_is_connected(account):
|
|
||||||
if connections[account].connected > 1: # 0 is offline, 1 is connecting
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def account_is_disconnected(account):
|
|
||||||
return not account_is_connected(account)
|
|
||||||
|
|
||||||
def get_jid_from_account(account_name):
|
def get_jid_from_account(account_name):
|
||||||
'''return the jid we use in the given account'''
|
'''return the jid we use in the given account'''
|
||||||
name = config.get_per('accounts', account_name, 'name')
|
name = config.get_per('accounts', account_name, 'name')
|
||||||
|
|
|
@ -145,8 +145,7 @@ class RosterWindow:
|
||||||
show = gajim.SHOW_LIST[gajim.connections[account].connected]
|
show = gajim.SHOW_LIST[gajim.connections[account].connected]
|
||||||
|
|
||||||
tls_pixbuf = None
|
tls_pixbuf = None
|
||||||
if gajim.con_types.has_key(account) and \
|
if gajim.account_is_securely_connected(account):
|
||||||
gajim.con_types[account] in ('tls', 'ssl'):
|
|
||||||
tls_pixbuf = self.window.render_icon(gtk.STOCK_DIALOG_AUTHENTICATION,
|
tls_pixbuf = self.window.render_icon(gtk.STOCK_DIALOG_AUTHENTICATION,
|
||||||
gtk.ICON_SIZE_MENU) # the only way to create a pixbuf from stock
|
gtk.ICON_SIZE_MENU) # the only way to create a pixbuf from stock
|
||||||
|
|
||||||
|
@ -164,11 +163,7 @@ class RosterWindow:
|
||||||
else:
|
else:
|
||||||
accounts = [account]
|
accounts = [account]
|
||||||
num_of_accounts = len(accounts)
|
num_of_accounts = len(accounts)
|
||||||
num_of_secured = 0
|
num_of_secured = gajim.get_number_of_securely_connected_accounts()
|
||||||
for acct in accounts:
|
|
||||||
if gajim.con_types.has_key(acct) and \
|
|
||||||
gajim.con_types[acct] in ('tls', 'ssl'):
|
|
||||||
num_of_secured += 1
|
|
||||||
if num_of_secured:
|
if num_of_secured:
|
||||||
tls_pixbuf = self.window.render_icon(gtk.STOCK_DIALOG_AUTHENTICATION,
|
tls_pixbuf = self.window.render_icon(gtk.STOCK_DIALOG_AUTHENTICATION,
|
||||||
gtk.ICON_SIZE_MENU) # the only way to create a pixbuf from stock
|
gtk.ICON_SIZE_MENU) # the only way to create a pixbuf from stock
|
||||||
|
@ -2334,14 +2329,16 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
|
||||||
dlg = dialogs.ChangeStatusMessageDialog(status)
|
dlg = dialogs.ChangeStatusMessageDialog(status)
|
||||||
message = dlg.run()
|
message = dlg.run()
|
||||||
if message is not None: # None if user pressed Cancel
|
if message is not None: # None if user pressed Cancel
|
||||||
for acct in accounts:
|
for account in accounts:
|
||||||
if not gajim.config.get_per('accounts', acct,
|
if not gajim.config.get_per('accounts', account,
|
||||||
'sync_with_global_status'):
|
'sync_with_global_status'):
|
||||||
continue
|
continue
|
||||||
current_show = gajim.SHOW_LIST[gajim.connections[acct].connected]
|
current_show = gajim.SHOW_LIST[
|
||||||
self.send_status(acct, current_show, message)
|
gajim.connections[account].connected]
|
||||||
|
self.send_status(account, current_show, message)
|
||||||
self.combobox_callback_active = False
|
self.combobox_callback_active = False
|
||||||
self.status_combobox.set_active(self.previous_status_combobox_active)
|
self.status_combobox.set_active(
|
||||||
|
self.previous_status_combobox_active)
|
||||||
self.combobox_callback_active = True
|
self.combobox_callback_active = True
|
||||||
return
|
return
|
||||||
# we are about to change show, so save this new show so in case
|
# we are about to change show, so save this new show so in case
|
||||||
|
@ -2351,13 +2348,13 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
|
||||||
connected_accounts = gajim.get_number_of_connected_accounts()
|
connected_accounts = gajim.get_number_of_connected_accounts()
|
||||||
if status == 'invisible':
|
if status == 'invisible':
|
||||||
bug_user = False
|
bug_user = False
|
||||||
for acct in accounts:
|
for account in accounts:
|
||||||
if connected_accounts < 1 or gajim.account_is_connected(account):
|
if connected_accounts < 1 or gajim.account_is_connected(account):
|
||||||
if not gajim.config.get_per('accounts', acct,
|
if not gajim.config.get_per('accounts', account,
|
||||||
'sync_with_global_status'):
|
'sync_with_global_status'):
|
||||||
continue
|
continue
|
||||||
# We're going to change our status to invisible
|
# We're going to change our status to invisible
|
||||||
if self.connected_rooms(acct):
|
if self.connected_rooms(account):
|
||||||
bug_user = True
|
bug_user = True
|
||||||
break
|
break
|
||||||
if bug_user:
|
if bug_user:
|
||||||
|
@ -2419,8 +2416,8 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
|
||||||
status_message = _('♪ "%(title)s" by %(artist)s ♪') % \
|
status_message = _('♪ "%(title)s" by %(artist)s ♪') % \
|
||||||
{'title': music_track_info.title,
|
{'title': music_track_info.title,
|
||||||
'artist': music_track_info.artist }
|
'artist': music_track_info.artist }
|
||||||
for acct in accounts:
|
for account in accounts:
|
||||||
if not gajim.config.get_per('accounts', acct,
|
if not gajim.config.get_per('accounts', account,
|
||||||
'sync_with_global_status'):
|
'sync_with_global_status'):
|
||||||
continue
|
continue
|
||||||
if not gajim.connections[acct].connected:
|
if not gajim.connections[acct].connected:
|
||||||
|
|
Loading…
Add table
Reference in a new issue