Unify to use app.get_account_label()

This commit is contained in:
Sophie Herold 2018-08-30 19:27:40 +02:00 committed by Philipp Hörist
parent 41a7196620
commit afbc0c325f
9 changed files with 30 additions and 39 deletions

View File

@ -377,8 +377,7 @@ class Account(Gtk.Box):
self.options = AccountPage(account, parent)
self.parent = parent
account_label = app.config.get_per('accounts', account, 'account_label')
self.label = Gtk.Label(label=account_label or account)
self.label = Gtk.Label(app.get_account_label(account))
self.label.set_halign(Gtk.Align.START)
self.label.set_hexpand(True)
@ -402,9 +401,7 @@ class Account(Gtk.Box):
self.parent.set_page(self.options, 'account')
def update(self):
account_label = app.config.get_per(
'accounts', self.account, 'account_label')
self.label.set_text(account_label or self.account)
self.label.set_text(app.get_account_label(self.account))
self._update_image()
def _update_image(self):
@ -453,10 +450,9 @@ class GenericOptionPage(Gtk.Box):
row.get_child().on_row_activated()
def set_entry_text(self, toggle, update=False):
account_label = app.config.get_per(
'accounts', self.account, 'account_label')
account_label = app.get_account_label(self.account)
if update:
self.entry.set_text(account_label or self.account)
self.entry.set_text(account_label)
return
if toggle.get_active():
self.entry.set_sensitive(True)
@ -465,7 +461,7 @@ class GenericOptionPage(Gtk.Box):
self.entry.set_sensitive(False)
value = self.entry.get_text()
if not value:
value = account_label or self.account
value = account_label
app.config.set_per('accounts', self.account,
'account_label', value or self.account)
if app.config.get_per('accounts', self.account, 'active'):

View File

@ -663,7 +663,8 @@ class ChatControl(ChatControlBase):
if other_contact_.get_shown_name() == \
self.contact.get_shown_name():
acct_info = i18n.direction_mark + ' (%s)' % \
GLib.markup_escape_text(self.account)
GLib.markup_escape_text(
app.get_account_label(self.account))
break
status = contact.status

View File

@ -411,13 +411,14 @@ def get_enabled_accounts_with_labels(exclude_local=True, connected_only=False,
if private_storage_only and not account_supports_private_storage(acc):
continue
acc_label = config.get_per(
'accounts', acc, 'account_label') or acc
accounts.append([acc, acc_label])
accounts.append([acc, get_account_label(acc)])
accounts.sort(key=lambda xs: str.lower(xs[1]))
return accounts
def get_account_label(account):
return config.get_per('accounts', account, 'account_label') or account
def account_is_zeroconf(account):
return connections[account].is_zeroconf

View File

@ -1121,10 +1121,9 @@ def get_accounts_info():
message = message.strip()
if message != '':
single_line += ': ' + message
account_label = app.config.get_per(
'accounts', account, 'account_label')
account_label = app.get_account_label(account)
accounts.append({'name': account,
'account_label': account_label or account,
'account_label': account_label,
'status_line': single_line,
'show': status,
'message': message})

View File

@ -262,8 +262,7 @@ class ContactRow(Gtk.Grid):
self.set_column_spacing(12)
self.set_size_request(260, -1)
self.account = account
self.account_label = app.config.get_per(
'accounts', account, 'account_label') or account
self.account_label = app.get_account_label(account)
self.show_account = show_account
self.jid = jid
self.contact = contact

View File

@ -799,10 +799,9 @@ def build_accounts_menu():
return
if len(accounts_list) > 1:
for acc in accounts_list:
label = escape_mnemonic(
app.config.get_per('accounts', acc, 'account_label'))
label = escape_mnemonic(app.get_account_label(acc))
acc_menu.append_submenu(
label or acc, get_account_menu(acc))
label, get_account_menu(acc))
else:
acc_menu = get_account_menu(accounts_list[0])
menubar.remove(menu_position)

View File

@ -1075,8 +1075,7 @@ class RosterWindow:
account_name = _('Merged accounts')
accounts = []
else:
acclabel = app.config.get_per('accounts', account, 'account_label')
account_name = acclabel or account
account_name = app.get_account_label(account)
accounts = [account]
if account in self.collapsed_rows and \
@ -5075,9 +5074,8 @@ class RosterWindow:
accounts.append(account)
accounts.sort()
for account in accounts:
label = app.config.get_per('accounts', account,
'account_label')
item = Gtk.MenuItem.new_with_label(label or account)
label = app.get_account_label(account)
item = Gtk.MenuItem.new_with_label(label)
account_menu = self.build_account_menu(account)
item.set_submenu(account_menu)
menu.append(item)

View File

@ -243,8 +243,7 @@ class StatusIcon:
self.popup_menus.append(account_menu_for_chat_with)
for account in accounts_list:
account_label = app.config.get_per(
'accounts', account, 'account_label') or account
account_label = app.get_account_label(account)
if app.account_is_connected(account):
# for chat_with
item = Gtk.MenuItem.new_with_label(
@ -287,8 +286,7 @@ class StatusIcon:
self.popup_menus.append(account_menu_for_single_message)
for account in accounts_list:
account_label = app.config.get_per(
'accounts', account, 'account_label') or account
account_label = app.get_account_label(account)
if app.connections[account].is_zeroconf or \
not app.account_is_connected(account):
continue

View File

@ -150,12 +150,12 @@ class NotificationAreaTooltip(StatusTable):
show_lock = False
if message:
self.add_status_row(file_path, acct['show'],
GLib.markup_escape_text(acct['account_label']) + ' - ' + message,
show_lock=show_lock, indent=False)
GLib.markup_escape_text(acct['account_label']) + ' - ' + \
message, show_lock=show_lock, indent=False)
else:
self.add_status_row(file_path, acct['show'],
GLib.markup_escape_text(acct['account_label']), show_lock=show_lock,
indent=False)
GLib.markup_escape_text(acct['account_label']),
show_lock=show_lock, indent=False)
for line in acct['event_lines']:
self.add_text_row(' ' + line, 1)
@ -333,12 +333,12 @@ class RosterTooltip(Gtk.Window, StatusTable):
show_lock = False
if message:
self.add_status_row(file_path, acct['show'],
GLib.markup_escape_text(acct['name']) + ' - ' + message,
show_lock=show_lock, indent=False)
GLib.markup_escape_text(acct['account_label']) + ' - ' + \
message, show_lock=show_lock, indent=False)
else:
self.add_status_row(file_path, acct['show'],
GLib.markup_escape_text(acct['name']), show_lock=show_lock,
indent=False)
GLib.markup_escape_text(acct['account_label']),
show_lock=show_lock, indent=False)
for line in acct['event_lines']:
self.add_text_row(' ' + line, 1)
@ -371,7 +371,7 @@ class RosterTooltip(Gtk.Window, StatusTable):
nbr_on, nbr_total = app.\
contacts.get_nb_online_total_contacts(
accounts=[account])
account_name = account
account_name = app.get_account_label(account)
if app.account_is_connected(account):
account_name += ' (%s/%s)' % (repr(nbr_on),
repr(nbr_total))