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

View File

@ -663,7 +663,8 @@ class ChatControl(ChatControlBase):
if other_contact_.get_shown_name() == \ if other_contact_.get_shown_name() == \
self.contact.get_shown_name(): self.contact.get_shown_name():
acct_info = i18n.direction_mark + ' (%s)' % \ acct_info = i18n.direction_mark + ' (%s)' % \
GLib.markup_escape_text(self.account) GLib.markup_escape_text(
app.get_account_label(self.account))
break break
status = contact.status 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): if private_storage_only and not account_supports_private_storage(acc):
continue continue
acc_label = config.get_per( accounts.append([acc, get_account_label(acc)])
'accounts', acc, 'account_label') or acc
accounts.append([acc, acc_label])
accounts.sort(key=lambda xs: str.lower(xs[1])) accounts.sort(key=lambda xs: str.lower(xs[1]))
return accounts return accounts
def get_account_label(account):
return config.get_per('accounts', account, 'account_label') or account
def account_is_zeroconf(account): def account_is_zeroconf(account):
return connections[account].is_zeroconf return connections[account].is_zeroconf

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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