diff --git a/gajim/data/gui/chat_control.ui b/gajim/data/gui/chat_control.ui index 7fbba4a93a3a4ae8ad26ba425732c61d417dbc66..8526db581fec15dc6201d6b65b5da392efcb536d 100644 --- a/gajim/data/gui/chat_control.ui +++ b/gajim/data/gui/chat_control.ui @@ -501,9 +501,9 @@ </packing> </child> <child> - <object class="GtkBox" id="account_badge"> - <property name="visible">True</property> + <object class="GtkBox" id="account_badge_box"> <property name="can-focus">False</property> + <property name="no-show-all">True</property> <property name="halign">end</property> <property name="valign">center</property> <property name="orientation">vertical</property> diff --git a/gajim/data/gui/groupchat_control.ui b/gajim/data/gui/groupchat_control.ui index 7a3c2a14f6bb84d1f12fd38a1752a3f76bc02391..16edbde7cf5ec7b4291ed14149b06044a2b0472a 100644 --- a/gajim/data/gui/groupchat_control.ui +++ b/gajim/data/gui/groupchat_control.ui @@ -284,9 +284,9 @@ <property name="visible">True</property> <property name="can-focus">False</property> <child> - <object class="GtkBox" id="account_badge"> - <property name="visible">True</property> + <object class="GtkBox" id="account_badge_box"> <property name="can-focus">False</property> + <property name="no-show-all">True</property> <property name="halign">end</property> <property name="valign">center</property> <property name="margin-end">6</property> @@ -623,9 +623,6 @@ <property name="name">groupchat</property> </packing> </child> - <child> - <placeholder/> - </child> <child> <object class="GtkBox"> <property name="visible">True</property> @@ -749,7 +746,7 @@ </object> <packing> <property name="name">nickname</property> - <property name="position">2</property> + <property name="position">1</property> </packing> </child> <child> @@ -884,7 +881,7 @@ </object> <packing> <property name="name">subject</property> - <property name="position">3</property> + <property name="position">2</property> </packing> </child> <child> @@ -1010,7 +1007,7 @@ </object> <packing> <property name="name">password</property> - <property name="position">4</property> + <property name="position">3</property> </packing> </child> <child> @@ -1123,7 +1120,7 @@ </object> <packing> <property name="name">captcha</property> - <property name="position">5</property> + <property name="position">4</property> </packing> </child> <child> @@ -1286,7 +1283,7 @@ </object> <packing> <property name="name">error</property> - <property name="position">6</property> + <property name="position">5</property> </packing> </child> <child> @@ -1411,7 +1408,7 @@ </object> <packing> <property name="name">captcha-error</property> - <property name="position">7</property> + <property name="position">6</property> </packing> </child> <child> @@ -1521,7 +1518,7 @@ </object> <packing> <property name="name">muc-info</property> - <property name="position">8</property> + <property name="position">7</property> </packing> </child> <child> @@ -1672,7 +1669,7 @@ </object> <packing> <property name="name">kick</property> - <property name="position">9</property> + <property name="position">8</property> </packing> </child> <child> @@ -1823,7 +1820,7 @@ </object> <packing> <property name="name">ban</property> - <property name="position">10</property> + <property name="position">9</property> </packing> </child> <child> @@ -2019,7 +2016,7 @@ </object> <packing> <property name="name">destroy</property> - <property name="position">11</property> + <property name="position">10</property> </packing> </child> <child> @@ -2145,7 +2142,7 @@ </object> <packing> <property name="name">rename</property> - <property name="position">12</property> + <property name="position">11</property> </packing> </child> <child> @@ -2245,7 +2242,7 @@ </object> <packing> <property name="name">invite</property> - <property name="position">13</property> + <property name="position">12</property> </packing> </child> <child> @@ -2374,7 +2371,7 @@ </object> <packing> <property name="name">muc-settings</property> - <property name="position">14</property> + <property name="position">13</property> </packing> </child> <child> diff --git a/gajim/gtk/chat_list.py b/gajim/gtk/chat_list.py index f95f9eebb9ace774b4e396a1b18a2b881dade500..fe0c7e81768b812595e08eafe970f73297d6d941 100644 --- a/gajim/gtk/chat_list.py +++ b/gajim/gtk/chat_list.py @@ -19,6 +19,7 @@ from gi.repository import Gtk from gajim.common import app +from gajim.common import ged from gajim.common.const import AvatarSize from gajim.common.const import KindConstant from gajim.common.const import RowHeaderType @@ -30,13 +31,15 @@ from gajim.gui_menu_builder import get_chat_list_row_menu from .util import get_builder +from .util import EventHelper log = logging.getLogger('gajim.gui.chatlist') -class ChatList(Gtk.ListBox): +class ChatList(Gtk.ListBox, EventHelper): def __init__(self, workspace_id): Gtk.ListBox.__init__(self) + EventHelper.__init__(self) self._chats = {} self._current_filter_text = '' @@ -48,6 +51,11 @@ def __init__(self, workspace_id): self.set_sort_func(self._sort_func) self._set_placeholder() + self.register_events([ + ('account-enabled', ged.GUI2, self._on_account_changed), + ('account-disabled', ged.GUI2, self._on_account_changed), + ]) + self.connect('destroy', self._on_destroy) self._timer_id = GLib.timeout_add_seconds(60, self._update_timer) @@ -262,6 +270,10 @@ def _add_unread(row, properties): row.add_unread() + def _on_account_changed(self, *args): + for row in self.get_children(): + row.update_account_identifier() + class ChatRow(Gtk.ListBoxRow): def __init__(self, workspace_id, account, jid, type_, pinned): @@ -295,16 +307,12 @@ def __init__(self, workspace_id, account, jid, type_, pinned): self._ui.eventbox.connect('button-press-event', self._on_button_press) self._ui.close_button.connect('clicked', self._on_close_button_clicked) - account_class = app.css_config.get_dynamic_class(account) - self._ui.account_identifier.get_style_context().add_class(account_class) - if len(app.get_enabled_accounts_with_labels()) > 1: - self._ui.account_identifier.show() - if self.type == 'groupchat': self._ui.group_chat_indicator.show() self.update_avatar() self.update_name() + self.update_account_identifier() # Get last chat message from archive line = app.storage.archive.get_last_conversation_line(account, jid) @@ -399,6 +407,12 @@ def update_name(self): self._ui.name_label.set_text(self.contact.name) + def update_account_identifier(self): + account_class = app.css_config.get_dynamic_class(self.account) + self._ui.account_identifier.get_style_context().add_class(account_class) + show = len(app.settings.get_active_accounts()) > 1 + self._ui.account_identifier.set_visible(show) + def _on_chatstate_update(self, contact, _signal_name): if contact.chatstate is None: self._ui.chatstate_image.hide() diff --git a/gajim/gtk/chat_stack.py b/gajim/gtk/chat_stack.py index 0fbc888d331e162517313d38594dc504618560b6..3d2bc19075cef1bfc8d45a8b8feec54c1c467039 100644 --- a/gajim/gtk/chat_stack.py +++ b/gajim/gtk/chat_stack.py @@ -16,23 +16,32 @@ from gi.repository import Gtk +from gajim.common import ged + from gajim.gui.controls.chat import ChatControl from gajim.gui.controls.groupchat import GroupchatControl from gajim.gui.controls.private import PrivateChatControl +from .util import EventHelper log = logging.getLogger('gajim.gui.chatstack') -class ChatStack(Gtk.Stack): +class ChatStack(Gtk.Stack, EventHelper): def __init__(self): Gtk.Stack.__init__(self) + EventHelper.__init__(self) self.set_vexpand(True) self.set_hexpand(True) self.add_named(Gtk.Box(), 'empty') + self.register_events([ + ('account-enabled', ged.GUI2, self._on_account_changed), + ('account-disabled', ged.GUI2, self._on_account_changed), + ]) + self.show_all() self._controls = {} @@ -97,3 +106,7 @@ def remove_chats_for_account(self, account): if chat_account != account: continue self.remove_chat(account, jid) + + def _on_account_changed(self, *args): + for control in self._controls.values(): + control.update_account_badge() diff --git a/gajim/gtk/controls/base.py b/gajim/gtk/controls/base.py index 821970ad2b9b8b5cb5fa5578b839a17473abd3f7..ec54ab8b0cc9d1e7bb2b37b074737925a366f9cb 100644 --- a/gajim/gtk/controls/base.py +++ b/gajim/gtk/controls/base.py @@ -56,7 +56,7 @@ from gajim.gui.message_input import MessageInputTextView from gajim.gui.util import get_hardware_key_codes from gajim.gui.util import get_builder -from gajim.gui.util import generate_account_badge +from gajim.gui.util import AccountBadge from gajim.gui.const import ControlType # pylint: disable=unused-import from gajim.gui.emoji_chooser import emoji_chooser @@ -126,13 +126,10 @@ def __init__(self, widget_name, account, jid): self.xml.connect_signals(self) self.widget = self.xml.get_object('%s_hbox' % widget_name) - self._accounts = app.get_enabled_accounts_with_labels() - if len(self._accounts) > 1: - account_badge = generate_account_badge(self.account) - account_badge.set_tooltip_text( - _('Account: %s') % app.get_account_label(self.account)) - self.xml.account_badge.add(account_badge) - account_badge.show() + self._account_badge = AccountBadge(self.account) + self.xml.account_badge_box.add(self._account_badge) + show = len(app.settings.get_active_accounts()) > 1 + self.xml.account_badge_box.set_visible(show) # Drag and drop self.xml.overlay.add_overlay(self.xml.drop_area) @@ -1399,6 +1396,10 @@ def scroll_messages(self, direction, msg_buf, msg_type): message = '> %s\n' % message.replace('\n', '\n> ') msg_buf.set_text(message) + def update_account_badge(self): + show = len(app.settings.get_active_accounts()) > 1 + self.xml.account_badge_box.set_visible(show) + class ScrolledWindow(Gtk.ScrolledWindow): def __init__(self, *args, **kwargs): diff --git a/gajim/gtk/groupchat_invitation.py b/gajim/gtk/groupchat_invitation.py index d3f26ee4d8c914abee24fb971edbdcfb445bed9b..1133a429e6236cd675ce7224f496022e94d002c9 100644 --- a/gajim/gtk/groupchat_invitation.py +++ b/gajim/gtk/groupchat_invitation.py @@ -21,7 +21,7 @@ from .groupchat_info import GroupChatInfoScrolled from .groupchat_nick import NickChooser -from .util import generate_account_badge +from .util import AccountBadge class GroupChatInvitation(Gtk.ApplicationWindow): @@ -63,9 +63,7 @@ def __init__(self, account, event): enabled_accounts = app.get_enabled_accounts_with_labels() if len(enabled_accounts) > 1: - account_badge = generate_account_badge(account) - account_badge.set_tooltip_text( - _('Account: %s') % app.get_account_label(account)) + account_badge = AccountBadge(account) contact_box.add(account_badge) invitation_label = Gtk.Label( diff --git a/gajim/gtk/groupchat_invite.py b/gajim/gtk/groupchat_invite.py index 1c06261f562d686f968bd32f4fdcd396a87589f7..ab33d6f22390bdd44e6ed3b62e5a6457f6921af9 100644 --- a/gajim/gtk/groupchat_invite.py +++ b/gajim/gtk/groupchat_invite.py @@ -26,7 +26,7 @@ from gajim.common.helpers import validate_jid from .util import get_builder -from .util import generate_account_badge +from .util import AccountBadge class GroupChatInvite(Gtk.Box): @@ -302,9 +302,7 @@ def __init__(self, account, contact, jid, name, show_account): name_box.add(self.name_label) if show_account: - account_badge = generate_account_badge(account) - account_badge.set_tooltip_text( - _('Account: %s' % self.account_label)) + account_badge = AccountBadge(account) account_badge.set_halign(Gtk.Align.END) account_badge.set_valign(Gtk.Align.START) account_badge.set_hexpand(True) diff --git a/gajim/gtk/start_chat.py b/gajim/gtk/start_chat.py index 219550845db2f970777558c46a1ee5e780204c74..617efa659684c92d4a741396a3bb26f762edaf04 100644 --- a/gajim/gtk/start_chat.py +++ b/gajim/gtk/start_chat.py @@ -39,7 +39,7 @@ from .groupchat_nick import NickChooser from .util import get_builder from .util import get_icon_name -from .util import generate_account_badge +from .util import AccountBadge class Search(IntEnum): @@ -646,9 +646,7 @@ def __init__(self, account, contact, jid, name, show_account, name_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6) name_box.add(self.name_label) if show_account: - account_badge = generate_account_badge(account) - account_badge.set_tooltip_text( - _('Account: %s') % self.account_label) + account_badge = AccountBadge(account) account_badge.set_halign(Gtk.Align.END) account_badge.set_valign(Gtk.Align.START) account_badge.set_hexpand(True) diff --git a/gajim/gtk/util.py b/gajim/gtk/util.py index abd324fefec5ce56a20b282bf87f6ef9716267b4..f201a010fc67d88907268489f3cab28e8c804ecc 100644 --- a/gajim/gtk/util.py +++ b/gajim/gtk/util.py @@ -694,19 +694,6 @@ def get_color_for_account(account: str) -> str: return rgba.to_string() -def generate_account_badge(account): - account_label = app.get_account_label(account) - badge = Gtk.Label(label=account_label) - badge.set_ellipsize(Pango.EllipsizeMode.END) - badge.set_max_width_chars(12) - badge.set_size_request(50, -1) - account_class = app.css_config.get_dynamic_class(account) - badge_context = badge.get_style_context() - badge_context.add_class(account_class) - badge_context.add_class('badge') - return badge - - @lru_cache(maxsize=16) def get_css_show_class(show): if show in ('online', 'chat'): @@ -896,3 +883,23 @@ def _on_realize(*args): event_box.add(widget) return event_box return klass_wrapper + + +class AccountBadge(Gtk.Label): + def __init__(self, account): + Gtk.Label.__init__(self) + self.set_ellipsize(Pango.EllipsizeMode.END) + self.set_max_width_chars(12) + self.set_size_request(50, -1) + self.get_style_context().add_class('badge') + self._account = account + + self.refresh() + self.show() + + def refresh(self): + label = app.get_account_label(self._account) + self.set_text(label) + account_class = app.css_config.get_dynamic_class(self._account) + self.get_style_context().add_class(account_class) + self.set_tooltip_text(_('Account: %s') % label)