Daniel Brötzmann pushed to branch master at gajim / gajim

Commits:

2 changed files:

Changes:

  • gajim/gtk/contacts_flowbox.py
    ... ... @@ -23,26 +23,33 @@
    23 23
     
    
    24 24
     
    
    25 25
     class ContactItem(Gtk.FlowBoxChild):
    
    26
    -    def __init__(self, account: str, jid: str) -> None:
    
    26
    +    def __init__(self, account: str, jid: str, is_new: bool = False) -> None:
    
    27 27
             Gtk.FlowBoxChild.__init__(self)
    
    28 28
             self.set_size_request(150, -1)
    
    29 29
     
    
    30 30
             self.account = account
    
    31 31
             self.jid = jid
    
    32
    +        self.is_new = is_new
    
    32 33
     
    
    33
    -        client = app.get_client(account)
    
    34
    -        contact = client.get_module('Contacts').get_contact(jid)
    
    35
    -
    
    36
    -        surface = contact.get_avatar(
    
    37
    -            AvatarSize.ROSTER, self.get_scale_factor())
    
    38
    -        avatar_image = Gtk.Image.new_from_surface(surface)
    
    39
    -
    
    40
    -        name_label = Gtk.Label(label=contact.name)
    
    41
    -        name_label.set_tooltip_text(contact.name)
    
    34
    +        name_label = Gtk.Label()
    
    42 35
             name_label.set_ellipsize(Pango.EllipsizeMode.END)
    
    43 36
             name_label.set_max_width_chars(12)
    
    44 37
             name_label.get_style_context().add_class('bold')
    
    45 38
     
    
    39
    +        if is_new:
    
    40
    +            avatar_image =  Gtk.Image.new_from_icon_name(
    
    41
    +                'avatar-default', Gtk.IconSize.DND)
    
    42
    +            name_label.set_text(jid)
    
    43
    +            name_label.set_tooltip_text(jid)
    
    44
    +        else:
    
    45
    +            client = app.get_client(account)
    
    46
    +            contact = client.get_module('Contacts').get_contact(jid)
    
    47
    +            surface = contact.get_avatar(
    
    48
    +                AvatarSize.ROSTER, self.get_scale_factor())
    
    49
    +            avatar_image = Gtk.Image.new_from_surface(surface)
    
    50
    +            name_label.set_text(contact.name)
    
    51
    +            name_label.set_tooltip_text(contact.name)
    
    52
    +
    
    46 53
             remove_button = Gtk.Button.new_from_icon_name(
    
    47 54
                 'window-close', Gtk.IconSize.BUTTON)
    
    48 55
             remove_button.set_valign(Gtk.Align.CENTER)
    
    ... ... @@ -68,7 +75,11 @@ def _on_remove(self, _button: Gtk.Button) -> None:
    68 75
     class ContactsFlowBox(Gtk.FlowBox):
    
    69 76
     
    
    70 77
         __gsignals__ = {
    
    71
    -        'contact-removed': (GObject.SignalFlags.RUN_LAST, None, (str, str))
    
    78
    +        'contact-removed': (
    
    79
    +            GObject.SignalFlags.RUN_LAST,
    
    80
    +            None,
    
    81
    +            (str, str, bool)
    
    82
    +        )
    
    72 83
         }
    
    73 84
     
    
    74 85
         def __init__(self) -> None:
    
    ... ... @@ -85,8 +96,12 @@ def _remove(item):
    85 96
                 item.destroy()
    
    86 97
             self.foreach(_remove)
    
    87 98
     
    
    88
    -    def add_contact(self, account: str, jid: str) -> None:
    
    89
    -        contact_item = ContactItem(account, jid)
    
    99
    +    def add_contact(self,
    
    100
    +                    account: str,
    
    101
    +                    jid: str,
    
    102
    +                    is_new: bool = False
    
    103
    +                    ) -> None:
    
    104
    +        contact_item = ContactItem(account, jid, is_new=is_new)
    
    90 105
             self.add(contact_item)
    
    91 106
     
    
    92 107
         def has_contacts(self) -> bool:
    
    ... ... @@ -101,5 +116,6 @@ def get_contact_jids(self) -> List[str]:
    101 116
         def on_contact_removed(self, row: ContactItem) -> None:
    
    102 117
             account = row.account
    
    103 118
             jid = row.jid
    
    119
    +        is_new = row.is_new
    
    104 120
             row.destroy()
    
    105
    -        self.emit('contact-removed', account, jid)
    121
    +        self.emit('contact-removed', account, jid, is_new)

  • gajim/gtk/groupchat_inviter.py
    ... ... @@ -101,8 +101,10 @@ def __init__(self,
    101 101
             self.add(grid)
    
    102 102
             self.show_all()
    
    103 103
     
    
    104
    -    def _get_avatar_image(self, contact: types.BareContact) -> Gtk.Image:
    
    105
    -        if self.is_new:
    
    104
    +    def _get_avatar_image(self,
    
    105
    +                          contact: Optional[types.BareContact]
    
    106
    +                          ) -> Gtk.Image:
    
    107
    +        if contact is None:
    
    106 108
                 icon_name = 'avatar-default'
    
    107 109
                 return Gtk.Image.new_from_icon_name(icon_name, Gtk.IconSize.DND)
    
    108 110
     
    
    ... ... @@ -189,7 +191,7 @@ def _add_contacts(self) -> None:
    189 191
     
    
    190 192
         def _on_contacts_row_activated(self,
    
    191 193
                                        listbox: Gtk.ListBox,
    
    192
    -                                   row: Gtk.ListBoxRow
    
    194
    +                                   row: ContactRow
    
    193 195
                                        ) -> None:
    
    194 196
             if row.is_new:
    
    195 197
                 jid = row.jid
    
    ... ... @@ -207,7 +209,7 @@ def _on_contacts_row_activated(self,
    207 209
                     Gtk.EntryIconPosition.SECONDARY, None)
    
    208 210
                 self._remove_new_contact_row()
    
    209 211
     
    
    210
    -        self._invitees_box.add_contact(row.account, row.jid)
    
    212
    +        self._invitees_box.add_contact(row.account, row.jid, is_new=row.is_new)
    
    211 213
     
    
    212 214
             if not row.is_new:
    
    213 215
                 listbox.remove(row)
    
    ... ... @@ -223,17 +225,19 @@ def _on_contacts_row_activated(self,
    223 225
         def _on_invitee_removed(self,
    
    224 226
                                 flowbox: ContactsFlowBox,
    
    225 227
                                 account: str,
    
    226
    -                            jid: str
    
    228
    +                            jid: str,
    
    229
    +                            is_new: bool
    
    227 230
                                 ) -> None:
    
    228
    -        show_account = len(self._accounts) > 1
    
    229
    -        client = app.get_client(account)
    
    230
    -        contact = client.get_module('Contacts').get_contact(jid)
    
    231
    -        row = ContactRow(account,
    
    232
    -                         contact,
    
    233
    -                         str(contact.jid),
    
    234
    -                         contact.name,
    
    235
    -                         show_account)
    
    236
    -        self._ui.contacts_listbox.add(row)
    
    231
    +        if not is_new:
    
    232
    +            show_account = len(self._accounts) > 1
    
    233
    +            client = app.get_client(account)
    
    234
    +            contact = client.get_module('Contacts').get_contact(jid)
    
    235
    +            row = ContactRow(account,
    
    236
    +                            contact,
    
    237
    +                            str(contact.jid),
    
    238
    +                            contact.name,
    
    239
    +                            show_account)
    
    240
    +            self._ui.contacts_listbox.add(row)
    
    237 241
             self._ui.search_entry.grab_focus()
    
    238 242
             self.emit('listbox-changed', flowbox.has_contacts())
    
    239 243
     
    
    ... ... @@ -279,11 +283,10 @@ def _add_new_contact_row(self) -> None:
    279 283
                 row = ContactRow(account,
    
    280 284
                                  None,
    
    281 285
                                  '',
    
    282
    -                             None,
    
    286
    +                             _('New Contact'),
    
    283 287
                                  show_account)
    
    284 288
                 self._new_contact_rows[account] = row
    
    285 289
                 self._ui.contacts_listbox.add(row)
    
    286
    -            row.get_parent().show_all()
    
    287 290
             self._new_contact_row_visible = True
    
    288 291
     
    
    289 292
         def _remove_new_contact_row(self) -> None: