diff options
author | Philipp Hörist <philipp@hoerist.com> | 2022-10-09 20:42:41 +0300 |
---|---|---|
committer | Philipp Hörist <philipp@hoerist.com> | 2022-10-09 20:42:41 +0300 |
commit | 6d6774065f5f15cdc54b335b5f4e65fd8aa24424 (patch) | |
tree | 136fcfdd048e3cf320a12741a33b5ad1cc39f6d7 | |
parent | f2b86948fae7037ab253ca498f63cdccfd0ed9bf (diff) |
refactor: Rows: Add NicknameLabel
-rw-r--r-- | gajim/gtk/conversation/rows/base.py | 16 | ||||
-rw-r--r-- | gajim/gtk/conversation/rows/call.py | 3 | ||||
-rw-r--r-- | gajim/gtk/conversation/rows/file_transfer_jingle.py | 3 | ||||
-rw-r--r-- | gajim/gtk/conversation/rows/message.py | 3 | ||||
-rw-r--r-- | gajim/gtk/conversation/rows/widgets.py | 18 |
5 files changed, 24 insertions, 19 deletions
diff --git a/gajim/gtk/conversation/rows/base.py b/gajim/gtk/conversation/rows/base.py index 9871fbf56..3b81d37da 100644 --- a/gajim/gtk/conversation/rows/base.py +++ b/gajim/gtk/conversation/rows/base.py @@ -18,7 +18,6 @@ from typing import Optional from datetime import datetime -from gi.repository import GLib from gi.repository import Gtk from gi.repository import Pango @@ -60,20 +59,5 @@ class BaseRow(Gtk.ListBoxRow): return self._merged @staticmethod - def create_name_widget(name: str, from_us: bool) -> Gtk.Label: - label = Gtk.Label() - label.set_selectable(True) - label.set_ellipsize(Pango.EllipsizeMode.END) - label.set_valign(Gtk.Align.END) - label.get_style_context().add_class('conversation-nickname') - label.set_markup(GLib.markup_escape_text(name)) - - if from_us: - label.get_style_context().add_class('gajim-outgoing-nickname') - else: - label.get_style_context().add_class('gajim-incoming-nickname') - return label - - @staticmethod def __destroy(widget: Gtk.Widget) -> None: app.check_finalize(widget) diff --git a/gajim/gtk/conversation/rows/call.py b/gajim/gtk/conversation/rows/call.py index c174fc71c..0e623bd6b 100644 --- a/gajim/gtk/conversation/rows/call.py +++ b/gajim/gtk/conversation/rows/call.py @@ -32,6 +32,7 @@ from gajim.common.jingle_session import JingleSession from gajim.common.storage.archive import ConversationRow from .widgets import DateTimeLabel +from .widgets import NicknameLabel from .widgets import SimpleLabel from .base import BaseRow @@ -138,7 +139,7 @@ class CallRow(BaseRow): avatar_image = Gtk.Image.new_from_surface(avatar) self._avatar_placeholder.add(avatar_image) - name_widget = self.create_name_widget(contact.name, is_self) + name_widget = NicknameLabel(contact.name, is_self) name_widget.set_halign(Gtk.Align.START) name_widget.set_valign(Gtk.Align.START) diff --git a/gajim/gtk/conversation/rows/file_transfer_jingle.py b/gajim/gtk/conversation/rows/file_transfer_jingle.py index 954bf9def..a93c1861b 100644 --- a/gajim/gtk/conversation/rows/file_transfer_jingle.py +++ b/gajim/gtk/conversation/rows/file_transfer_jingle.py @@ -49,6 +49,7 @@ from gajim.common.storage.archive import ConversationRow from .base import BaseRow from .widgets import DateTimeLabel +from .widgets import NicknameLabel from ...builder import get_builder from ...util import format_eta @@ -122,7 +123,7 @@ class FileTransferJingleRow(BaseRow): avatar_image = Gtk.Image.new_from_surface(avatar) avatar_placeholder.add(avatar_image) - name_widget = self.create_name_widget(contact.name, is_self) + name_widget = NicknameLabel(contact.name, is_self) name_widget.set_halign(Gtk.Align.START) name_widget.set_valign(Gtk.Align.START) diff --git a/gajim/gtk/conversation/rows/message.py b/gajim/gtk/conversation/rows/message.py index 9d520489b..d49dddac6 100644 --- a/gajim/gtk/conversation/rows/message.py +++ b/gajim/gtk/conversation/rows/message.py @@ -50,6 +50,7 @@ from gajim.common.types import ChatContactT from .base import BaseRow from .widgets import DateTimeLabel +from .widgets import NicknameLabel from .widgets import MoreMenuButton from ..message_widget import MessageWidget from ...dialogs import InputDialog @@ -136,7 +137,7 @@ class MessageRow(BaseRow): if self._contact.jid == self._client.get_own_jid().bare: name = _('Me') - name_widget = self.create_name_widget(name, from_us) + name_widget = NicknameLabel(name, from_us) self._meta_box = Gtk.Box(spacing=6) self._meta_box.set_hexpand(True) diff --git a/gajim/gtk/conversation/rows/widgets.py b/gajim/gtk/conversation/rows/widgets.py index 666033c1e..6b30a5cf9 100644 --- a/gajim/gtk/conversation/rows/widgets.py +++ b/gajim/gtk/conversation/rows/widgets.py @@ -178,3 +178,21 @@ class DateTimeLabel(Gtk.Label): self.set_margin_end(3) self.get_style_context().add_class('conversation-meta') self.set_tooltip_text(timestamp.strftime('%a, %d %b %Y - %X')) + + +class NicknameLabel(Gtk.Label): + def __init__(self, name: str, from_us: bool) -> None: + Gtk.Label.__init__(self) + + self.set_selectable(True) + self.set_ellipsize(Pango.EllipsizeMode.END) + self.set_valign(Gtk.Align.END) + self.get_style_context().add_class('conversation-nickname') + self.set_text(name) + + if from_us: + css_class = 'gajim-outgoing-nickname' + else: + css_class = 'gajim-incoming-nickname' + + self.get_style_context().add_class(css_class) |