Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 398678cd by wurstsalat at 2021-12-25T00:45:30+01:00 GroupChatInviter: Improvements
- - - - -
2 changed files:
- gajim/gtk/contacts_flowbox.py - gajim/gtk/groupchat_inviter.py
Changes:
===================================== gajim/gtk/contacts_flowbox.py ===================================== @@ -23,26 +23,33 @@
class ContactItem(Gtk.FlowBoxChild): - def __init__(self, account: str, jid: str) -> None: + def __init__(self, account: str, jid: str, is_new: bool = False) -> None: Gtk.FlowBoxChild.__init__(self) self.set_size_request(150, -1)
self.account = account self.jid = jid + self.is_new = is_new
- client = app.get_client(account) - contact = client.get_module('Contacts').get_contact(jid) - - surface = contact.get_avatar( - AvatarSize.ROSTER, self.get_scale_factor()) - avatar_image = Gtk.Image.new_from_surface(surface) - - name_label = Gtk.Label(label=contact.name) - name_label.set_tooltip_text(contact.name) + name_label = Gtk.Label() name_label.set_ellipsize(Pango.EllipsizeMode.END) name_label.set_max_width_chars(12) name_label.get_style_context().add_class('bold')
+ if is_new: + avatar_image = Gtk.Image.new_from_icon_name( + 'avatar-default', Gtk.IconSize.DND) + name_label.set_text(jid) + name_label.set_tooltip_text(jid) + else: + client = app.get_client(account) + contact = client.get_module('Contacts').get_contact(jid) + surface = contact.get_avatar( + AvatarSize.ROSTER, self.get_scale_factor()) + avatar_image = Gtk.Image.new_from_surface(surface) + name_label.set_text(contact.name) + name_label.set_tooltip_text(contact.name) + remove_button = Gtk.Button.new_from_icon_name( 'window-close', Gtk.IconSize.BUTTON) remove_button.set_valign(Gtk.Align.CENTER) @@ -68,7 +75,11 @@ def _on_remove(self, _button: Gtk.Button) -> None: class ContactsFlowBox(Gtk.FlowBox):
__gsignals__ = { - 'contact-removed': (GObject.SignalFlags.RUN_LAST, None, (str, str)) + 'contact-removed': ( + GObject.SignalFlags.RUN_LAST, + None, + (str, str, bool) + ) }
def __init__(self) -> None: @@ -85,8 +96,12 @@ def _remove(item): item.destroy() self.foreach(_remove)
- def add_contact(self, account: str, jid: str) -> None: - contact_item = ContactItem(account, jid) + def add_contact(self, + account: str, + jid: str, + is_new: bool = False + ) -> None: + contact_item = ContactItem(account, jid, is_new=is_new) self.add(contact_item)
def has_contacts(self) -> bool: @@ -101,5 +116,6 @@ def get_contact_jids(self) -> List[str]: def on_contact_removed(self, row: ContactItem) -> None: account = row.account jid = row.jid + is_new = row.is_new row.destroy() - self.emit('contact-removed', account, jid) + self.emit('contact-removed', account, jid, is_new)
===================================== gajim/gtk/groupchat_inviter.py ===================================== @@ -101,8 +101,10 @@ def __init__(self, self.add(grid) self.show_all()
- def _get_avatar_image(self, contact: types.BareContact) -> Gtk.Image: - if self.is_new: + def _get_avatar_image(self, + contact: Optional[types.BareContact] + ) -> Gtk.Image: + if contact is None: icon_name = 'avatar-default' return Gtk.Image.new_from_icon_name(icon_name, Gtk.IconSize.DND)
@@ -189,7 +191,7 @@ def _add_contacts(self) -> None:
def _on_contacts_row_activated(self, listbox: Gtk.ListBox, - row: Gtk.ListBoxRow + row: ContactRow ) -> None: if row.is_new: jid = row.jid @@ -207,7 +209,7 @@ def _on_contacts_row_activated(self, Gtk.EntryIconPosition.SECONDARY, None) self._remove_new_contact_row()
- self._invitees_box.add_contact(row.account, row.jid) + self._invitees_box.add_contact(row.account, row.jid, is_new=row.is_new)
if not row.is_new: listbox.remove(row) @@ -223,17 +225,19 @@ def _on_contacts_row_activated(self, def _on_invitee_removed(self, flowbox: ContactsFlowBox, account: str, - jid: str + jid: str, + is_new: bool ) -> None: - show_account = len(self._accounts) > 1 - client = app.get_client(account) - contact = client.get_module('Contacts').get_contact(jid) - row = ContactRow(account, - contact, - str(contact.jid), - contact.name, - show_account) - self._ui.contacts_listbox.add(row) + if not is_new: + show_account = len(self._accounts) > 1 + client = app.get_client(account) + contact = client.get_module('Contacts').get_contact(jid) + row = ContactRow(account, + contact, + str(contact.jid), + contact.name, + show_account) + self._ui.contacts_listbox.add(row) self._ui.search_entry.grab_focus() self.emit('listbox-changed', flowbox.has_contacts())
@@ -279,11 +283,10 @@ def _add_new_contact_row(self) -> None: row = ContactRow(account, None, '', - None, + _('New Contact'), show_account) self._new_contact_rows[account] = row self._ui.contacts_listbox.add(row) - row.get_parent().show_all() self._new_contact_row_visible = True
def _remove_new_contact_row(self) -> None:
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/398678cdbb977f05d130c1406341cf9d7...